* diff alias which used to work in version 2.27, failing from version 2.28 onwards
@ 2023-08-24 10:19 Reverdell Auriane
2023-08-24 14:32 ` Jeff King
2023-09-09 18:45 ` Mikael Magnusson
0 siblings, 2 replies; 3+ messages in thread
From: Reverdell Auriane @ 2023-08-24 10:19 UTC (permalink / raw)
To: git@vger.kernel.org
Hi,
To output the diff of a specific commit, I created the alias dici (see below), git dici 12345 or git dici to output the diff of the HEAD:
[alias]
dici = !git diff ${1:-HEAD}^..${1:-HEAD}
a trace for this alias gives (same trace for both git 2.27 and 2.28!):
14:38:45.275964 git.c:439 trace: built-in: git diff a2028e7b^..a2028e7b a2028e7b
The commit number is put again at the end of the command (the wanted alias is supposed to output only `git diff a2028e7b^..a2028e7b`), this was accepted by version 2.27 but not by the version 2.28. For now, my temporary fix is adding a bash comment at the end of the alias:
[alias]
dici = "!git diff ${1:-HEAD}^..${1:-HEAD} #"
Note: the first alias still doesn't work with the latest git versions (tested with 2.40.0, 2.39.2, 2.37.5).
Is that expected behavior? if yes, how is the right/clean way to discard the command line argument of the alias?
Thanks in advance!
Auriane
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards
2023-08-24 10:19 diff alias which used to work in version 2.27, failing from version 2.28 onwards Reverdell Auriane
@ 2023-08-24 14:32 ` Jeff King
2023-09-09 18:45 ` Mikael Magnusson
1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2023-08-24 14:32 UTC (permalink / raw)
To: Reverdell Auriane; +Cc: git@vger.kernel.org
On Thu, Aug 24, 2023 at 10:19:18AM +0000, Reverdell Auriane wrote:
> 14:38:45.275964 git.c:439 trace: built-in: git diff a2028e7b^..a2028e7b a2028e7b
> [...]
> Is that expected behavior? if yes, how is the right/clean way to
> discard the command line argument of the alias?
Yes, that's expected. Your alias was always a little broken by adding
the extra argument, but "git diff" got a little more careful about its
input in 8bfcb3a690 (git diff: improve range handling, 2020-06-12),
which as part of v2.28.
The usual way for manipulating arguments in a shell snippet is to make a
function, like:
[alias]
dici = "!f() { git diff ${1:-HEAD}^..${1:-HEAD}; }; f"
Then Git ends up running "f a2028e7b", and the shell does the rest. It's
obviously a bit more verbose to write, but you're free to do even more
manipulation (e.g., using the first non-option argument as the rev and
taking the rest as options).
All that said, there is a shorthand that may make your alias obsolete.
From "git help revisions":
<rev>^-<n>, e.g. HEAD^-, HEAD^-2
Equivalent to <rev>^<n>..<rev>, with <n> = 1 if not given.
So just:
git diff a2028e7b^-
does what you want.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards
2023-08-24 10:19 diff alias which used to work in version 2.27, failing from version 2.28 onwards Reverdell Auriane
2023-08-24 14:32 ` Jeff King
@ 2023-09-09 18:45 ` Mikael Magnusson
1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2023-09-09 18:45 UTC (permalink / raw)
To: Reverdell Auriane; +Cc: git@vger.kernel.org
On 8/24/23, Reverdell Auriane <auriane.reverdell@cscs.ch> wrote:
> Hi,
>
> To output the diff of a specific commit, I created the alias dici (see
> below), git dici 12345 or git dici to output the diff of the HEAD:
>
> [alias]
> dici = !git diff ${1:-HEAD}^..${1:-HEAD}
>
> a trace for this alias gives (same trace for both git 2.27 and 2.28!):
>
> 14:38:45.275964 git.c:439 trace: built-in: git diff
> a2028e7b^..a2028e7b a2028e7b
>
> The commit number is put again at the end of the command (the wanted alias
> is supposed to output only `git diff a2028e7b^..a2028e7b`), this was
> accepted by version 2.27 but not by the version 2.28. For now, my temporary
> fix is adding a bash comment at the end of the alias:
>
> [alias]
> dici = "!git diff ${1:-HEAD}^..${1:-HEAD} #"
>
> Note: the first alias still doesn't work with the latest git versions
> (tested with 2.40.0, 2.39.2, 2.37.5).
>
> Is that expected behavior? if yes, how is the right/clean way to discard the
> command line argument of the alias?
If you want to interpolate arguments in the command string, the safest
way is something like
dici = !sh -c 'git diff ${1:-HEAD}~..${1:-HEAD}' sh
(but why not just use git show?)
you can also use the ^! syntax instead:
dici = !sh -c 'git diff ${1:-HEAD}^!' sh
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-09 18:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-24 10:19 diff alias which used to work in version 2.27, failing from version 2.28 onwards Reverdell Auriane
2023-08-24 14:32 ` Jeff King
2023-09-09 18:45 ` Mikael Magnusson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).