(t *testing.T)
| 6 | ) |
| 7 | |
| 8 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…