chiark / gitweb /
Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree fixes/ensure-worktree
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 28 Dec 2011 01:51:43 +0000 (01:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 28 Dec 2011 01:51:43 +0000 (01:51 +0000)
Conflicts:
tg.sh

1  2 
tg.sh

diff --cc tg.sh
index 85f004760dc9d48c72faf2c7e7dc57a2b38438b5,9082d88910569af146dde388332bedd0b555ffc1..87d34247b680f9d02d721745d5fe05d4810902f8
--- 1/tg.sh
--- 2/tg.sh
+++ b/tg.sh
@@@ -18,38 -18,27 +18,41 @@@ die(
        exit 1
  }
  
- # cat_file "topic:file"
- # Like `git cat-file blob $1`, but topics '(i)' and '(w)' means index and worktree
 +# 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:PATH [FROM]
+ # cat the file PATH from branch TOPIC when FROM is empty.
+ # FROM can be -i or -w, than the file will be from the index or worktree,
+ # respectively. The caller should than ensure that HEAD is TOPIC, to make sense.
  cat_file()
  {
-       arg="$1"
-       case "$arg" in
-       '(w):'*)
-               arg=$(echo "$arg" | tail --bytes=+5)
-               cat "$arg"
-               return
+       path="$1"
+       case "${2-}" in
+       -w)
+               cat "$root_dir/${path#*:}"
                ;;
-       '(i):'*)
+       -i)
                # ':file' means cat from index
-               arg=$(echo "$arg" | tail --bytes=+5)
-               git cat-file blob ":$arg"
+               git cat-file blob ":${path#*:}"
+               ;;
+       '')
+               git cat-file blob "$path"
                ;;
        *)
-               git cat-file blob "$arg"
+               die "Wrong argument to cat_file: '$2'"
+               ;;
        esac
  }