chiark / gitweb /
Merge branch 'upstream' of git.debian.org:/git/collab-maint/topgit
[topgit.git] / tg.sh
diff --git a/tg.sh b/tg.sh
index 7c6c09f2eaa709933dc4631495c7b440556882db..f0496f1b6ade99b1f9290f3cc5fe7096fc4373ba 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -99,7 +99,7 @@ measure_branch()
 # Whether B1 is a superset of B2.
 branch_contains()
 {
-       [ -z "$(git rev-list ^"$1" "$2" --)" ]
+       [ -z "$(git rev-list --max-count=1 ^"$1" "$2" --)" ]
 }
 
 # ref_exists REF
@@ -116,6 +116,16 @@ has_remote()
        [ -n "$base_remote" ] && ref_exists "remotes/$base_remote/$1"
 }
 
+branch_annihilated()
+{
+       _name="$1";
+
+       # use the merge base in case the base is ahead.
+       mb="$(git merge-base "refs/top-bases/$_name" "$_name")";
+
+       test "$(git rev-parse "$mb^{tree}")" = "$(git rev-parse "$_name^{tree}")";
+}
+
 # recurse_deps CMD NAME [BRANCHPATH...]
 # Recursively eval CMD on all dependencies of NAME.
 # CMD can refer to $_name for queried branch name,
@@ -138,7 +148,12 @@ recurse_deps()
        if has_remote "top-bases/$_name"; then
                echo "refs/remotes/$base_remote/top-bases/$_name" >>"$_depsfile"
        fi
-       git cat-file blob "$_name:.topdeps" >>"$_depsfile"
+
+       # if the branch was annihilated, there exists no .topdeps file
+       if ! branch_annihilated "$_name"; then
+               #TODO: handle nonexisting .topdeps?
+               git cat-file blob "$_name:.topdeps" >>"$_depsfile";
+       fi;
 
        _ret=0
        while read _dep; do