(t *testing.T)
| 241 | } |
| 242 | |
| 243 | func TestApplyDiffAddfile(t *testing.T) { |
| 244 | repo := createTestRepo(t) |
| 245 | defer cleanupTestRepo(t, repo) |
| 246 | |
| 247 | seedTestRepo(t, repo) |
| 248 | |
| 249 | addFirstFileCommit, addFirstFileTree := addAndGetTree(t, repo, "file1", `hello`) |
| 250 | defer addFirstFileCommit.Free() |
| 251 | defer addFirstFileTree.Free() |
| 252 | addSecondFileCommit, addSecondFileTree := addAndGetTree(t, repo, "file2", `hello2`) |
| 253 | defer addSecondFileCommit.Free() |
| 254 | defer addSecondFileTree.Free() |
| 255 | |
| 256 | diff, err := repo.DiffTreeToTree(addFirstFileTree, addSecondFileTree, nil) |
| 257 | checkFatal(t, err) |
| 258 | defer diff.Free() |
| 259 | |
| 260 | t.Run("check does not apply to current tree because file exists", func(t *testing.T) { |
| 261 | err = repo.ResetToCommit(addSecondFileCommit, ResetHard, &CheckoutOptions{}) |
| 262 | checkFatal(t, err) |
| 263 | |
| 264 | err = repo.ApplyDiff(diff, ApplyLocationBoth, nil) |
| 265 | if err == nil { |
| 266 | t.Error("expecting applying patch to current repo to fail") |
| 267 | } |
| 268 | }) |
| 269 | |
| 270 | t.Run("check apply to correct commit", func(t *testing.T) { |
| 271 | err = repo.ResetToCommit(addFirstFileCommit, ResetHard, &CheckoutOptions{}) |
| 272 | checkFatal(t, err) |
| 273 | |
| 274 | err = repo.ApplyDiff(diff, ApplyLocationBoth, nil) |
| 275 | checkFatal(t, err) |
| 276 | |
| 277 | t.Run("Check that diff only changed one file", func(t *testing.T) { |
| 278 | checkSecondFileStaged(t, repo) |
| 279 | |
| 280 | index, err := repo.Index() |
| 281 | checkFatal(t, err) |
| 282 | defer index.Free() |
| 283 | |
| 284 | newTreeOID, err := index.WriteTreeTo(repo) |
| 285 | checkFatal(t, err) |
| 286 | |
| 287 | newTree, err := repo.LookupTree(newTreeOID) |
| 288 | checkFatal(t, err) |
| 289 | defer newTree.Free() |
| 290 | |
| 291 | _, err = repo.CreateCommit("HEAD", signature(), signature(), fmt.Sprintf("patch apply"), newTree, addFirstFileCommit) |
| 292 | checkFatal(t, err) |
| 293 | }) |
| 294 | |
| 295 | t.Run("test applying patch produced the same diff", func(t *testing.T) { |
| 296 | head, err := repo.Head() |
| 297 | checkFatal(t, err) |
| 298 | |
| 299 | commit, err := repo.LookupCommit(head.Target()) |
| 300 | checkFatal(t, err) |
nothing calls this directly
no test coverage detected
searching dependent graphs…