Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git log -n 1 doesn't seem to work #69

Open
jamielinux opened this issue Mar 15, 2022 · 5 comments · May be fixed by #70
Open

git log -n 1 doesn't seem to work #69

jamielinux opened this issue Mar 15, 2022 · 5 comments · May be fixed by #70
Labels

Comments

@jamielinux
Copy link

Hi, thanks for this great tool. git isn't the same without it.

I think I found a bug. git log -1 and git log -n1 work fine, but git log -n 1 only works for non-scmpuff git.

$ git clone https://github.com/mroth/scmpuff.git
$ cd scmpuff
$ git log -n 1  --pretty=format:%H
(no output)
$ git log -1  --pretty=format:%H
9d53550badab476bf97b50d79a572840138871a2
$ git log -n1  --pretty=format:%H
9d53550badab476bf97b50d79a572840138871a2
$ /usr/bin/git log -n 1  --pretty=format:%H
9d53550badab476bf97b50d79a572840138871a2
@jamielinux
Copy link
Author

jamielinux commented Mar 15, 2022

Oops, forgot to add:

$  echo $SHELL
/bin/bash

$  bash --version | head -n1
GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)

$  scmpuff version
scmpuff 0.5.0

$  git --version
git version 2.35.1

$  which git
git ()
{
    case $1 in
        commit | blame | log | rebase | merge)
            scmpuff exec -- "$SCMPUFF_GIT_CMD" "$@"
        ;;
        checkout | diff | rm | reset | restore)
            scmpuff exec --relative -- "$SCMPUFF_GIT_CMD" "$@"
        ;;
        add)
            scmpuff exec -- "$SCMPUFF_GIT_CMD" "$@";
            scmpuff_status
        ;;
        *)
            "$SCMPUFF_GIT_CMD" "$@"
        ;;
    esac
}

Running on Fedora 35.

@mroth
Copy link
Owner

mroth commented Mar 26, 2022

Ah interesting. This is an edge case that was never considered. I'm not sure if this is a generic way to handle this, so we'd have to special case all known single flag git arguments that can take an integer argument after a space. That requires keeping scmpuff in lockstep with potential git porcelain changes in the future, but I can't think of a way around that that would handle this edge case.

@mroth mroth added the bug label Mar 26, 2022
mroth added a commit that referenced this issue Mar 26, 2022
@mroth
Copy link
Owner

mroth commented Mar 26, 2022

For git log alone, this will probably also affect --max-count=<number> and --skip=<number>, and --min-parents=<number>/--max-parents=<number>. In theory the double dash flags should require the = sign which wouldn't be an issue, but I'm willing to bet git does "forgiving" parsing rather than obeying the rules, and will permit dangling numbers on their own.

Sigh, yep, confirmed, it does...

@mroth
Copy link
Owner

mroth commented Mar 26, 2022

Adding more and more test cases in #70 just for git log.

Git CLI is really inconsistent here. In short it's going to be a mess to special case everything.

Git does not (or at least the version on my laptop) to appear allow combining short flags, so we wouldn't have to deal with parsing git log -ign 1 versus git log -ing 1...

In contrast, git diff does allow combing short flags, and produces different results depending on the ordering. E.g. mutually exclusive flags -p and -s such that git diff -ps and git diff -sp produce different results (they appear to be processed in order, with the later overriding). Additionally git diff -U<number> does not allow the space before the numeric arg, unlike git log -n<number> which also accepts undocumented git log -n <number>.

And that's just what I've found on a quick glance... going to go for a walk and clear my head before thinking more of this. If the list of special cases and exceptions becomes large, it's going to be difficult to keep in sync with various versions of git CLI.

@jamielinux
Copy link
Author

Ouch, I'd never really paid attention before to how inconsistent Git CLI is. Seems like this is going to be tricky 😬

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants