You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When executing an add operation/command, the command line git by default removes the missing files from index where as the JGit does not.
The steps for comparison are
Create a new file
Add the file to index
Delete the file with rm
Add the file for removal from index
$ git status
On branch Test1
Your branch is up to date with 'origin/Test1'.
nothing to commit, working tree clean
$ echo "Test file for missing in index" > test2.txt
$ git status
On branch Test1
Your branch is up to date with 'origin/Test1'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
test2.txt
nothing added to commit but untracked files present (use "git add" to track)
$ git add test2.txt
warning: in the working copy of 'test2.txt', LF will be replaced by CRLF the next time Git touches it
$ rm -f test2.txt
$ git status
On branch Test1
Your branch is up to date with 'origin/Test1'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: test2.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: test2.txt
$ git add test2.txt
$ git status
On branch Test1
Your branch is up to date with 'origin/Test1'.
nothing to commit, working tree clean
$
Notice that the second add command after delete of file removes the file from staged/index by default.
To replicate the same with JGit used the snippet
public void simulateMissingFilesAdd(String dotFilename) throws IOException, GitAPIException{
Git git = getGitRepo(dirPath);
String filePath = dirPath+"/"+dotFilename;
//create a dot file and add to index to the repo
try ( PrintWriter writer = new PrintWriter(filePath, "UTF-8"))
{
writer.println("Line1 text");
writer.println("Line2 text");
}
System.out.println("Created file "+dotFilename+ " and adding it ...");
git.add().setUpdate(false).addFilepattern(".").call();
printStatus(git);
System.out.println("Deleting file "+dotFilename+ " ...");
// remove dot file and add
File file = new File(filePath);
file.delete();
printStatus(git);
System.out.println("Adding file "+dotFilename+ " ...");
git.add().setUpdate(false).addFilepattern(dotFilename).call();
git.commit().setMessage("After removing the file "+dotFilename).call();
System.out.println("Committed removal of file "+dotFilename+ " ...");
printStatus(git);
}
void printStatus(Git git) throws GitAPIException{
Status status = git.status().call();
System.out.println("\nClean : "+status.isClean());
System.out.println("getAdded : "+status.getAdded());
System.out.println("getMissing : "+status.getMissing());
System.out.println("getRemoved : "+status.getRemoved());
System.out.println("getUncommittedChanges : "+status.getUncommittedChanges());
System.out.println("getUntracked : "+status.getUntracked());
}
Version
6.7.0
Operating System
Linux/Unix, Windows
Bug description
When executing an add operation/command, the command line git by default removes the missing files from index where as the JGit does not.
The steps for comparison are
rm
Notice that the second add command after delete of file removes the file from staged/index by default.
To replicate the same with JGit used the snippet
And results are of the run.
Notice that the add after file delete does not remove the missing file from index with not clean status.
c-git provides a switch to override default with
--ignore-missing switch
so something similar can be done for JGit.Actual behavior
Actual behaviour of Jgit is not consistent with that of C-Git where by default the file is not removed during add.
Expected behavior
Expected behaviour of Jgit to be consistent with that of C-Git where by default the file is removed during add and overridden with a flag/property
Relevant log output
No response
Other information
No response
The text was updated successfully, but these errors were encountered: