Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Incomplete
-
1.9.5
-
None
-
None
-
Patch
Description
Scenario:
Start with a clean working copy. Create a new file in the working copy and add it to the index. Now run a checkin with JGitCheckinCommand. It will not commit the new file when nothing else has changed (no modified file for example) in the working copy.
This is the original code in 1.9.5:
protected CheckInScmResult executeCheckInCommand(ScmProviderRepository repo, ScmFileSet fileSet, String message, ScmVersion version) throws ScmException { Git git = null; try { File basedir = fileSet.getBasedir(); git = JGitUtils.openRepo( basedir ); boolean doCommit = false; if (!fileSet.getFileList().isEmpty()) { doCommit = JGitUtils.addAllFiles( git, fileSet ).size() > 0; } else { // add all tracked files which are modified manually Set<String> changeds = git.status().call().getModified(); if ( changeds.isEmpty() ) { // warn there is nothing to add // here is the bug: status().call().getModified() does not return files that have already been added to the index, it only returns files that have been modified but not added to the index getLogger().warn( "there are no files to be added" ); doCommit = false; } else { AddCommand add = git.add(); for ( String changed : changeds ) { getLogger().debug( "add manualy: " + changed ); add.addFilepattern( changed ); doCommit = true; } add.call(); } } List<ScmFile> checkedInFiles = Collections.emptyList(); if ( doCommit ) { .... } ... }
A possible fix would be:
if (!fileSet.getFileList().isEmpty()) { doCommit = JGitUtils.addAllFiles(git, fileSet).size() > 0; } else { // Bugfix: Files that have been added in advance by // the user will not be committed if nothing else has changed. // add all tracked files which are modified manually Set<String> changeds = git.status().call().getModified(); if (!changeds.isEmpty()) { AddCommand add = git.add(); for (String changed : changeds) { getLogger().debug("add manually: " + changed); add.addFilepattern(changed); doCommit = true; } add.call(); } Status status = git.status().call(); doCommit = !status.getUncommittedChanges().isEmpty(); if (!doCommit) { getLogger().warn("there are no files to commit"); } } List<ScmFile> checkedInFiles = Collections.emptyList(); if (doCommit) { ...