Code

Define cd_to_toplevel shell function in git-sh-setup
authorJunio C Hamano <junkio@cox.net>
Fri, 12 Jan 2007 20:44:08 +0000 (12:44 -0800)
committerJunio C Hamano <junkio@cox.net>
Sat, 13 Jan 2007 00:54:38 +0000 (16:54 -0800)
Signed-off-by: Junio C Hamano <junkio@cox.net>
git-sh-setup.sh

index 57f7f7777602eadc79b6bb04e6652d81d14d770c..6b1c1423ebb7fde53aae566fa09211d331c422bc 100755 (executable)
@@ -36,6 +36,17 @@ is_bare_repository () {
        esac
 }
 
+cd_to_toplevel () {
+       cdup=$(git-rev-parse --show-cdup)
+       if test ! -z "$cdup"
+       then
+               cd "$cdup" || {
+                       echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
+                       exit 1
+               }
+       fi
+}
+
 require_work_tree () {
        test $(is_bare_repository) = false ||
        die "fatal: $0 cannot be used without a working tree."