diff options
| author | Carlos Martín Nieto <[email protected]> | 2015-03-11 17:05:16 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <[email protected]> | 2015-03-11 17:05:16 +0100 |
| commit | d300110b8582cd44511efc26a7a0ce04d409f8ce (patch) | |
| tree | 58652052be2848d110ff3c894517452577f44a95 /cherrypick_test.go | |
| parent | 755721e68453c5d6de0681789dbe3307744fc9c4 (diff) | |
| parent | 9eae50f29a69fa47cecf3cf4dfb032414cf27a50 (diff) | |
Merge pull request #178 from schani/master
Fixes and improvements
Diffstat (limited to 'cherrypick_test.go')
| -rw-r--r-- | cherrypick_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/cherrypick_test.go b/cherrypick_test.go new file mode 100644 index 0000000..f06dbdd --- /dev/null +++ b/cherrypick_test.go @@ -0,0 +1,83 @@ +package git + +import ( + "io/ioutil" + "testing" +) + +func checkout(t *testing.T, repo *Repository, commit *Commit) { + tree, err := commit.Tree() + if err != nil { + t.Fatal(err) + } + + err = repo.CheckoutTree(tree, &CheckoutOpts{Strategy: CheckoutSafe}) + if err != nil { + t.Fatal(err) + } + + err = repo.SetHeadDetached(commit.Id(), commit.Author(), "checkout") + if err != nil { + t.Fatal(err) + } +} + +const content = "Herro, Worrd!" + +func readReadme(t *testing.T, repo *Repository) string { + bytes, err := ioutil.ReadFile(pathInRepo(repo, "README")) + if err != nil { + t.Fatal(err) + } + return string(bytes) +} + +func TestCherrypick(t *testing.T) { + repo := createTestRepo(t) + c1, _ := seedTestRepo(t, repo) + c2, _ := updateReadme(t, repo, content) + + commit1, err := repo.LookupCommit(c1) + if err != nil { + t.Fatal(err) + } + commit2, err := repo.LookupCommit(c2) + if err != nil { + t.Fatal(err) + } + + checkout(t, repo, commit1) + + if readReadme(t, repo) == content { + t.Fatalf("README has wrong content after checking out initial commit") + } + + opts, err := DefaultCherrypickOptions() + if err != nil { + t.Fatal(err) + } + + err = repo.Cherrypick(commit2, opts) + if err != nil { + t.Fatal(err) + } + + if readReadme(t, repo) != content { + t.Fatalf("README has wrong contents after cherry-picking") + } + + state := repo.State() + if state != RepositoryStateCherrypick { + t.Fatal("Incorrect repository state: ", state) + } + + err = repo.StateCleanup() + if err != nil { + t.Fatal(err) + } + + state = repo.State() + if state != RepositoryStateNone { + t.Fatal("Incorrect repository state: ", state) + } +} |
