[+] brup
This commit is contained in:
@@ -98,6 +98,16 @@ function git-update-main --description 'Checkout and fast-forward the main branc
|
||||
command git pull --ff-only
|
||||
end
|
||||
|
||||
function git-fetch-main --description 'Fetch the latest main branch from origin'
|
||||
set -l main_branch $argv[1]
|
||||
if test -z "$main_branch"
|
||||
set main_branch (git-main-branch); or return 1
|
||||
end
|
||||
|
||||
command git fetch origin "+refs/heads/$main_branch:refs/remotes/origin/$main_branch"; or return 1
|
||||
printf '%s\n' "$main_branch"
|
||||
end
|
||||
|
||||
function br --description 'Switch to an existing branch, or create one from updated main'
|
||||
if test (count $argv) -ne 1
|
||||
echo 'Usage: br <branch-name>'
|
||||
@@ -137,6 +147,19 @@ function bru --description 'Update the current branch by rebasing it on updated
|
||||
command git rebase "$main_branch"
|
||||
end
|
||||
|
||||
function brup --description 'Merge the latest origin main branch into the current branch'
|
||||
set -l current_branch (command git symbolic-ref --quiet --short HEAD 2>/dev/null)
|
||||
if test -z "$current_branch"
|
||||
echo 'Could not determine current branch.'
|
||||
return 1
|
||||
end
|
||||
|
||||
git-require-clean; or return 1
|
||||
|
||||
set -l main_branch (git-fetch-main); or return 1
|
||||
command git merge "refs/remotes/origin/$main_branch"
|
||||
end
|
||||
|
||||
function git-env --description 'Alias common git subcommands into the shell'
|
||||
set -l git_commands add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag
|
||||
for cmd in $git_commands
|
||||
|
||||
+25
-1
@@ -547,7 +547,7 @@ function git-main-branch {
|
||||
}
|
||||
|
||||
Write-Error 'Could not determine main branch.'
|
||||
return 1
|
||||
return
|
||||
}
|
||||
|
||||
function git-update-main {
|
||||
@@ -560,6 +560,16 @@ function git-update-main {
|
||||
Invoke-RawGit pull --ff-only
|
||||
}
|
||||
|
||||
function git-fetch-main {
|
||||
param([string]$MainBranch)
|
||||
if (-not $MainBranch) { $MainBranch = git-main-branch | Select-Object -First 1 }
|
||||
if (-not $MainBranch) { return }
|
||||
|
||||
Invoke-RawGit fetch origin "+refs/heads/${MainBranch}:refs/remotes/origin/${MainBranch}"
|
||||
if ($LASTEXITCODE -ne 0) { return }
|
||||
Write-Output $MainBranch
|
||||
}
|
||||
|
||||
function br {
|
||||
param([Parameter(Mandatory = $true)][string]$Branch)
|
||||
if (-not (Test-GitCleanWorktree)) { return 1 }
|
||||
@@ -600,6 +610,20 @@ function bru {
|
||||
Invoke-RawGit rebase $mainBranch
|
||||
}
|
||||
|
||||
function brup {
|
||||
$currentBranch = Invoke-RawGit symbolic-ref --quiet --short HEAD 2>$null
|
||||
if ($LASTEXITCODE -ne 0 -or -not $currentBranch) {
|
||||
Write-Error 'Could not determine current branch.'
|
||||
return 1
|
||||
}
|
||||
|
||||
if (-not (Test-GitCleanWorktree)) { return 1 }
|
||||
|
||||
$mainBranch = git-fetch-main | Select-Object -First 1
|
||||
if (-not $mainBranch) { return 1 }
|
||||
Invoke-RawGit merge "refs/remotes/origin/$mainBranch"
|
||||
}
|
||||
|
||||
function git-env {
|
||||
foreach ($cmd in @('add', 'bisect', 'branch', 'checkout', 'clone', 'commit', 'diff', 'fetch', 'grep', 'init', 'log', 'merge', 'pull', 'push', 'rebase', 'reset', 'restore', 'show', 'stash', 'tag')) {
|
||||
$name = $cmd
|
||||
|
||||
@@ -97,6 +97,16 @@ git-update-main() {
|
||||
command git pull --ff-only
|
||||
}
|
||||
|
||||
git-fetch-main() {
|
||||
local main_branch="$1"
|
||||
if [[ -z "$main_branch" ]]; then
|
||||
main_branch=$(git-main-branch) || return 1
|
||||
fi
|
||||
|
||||
command git fetch origin "+refs/heads/${main_branch}:refs/remotes/origin/${main_branch}" || return 1
|
||||
echo "$main_branch"
|
||||
}
|
||||
|
||||
br() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
echo 'Usage: br <branch-name>'
|
||||
@@ -139,6 +149,21 @@ bru() {
|
||||
command git rebase "$main_branch"
|
||||
}
|
||||
|
||||
brup() {
|
||||
local current_branch
|
||||
current_branch=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null)
|
||||
if [[ -z "$current_branch" ]]; then
|
||||
echo 'Could not determine current branch.'
|
||||
return 1
|
||||
fi
|
||||
|
||||
git-require-clean || return 1
|
||||
|
||||
local main_branch
|
||||
main_branch=$(git-fetch-main) || return 1
|
||||
command git merge "refs/remotes/origin/$main_branch"
|
||||
}
|
||||
|
||||
# Git environment
|
||||
git-env() {
|
||||
git_commands=( add bisect branch checkout clone commit diff fetch grep init log merge pull push rebase reset restore show stash tag )
|
||||
|
||||
Reference in New Issue
Block a user