git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v4] git-completion.bash: add support for path completion

From
Manlio Perillo <manlio.perillo@gmail.com>
Date
Dec 21, 2012, 19:02 UTC
Message-ID
<50D4B23D.2030507@gmail.com>
In-Reply-To
<7vmwx71e2y.fsf@alter.siamese.dyndns.org>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Il 21/12/2012 18:59, Junio C Hamano ha scritto:
Show 8 quoted lines
> Manlio Perillo <manlio.perillo@gmail.com> writes:
> 
>> +		case "$path" in
>> +		?*/*) echo "${path%%/*}/" ;;
>> +		*) echo $path ;;
> 
> $path unquoted???
> 

Missed again, thanks. I hope this is really the last one!

Show 14 quoted lines
> [...]
>> +__git_index_files ()
>> +{
>> +	local dir="$(__gitdir)"
>> +
>> +	if [ -d "$dir" ]; then
>> +		# NOTE: $1 is not quoted in order to support multiple options
> 
> Good thinking to document this.  Thanks.
> 
> I take it that $1 never comes from the end user and it is known that
> it is correct to split them at $IFS?  That is the way I read callers
> of this function in this patch, but I am just double-checking.
> 

Yes, $1 is always set internally (but I will check again) Probably there are better solutions.

Show 10 quoted lines
>> @@ -998,7 +1093,13 @@ _git_commit ()
>>  			"
>>  		return
>>  	esac
>> -	COMPREPLY=()
>> +
>> +	if git rev-parse --verify --quiet HEAD 1>/dev/null; then
> 
> s/1>/>/;
> 

What is the reason? Coding style?

Show 17 quoted lines
>> +		__git_complete_diff_index_file "HEAD"
> 
> As this runs "git diff-index" without --cached, 
> 
> The completion will give only for paths that have difference between
> the working tree and the HEAD.  If the user has a bogus contents
> that was "git add"ed earlier, (i.e. the index is different from
> HEAD), then realizes the mistake and fixes it in the working tree
> with his editor to match "HEAD" (i.e. the working tree is the same
> as HEAD):
> 
> 	git commit the-prefix-to-that-file<TAB>
> 
> to complete the filename will not give that file.  I do not think it
> is a show-stopper, but it may puzzle the users when they encounter
> the situation.
> 
Umh, I just checked this case.
  0) git init test
  1) Added a README file with "Hello World.", and committed.
  2) Modified the README file with "Hello World!" and executed
     git add README
  3) Modified the README file with "Hello World." (the original content)
  4) $ git diff HEAD:README README
     $ git diff-index --name-only HEAD
     README
     git commit <TAB> shows the README file.

If I understand correctly the documentation of diff-index, it will always compare the content of the index with HEAD. If --cached is specified, it will ignore the stat state of the file on disk.

> I am wondering if reading from "git status --porcelain" might be a
> better alternative, or if it is too much trouble and slow things
> down to cover such a corner case.
> 
It have considered it.

The problem is that the output of "git status --porcelain" is not trivial to parse.

Show 17 quoted lines
>> @@ -1362,7 +1464,14 @@ _git_mv ()
>>  		return
>>  		;;
>>  	esac
>> -	COMPREPLY=()
>> +
>> +	if [ $cword -gt 2 ]; then
>> +		# We need to show both cached and untracked files (including
>> +		# empty directories) since this may not be the last argument.
>> +		__git_complete_index_file "--cached --others --directory"
>> +	else
>> +		__git_complete_index_file "--cached"
>> +	fi
> 
> Is $cword affected by the presense of "-f" in "git mv [-f] foo bar"?
> Just being curious.
> 

Yes, it is affected; I missed it, thanks. It should count only non-option arguments.

Show 7 quoted lines
> Other than that, I do not see anything majorly wrong from the coding
> and semantics point of view in the patch.  As to the interaction
> with the rest of the completion machinery, I'll leave the review to
> the area experts CC'ed and wait for their comments.
> 
> Thanks.
> 
Thanks for your review.
Manlio
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlDUsjwACgkQscQJ24LbaUSGuwCffon7/VGFo98CCBsZlmOdNYYE 91oAn3X8fbr5jtzMUOZkMp9CuGWCa7Cf =Qzsv -----END PGP SIGNATURE-----

Previous: Junio C HamanoNext: Marc Khouzam
Message 3 of 15 in “git-completion.bash: add support for path completion”
  1. git-completion.bash: add support for path completionManlio Perillo, Dec 21, 2012
  2. Junio C HamanoDec 21, 2012
  3. Manlio PerilloDec 21, 2012
  4. Marc KhouzamJan 4, 2013
  5. Junio C HamanoJan 4, 2013
  6. Junio C HamanoJan 5, 2013
  7. Marc KhouzamJan 5, 2013
  8. Manlio PerilloJan 5, 2013
  9. Manlio PerilloJan 6, 2013
  10. Manlio PerilloJan 7, 2013
  11. Marc KhouzamJan 7, 2013
  12. Manlio PerilloJan 8, 2013
  13. John KeepingJan 8, 2013
  14. Manlio PerilloJan 8, 2013
  15. Manlio PerilloJan 6, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.