From 867bd8ed52fad241a371cfc2dbce9f53e775cb7b Mon Sep 17 00:00:00 2001 From: Alejandro Gonzalez <106210314+alex-glez-felix@users.noreply.github.com> Date: Tue, 18 Feb 2025 11:11:33 -0600 Subject: [PATCH] add gswm and gswd command --- aliases.md | 2 ++ src/aliases.ps1 | 8 ++++++++ src/git-aliases.psm1 | 2 ++ src/utils.ps1 | 18 ++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/aliases.md b/aliases.md index 6271db7..be8babc 100644 --- a/aliases.md +++ b/aliases.md @@ -118,6 +118,8 @@ | `gsts` | `git stash show --text $args` | | `gsu` | `git submodule update $args` | | `gsw` | `git switch $args` | +| `gswm` | Script to switch to main branch. | +| `gswd` | Script to switch to develop branch. | | `gts` | `git tag -s $args` | | `gunignore`| `git update-index --no-assume-unchanged $args` | | `gunwip`| Script to remove a WIP commit. | diff --git a/src/aliases.ps1 b/src/aliases.ps1 index 89f1f81..1738c63 100644 --- a/src/aliases.ps1 +++ b/src/aliases.ps1 @@ -400,6 +400,14 @@ function gsu { function gsw { git switch $args } +function gswm { + $MainBranch = Get-Git-MainBranch + git switch $MainBranch $args +} +function gswm { + $DevelopBranch = Get-Git-DevelopBranch + git switch $DevelopBranch $args +} function gts { git tag -s $args } diff --git a/src/git-aliases.psm1 b/src/git-aliases.psm1 index 393e3bf..f9c2a6b 100644 --- a/src/git-aliases.psm1 +++ b/src/git-aliases.psm1 @@ -123,6 +123,8 @@ $FunctionsToExport = @( 'gsts', 'gsu', 'gsw', + 'gswm', + 'gswd', 'gts', 'gunignore', 'gunwip', diff --git a/src/utils.ps1 b/src/utils.ps1 index 87f8a47..e4a3e70 100644 --- a/src/utils.ps1 +++ b/src/utils.ps1 @@ -32,6 +32,24 @@ function Get-Git-MainBranch { return 'master' } +function Get-Git-DevelopBranch { + git rev-parse --git-dir *> $null + if ($LASTEXITCODE -ne 0) { + return + } + + $branches = @("dev", "devel", "develop", "development") + + foreach ($branch in $branches) { + & git show-ref -q --verify "refs/heads/$branch" *> $null + if ($LASTEXITCODE -eq 0) { + return $branch + } + } + + return "develop" +} + # Don't add `Remove-Alias` on PowerShell >= 6. # PowerShell >= 6 already has built-in `Remove-Alias`. # Let use built-in `Remove-Alias` on PowerShell >= 6.