Skip to content

Adding .git/SQUASH_MSG detection to commit message auto-fill #101078#101114

Merged
joaomoreno merged 5 commits intomicrosoft:masterfrom
daniel-j-davis:feature/add-git-squash-message
Jun 29, 2020
Merged

Adding .git/SQUASH_MSG detection to commit message auto-fill #101078#101114
joaomoreno merged 5 commits intomicrosoft:masterfrom
daniel-j-davis:feature/add-git-squash-message

Conversation

@daniel-j-davis
Copy link

This PR fixes #101078

As discussed in the issue, just like .git/MERGE_MSG is auto-filled if there's no commit message in the box, .git/SQUASH_MSG should also be auto-filled if present. This behaviour works the same way as git-gui does, in the sense that MERGE_MSG has precedence over SQUASH_MSG, so it looks for MERGE first, then SQUASH.

This can be tested by using the git merge <branch> --squash command, or alternatively, going into the .git directory and adding SQUASH_MSG with some commit message inside.

@ghost
Copy link

ghost commented Jun 26, 2020

CLA assistant check
All CLA requirements met.

async getInputTemplate(): Promise<string> {
const mergeMessage = await this.repository.getMergeMessage();
const squashMessage = await this.repository.getSquashMessage();
const commitMessage = await this.repository.getMergeMessage() || await this.repository.getSquashMessage();
Copy link
Member

Choose a reason for hiding this comment

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

No I don't think that's correct. You should use Promise.all(). Or even Promise.race() since we really only care about whether one of them succeeds.

Copy link
Author

@daniel-j-davis daniel-j-davis Jun 26, 2020

Choose a reason for hiding this comment

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

Will look into implementing this now, haven't really used Promise.race() but familiarising myself with it and working on implementation now. I'll comment here once my commits are final with Promise.race() implemented. Sorry about that.

Copy link
Author

@daniel-j-davis daniel-j-davis Jun 26, 2020

Choose a reason for hiding this comment

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

Is using Promise.race() going to require some refactoring of those two functions and what they return, though? Seems like Promise.race() will stop at the first promise resolution or rejection, unless I'm misunderstanding it.

EDIT: I guess we could do... const [mergeMessage, squashMessage] = await Promise.all([this.repository.getMergeMessage(), this.repository.getSquashMessage()]);, would that be appropriate?

Copy link
Member

@joaomoreno joaomoreno Jun 26, 2020

Choose a reason for hiding this comment

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

Yeah we'd kind of need Promise.any which isn't available. Let's maybe just do Promise.all and use the first non undefined result.

Copy link
Author

Choose a reason for hiding this comment

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

How's that (latest commit)? Hopefully this hits the nail on the head!

Copy link
Member

@joaomoreno joaomoreno left a comment

Choose a reason for hiding this comment

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

Cool thanks! 🍻

@joaomoreno joaomoreno added this to the June 2020 milestone Jun 29, 2020
@joaomoreno joaomoreno added the git GIT issues label Jun 29, 2020
@joaomoreno joaomoreno merged commit 57f08f6 into microsoft:master Jun 29, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

git GIT issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for using .git/SQUASH_MSG in Git commit message box

2 participants