chiark / gitweb /
tg2quilt.mk: don't call git-status with git-commit options
[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 git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"
26
27
28 ## Configure the remote
29
30 git config --replace-all "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*" "\\+refs/top-bases/\\*:refs/remotes/$name/top-bases/\\*"
31
32 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
33         info "Probably you want to remove the push specs introduced by an old version of topgit:"
34         info '       git config --unset-all "remote.'$name'.push" "\\+refs/top-bases/\\*:refs/top-bases/\\*"'
35         info '       git config --unset-all "remote.'$name'.push" "\\+refs/heads/\\*:refs/heads/\\*"'
36         info '(or use git config --bool --add topgit.dontwarnonoldpushspecs true to get rid of this warning)'
37 fi
38
39 info "Remote $name can now follow TopGit topic branches."
40 if [ -z "$populate" ]; then
41         info "Next, do: git fetch $name"
42         exit
43 fi
44
45
46 ## Populate local branches
47
48 info "Populating local topic branches from remote '$name'..."
49
50 git fetch "$name"
51 git for-each-ref "refs/remotes/$name/top-bases" |
52         while read rev type ref; do
53                 branch="${ref#refs/remotes/$name/top-bases/}"
54                 if git rev-parse "$branch" >/dev/null 2>&1; then
55                         git rev-parse "refs/top-bases/$branch" >/dev/null 2>&1 ||
56                                 git update-ref "refs/top-bases/$branch" "$rev"
57                         info "Skipping branch $branch: Already exists"
58                         continue
59                 fi
60                 info "Adding branch $branch..."
61                 git update-ref "refs/top-bases/$branch" "$rev"
62                 git update-ref "refs/heads/$branch" "$(git rev-parse "$name/$branch")"
63         done
64
65 git config "topgit.remote" "$name"
66 info "The remote '$name' is now the default source of topic branches."
67
68 # vim:noet