Skip to content

Commit dcf2a42

Browse files
authored
feat: custom remote branch path support option for move command (#58)
It adds support for using a custom remote branch path like `<origin>/<master>` when wanting to switch to a specific remote branch. It makes it easier to switch between multiple remote branches apart from the current one (e.g., `origin`). The `-r, --remote-branch` option requires the `-u, --upstream` to be provided together. ``` # Using it with `-u, --upstream` move --upstream --remote-branch my-remote/my-branch move -u -r my-remote/some/branch move -ur my-remote/my-branch # Using it with `-n, --no-apply-stash` move -nur my-remote/my-branch move -unr my-remote/some/branch ```
1 parent 91bda1d commit dcf2a42

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

completions/move.fish

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ complete -f -x -c move \
2424
-s u -l upstream \
2525
-a '(__fish_git_branches)' \
2626
-d "Fetch a remote branch and switch to it applying current stash"
27+
28+
complete -f -x -c move \
29+
-s r -l remote-branch \
30+
-n 'contains -- -u (commandline -opc); or contains -- --upstream (commandline -opc)' \
31+
-a '(__fish_git_branches)' \
32+
-d "Use a custom remote branch path like '<origin>/<master>' when wanting to switch."

conf.d/gitnow.fish

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
359359

360360
set -l v_upstream
361361
set -l v_no_apply_stash
362+
set -l v_remote
363+
set -l v_remote_v
362364
set -l v_branch
363365
set -l v_prev
364366

@@ -368,9 +370,18 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
368370
set v_upstream $v
369371
case -n --no-apply-stash
370372
set v_no_apply_stash $v
373+
case -r --remote
374+
set v_remote $v
371375
case -nu -un
372376
set v_upstream "-u"
373377
set v_no_apply_stash "-n"
378+
case -nur -unr
379+
set v_upstream "-u"
380+
set v_no_apply_stash "-n"
381+
set v_remote "-r"
382+
case -ur
383+
set v_upstream "-u"
384+
set v_remote "-r"
374385
case -p --prev
375386
set v_prev "true"
376387
case -h --help
@@ -382,12 +393,18 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
382393
echo "OPTIONS:"
383394
echo " -n --no-apply-stash Switch to a local branch but without applying current stash"
384395
echo " -u --upstream Fetch a remote branch and switch to it applying current stash. It can be combined with --no-apply-stash"
396+
echo " -r --remote-branch Use a custom remote branch path like '<origin>/<master>' when wanting to switch. It requires the '-u, --upstream' option."
385397
echo " -p --prev Switch to a previous branch if different than the current one (equivalent to \"move -\"). It uses `--no-apply-stash` option by default."
386398
echo " -h --help Show information about the options for this command"
387399
return
388400
case -\*
389401
case '*'
390-
set v_branch $v
402+
if begin test -n "$v_remote"; and not test -n "$v_remote_v"; end
403+
set v_remote_v (command echo "$v" | cut -d '/' -f 1)
404+
set v_branch (command echo "$v" | cut -d '/' -f 2)
405+
else
406+
set v_branch $v
407+
end
391408
end
392409
end
393410

@@ -414,9 +431,18 @@ function move -d "GitNow: Switch from current branch to another but stashing unc
414431

415432
# Fetch branch from remote
416433
if test -n "$v_upstream"
417-
set -l v_remote (__gitnow_current_remote)
418-
command git fetch $v_remote $v_branch:refs/remotes/$v_remote/$v_branch
419-
command git checkout --track $v_remote/$v_branch
434+
echo "Switching to the specified remote branch."
435+
436+
set -l remote "$v_remote_v"
437+
if test -n "$remote"
438+
echo "A specific remote is provided, using '$remote'..."
439+
else
440+
set remote (__gitnow_current_remote)
441+
echo "Using the default remote '$remote'..."
442+
end
443+
444+
command git fetch $remote $v_branch:refs/remotes/$remote/$v_branch
445+
command git checkout --track $remote/$v_branch
420446
return
421447
end
422448

0 commit comments

Comments
 (0)