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

Fix missing CHERRY-PICKING, MERGING, REVERTING, etc #894

Merged
merged 7 commits into from
Mar 27, 2022
Merged

Conversation

dahlbyk
Copy link
Owner

@dahlbyk dahlbyk commented Mar 27, 2022

Adding tests for #828

@dahlbyk
Copy link
Owner Author

dahlbyk commented Mar 27, 2022

Revert "fix CHERRY-PICKING display bug"

@NihilityT your fix does work, but I ended up reverting it to gain some performance. Not using the status branch name if we have it leads to two extra git calls on every prompt (see failures). Since we nearly always have a branch, we should try to use it as an optimization.

So the logic ends up being:

  1. Get branch from status (but only if not in .git or bare)
  2. Always call Get-GitBranch to add the necessary suffix, but with new parameters -Branch and -IsDotGitOrBare (which we know from before calling git status)
  3. Only make the extra git rev-parse calls for .git/bare if we need to

@dahlbyk dahlbyk requested a review from rkeithhill March 27, 2022 17:15
Copy link
Collaborator

@rkeithhill rkeithhill left a comment

Choose a reason for hiding this comment

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

A few style comments but otherwise LGTM

@@ -59,7 +59,7 @@ function Get-GitDirectory {
}
}

function Get-GitBranch($gitDir = $(Get-GitDirectory), [Diagnostics.Stopwatch]$sw) {
function Get-GitBranch($branch = $null, $gitDir = $(Get-GitDirectory), [switch]$isDotGitOrBare, [Diagnostics.Stopwatch]$sw) {
Copy link
Collaborator

@rkeithhill rkeithhill Mar 27, 2022

Choose a reason for hiding this comment

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

This is not an exported command but, in general, I'd add new parameters at the end of the parameter list to avoid breaking any callers that use positional parameters. That said, the only caller is in this file - besides to Pester test calls to this command. So, if it makes more sense for the Branch parameter to be first then go for it. In retrospect, we probably should have been more consistent in using PascalCasing on all function parameters given that they correspond to command parameters e.g.: Get-GitBranch -Branch main -GitDir ~\.git.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This is not an exported command but, in general, I'd add new parameters at the end of the parameter list to avoid breaking any callers that use positional parameters. That said, the only caller is in this file - besides to Pester test calls to this command. So, if it makes more sense for the Branch parameter to be first then go for it.

I generally agree, but I wanted to keep $sw last so figured all bets are off.

In retrospect, we probably should have been more consistent in using PascalCasing on all function parameters given that they correspond to command parameters e.g.: Get-GitBranch -Branch main -GitDir ~\.git.

Consistency would be good. Can revisit holistically after I get a release out.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it would be better to have style changes and semantic changes in separate PRs. Makes them both easier to review. 😁

$b = Invoke-NullCoalescing `
$b `
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, I never realized until now that our Inovke-NullCoalescing command handles an infinite list of args. Nice. The new PowerShell ?? operator allows this but not via a single operator e.g. $b = $b ?? $branch ?? { dbg...; git ... HEAD -q } ?? ... And the ?? operator is PS checks for equality to $null and not "truthiness" which can be surprising. And since the PS ?? operator is not in Windows PS 5, we can't use it here.

src/GitUtils.ps1 Show resolved Hide resolved
src/GitUtils.ps1 Show resolved Hide resolved
@dahlbyk dahlbyk merged commit dc2b636 into master Mar 27, 2022
@dahlbyk dahlbyk deleted the NihilityT/master branch March 27, 2022 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants