MCPcopy Create free account
hub / github.com/libgit2/git2go / TestResetToCommit

Function TestResetToCommit

reset_test.go:8–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

6)
7
8func TestResetToCommit(t *testing.T) {
9 t.Parallel()
10 repo := createTestRepo(t)
11 defer cleanupTestRepo(t, repo)
12
13 seedTestRepo(t, repo)
14 // create commit to reset to
15 commitId, _ := updateReadme(t, repo, "testing reset")
16 // create commit to reset from
17 nextCommitId, _ := updateReadme(t, repo, "will be reset")
18
19 // confirm that we wrote "will be reset" to the readme
20 newBytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
21 checkFatal(t, err)
22 if string(newBytes) != "will be reset" {
23 t.Fatalf("expected %s to equal 'will be reset'", string(newBytes))
24 }
25
26 // confirm that the head of the repo is the next commit id
27 head, err := repo.Head()
28 checkFatal(t, err)
29 if head.Target().String() != nextCommitId.String() {
30 t.Fatalf(
31 "expected to be at latest commit %s, but was %s",
32 nextCommitId.String(),
33 head.Target().String(),
34 )
35 }
36
37 commitToResetTo, err := repo.LookupCommit(commitId)
38 checkFatal(t, err)
39
40 repo.ResetToCommit(commitToResetTo, ResetHard, &CheckoutOptions{})
41
42 // check that the file now reads "testing reset" like it did before
43 bytes, err := ioutil.ReadFile(pathInRepo(repo, "README"))
44 checkFatal(t, err)
45 if string(bytes) != "testing reset" {
46 t.Fatalf("expected %s to equal 'testing reset'", string(bytes))
47 }
48}

Callers

nothing calls this directly

Calls 11

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
seedTestRepoFunction · 0.85
updateReadmeFunction · 0.85
pathInRepoFunction · 0.85
checkFatalFunction · 0.85
HeadMethod · 0.80
LookupCommitMethod · 0.80
ResetToCommitMethod · 0.80
StringMethod · 0.45
TargetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…