Subject: [PATCH 0/3] Better support for customising context lines in --patch commands

From: "Leon Michalak via GitGitGadget" <[email-masked]>
Date: Mon, 05 May 2025 09:18:36 +0000

This series of patches attempt to give --interactive/--patch compatible
builtins ("add", "commit", "checkout", "reset", "restore" and "stash")
better support and nicer experience for configuring how many context lines
are shown in diffs through a variety of ways.

Prior to these patches, the user could not choose how many context lines
they saw in --patch commands (apart from one workaround by using
GIT_DIFF_OPTS=-u<number> ..., however this isn't a good user experience or a
persistent solution). Additionally, the behaviour around reading from the
diff.context and diff.interHunkContext configs was also inconsistent with
other diff generating commands such as "log -p".

The summarised changes below hopefully make this experience better and fix
some inconsistencies:

 * diff.context and diff.interHunkContext configs are now respected by
   --patch compatible commands
 * --unified and --inter-hunk-context command line options have been added
   to --patch compatible commands (which take prescendence over file
   configs)
 * "add" and "commit" in --interactive mode now expose a new "context"
   subcommand which configures the amount of context lines you wish to see
   in subsequent diffs generated from other subcommands such as "patch" or
   "diff"

The original discussion for this can be read at:

 * https://lore.kernel.org/git/CAP9jKjGb-Rcr=[email-masked]/

Leon Michalak (3):
  add-patch: respect diff.context configuration
  add-patch: add diff.context command line overrides
  add-interactive: add new "context" subcommand

 Documentation/git-add.adoc      |  21 ++++++-
 Documentation/git-checkout.adoc |  11 ++++
 Documentation/git-commit.adoc   |  11 ++++
 Documentation/git-reset.adoc    |  11 ++++
 Documentation/git-restore.adoc  |  11 ++++
 Documentation/git-stash.adoc    |  11 ++++
 add-interactive.c               | 107 +++++++++++++++++++++++++++++---
 add-interactive.h               |  17 ++++-
 add-patch.c                     |  11 +++-
 builtin/add.c                   |  21 +++++--
 builtin/checkout.c              |  28 ++++++++-
 builtin/commit.c                |  15 ++++-
 builtin/reset.c                 |  16 ++++-
 builtin/stash.c                 |  54 ++++++++++++----
 commit.h                        |   3 +-
 t/t3701-add-interactive.sh      |  36 +++++++++--
 t/t4055-diff-context.sh         |  78 ++++++++++++++++++++++-
 t/t9902-completion.sh           |   2 +
 18 files changed, 420 insertions(+), 44 deletions(-)

base-commit: f65182a99e545d2f2bc22e6c1c2da192133b16a3
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1915%2FNinjaInShade%2Finteractive-patch-context-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1915/NinjaInShade/interactive-patch-context-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1915
-- 
gitgitgadget