tg-completion: complete options for `tg remote`
[topgit/kirr.git] / tg-remote.sh
blobc3e8bd3968b9075963743a39198e9adcb2124140
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz> 2008
4 # GPLv2
6 populate= # Set to 1 if we shall seed local branches with this
7 name=
10 ## Parse options
12 while [ -n "$1" ]; do
13 arg="$1"; shift
14 case "$arg" in
15 --populate)
16 populate=1;;
17 -*)
18 echo "Usage: tg [...] remote [--populate] REMOTE" >&2
19 exit 1;;
21 name="$arg";;
22 esac
23 done
25 git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"
28 ## Configure the remote
30 git config --add "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*"
31 git config --add "remote.$name.push" "+refs/top-bases/*:refs/top-bases/*"
32 git config --add "remote.$name.push" "+refs/heads/*:refs/heads/*"
34 info "Remote $name can now follow TopGit topic branches."
35 if [ -z "$populate" ]; then
36 info "Next, do: git fetch $name"
37 exit
41 ## Populate local branches
43 info "Populating local topic branches from remote '$name'..."
45 git fetch "$name"
46 git for-each-ref "refs/remotes/$name/top-bases" |
47 while read rev type ref; do
48 branch="${ref#refs/remotes/$name/top-bases/}"
49 if git rev-parse "$branch" >/dev/null 2>&1; then
50 git rev-parse "refs/top-bases/$branch" >/dev/null 2>&1 ||
51 git update-ref "refs/top-bases/$branch" "$rev"
52 info "Skipping branch $branch: Already exists"
53 continue
55 info "Adding branch $branch..."
56 git update-ref "refs/top-bases/$branch" "$rev"
57 git update-ref "refs/heads/$branch" "$(git rev-parse "$name/$branch")"
58 done
60 git config "topgit.remote" "$name"
61 info "The remote '$name' is now the default source of topic branches."
63 # vim:noet