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

Method doAdd

worktree_status.go:336–372  ·  view source on GitHub ↗
(path string, ignorePattern []gitignore.Pattern, skipStatus bool)

Source from the content-addressed store, hash-verified

334}
335
336func (w *Worktree) doAdd(path string, ignorePattern []gitignore.Pattern, skipStatus bool) (plumbing.Hash, error) {
337 idx, err := w.r.Storer.Index()
338 if err != nil {
339 return plumbing.ZeroHash, err
340 }
341
342 var h plumbing.Hash
343 var added bool
344
345 fi, err := w.Filesystem.Lstat(path)
346
347 // status is required for doAddDirectory
348 var s Status
349 var err2 error
350 if !skipStatus || fi == nil || fi.IsDir() {
351 s, err2 = w.Status()
352 if err2 != nil {
353 return plumbing.ZeroHash, err2
354 }
355 }
356
357 if err != nil || !fi.IsDir() {
358 added, h, err = w.doAddFile(idx, s, path, ignorePattern)
359 } else {
360 added, err = w.doAddDirectory(idx, s, path, ignorePattern)
361 }
362
363 if err != nil {
364 return h, err
365 }
366
367 if !added {
368 return h, nil
369 }
370
371 return h, w.r.Storer.SetIndex(idx)
372}
373
374// AddGlob adds all paths, matching pattern, to the index. If pattern matches a
375// directory path, all directory contents are added to the index recursively. No

Callers 2

AddMethod · 0.95
AddWithOptionsMethod · 0.95

Calls 7

StatusMethod · 0.95
doAddFileMethod · 0.95
doAddDirectoryMethod · 0.95
LstatMethod · 0.80
IndexMethod · 0.65
IsDirMethod · 0.65
SetIndexMethod · 0.65

Tested by

no test coverage detected