Skip to content
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

Closed
grunenwflorian opened this issue Aug 31, 2017 · 4 comments
Closed
Labels

Comments

@grunenwflorian
Copy link
Contributor

grunenwflorian commented Aug 31, 2017

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 !

@grunenwflorian grunenwflorian changed the title git commit -a should not only refer to the storage but to filesystem git commit -a should not refer to the storage but to the filesystem Aug 31, 2017
@mcuadros
Copy link
Contributor

Yep ,this is correct, we should avoid return a err when a file is deleted. Happy to accept a PR with the solution.

@mcuadros mcuadros added the bug label Aug 31, 2017
@grunenwflorian
Copy link
Contributor Author

grunenwflorian commented Sep 4, 2017

Hi,

I'm ready to submit a PR, could you give me the rights ?

Thanks.

@orirawlings
Copy link
Contributor

Hey @grunenwflorian,

Feel free to open the PR. You should have permissions to fork the src-d/go-git repository and file a PR from your fork to the main project.

Thanks!

@grunenwflorian
Copy link
Contributor Author

Thanks @orirawlings.

My bad, I'm so used to create branch that I forgot the fork option.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants