MCPcopy Index your code
hub / github.com/go-git/go-git / setupForRestore

Function setupForRestore

worktree_test.go:3285–3345  ·  view source on GitHub ↗
(c *C, s *WorktreeSuite)

Source from the content-addressed store, hash-verified

3283}
3284
3285func setupForRestore(c *C, s *WorktreeSuite) (fs billy.Filesystem, w *Worktree, names []string) {
3286 fs = memfs.New()
3287 w = &Worktree{
3288 r: s.Repository,
3289 Filesystem: fs,
3290 }
3291
3292 err := w.Checkout(&CheckoutOptions{})
3293 c.Assert(err, IsNil)
3294
3295 names = []string{"foo", "CHANGELOG", "LICENSE", "binary.jpg"}
3296 verifyStatus(c, "Checkout", w, names, []FileStatus{
3297 {Worktree: Untracked, Staging: Untracked},
3298 {Worktree: Untracked, Staging: Untracked},
3299 {Worktree: Untracked, Staging: Untracked},
3300 {Worktree: Untracked, Staging: Untracked},
3301 })
3302
3303 // Touch of bunch of files including create a new file and delete an exsiting file
3304 for _, name := range names {
3305 err = util.WriteFile(fs, name, []byte("Foo Bar"), 0755)
3306 c.Assert(err, IsNil)
3307 }
3308 err = util.RemoveAll(fs, names[3])
3309 c.Assert(err, IsNil)
3310
3311 // Confirm the status after doing the edits without staging anything
3312 verifyStatus(c, "Edits", w, names, []FileStatus{
3313 {Worktree: Untracked, Staging: Untracked},
3314 {Worktree: Modified, Staging: Unmodified},
3315 {Worktree: Modified, Staging: Unmodified},
3316 {Worktree: Deleted, Staging: Unmodified},
3317 })
3318
3319 // Stage all files and verify the updated status
3320 for _, name := range names {
3321 _, err = w.Add(name)
3322 c.Assert(err, IsNil)
3323 }
3324 verifyStatus(c, "Staged", w, names, []FileStatus{
3325 {Worktree: Unmodified, Staging: Added},
3326 {Worktree: Unmodified, Staging: Modified},
3327 {Worktree: Unmodified, Staging: Modified},
3328 {Worktree: Unmodified, Staging: Deleted},
3329 })
3330
3331 // Add secondary changes to a file to make sure we only restore the staged file
3332 err = util.WriteFile(fs, names[1], []byte("Foo Bar:11"), 0755)
3333 c.Assert(err, IsNil)
3334 err = util.WriteFile(fs, names[2], []byte("Foo Bar:22"), 0755)
3335 c.Assert(err, IsNil)
3336
3337 verifyStatus(c, "Secondary Edits", w, names, []FileStatus{
3338 {Worktree: Unmodified, Staging: Added},
3339 {Worktree: Modified, Staging: Modified},
3340 {Worktree: Modified, Staging: Modified},
3341 {Worktree: Unmodified, Staging: Deleted},
3342 })

Callers 3

TestRestoreStagedMethod · 0.85
TestRestoreWorktreeMethod · 0.85
TestRestoreBothMethod · 0.85

Calls 3

verifyStatusFunction · 0.85
CheckoutMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…