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

Re: [PATCH v2] completion: hide dotfiles for selected path completion

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 10, 2026, 18:56 UTC
Message-ID
<xmqqik7qusuc.fsf@gitster.g>
In-Reply-To
<pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>
"Zakariyah Ali via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 45 quoted lines
> -# __git_index_files accepts 1 or 2 arguments:
> +# __git_index_files accepts 1 to 4 arguments:
>  # 1: Options to pass to ls-files (required).
>  # 2: A directory path (optional).
>  #    If provided, only files within the specified directory are listed.
>  #    Sub directories are never recursed.  Path must have a trailing
>  #    slash.
>  # 3: List only paths matching this path component (optional).
> +# 4: Hide paths whose first component starts with a dot if this is
> +#    "hide-dotfiles" and the third argument is empty (optional).
>  __git_index_files ()
>  {
> -	local root="$2" match="$3"
> +	local root="$2" match="$3" hide_dotfiles="${4-}"
> +	local hide_dotfiles_awk=0
> +	if [ "$hide_dotfiles" = "hide-dotfiles" ] && [ -z "$match" ]; then
> +		hide_dotfiles_awk=1
> +	fi
>  
>  	__git_ls_files_helper "$root" "$1" "${match:-?}" |
> -	awk -F / -v pfx="${2//\\/\\\\}" '{
> +	awk -F / -v pfx="${2//\\/\\\\}" -v hide_dotfiles="$hide_dotfiles_awk" '{
>  		paths[$1] = 1
>  	}
>  	END {
>  		for (p in paths) {
>  			if (substr(p, 1, 1) != "\"") {
>  				# No special characters, easy!
> +				if (hide_dotfiles == 1 && substr(p, 1, 1) == ".")
> +					continue
>  				print pfx p
>  				continue
>  			}
> @@ -675,8 +683,10 @@ __git_index_files ()
>  				# We have seen the same directory unquoted,
>  				# skip it.
>  				continue
> -			else
> -				print pfx p
> +
> +			if (hide_dotfiles == 1 && substr(p, 1, 1) == ".")
> +				continue
> +			print pfx p
>  		}
>  	}

Having to repeat the same thing twice here is a bit unsatisfying, but that is not a fault of this addition. I suspect that it would have been simpler to patch if the original were first simplified into something like:

	for (p in paths) {
		if (substr(p, 1, 1) == "\"") {
			p = dequote(p);
			if ((p == "") || (p in paths))
				continue
		}
                print pfx p
	}

Then the new "ah, that thing begins with a dot" logic can be added only once and at an obvious place.

Show 7 quoted lines
> @@ -2164,7 +2176,7 @@ _git_ls_files ()
>  
>  	# XXX ignore options like --modified and always suggest all cached
>  	# files.
> -	__git_complete_index_file "--cached"
> +	__git_complete_index_file "--cached" hide-dotfiles
>  }

In this patch, it is hard to tell from the patch what _other_ calls to the __git_complete_index_file helper lack hide-dotfiles flag (i.e., they are to show everything including the path that begins with a dot). I will not try to be exhaustive, but for example _git_add does not get hide-dotfiles but it is unclear why. The same for _clean, _commit. But _mv does hide them. The choice seems arbitrary and incoherent.

A few ideas (some of them may be mutually incompatible)
 * Instead of "empty vs hide-dotfiles", perhaps make the 2nd option
   mandatory for __git_complete_index_file, e.g., "hide-" vs
   "include-" dotfiles, to make it easier to see in the patch which
   ones exclude and which ones include dotfiles.
 * Extend comments like we saw in the above hunk to say why we treat
   files that begin with dot specially.
 * Make __git_complete_index_file unconditionally hide the dotfiles
   when there is no match pattern for consistency (getting rid of
   the need to explay why).
Previous: Zakariyah AliNext: Zakariyah Ali via GitGitGadget
Message 6 of 14 in “completion: hide dotfiles for selected path completion”
  1. completion: hide dotfiles for selected path completionZakariyah Ali via GitGitGadget, May 24, 2026
  2. Junio C HamanoMay 24, 2026
  3. completion: hide dotfiles for selected path completionZakariyah Ali via GitGitGadget, May 26, 2026
  4. Junio C HamanoMay 27, 2026
  5. Follow-up and appreciation regarding Git contributionsZakariyah Ali, Jun 3, 2026
  6. Junio C HamanoJun 10, 2026
  7. 0/2 completion: hide dotfiles for selected path completionZakariyah Ali via GitGitGadget, Jun 20, 2026
  8. 1/2 completion: hide dotfiles for selected path completionZakariyah Ali via GitGitGadget, Jun 20, 2026
  9. 2/2 completion: hide dotfiles by default for path completionZakariyah Ali via GitGitGadget, Jun 20, 2026
  10. Junio C HamanoJun 21, 2026
  11. D. Ben KnobleJun 21, 2026
  12. Junio C HamanoJun 21, 2026
  13. Junio C HamanoJun 29, 2026
  14. Junio C HamanoJul 23, 2026

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.