From 8d1566c688059ef631b9a2456021978c5102372a Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 6 Jan 2012 16:05:40 +0800 Subject: [PATCH] Added 'git_swap_remotes' script to swap names between two remotes --- lib/git/tools.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/git/tools.sh b/lib/git/tools.sh index b8b1e7f..c04bce2 100644 --- a/lib/git/tools.sh +++ b/lib/git/tools.sh @@ -71,7 +71,7 @@ git_exclude_basename() { # git_bisect_grep() { if [ -z "$2" ]; then - echo "Usage: git_bisect_grep "; + echo "Usage: $0 "; exit 1 fi if [ -n "$3" ]; then search_path="$3"; else search_path="."; fi @@ -88,7 +88,7 @@ git_bisect_grep() { # and runs git rm --cached path/to/submodule. git_submodule_rm() { if [ -z "$1" ]; then - echo "Usage: git_submodule_rm path/to/submodule (no trailing slash)" + echo "Usage: $0 path/to/submodule (no trailing slash)" exit 1 fi git config -f .git/config --remove-section "submodule.$1" @@ -97,3 +97,21 @@ git_submodule_rm() { rm -rf "$1" git rm --cached "$1" } + + +# Swaps git remotes +# i.e. swap origin <-> username +git_swap_remotes() { + if [ -z "$2" ]; then + echo "Usage: $0 remote1 remote2" + exit 1 + fi + git remote rename "$1" "$1_temp" + git remote rename "$2" "$1" + git remote rename "$1_temp" "$2" + echo "Swapped $1 <-> $2" +} +# (use git fetch tab completion) +if [ "$shell" = "bash" ]; then + complete -o default -o nospace -F _git_fetch git_swap_remotes +fi \ No newline at end of file