]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/checkout: fix `git checkout -p HEAD...` bug
authorDenton Liu <liu.denton@gmail.com>
Wed, 7 Oct 2020 07:56:15 +0000 (00:56 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Oct 2020 16:49:05 +0000 (09:49 -0700)
commit5602b500c3cd9ac308bf9af0d5f0a79bd2195346
treef16567fb4a2d796614bc267ce59f53a0dbdb7dae
parent47ae905ffb98cc4d4fd90083da6bc8dab55d9ecc
builtin/checkout: fix `git checkout -p HEAD...` bug

Running `git checkout -p` with a merge-base rev results in an error:

$ git checkout -p HEAD...
usage: git diff-index [-m] [--cached] [<common-diff-options>] <tree-ish> [<path>...]
common diff options:
  -z            output diff-raw with lines terminated with NUL.
  -p            output patch format.
  -u            synonym for -p.
  --patch-with-raw
output both a patch and the diff-raw format.
  --stat        show diffstat instead of patch.
  --numstat     show numeric diffstat instead of patch.
  --patch-with-stat
output a patch and prepend its diffstat.
  --name-only   show only names of changed files.
  --name-status show names and status of changed files.
  --full-index  show full object name on index lines.
  --abbrev=<n>  abbreviate object names in diff-tree header and diff-raw.
  -R            swap input file pairs.
  -B            detect complete rewrites.
  -M            detect renames.
  -C            detect copies.
  --find-copies-harder
try unchanged files as candidate for copy detection.
  -l<n>         limit rename attempts up to <n> paths.
  -O<file>      reorder diffs according to the <file>.
  -S<string>    find filepair whose only one side contains the string.
  --pickaxe-all
show all files diff when -S is used and hit is found.
  -a  --text    treat all files as text.

Cannot close git diff-index --cached --numstat --summary HEAD... -- () at <redacted>/libexec/git-core/git-add--interactive line 183.

This happens because checkout passes the literal argument (in the
example, `HEAD...`) to diff-index which does not recognise merge-base
revs.

Fix this by using the hex of the found commit instead of the given name.
Note that "HEAD" is handled specially in run_add_interactive() so it's
explicitly not changed.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
t/t2016-checkout-patch.sh
t/t2071-restore-patch.sh