chiark / gitweb /
Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree
authormartin f. krafft <madduck@debian.org>
Fri, 23 Jan 2009 05:35:35 +0000 (16:35 +1100)
committermartin f. krafft <madduck@debian.org>
Fri, 23 Jan 2009 05:35:35 +0000 (16:35 +1100)
Conflicts:
tg.sh

1  2 
tg.sh

diff --cc tg.sh
index f8c8de4ba859d76d254580ef88041b3bdce05f19,7c6c09f2eaa709933dc4631495c7b440556882db..21c4d6bc93c123b2a3c73f344e516f89a3051ba5
--- 1/tg.sh
--- 2/tg.sh
+++ b/tg.sh
@@@ -17,20 -18,27 +18,41 @@@ 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()
+ {
+       arg="$1"
+       case "$arg" in
+       '(w):'*)
+               arg=$(echo "$arg" | tail --bytes=+5)
+               cat "$arg"
+               return
+               ;;
+       '(i):'*)
+               # ':file' means cat from index
+               arg=$(echo "$arg" | tail --bytes=+5)
+               git cat-file blob ":$arg"
+               ;;
+       *)
+               git cat-file blob "$arg"
+       esac
+ }
  # setup_hook NAME
  setup_hook()
  {