Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-3760: Fix git commit not staged specified path with amend #3833

Merged
merged 2 commits into from
Mar 3, 2017

Conversation

vinokurig
Copy link
Contributor

@vinokurig vinokurig commented Jan 20, 2017

What does this PR do?

Fix throwing exception if working directory is clean or nothing added to commit.
Add a workaround to allow empty commit with amend and specified paths.

What issues does this PR fix or reference?

#3760

Changelog

BugFix: Fix throwing exception on Git commit, if working directory is clean or nothing added to commit.

Release Notes

BugFix N/A

Docs PR

BugFix N/A

@vinokurig vinokurig requested a review from skabashnyuk January 20, 2017 15:14
@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@@ -564,14 +589,27 @@ public Revision commit(CommitParams params) throws GitException {
}

CommitCommand commitCommand = getGit().commit()
.setCommitter(committerName, committerEmail).setAuthor(committerName, committerEmail)
.setAllowEmpty(params.isAmend())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this setting to .setAmend(...) and add comment why is it needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if other changes are present, but the list of changed and specified paths is empty, to prevent committing other paths.
TODO Remove throwing exception when the bug will be fixed.
*/
if (!specified.isEmpty() && !(params.isAll() ? changed.isEmpty() : staged.isEmpty()) && specifiedChanged.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this check above to other checks before creating commit comand

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double check that it is right check. Looks like we should throw exception here in case when specified is not empty and specifiedChanged is empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the check. Added tests for this exception.

if (!params.isAmend()) {
// Check that there are staged changes present for commit, or any changes if 'isAll' is enabled
if (status.isClean()) {
throw new GitException("Nothing to commit, working directory clean");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we throw exception that are related to changes and then about missing commiter's name and email?
Please check behavior of native git and do in the same way.
Any way I think we should check repository state and https://github.com/eclipse/che/pull/3833/files#diff-7f323c0167c366f41270f82a35ed368dR579 and only then throw exception related to changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the check

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

Copy link
Member

@sleshchenko sleshchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other looks good to me!

if (message == null) {
throw new GitException("Message wasn't set");
// Check repository state
if (!repository.getRepositoryState().canCommit()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is getRepositoryState easy operation? I'd save result to variable and then reuse it

.setMessage(message)
.setAll(params.isAll())
.setAmend(params.isAmend());
.setAmend(params.isAmend())
// Allow empty commits with specified paths with amend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment says about commits with specified paths but code in next line doesn't do it. Fix code or comment

only changed and specified paths. If other changes are present, but the list of changed and specified paths is empty,
throw exception to prevent committing other paths. TODO Remove this check when the bug will be fixed.
*/
} else if (!specified.isEmpty() && !(params.isAll() ? changed.isEmpty() : staged.isEmpty()) && specifiedChanged.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make comment clear I'd rewrite it as

if (!params.isAmend()) {
  ...
} else {
    // comment with TODO to remove this block
    if (...) {
       ...
    }
}

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

@codenvy-ci
Copy link

Build finished.
Build success. $BUILD_URL

@codenvy-ci
Copy link

@vinokurig vinokurig merged commit 6a644e7 into master Mar 3, 2017
@vinokurig vinokurig deleted the CHE-3760 branch March 3, 2017 10:14
@vinokurig vinokurig added this to the 5.5.0 milestone Mar 3, 2017
@vinokurig vinokurig added the kind/bug Outline of a bug - must adhere to the bug report template. label Mar 3, 2017
@JamesDrummond JamesDrummond mentioned this pull request Mar 17, 2017
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Outline of a bug - must adhere to the bug report template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants