From: martin f. krafft Date: Fri, 23 Jan 2009 05:35:35 +0000 (+1100) Subject: Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7d639febf13c030f524d6fa41cdb9c06d0cfc83d;p=topgit.git Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree Conflicts: tg.sh --- 7d639febf13c030f524d6fa41cdb9c06d0cfc83d diff --cc tg.sh index f8c8de4,7c6c09f..21c4d6b --- a/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() {