From: "Greg Hurrell via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>,
Greg Hurrell <greg.hurrell@datadoghq.com>,
Greg Hurrell <greg.hurrell@datadoghq.com>
Subject: [PATCH] git-jump: pick a mode automatically when invoked without arguments
Date: Fri, 08 May 2026 09:07:34 +0000 [thread overview]
Message-ID: <pull.2108.git.1778231254871.gitgitgadget@gmail.com> (raw)
From: Greg Hurrell <greg.hurrell@datadoghq.com>
When `git jump` is invoked with no positional arguments (and no
arguments after `--stdout`) it currently prints usage and exits with
status 1.
But there are two situations where we can usefully infer the most
valuable and likely mode that a user would want to use, and select it
automatically when they run `git jump` without arguments:
1. When there are unmerged paths in the index, the user likely
wants `git jump merge`.
2. When the working tree has unstaged changes, the user likely
wants `git jump diff`.
Detect these two cases and dispatch to the corresponding mode
automatically, falling back to the existing usage-and-exit behavior
when neither holds.
Signed-off-by: Greg Hurrell <greg.hurrell@datadoghq.com>
---
git-jump: pick a mode automatically when invoked without arguments
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2108%2Fwincent%2Fauto-jump-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2108/wincent/auto-jump-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2108
contrib/git-jump/README | 4 ++++
contrib/git-jump/git-jump | 16 +++++++++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/contrib/git-jump/README b/contrib/git-jump/README
index 3211841305..420b20b6a2 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 8d1d5d79a6..ac0ad2f037 100755
--- a/contrib/git-jump/git-jump
+++ b/contrib/git-jump/git-jump
@@ -2,7 +2,7 @@
usage() {
cat <<\EOF
-usage: git jump [--stdout] <mode> [<args>]
+usage: git jump [--stdout] [<mode>] [<args>]
Jump to interesting elements in an editor.
The <mode> 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; }
base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0
--
gitgitgadget
next reply other threads:[~2026-05-08 9:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 9:07 Greg Hurrell via GitGitGadget [this message]
2026-05-08 14:13 ` [PATCH] git-jump: pick a mode automatically when invoked without arguments Jeff King
2026-05-08 14:30 ` Greg Hurrell
2026-05-08 17:52 ` Jeff King
2026-05-14 15:40 ` Erik Cervin Edin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.2108.git.1778231254871.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=greg.hurrell@datadoghq.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.