X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;ds=sidebyside;f=tg.sh;h=f8c8de4ba859d76d254580ef88041b3bdce05f19;hb=e0e1ce4d27242585b6edeb35ca3cf62a6454b074;hp=4020527b2e27a1db9e5121275c9559c9307b92bd;hpb=e788f47b677d5814289d9af5c037e3e8ff730da7;p=topgit.git diff --git a/tg.sh b/tg.sh index 4020527..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() { @@ -63,8 +77,8 @@ measure_branch() _bname="$1"; _base="$2" [ -n "$_base" ] || _base="refs/top-bases/$_bname" # The caller should've verified $name is valid - _commits="$(git rev-list "$_bname" ^"$_base" | wc -l)" - _nmcommits="$(git rev-list --no-merges "$_bname" ^"$_base" | wc -l)" + _commits="$(git rev-list "$_bname" ^"$_base" -- | wc -l)" + _nmcommits="$(git rev-list --no-merges "$_bname" ^"$_base" -- | wc -l)" if [ $_commits -gt 1 ]; then _suffix="commits" else @@ -209,6 +223,12 @@ switch_to_base() do_help() { if [ -z "$1" ] ; then + # This is currently invoked in all kinds of circumstances, + # including when the user made a usage error. Should we end up + # providing more than a short help message, then we should + # differentiate. + # Petr's comment: http://marc.info/?l=git&m=122718711327376&w=2 + ## Build available commands list for help output cmds= @@ -243,6 +263,8 @@ do_help() [ -d "@cmddir@" ] || die "No command directory: '@cmddir@'" +ensure_git_repo_or_die + ## Initial setup set -e @@ -292,3 +314,5 @@ help|--help|-h) } . "@cmddir@"/tg-$cmd;; esac + +# vim:noet