MCPcopy
hub / github.com/go-git/go-git / resetWorktree

Method resetWorktree

worktree.go:446–485  ·  view source on GitHub ↗
(t *object.Tree, files []string)

Source from the content-addressed store, hash-verified

444}
445
446func (w *Worktree) resetWorktree(t *object.Tree, files []string) error {
447 changes, err := w.diffStagingWithWorktree(true, false)
448 if err != nil {
449 return err
450 }
451
452 idx, err := w.r.Storer.Index()
453 if err != nil {
454 return err
455 }
456 b := newIndexBuilder(idx)
457
458 filesMap := buildFilePathMap(files)
459 for _, ch := range changes {
460 if len(files) > 0 {
461 file := ""
462 if ch.From != nil {
463 file = ch.From.String()
464 } else if ch.To != nil {
465 file = ch.To.String()
466 }
467
468 if file == "" {
469 continue
470 }
471
472 contains := inFiles(filesMap, file)
473 if !contains {
474 continue
475 }
476 }
477
478 if err := w.checkoutChange(ch, t, b); err != nil {
479 return err
480 }
481 }
482
483 b.Write(idx)
484 return w.r.Storer.SetIndex(idx)
485}
486
487func (w *Worktree) checkoutChange(ch merkletrie.Change, t *object.Tree, idx *indexBuilder) error {
488 a, err := ch.Action()

Callers 1

ResetSparselyMethod · 0.95

Calls 9

checkoutChangeMethod · 0.95
newIndexBuilderFunction · 0.85
buildFilePathMapFunction · 0.85
inFilesFunction · 0.85
IndexMethod · 0.65
StringMethod · 0.65
SetIndexMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected