-
Notifications
You must be signed in to change notification settings - Fork 315
/
reset_test.go
48 lines (40 loc) · 1.27 KB
/
reset_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
package git
import (
"io/ioutil"
"testing"
)
func TestResetToCommit(t *testing.T) {
t.Parallel()
repo := createTestRepo(t)
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
// create commit to reset to
commitId, _ := updateReadme(t, repo, "testing reset")
// create commit to reset from
nextCommitId, _ := updateReadme(t, repo, "will be reset")
// confirm that we wrote "will be reset" to the readme
newBytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
checkFatal(t, err)
if string(newBytes) != "will be reset" {
t.Fatalf("expected %s to equal 'will be reset'", string(newBytes))
}
// confirm that the head of the repo is the next commit id
head, err := repo.Head()
checkFatal(t, err)
if head.Target().String() != nextCommitId.String() {
t.Fatalf(
"expected to be at latest commit %s, but was %s",
nextCommitId.String(),
head.Target().String(),
)
}
commitToResetTo, err := repo.LookupCommit(commitId)
checkFatal(t, err)
repo.ResetToCommit(commitToResetTo, ResetHard, &CheckoutOptions{})
// check that the file now reads "testing reset" like it did before
bytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
checkFatal(t, err)
if string(bytes) != "testing reset" {
t.Fatalf("expected %s to equal 'testing reset'", string(bytes))
}
}