summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-08-31 08:24:59 -0700
committerJunio C Hamano <gitster@pobox.com>2026-08-31 08:24:59 -0700
commit189ff3a56d34a1a23a53888e0431096a3f20436f (patch)
tree640133a2d3093184e52ae98b64282fc076fc2563
parent6e6f4b582c51cb4e9dab3c98529017871d23311f (diff)
parent328b3b9d6288b68fdabad2e8b8b38bd7492b6228 (diff)
Merge branch 'vm/complete-history'
The command line completion (in contrib/) has been taught to handle the experimental 'git history' command. * vm/complete-history: completion: complete 'git history split' pathspecs completion: complete 'git history --update-refs' values completion: complete 'git history --empty' values completion: add 'git history' subcommands
-rw-r--r--contrib/completion/git-completion.bash65
-rwxr-xr-xt/t9902-completion.sh50
2 files changed, 115 insertions, 0 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index e6dce62d3c..9f8b9b50ff 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2160,6 +2160,71 @@ _git_help ()
fi
}
+__git_history_has_revision ()
+{
+ local i
+
+ for ((i = __git_cmd_idx + 2; i < cword; i++)); do
+ case "${words[i]}" in
+ -*)
+ ;;
+ *)
+ return 0
+ ;;
+ esac
+ done
+ return 1
+}
+
+_git_history ()
+{
+ local subcommands subcommand
+
+ __git_resolve_builtins "history"
+
+ subcommands="$___git_resolved_builtins"
+ subcommand="$(__git_find_subcommand "$subcommands")"
+
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ if ! __git_has_doubledash; then
+ case "$cur" in
+ --empty=*)
+ case "$subcommand" in
+ drop|fixup)
+ __gitcomp "drop keep abort" "" \
+ "${cur##--empty=}"
+ ;;
+ esac
+ return
+ ;;
+ --update-refs=*)
+ __gitcomp "branches head" "" \
+ "${cur##--update-refs=}"
+ return
+ ;;
+ --*)
+ __gitcomp_builtin "history_$subcommand"
+ return
+ ;;
+ esac
+ fi
+
+ if ! __git_history_has_revision; then
+ __git_complete_refs
+ return
+ fi
+
+ case "$subcommand" in
+ split)
+ __git_complete_index_file "--cached"
+ ;;
+ esac
+}
+
_git_init ()
{
case "$cur" in
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 628f632ebf..38cf221718 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -3221,6 +3221,56 @@ test_expect_success 'git clone --config= - value' '
EOF
'
+test_expect_success 'git history subcommands' '
+ test_completion "git history " <<-\EOF &&
+ drop Z
+ fixup Z
+ reword Z
+ split Z
+ EOF
+ test_completion "git history --" ""
+'
+
+test_expect_success 'git history subcommand options' '
+ test_completion "git history split main --" <<-\EOF &&
+ --update-refs=Z
+ --dry-run Z
+ --no-dry-run Z
+ EOF
+ test_completion "git history fixup --upd" "--update-refs=" &&
+ test_completion "git history fixup --ree" "--reedit-message " &&
+ test_completion "git history split --upd" "--update-refs=" &&
+ test_completion "git history split main --dry" "--dry-run " &&
+ test_completion "git history reword main -- --d" "" &&
+ test_completion "git history fixup --empty=ke" "keep " &&
+ test_completion "git history fixup --empty=drop" "drop " &&
+ test_completion "git history drop --empty=ab" "abort " &&
+ test_completion "git history reword --empty=ke" "" &&
+ test_completion "git history fixup --update-refs=branch" "branches " &&
+ test_completion "git history split --update-refs=he" "head " &&
+ test_completion "git history reword main -- --update-refs=he" ""
+'
+
+test_expect_success 'git history revisions' '
+ test_completion "git history split ma" "main " &&
+ test_completion "git history split --update-refs=head ma" "main " &&
+ test_completion "git history fixup --empty=drop ma" "main " &&
+ test_completion "git history reword main m" ""
+'
+
+test_expect_success 'git history split pathspecs' '
+ test_completion "git history split main -- --update-refs=h" "" &&
+ test_completion "git history split main -- --update-refs h" "" &&
+ test_completion "git history split --dry-run main file" <<-\EOF &&
+ file1Z
+ file2Z
+ EOF
+ test_completion "git history split main -- file" <<-\EOF
+ file1Z
+ file2Z
+ EOF
+'
+
test_expect_success 'git reflog show' '
test_when_finished "git checkout - && git branch -d shown" &&
git checkout -b shown &&