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

Method doAddFile

worktree_status.go:450–478  ·  view source on GitHub ↗

doAddFile create a new blob from path and update the index, added is true if the file added is different from the index. if s status is nil will skip the status check and update the index anyway

(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern)

Source from the content-addressed store, hash-verified

448// the file added is different from the index.
449// if s status is nil will skip the status check and update the index anyway
450func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) {
451 if s != nil && s.File(path).Worktree == Unmodified {
452 return false, h, nil
453 }
454 if len(ignorePattern) > 0 {
455 m := gitignore.NewMatcher(ignorePattern)
456 matchPath := strings.Split(path, string(os.PathSeparator))
457 if m.Match(matchPath, true) {
458 // ignore
459 return false, h, nil
460 }
461 }
462
463 h, err = w.copyFileToStorage(path)
464 if err != nil {
465 if os.IsNotExist(err) {
466 added = true
467 h, err = w.deleteFromIndex(idx, path)
468 }
469
470 return
471 }
472
473 if err := w.addOrUpdateFileToIndex(idx, path, h); err != nil {
474 return false, h, err
475 }
476
477 return true, h, err
478}
479
480func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error) {
481 fi, err := w.Filesystem.Lstat(path)

Callers 4

doAddDirectoryMethod · 0.95
doAddMethod · 0.95
AddGlobMethod · 0.95

Calls 6

MatchMethod · 0.95
copyFileToStorageMethod · 0.95
deleteFromIndexMethod · 0.95
NewMatcherFunction · 0.92
FileMethod · 0.45

Tested by

no test coverage detected