-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f7f7aa
commit d5fe56d
Showing
3 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,8 +146,30 @@ func Test_Integration(t *testing.T) { | |
assertStatus(t, map[string]IndexStatus{"c": AddedInIndex}, map[string]WDStatus{"c": IndexAndWorkingTreeMatch}) | ||
} | ||
|
||
// check for semantics when switching branch | ||
// | ||
// restore a file | ||
{ | ||
// commit change to 'c' | ||
_ = assertCreateCommit(t, &Commit{ | ||
Author: fmt.Sprintf("%s <%s>", "tester", "[email protected]"), | ||
AuthoredTime: time.Now(), | ||
Committer: fmt.Sprintf("%s <%s>", "tester", "[email protected]"), | ||
CommittedTime: time.Now(), | ||
Message: []byte("this is yet another commit message"), | ||
}) | ||
// change 'c' | ||
e(os.WriteFile(filepath.Join(dir, "c"), []byte("cc"), 0644), t) | ||
// check status is correct | ||
assertStatus(t, map[string]IndexStatus{"c": NotUpdated}, map[string]WDStatus{"c": WorktreeChangedSinceIndex}) | ||
// add to index | ||
assertAddFiles(t, []string{"c"}) | ||
// check status | ||
assertStatus(t, map[string]IndexStatus{"c": UpdatedInIndex}, map[string]WDStatus{"c": IndexAndWorkingTreeMatch}) | ||
// restore --staged c | ||
assertRestore(t, "c", true) | ||
// check status | ||
assertStatus(t, map[string]IndexStatus{"c": NotUpdated}, map[string]WDStatus{"c": WorktreeChangedSinceIndex}) | ||
|
||
} | ||
|
||
} | ||
|
||
|
@@ -158,6 +180,12 @@ func e(err error, t *testing.T) { | |
} | ||
} | ||
|
||
func assertRestore(t *testing.T, path string, staged bool) { | ||
if err := Restore(path, staged); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func assertLookupCommit(t *testing.T, sha Sha, f func(*testing.T, *Commit)) { | ||
t.Helper() | ||
commit, err := ReadCommit(sha) | ||
|
@@ -256,7 +284,7 @@ func assertStatus(t *testing.T, i map[string]IndexStatus, w map[string]WDStatus) | |
t.Fatalf("expected file '%s'", k) | ||
} | ||
if f.wdStatus != v { | ||
t.Errorf("expected file '%s' to have working directory status '%d' got '%d'", k, v, f.wdStatus) | ||
t.Errorf("expected file '%s' to have working directory status '%s' got '%s'", k, v, f.wdStatus) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters