summaryrefslogtreecommitdiff
path: root/reset_test.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
committerCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
commit6d3a3499f1639a6272e334f9f74b1e0cf6b0bb49 (patch)
tree04b27dfdf1faadcaff6ca40fa27d8edd690045d1 /reset_test.go
parent157593f38da780c4f6cb6dc61275b9b36a3327bf (diff)
parent4090c401c8bf3f062e898f75bde01e2ef27b3911 (diff)
Merge branch 'master-v23'
Diffstat (limited to 'reset_test.go')
-rw-r--r--reset_test.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/reset_test.go b/reset_test.go
new file mode 100644
index 0000000..ec578bd
--- /dev/null
+++ b/reset_test.go
@@ -0,0 +1,45 @@
+package git
+
+import (
+ "io/ioutil"
+ "testing"
+)
+
+func TestResetToCommit(t *testing.T) {
+ repo := createTestRepo(t)
+ 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, &CheckoutOpts{})
+
+ // 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))
+ }
+}