MCPcopy Create free account
hub / github.com/go-git/go-git / doAddFile

Method doAddFile

worktree_status.go:431–459  ·  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

429// the file added is different from the index.
430// if s status is nil will skip the status check and update the index anyway
431func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) {
432 if s != nil && s.File(path).Worktree == Unmodified {
433 return false, h, nil
434 }
435 if len(ignorePattern) > 0 {
436 m := gitignore.NewMatcher(ignorePattern)
437 matchPath := strings.Split(path, string(os.PathSeparator))
438 if m.Match(matchPath, true) {
439 // ignore
440 return false, h, nil
441 }
442 }
443
444 h, err = w.copyFileToStorage(path)
445 if err != nil {
446 if os.IsNotExist(err) {
447 added = true
448 h, err = w.deleteFromIndex(idx, path)
449 }
450
451 return
452 }
453
454 if err := w.addOrUpdateFileToIndex(idx, path, h); err != nil {
455 return false, h, err
456 }
457
458 return true, h, err
459}
460
461func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error) {
462 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