chiark / gitweb /
put worktree checks in place
[topgit.git] / tg.sh
diff --git a/tg.sh b/tg.sh
index 8c23d26b9a62ddcc1869bb70299862c32edd4403..a3ee0f8de1c4c106b553e0f2f3ae008a146c44e4 100644 (file)
--- a/tg.sh
+++ b/tg.sh
@@ -249,6 +249,16 @@ do_help()
 [ -d "@cmddir@" ] ||
        die "No command directory: '@cmddir@'"
 
+# Make sure we are in the worktree, not under .git
+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
+
 ## Initial setup
 
 set -e