diff --git a/contrib/git-jump/README b/contrib/git-jump/README index 3211841305fcb3..420b20b6a2c29e 100644 --- a/contrib/git-jump/README +++ b/contrib/git-jump/README @@ -55,6 +55,10 @@ To use it, just drop git-jump in your PATH, and then invoke it like this: -------------------------------------------------- +# pick a mode automatically: "merge" if there are unmerged paths, +# "diff" if the worktree has unstaged changes, otherwise show usage +git jump + # jump to changes not yet staged for commit git jump diff diff --git a/contrib/git-jump/git-jump b/contrib/git-jump/git-jump index 8d1d5d79a69854..ac0ad2f0371e23 100755 --- a/contrib/git-jump/git-jump +++ b/contrib/git-jump/git-jump @@ -2,7 +2,7 @@ usage() { cat <<\EOF -usage: git jump [--stdout] [] +usage: git jump [--stdout] [] [] Jump to interesting elements in an editor. The parameter is one of: @@ -99,8 +99,18 @@ while test $# -gt 0; do shift done if test $# -lt 1; then - usage >&2 - exit 1 + if test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" != "true"; then + usage >&2 + exit 1 + fi + if test -n "$(git ls-files -u)"; then + set -- merge + elif ! git diff --quiet; then + set -- diff + else + usage >&2 + exit 1 + fi fi mode=$1; shift type "mode_$mode" >/dev/null 2>&1 || { usage >&2; exit 1; }