IDEA-191309 git: update staging area using "git add -A" on commit

Unify logic for deleted, new, modified, renamed, etc files.
This prevents possible "Deleted-Unversioned" file status when
we expected file to be removed, but it is actually a modification on disk.
(ex: because pre-commit hook recreated a file that was deleted before)

Use "-A" as a parameter for "addPaths", to unify logic between git versions.
(This flag is set by default since git 2.0.0)
This commit is contained in:
Aleksey Pivovarov
2018-05-13 19:06:40 +03:00
parent 583bc17b5c
commit 1c40c8af36
2 changed files with 14 additions and 20 deletions
@@ -646,26 +646,17 @@ public class GitCheckinEnvironment implements CheckinEnvironment {
final Collection<FilePath> added,
final Collection<FilePath> removed,
final List<VcsException> exceptions) {
boolean rc = true;
if (!added.isEmpty()) {
try {
GitFileUtils.addPaths(project, root, added);
}
catch (VcsException ex) {
exceptions.add(ex);
rc = false;
}
try {
List<FilePath> files = new ArrayList<>();
files.addAll(added);
files.addAll(removed);
GitFileUtils.addPaths(project, root, files);
return true;
}
if (!removed.isEmpty()) {
try {
GitFileUtils.delete(project, root, removed, "--ignore-unmatch", "--cached");
}
catch (VcsException ex) {
exceptions.add(ex);
rc = false;
}
catch (VcsException ex) {
exceptions.add(ex);
return false;
}
return rc;
}
/**
@@ -23,7 +23,10 @@ import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.vcsUtil.VcsFileUtil;
import git4idea.GitUtil;
import git4idea.commands.*;
import git4idea.commands.Git;
import git4idea.commands.GitBinaryHandler;
import git4idea.commands.GitCommand;
import git4idea.commands.GitLineHandler;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
@@ -126,7 +129,7 @@ public class GitFileUtils {
continue;
}
GitLineHandler handler = new GitLineHandler(project, root, GitCommand.ADD);
handler.addParameters("--ignore-errors");
handler.addParameters("--ignore-errors", "-A");
handler.endOptions();
handler.addParameters(paths);
Git.getInstance().runCommand(handler).getOutputOrThrow();