chiark / gitweb /
tg remote: New command
authorPetr Baudis <pasky@suse.cz>
Mon, 1 Sep 2008 00:33:47 +0000 (02:33 +0200)
committerPetr Baudis <pasky@suse.cz>
Mon, 1 Sep 2008 00:33:47 +0000 (02:33 +0200)
Register TopGit-aware remote, populate local branches from one.

README
tg-remote.sh [new file with mode: 0644]

diff --git a/README b/README
index 89899041088cf0b3303d168eb9178b1fb9133ee3..0c0002c7dd416c51bc22f05cc46cfca0306b1a75 100644 (file)
--- a/README
+++ b/README
@@ -250,6 +250,19 @@ tg patch
        TODO: tg patch -i to base at index instead of branch,
                -w for working tree
 
+tg remote
+~~~~~~~~~
+       Register given remote as TopGit-controlled. This will create
+       the namespace for the remote branch bases and teach 'git fetch'
+       and 'git push' to operate on them.
+
+       It takes a mandatory remote name argument, and optional
+       '--populate' switch - use that for your origin-style remote,
+       it will seed the local topic branch system based on the
+       remote topic branches. '--populate' will also make 'tg remote'
+       automatically fetch the remote and 'tg update' to look at
+       branches of this remote for updates by default.
+
 tg summary
 ~~~~~~~~~~
        Show overview of all TopGit-tracked topic branches and their
@@ -434,7 +447,8 @@ self-contained topic system in the remote repository, and increased conceptual
 simplicity.
 
 Thus, we choose to instantiate all the topic branches of given remote locally;
-tg update will also check if a branch can be updated from its corresponding
+this is performed by 'tg remote --populate'.
+'tg update' will also check if a branch can be updated from its corresponding
 remote branch. The logic is somewhat involved if we should DTRT.
 First, we update the base, handling the remote branch as if it was the first
 dependency; thus, conflict resolutions made in the remote branch will be
diff --git a/tg-remote.sh b/tg-remote.sh
new file mode 100644 (file)
index 0000000..dd3d666
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/sh
+# TopGit - A different patch queue manager
+# (c) Petr Baudis <pasky@suse.cz>  2008
+# GPLv2
+
+populate= # Set to 1 if we shall seed local branches with this
+name=
+
+
+## Parse options
+
+while [ -n "$1" ]; do
+       arg="$1"; shift
+       case "$arg" in
+       --populate)
+               populate=1;;
+       -*)
+               echo "Usage: tg remote [--populate] REMOTE" >&2
+               exit 1;;
+       *)
+               name="$arg";;
+       esac
+done
+
+git config "remote.$name.url" >/dev/null || die "unknown remote '$name'"
+
+
+## Configure the remote
+
+git config --add "remote.$name.fetch" "+refs/top-bases/*:refs/remotes/$name/top-bases/*"
+git config --add "remote.$name.push" "+refs/top-bases/*:refs/top-bases/*"
+git config --add "remote.$name.push" "+refs/heads/*:refs/heads/*"
+
+info "Remote $name can now follow TopGit topic branches."
+if [ -z "$populate" ]; then
+       info "Next, do: git fetch $name"
+       exit
+fi
+
+
+## Populate local branches
+
+info "Populating local topic branches from remote '$name'..."
+
+git fetch "$name"
+git for-each-ref "refs/remotes/$name/top-bases" |
+       while read rev type ref; do
+               branch="${ref#refs/remotes/$name/top-bases/}"
+               if git rev-parse "$branch" >/dev/null 2>&1; then
+                       git rev-parse "refs/top-bases/$branch" >/dev/null 2>&1 ||
+                               git update-ref "refs/top-bases/$branch" "$rev"
+                       info "Skipping branch $branch: Already exists"
+                       continue
+               fi
+               info "Adding branch $branch..."
+               git update-ref "refs/top-bases/$branch" "$rev"
+               git update-ref "refs/heads/$branch" "$(git rev-parse "$name/$branch")"
+       done
+
+git config "topgit.remote" "$name"
+info "The remote '$name' is now the default source of topic branches."