From e0e1ce4d27242585b6edeb35ca3cf62a6454b074 Mon Sep 17 00:00:00 2001 From: "martin f. krafft" Date: Fri, 21 Nov 2008 13:04:43 +0100 Subject: [PATCH] factor out checks into function Signed-off-by: martin f. krafft --- tg.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tg.sh b/tg.sh index a3ee0f8..f8c8de4 100644 --- a/tg.sh +++ b/tg.sh @@ -17,6 +17,20 @@ 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 +} + # setup_hook NAME setup_hook() { @@ -249,15 +263,7 @@ 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 +ensure_git_repo_or_die ## Initial setup -- 2.30.2