forked from libgit2/git2go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcherrypick_test.go
86 lines (69 loc) · 1.55 KB
/
cherrypick_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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())
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) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
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)
}
}