From 8b910edb149c2bdf65343c322418e66c97b4d7ed Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 25 Jun 2022 17:34:56 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=86=95=20feat(ggck):=20support=20chec?= =?UTF-8?q?kout=20the=20origin=20branch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PSGitUtils/PSGitUtils.psm1 | 55 +++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/PSGitUtils/PSGitUtils.psm1 b/PSGitUtils/PSGitUtils.psm1 index f8e6bc1..a5cff43 100644 --- a/PSGitUtils/PSGitUtils.psm1 +++ b/PSGitUtils/PSGitUtils.psm1 @@ -253,13 +253,62 @@ function Get-OptionsForChoosingLocalBranch { return $localBranches[$choice] } +function Get-OptionsForChoosingLocalOrOriginBranch { + param ( + [string]$title = 'Choose branch', + [string]$message = 'Please choose a branch' + ) + [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') + + for ($i = 0; $i -lt $branches.Count; $i++) { + $branch = $branches[$i] + + [int]$branchCharIndex = -1 + + [string[]]$types = "feature","bugfix","hotfix","experimental","build","release","merge" + + $type = $types.Where({$branch.StartsWith($_)})[0] + $typeLength = 0 + if ($null -ne $type) { + $typeLength = $type.Length + 1 + } + + [char[]]$branchChars = $branch.Substring($typeLength).ToCharArray() + for ($j = 0; $j -lt $branchChars.Count; $j++) { + $char = $branchChars[$j] + + if (!$existChars.Contains($char)) { + $branchCharIndex = $j + $existChars += $char + break + } + } + + if ($branchCharIndex -ne -1) { + $branch = $branch.Insert(($branchCharIndex + $typeLength), '&') + } + + $branchOptions += $branch + } + + $branchOptions += "&quit" + + $choice = $host.UI.PromptForChoice($title, $message, $branchOptions, $branchOptions.Count - 1) + + return $branches[$choice] +} + ## git checkout [$args] function Invoke-GitCheckout { if ($args.Count -eq 0) { - $localBranch = Get-OptionsForChoosingLocalBranch "Switch branch" "Please choose a branch to switch" + $branch = Get-OptionsForChoosingLocalOrOriginBranch "Switch branch" "Please choose a branch to switch" - if ($localBranch) { - git checkout $localBranch + if ($branch) { + git checkout $branch } } else { From c1ac41dad9098025a9191230fe4ecf297dd27e2f Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 25 Jun 2022 17:35:54 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=86=95=20feat(ggdc):=20add=20Invoke-G?= =?UTF-8?q?itDiffCached?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PSGitUtils/PSGitUtils.psd1 | 3 ++- PSGitUtils/PSGitUtils.psm1 | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/PSGitUtils/PSGitUtils.psd1 b/PSGitUtils/PSGitUtils.psd1 index cfb1dd8..c41a008 100644 --- a/PSGitUtils/PSGitUtils.psd1 +++ b/PSGitUtils/PSGitUtils.psd1 @@ -82,6 +82,7 @@ 'Invoke-GitPush', 'Invoke-GitReset', 'Invoke-GitDiff', + 'Invoke-GitDiffCached', 'Remove-LocalBranchesThatNoLongerExistOnRemote' ) @@ -94,7 +95,7 @@ ) # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. - AliasesToExport = 'ggc', 'ggl', 'emojify', 'gga', 'ggb', 'ggbd', 'ggs', 'ggck', 'ggckb', 'ggpl', 'ggps', 'ggrst', 'ggd', 'ggbs' + AliasesToExport = 'ggc', 'ggl', 'emojify', 'gga', 'ggb', 'ggbd', 'ggs', 'ggck', 'ggckb', 'ggpl', 'ggps', 'ggrst', 'ggd', 'ggdc', 'ggbs' # DSC resources to export from this module # DscResourcesToExport = @() diff --git a/PSGitUtils/PSGitUtils.psm1 b/PSGitUtils/PSGitUtils.psm1 index a5cff43..a7c67ed 100644 --- a/PSGitUtils/PSGitUtils.psm1 +++ b/PSGitUtils/PSGitUtils.psm1 @@ -425,6 +425,9 @@ function Invoke-GitReset { git reset $args } ## git diff function Invoke-GitDiff { git diff $args } +## git diff +function Invoke-GitDiffCached { git diff --cached } + <# .SYNOPSIS Try to delete the local branches that no longer exist on the remote @@ -713,10 +716,11 @@ Set-Alias ggpl Invoke-GitPull Set-Alias ggps Invoke-GitPush Set-Alias ggrst Invoke-GitReset Set-Alias ggd Invoke-GitDiff +Set-Alias ggdc Invoke-GitDiffCached Set-Alias ggl Invoke-GitHistory Set-Alias emojify Invoke-Emojify Set-Alias ggbs Remove-LocalBranchesThatNoLongerExistOnRemote -Export-ModuleMember -Function Invoke-GitCommit, Format-GitCommitMessage, Invoke-GitHistory, Invoke-Emojify, Invoke-GitAdd, Invoke-GitBranch, Invoke-GitBranchDelete, Invoke-GitStatus, Invoke-GitCheckout, Get-GitOriginBranches, Invoke-GitCheckoutNewBranch, Invoke-GitPull, Invoke-GitPush, Invoke-GitReset, Invoke-GitDiff, Remove-LocalBranchesThatNoLongerExistOnRemote -Export-ModuleMember -Alias ggc, ggl, emojify, gga, ggb, ggbd, ggs, ggck, ggckb, ggpl, ggps, ggrst, ggd, ggbs +Export-ModuleMember -Function Invoke-GitCommit, Format-GitCommitMessage, Invoke-GitHistory, Invoke-Emojify, Invoke-GitAdd, Invoke-GitBranch, Invoke-GitBranchDelete, Invoke-GitStatus, Invoke-GitCheckout, Get-GitOriginBranches, Invoke-GitCheckoutNewBranch, Invoke-GitPull, Invoke-GitPush, Invoke-GitReset, Invoke-GitDiff, Invoke-GitDiffCached, Remove-LocalBranchesThatNoLongerExistOnRemote +Export-ModuleMember -Alias ggc, ggl, emojify, gga, ggb, ggbd, ggs, ggck, ggckb, ggpl, ggps, ggrst, ggd, ggdc, ggbs Export-ModuleMember -Variable $global:GitUtilsConfig From e6e1793d5199de656d6bfc9a97854f61aff80c9a Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 25 Jun 2022 17:54:53 +0800 Subject: [PATCH 3/5] feat(ggckb)(ggckb): ignore the type name of branch in ggckb --- PSGitUtils/PSGitUtils.psm1 | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/PSGitUtils/PSGitUtils.psm1 b/PSGitUtils/PSGitUtils.psm1 index a7c67ed..b85be43 100644 --- a/PSGitUtils/PSGitUtils.psm1 +++ b/PSGitUtils/PSGitUtils.psm1 @@ -273,7 +273,7 @@ function Get-OptionsForChoosingLocalOrOriginBranch { $type = $types.Where({$branch.StartsWith($_)})[0] $typeLength = 0 - if ($null -ne $type) { + if ($type) { $typeLength = $type.Length + 1 } @@ -363,15 +363,10 @@ function Invoke-GitCheckoutNewBranch { $typeIndex = (Get-Host).UI.PromptForChoice("Creating a new branch and checkout to...", "${step}. Please choose a type for the new branch", $branchTypeOptions, 7) - switch ($typeIndex) { - 0 { $branch = "feature/$branch" } - 1 { $branch = "bugfix/$branch" } - 2 { $branch = "hotfix/$branch" } - 3 { $branch = "experimental/$branch" } - 4 { $branch = "build/$branch" } - 5 { $branch = "release/$branch" } - 6 { $branch = "merge/$branch" } - Default {} + [string[]]$types = "feature","bugfix","hotfix","experimental","build","release","merge" + [string]$type = $types[$typeIndex] + if ($type) { + $branch = $type + "/" + $branch } Write-Host @@ -380,11 +375,19 @@ function Invoke-GitCheckoutNewBranch { [System.Management.Automation.Host.ChoiceDescription[]]$originBranchOptions = @() [string[]]$originBranches = Get-GitOriginBranches -onlyName [char[]]$existChars = @('n') + for ($i = 0; $i -lt $originBranches.Count; $i++) { $originBranch = $originBranches[$i] [int]$originBranchCharIndex = -1 - [char[]]$originBranchChars = $originBranch.ToCharArray() + + $type = $types.Where({$originBranch.StartsWith($_)})[0] + $typeLength = 0 + if ($type) { + $typeLength = $type.Length + 1 + } + + [char[]]$originBranchChars = $originBranch.Substring($typeLength).ToCharArray() for ($j = 0; $j -lt $originBranchChars.Count; $j++) { $char = $originBranchChars[$j] @@ -396,7 +399,8 @@ function Invoke-GitCheckoutNewBranch { } if ($originBranchCharIndex -ne -1) { - $originBranch = $originBranch.Insert($originBranchCharIndex, '&') + Write-Host $originBranchCharIndex $typeLength $originBranch + $originBranch = $originBranch.Insert(($originBranchCharIndex + $typeLength), '&') } $item = 'origin/' + $originBranch From 994a7279fa67c5970c817299dbd8b34f010179a6 Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 25 Jun 2022 17:55:30 +0800 Subject: [PATCH 4/5] chore: 1.11.0 --- PSGitUtils/PSGitUtils.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSGitUtils/PSGitUtils.psd1 b/PSGitUtils/PSGitUtils.psd1 index c41a008..aa8d175 100644 --- a/PSGitUtils/PSGitUtils.psd1 +++ b/PSGitUtils/PSGitUtils.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGitUtils.psm1' # Version number of this module. - ModuleVersion = '1.10.0' + ModuleVersion = '1.11.0' # Supported PSEditions # CompatiblePSEditions = @() From a15f2becbe7b242919687670e5977f0ba92586d7 Mon Sep 17 00:00:00 2001 From: capdiem Date: Sat, 25 Jun 2022 17:59:59 +0800 Subject: [PATCH 5/5] fix(ggcm)(ggcm): !EmojiFirst not work --- PSGitUtils/PSGitUtils.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PSGitUtils/PSGitUtils.psm1 b/PSGitUtils/PSGitUtils.psm1 index b85be43..0437c32 100644 --- a/PSGitUtils/PSGitUtils.psm1 +++ b/PSGitUtils/PSGitUtils.psm1 @@ -598,8 +598,8 @@ function Format-GitCommitMessage { $newMessage += $type } - if ($config.Scope -and ![string]::IsNullOrEmpty($scope)) { - $newMessage += "(" + $scope + ")" + if ($config.Emoji -and ![string]::IsNullOrEmpty($emoji)) { + $newMessage += $emoji + " " } }