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