chiark / gitweb /
Merge commit 'refs/top-bases/fixes/more-help' into fixes/more-help
[topgit.git] / tg-remote.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # (c) Petr Baudis <pasky@suse.cz>  2008
4 # GPLv2
5
6 populate= # Set to 1 if we shall seed local branches with this
7 name=
8
9
10 ## Parse options
11
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;;
20         *)
21                 name="$arg";;
22         esac
23 done
24
25 [ -n "$name" ] ||
26         name="$base_remote"
27
28 git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"
29
30
31 ## Configure the remote
32
33 git config --replace-all "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*" "\\+refs/top-bases/\\*:refs/remotes/$name/top-bases/\\*"
34
35 if git config --get-all "remote.$name.push" "\\+refs/top-bases/\\*:refs/top-bases/\\*" >/dev/null && test "xtrue" != "x$(git config --bool --get topgit.dontwarnonoldpushspecs)"; then
36         info "Probably you want to remove the push specs introduced by an old version of topgit:"
37         info '       git config --unset-all "remote.'$name'.push" "\\+refs/top-bases/\\*:refs/top-bases/\\*"'
38         info '       git config --unset-all "remote.'$name'.push" "\\+refs/heads/\\*:refs/heads/\\*"'
39         info '(or use git config --bool --add topgit.dontwarnonoldpushspecs true to get rid of this warning)'
40 fi
41
42 info "Remote $name can now follow TopGit topic branches."
43 if [ -z "$populate" ]; then
44         info "Next, do: git fetch $name"
45         exit
46 fi
47
48
49 ## Populate local branches
50
51 info "Populating local topic branches from remote '$name'..."
52
53 git fetch "$name"
54 git for-each-ref "refs/remotes/$name/top-bases" |
55         while read rev type ref; do
56                 branch="${ref#refs/remotes/$name/top-bases/}"
57                 if git rev-parse "$branch" >/dev/null 2>&1; then
58                         git rev-parse "refs/top-bases/$branch" >/dev/null 2>&1 ||
59                                 git update-ref "refs/top-bases/$branch" "$rev"
60                         info "Skipping branch $branch: Already exists"
61                         continue
62                 fi
63                 info "Adding branch $branch..."
64                 git update-ref "refs/top-bases/$branch" "$rev"
65                 git update-ref "refs/heads/$branch" "$(git rev-parse "$name/$branch")"
66         done
67
68 git config "topgit.remote" "$name"
69 info "The remote '$name' is now the default source of topic branches."
70
71 # vim:noet