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

Function TestStash

stash_test.go:14–122  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestStash(t *testing.T) {
15 repo := createTestRepo(t)
16 defer cleanupTestRepo(t, repo)
17
18 prepareStashRepo(t, repo)
19
20 sig := &Signature{
21 Name: "Rand Om Hacker",
22 Email: "random@hacker.com",
23 When: time.Now(),
24 }
25
26 stash1, err := repo.Stashes.Save(sig, "First stash", StashDefault)
27 checkFatal(t, err)
28
29 _, err = repo.LookupCommit(stash1)
30 checkFatal(t, err)
31
32 b, err := ioutil.ReadFile(pathInRepo(repo, "README"))
33 checkFatal(t, err)
34 if string(b) == "Update README goes to stash\n" {
35 t.Errorf("README still contains the uncommitted changes")
36 }
37
38 if !fileExistsInRepo(repo, "untracked.txt") {
39 t.Errorf("untracked.txt doesn't exist in the repo; should be untracked")
40 }
41
42 // Apply: default
43
44 opts, err := DefaultStashApplyOptions()
45 checkFatal(t, err)
46
47 err = repo.Stashes.Apply(0, opts)
48 checkFatal(t, err)
49
50 b, err = ioutil.ReadFile(pathInRepo(repo, "README"))
51 checkFatal(t, err)
52 if string(b) != "Update README goes to stash\n" {
53 t.Errorf("README changes aren't here")
54 }
55
56 // Apply: no stash for the given index
57
58 err = repo.Stashes.Apply(1, opts)
59 if !IsErrorCode(err, ErrorCodeNotFound) {
60 t.Errorf("expecting GIT_ENOTFOUND error code %d, got %v", ErrorCodeNotFound, err)
61 }
62
63 // Apply: callback stopped
64
65 opts.ProgressCallback = func(progress StashApplyProgress) error {
66 if progress == StashApplyProgressCheckoutModified {
67 return fmt.Errorf("Stop")
68 }
69 return nil
70 }
71

Callers

nothing calls this directly

Calls 15

createTestRepoFunction · 0.85
cleanupTestRepoFunction · 0.85
prepareStashRepoFunction · 0.85
checkFatalFunction · 0.85
pathInRepoFunction · 0.85
fileExistsInRepoFunction · 0.85
DefaultStashApplyOptionsFunction · 0.85
IsErrorCodeFunction · 0.85
checkStashesFunction · 0.85
SaveMethod · 0.80
LookupCommitMethod · 0.80
ApplyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…