-
Notifications
You must be signed in to change notification settings - Fork 315
/
revert_test.go
76 lines (56 loc) · 1.82 KB
/
revert_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
package git
import (
"testing"
)
const (
expectedRevertedReadmeContents = "foo\n"
)
func TestRevert(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
commitID, _ := updateReadme(t, repo, content)
commit, err := repo.LookupCommit(commitID)
checkFatal(t, err)
revertOptions, err := DefaultRevertOptions()
checkFatal(t, err)
err = repo.Revert(commit, &revertOptions)
checkFatal(t, err)
actualReadmeContents := readReadme(t, repo)
if actualReadmeContents != expectedRevertedReadmeContents {
t.Fatalf(`README has incorrect contents after revert. Expected: "%v", Actual: "%v"`,
expectedRevertedReadmeContents, actualReadmeContents)
}
state := repo.State()
if state != RepositoryStateRevert {
t.Fatalf("Incorrect repository state. Expected: %v, Actual: %v", RepositoryStateRevert, state)
}
err = repo.StateCleanup()
checkFatal(t, err)
state = repo.State()
if state != RepositoryStateNone {
t.Fatalf("Incorrect repository state. Expected: %v, Actual: %v", RepositoryStateNone, state)
}
}
func TestRevertCommit(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
commitID, _ := updateReadme(t, repo, content)
commit, err := repo.LookupCommit(commitID)
checkFatal(t, err)
revertOptions, err := DefaultRevertOptions()
checkFatal(t, err)
index, err := repo.RevertCommit(commit, commit, 0, &revertOptions.MergeOptions)
checkFatal(t, err)
defer index.Free()
err = repo.CheckoutIndex(index, &revertOptions.CheckoutOptions)
checkFatal(t, err)
actualReadmeContents := readReadme(t, repo)
if actualReadmeContents != expectedRevertedReadmeContents {
t.Fatalf(`README has incorrect contents after revert. Expected: "%v", Actual: "%v"`,
expectedRevertedReadmeContents, actualReadmeContents)
}
}