lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 1e1716f 5/7: Assert rather than assume


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 1e1716f 5/7: Assert rather than assume
Date: Thu, 16 Nov 2017 11:09:55 -0500 (EST)

branch: master
commit 1e1716ff2a40df817ab2390535c43f6509058583
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Assert rather than assume
    
    Added an enforced precondition that $PWD is a git toplevel directory.
    Renumbered exit codes so that each is unique.
---
 check_git_setup.sh | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/check_git_setup.sh b/check_git_setup.sh
index 3d151dd..2488292 100755
--- a/check_git_setup.sh
+++ b/check_git_setup.sh
@@ -21,10 +21,14 @@
 # email: <address@hidden>
 # snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
 
-# Do this in the directory where this script resides, which is
-# deliberately the "toplevel" directory.
+# Navigate to the directory where this script resides, and make sure
+# it's a git "toplevel" directory.
 
 cd $(dirname $(readlink -f $0))
+toplevel=$(git rev-parse --show-toplevel)
+printf "'%s' is current directory\n" $PWD
+printf "'%s' is git toplevel directory\n" $toplevel
+[ "$PWD" = "$toplevel" ] || { printf "fail: PWD is not toplevel\n"; exit 1; }
 
 # For msw (cygwin) only, make sure 'core.filemode' is "false". See:
 #   https://lists.nongnu.org/archive/html/lmi/2017-11/msg00018.html
@@ -66,11 +70,11 @@ case "$(readlink -f .git/hooks)" in
     ;;
   ("$PWD/.git/hooks")
     printf "attempted hooks/ change failed\n"
-    exit 1
+    exit 3
     ;;
   (*)
     printf "unanticipated error\n"
-    exit 2
+    exit 4
     ;;
 esac
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]