oh-my-bash: BUG: Git completion is not working on git version <2.19.2

TLDR: Blame https://github.com/ohmybash/oh-my-bash/pull/62 -> Doesn’t work on my machine

BASH: 4.3.48(1)-release
GIT: 2.7.4
GREP: 2.25
CUT(GNU coreutils): 8.25

Steps to reproduce

sh -c "$(curl -fsSL http://ix.io/1SDL |egrep "^ [a-z]*"|cut -d" " -f4)"

where http://ix.io/1SDL is output of git help -a on git 2.19.2

Suggestion

> git 2.19.2 help page changed -> new logic has to be provided to greb required variables since https://github.com/ohmybash/oh-my-bash/blob/429ffc1cbcd1a14f7ec0241a2e898d339eb634b6/completions/git.completion.sh#L627 is not sufficient for `= git 2.19.2

_Originally posted by @hashlash in https://github.com/ohmybash/oh-my-bash/pull/62#issuecomment-508893844_


I’m sorry but PR 62 doesn’t work on my machine. I don’t know if it caused by different bash, git, cut, or egrep version

hashlash@hashlash-K401UQK:~$ bash --posix 
bash-4.3$ bash --version
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
bash-4.3$ git help -a|egrep "^  [a-z]*"|cut -d" " -f4
...
<empty lines only>
...

But using third field on cut works out for me

bash-4.3$ git help -a|egrep "^  [a-z]*"|cut -d" " -f3




add
add--interactive
am
annotate
apply
...
merge-one-file

Note that it only show git command from add to merge-one-file. The following commands (merge-ours until write-tree) is not showing up

bash-4.3$ git --version
git version 2.7.4

bash-4.3$ egrep --version
grep (GNU grep) 2.25
...
bash-4.3$ cut --version
cut (GNU coreutils) 8.25
...

_Originally posted by @hashlash in https://github.com/ohmybash/oh-my-bash/pull/62#issuecomment-508893844_

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (13 by maintainers)

Commits related to this issue

Most upvoted comments

This should output all commands and should be compatible on all versions which should be a better option to using current 😃

This is not true, as this option was added git/git@0089521cacd99db8018b7a31e205dad0bf0738c7, i.e >= v2.18.0

Before that, --list-buitins existed git/git@8893fd95b66cbd6566136a289dd05fcf4e547281 but only for >= 2.14.0

Before those, the official completion used: git help -a|egrep '^ [a-zA-Z0-9]' with some filtering to separate porcelain from plumbing commands.

In general, look at how these areas of code changed over time. https://github.com/git/git/blob/468165c1d8a442994a825f3684528361727cd8c0/contrib/completion/git-completion.bash#L835-L948

https://github.com/git/git/blob/5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9/contrib/completion/git-completion.bash#L1025-L1030

@hashlash requesting output of git --list-cmds=main

This should output all commands and should be compatible on all versions which should be a better option to using current 😃

git --list-cmds=builtins,main,others,nohelpers,alias,config,list-mainporcelain,list-ancillarymanipulators,list-ancillaryinterrogators,list-foreignscminterface,list-plumbingmanipulators,list-plumbinginterrogators,list-synchingrepositories,list-synchelpers,list-purehelpers

Should output everything, but i think that we only need main

builtins,main,others,nohelpers,alias,config was suggested

This fix was suggested by rafasc on #bash thanks!

From available info assuming that git help -a|egrep "^ [a-z]*"|cut -d" " -f4 is sufficient for my configuration -> What needs to be done for oh-my-bash to support other configuration?

EDIT: noted https://github.com/ohmybash/oh-my-bash/issues/65#issuecomment-508919573 -> different git version requires different logic to output requested variables for git completetion