chiark / gitweb /
Optimize creation of orig.tar.gz a bit
[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 git config --replace-all "remote.$name.push" "+refs/top-bases/*:refs/top-bases/*" "\\+refs/top-bases/\\*:refs/top-bases/\\*"
32 git config --replace-all "remote.$name.push" "+refs/heads/*:refs/heads/*" "\\+refs/heads/\\*:refs/heads/\\*"
33
34 info "Remote $name can now follow TopGit topic branches."
35 if [ -z "$populate" ]; then
36         info "Next, do: git fetch $name"
37         exit
38 fi
39
40
41 ## Populate local branches
42
43 info "Populating local topic branches from remote '$name'..."
44
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
54                 fi
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
59
60 git config "topgit.remote" "$name"
61 info "The remote '$name' is now the default source of topic branches."
62
63 # vim:noet