Skip to content

Commit

Permalink
feat🆕 (Invoke-GitCheckout): support for searching branch before checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
capdiem committed Jun 27, 2023
1 parent 901f85c commit 26f59d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion PSGitUtils/PSGitUtils.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGitUtils.psm1'

# Version number of this module.
ModuleVersion = '1.14.2'
ModuleVersion = '1.15.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
16 changes: 15 additions & 1 deletion PSGitUtils/PSGitUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,19 @@ function Get-OptionsForChoosingLocalBranch {
function Get-OptionsForChoosingLocalOrOriginBranch {
param (
[string]$title = 'Choose branch',
[string]$message = 'Please choose a branch'
[string]$message = 'Please choose a branch',
[string]$pattern
)
[System.Management.Automation.Host.ChoiceDescription[]]$branchOptions = @()
[string[]]$localBranches = Get-GitLocalBranches
[string[]]$originBranches = Get-GitOriginBranches -onlyName
[string[]]$branches = $localBranches + $originBranches | Select-Object -Unique
[char[]]$existChars = @('q')

if ($pattern) {
$branches = $branches | where { $_ -match $pattern }
}

$charBranchDict = @() # char:branch key:value

for ($i = 0; $i -lt $branches.Count; $i++) {
Expand Down Expand Up @@ -324,6 +329,15 @@ function Invoke-GitCheckout {
git checkout $branch
}
}
# Invoke-GitCheckout -s key
elseif ($args.Count -eq 2 -and $args[0] -eq "-s") {
[string]$pattern = $args[1]
$branch = Get-OptionsForChoosingLocalOrOriginBranch "Switch branch" "Please choose a branch to switch" $pattern

if ($branch) {
git checkout $branch
}
}
else {
git checkout $args
}
Expand Down

0 comments on commit 26f59d6

Please sign in to comment.