[ 
https://issues.apache.org/jira/browse/SCM-843?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16584954#comment-16584954
 ] 

Michael Osipov commented on SCM-843:
------------------------------------

I'd be happy to commit this if I get a PR and a unit test for that.

> New files added to index are not checked in when nothing else has been 
> changed in the working copy
> --------------------------------------------------------------------------------------------------
>
>                 Key: SCM-843
>                 URL: https://issues.apache.org/jira/browse/SCM-843
>             Project: Maven SCM
>          Issue Type: Bug
>          Components: maven-scm-provider-jgit
>    Affects Versions: 1.9.5
>            Reporter: Lothar Wendehals
>            Priority: Major
>             Fix For: waiting-for-feedback
>
>
> 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:
> {code}
> 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 ) {
>                ....
>             }
>             ...
>     }
> {code}
> A possible fix would be:
> {code:java}
> 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) {
>    ...
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to