chiark / gitweb /
Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 3 Mar 2009 10:01:23 +0000 (11:01 +0100)
committerUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Tue, 3 Mar 2009 10:01:23 +0000 (11:01 +0100)
1  2 
tg.sh

diff --combined tg.sh
index 21c4d6bc93c123b2a3c73f344e516f89a3051ba5,f0496f1b6ade99b1f9290f3cc5fe7096fc4373ba..3183b80663ec4ab5accc48b8d60c5e26584051b2
--- 1/tg.sh
--- 2/tg.sh
+++ b/tg.sh
@@@ -18,20 -18,6 +18,20 @@@ die(
        exit 1
  }
  
 +# Make sure we are in the worktree, not under .git; die otherwise
 +ensure_git_repo_or_die()
 +{
 +      local is_inside_repo is_inside_git_dir
 +      is_inside_repo=1
 +      is_inside_git_dir=$(git rev-parse --is-inside-git-dir 2>/dev/null) ||
 +              is_inside_repo=0
 +
 +      case "$is_inside_repo/$is_inside_git_dir" in
 +      0*) die "Cannot run outside of a Git repository.";;
 +      1/true) die "Cannot run from inside \`.git\` hierarchy, please switch to work-tree.";;
 +      esac
 +}
 +
  # cat_file "topic:file"
  # Like `git cat-file blob $1`, but topics '(i)' and '(w)' means index and worktree
  cat_file()
@@@ -113,7 -99,7 +113,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
@@@ -130,6 -116,16 +130,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,
@@@ -152,7 -148,12 +162,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
@@@ -323,8 -324,6 +338,8 @@@ setup_pager(
  [ -d "@cmddir@" ] ||
        die "No command directory: '@cmddir@'"
  
 +ensure_git_repo_or_die
 +
  ## Initial setup
  
  set -e