git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Reverdell Auriane <auriane.reverdell@cscs.ch>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: diff alias which used to work in version 2.27, failing from version 2.28 onwards
Date: Sat, 9 Sep 2023 20:45:05 +0200	[thread overview]
Message-ID: <CAHYJk3SfG01wqFDC0O_iUueBn6JXi6kydyfGGoZfd5kgVVSfbw@mail.gmail.com> (raw)
In-Reply-To: <31866645d2ac4cb1be17e35fae742cb2@cscs.ch>

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

      parent reply	other threads:[~2023-09-09 18:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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=CAHYJk3SfG01wqFDC0O_iUueBn6JXi6kydyfGGoZfd5kgVVSfbw@mail.gmail.com \
    --to=mikachu@gmail.com \
    --cc=auriane.reverdell@cscs.ch \
    --cc=git@vger.kernel.org \
    /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 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).