From: Ian Jackson Date: Wed, 28 Dec 2011 01:51:43 +0000 (+0000) Subject: Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topgit.git;a=commitdiff_plain;h=6a1c58e7652027c584b14cd0037ad5eee8851e5c Merge commit 'refs/top-bases/fixes/ensure-worktree' into fixes/ensure-worktree Conflicts: tg.sh --- 6a1c58e7652027c584b14cd0037ad5eee8851e5c diff --cc tg.sh index 85f0047,9082d88..87d3424 --- a/tg.sh +++ b/tg.sh @@@ -18,38 -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 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 }