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 57f7f77..6b1c142 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."