Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

git commit -a should not refer to the storage but to the filesystem #571

@grunenwflorian

Description

@grunenwflorian

Hi,

[x] feature request

How would the same operation be performed using git from the command line terminal?
# bar.txt is tracked by git
rm -f bar.txt
git commit -am "Delete that file"

Current behavior:
Currently, removing a file in a repository without using go-git will break the git commit All functionalities. error = Lstat error no such file or directory

Expected behavior:
worktree_commit.go, Commit.

if opts.All {
		if err := w.autoAddModifiedAndDeleted(); err != nil {
			return plumbing.ZeroHash, err
		}
}
func (w *Worktree) autoAddModifiedAndDeleted() error {
	s, err := w.Status()
	if err != nil {
		return err
	}

	for path, fs := range s {
		if fs.Worktree != Modified && fs.Worktree != Deleted {
			continue
		}

		if _, err := w.Add(path); err != nil {
			return err
		}

	}

	return nil
}

If the file does not exist anymore Add will return an Lstat error, which is expected because a deletion can be considered a modification. Hence it should be covered by a Commit.

So my guess is, if not found the StatusCode of the FileStatus should be modified to Deleted.

go-git version:
~4.0.0-rc9

I'll be happy to submit a PR if you want.

If you have a better idea,I will be happy to read it !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions