[
https://issues.apache.org/jira/browse/SCM-843?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17965023#comment-17965023
]
Olivier Lamy commented on SCM-843:
----------------------------------
This project has moved from Jira to GitHub Issues. This issue was migrated to
[apache/maven-scm#1074|https://github.com/apache/maven-scm/issues/1074].
> 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 (Moved to GitHub Issues)
> Issue Type: Bug
> Components: maven-scm-provider-jgit
> Affects Versions: 1.9.5
> Reporter: Lothar Wendehals
> Priority: Major
>
> 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
(v8.20.10#820010)