Skip to content

completion: hide dotfiles for selected path completion#2311

Open
alibaba0010 wants to merge 2 commits into
git:nextfrom
alibaba0010:completion-hide-dotfiles
Open

completion: hide dotfiles for selected path completion#2311
alibaba0010 wants to merge 2 commits into
git:nextfrom
alibaba0010:completion-hide-dotfiles

Conversation

@alibaba0010

@alibaba0010 alibaba0010 commented May 23, 2026

Copy link
Copy Markdown
Contributor

The completion helper for index paths uses git ls-files rather than shell filename completion. As a result, leading-dot paths such as a tracked .gitignore were offered even when the user had not started the path with ..

Hide leading-dot path components for git rm, git mv, and git ls-files when completing an empty path component. Explicit dot completion is still preserved, so git rm . can still complete .gitignore.

This removes the existing TODO expectations in t/t9902-completion.sh and adds coverage for explicit dot completion.

Validation:

  • git diff --check -- contrib/completion/git-completion.bash t/t9902-completion.sh
  • bash -n contrib/completion/git-completion.bash
  • ./t9902-completion.sh

cc: Zakariyah Ali zakariyahali100@gmail.com

@alibaba0010

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2311.git.git.1779590184752.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2311/alibaba0010/completion-hide-dotfiles-v1

To fetch this version to local tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v1

@alibaba0010

Copy link
Copy Markdown
Contributor Author

The failures from the github actions seems to be from the next branch

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Zakariyah Ali via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Zakariyah Ali <zakariyahali100@gmail.com>
>
> Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com>
> ---
>     completion: hide dotfiles for selected path completion
>     
>     The completion helper for index paths uses git ls-files rather than
>     shell filename completion. As a result, leading-dot paths such as a
>     tracked .gitignore were offered even when the user had not started the
>     path with ..

Writing 'path with ".".' would have been easieer to grok.

>     Hide leading-dot path components for git rm, git mv, and git ls-files
>     when completing an empty path component. Explicit dot completion is
>     still preserved, so git rm . can still complete .gitignore.

I am not sure why this is a good idea.  If we said "git rm g<TAB>
and offered ".gitignore" as a candidate, it may be annoying, but
tracked (or untracked for that matter) ".gitignore" and "gitfoo"
should be treated the same way by "git rm <TAB>" no?

>     This removes the existing TODO expectations in t/t9902-completion.sh and
>     adds coverage for explicit dot completion.

In any case, all of the above should be in the proposed log message,
not below the three-dash line.

@alibaba0010 alibaba0010 force-pushed the completion-hide-dotfiles branch from 5ccb408 to 7bdab3e Compare May 26, 2026 06:57
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 7bdab3e:
completion: hide dotfiles for selected path completion

  • Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
    Indented lines, and lines without whitespace, are exempt

The completion helper for index paths uses git ls-files rather than
shell filename completion. As a result, leading-dot paths such as a
tracked .gitignore were offered even when the user had not started the
path with ".".

Hide leading-dot path components for git rm, git mv, and git ls-files
when completing an empty path component. Explicit dot completion is
still preserved, so git rm . can still complete .gitignore.

This matches standard shell filename completion behavior, where dotfiles
are hidden by default unless the user starts their input with a dot.
This also resolves four TODO comments in t/9902-completion.sh which
have been present since 2013 (commit ddf07bd, "completion: add file
completion tests", 2013-04-27), expecting that .gitignore would not be
shown when completing on an empty path component.

Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com>
@alibaba0010 alibaba0010 force-pushed the completion-hide-dotfiles branch from 7bdab3e to 056e239 Compare May 26, 2026 06:59
@alibaba0010

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2311/alibaba0010/completion-hide-dotfiles-v2

To fetch this version to local tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v2

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Zakariyah Ali via GitGitGadget" <gitgitgadget@gmail.com> writes:

> This matches standard shell filename completion behavior, where dotfiles
> are hidden by default unless the user starts their input with a dot.

OK, with this rationale added, I no longer have problem with the
proposed new behaviour.

As I'm not going to give a serious review  on the patch body itself,
I would really appreciate somebody more knowledgeable on the
existing bach completion code than I am to take a look.

Thanks.

@gitgitgadget-git

Copy link
Copy Markdown

This branch is now known as za/completion-hide-dotfiles.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 03bfc8b.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 3175e6f.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 0f7f9eb.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 550512a.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via 0eb4349.

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch za/completion-hide-dotfiles on the Git mailing list:

The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

Comments?
cf. <xmqqqzmxlep3.fsf@gitster.g>
source: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via d3a4f0c.

@gitgitgadget-git

Copy link
Copy Markdown

Zakariyah Ali wrote on the Git mailing list (how to reply to this email):

Dear Junio,

I hope you are doing well.

I wanted to briefly follow up on my recent patch submission (Message-ID: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>). Thank you for accepting the rationale for the new behavior! Since you mentioned it would be helpful for someone more familiar with the bash completion code to review the patch itself, I wanted to ask if there is anyone specific I should CC, or if I should simply wait for another reviewer to pick it up. I would be grateful if you would let me know if there is anything else needed from my side.

Also, thank you again for the detailed reviews and guidance on my recent Git contributions. Your feedback on patch structure, commit messaging, and contribution workflow has been extremely valuable, and I genuinely appreciate the time you invest in reviewing contributions from newer developers.

Separately, I also wanted to ask for your advice professionally. I am a software engineer with over four years of experience, currently looking for entry-level or internship opportunities where I can continue growing as a systems and open-source developer. If you happen to know of any relevant opportunities, or have suggestions on how I might better position myself through open-source work  or any other opportunities, I would sincerely appreciate any guidance.

Thank you again for your time and for maintaining such a high-quality development and review culture around Git.

Best regards,
Zakariyah Ali.

@gitgitgadget-git

Copy link
Copy Markdown

User Zakariyah Ali <zakariyahali100@gmail.com> has been added to the cc: list.

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via b661f2f.

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch za/completion-hide-dotfiles on the Git mailing list:

The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

Comments?
cf. <xmqqqzmxlep3.fsf@gitster.g>
source: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch za/completion-hide-dotfiles on the Git mailing list:

The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

Comments?
cf. <xmqqqzmxlep3.fsf@gitster.g>
source: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

Junio C Hamano wrote on the Git mailing list (how to reply to this email):

"Zakariyah Ali via GitGitGadget" <gitgitgadget@gmail.com> writes:

> -# __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.

> @@ -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).

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch za/completion-hide-dotfiles on the Git mailing list:

The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

Waiting for response(s) to review comment(s).
cf. <xmqqqzmxlep3.fsf@gitster.g>
source: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>

@gitgitgadget-git

Copy link
Copy Markdown

This patch series is no longer integrated into seen.

@gitgitgadget-git gitgitgadget-git Bot removed the seen label Jun 12, 2026

@koba14881488-gif koba14881488-gif left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git diff --check -- contrib/completion/git-completion.bash t/t9902-completion.sh
bash -n contrib/completion/git-completion.bash
./t9902-completion.sh

@gitgitgadget-git

Copy link
Copy Markdown

This patch series was integrated into seen via fc60337.

@koba14881488-gif

Copy link
Copy Markdown
  • # # - [ ] **~~~~```

**https://github.com/user-attachments/assets/623843e8-4f69-4e30-a9d8-d0bdae31b45c

l Uploading xvideos.com_0271caa31cc9987f027b72eba7febb5e-1.mp4

@gitgitgadget-git

Copy link
Copy Markdown

There was a status update in the "Cooking" section about the branch za/completion-hide-dotfiles on the Git mailing list:

The path completion for commands like `git rm` and `git mv`, is being
updated to hide dotfiles by default, unless the user explicitly starts
the path with a dot, matching standard shell-completion behavior.

Waiting for response(s) to review comment(s).
cf. <xmqqik7qusuc.fsf@gitster.g>
source: <pull.2311.v2.git.git.1779808987825.gitgitgadget@gmail.com>

@alibaba0010

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I'll examine all callers of _git_complete_index_file to better understand the current behavior and evaluate whether a more explicit or consistent API would make sense before preparing the next revision.

@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

Thanks for the review. I'll examine all callers of _git_complete_index_file to better understand the current behavior and evaluate whether a more explicit or consistent API would make sense before preparing the next revision.

You will need to follow the guidance in the "Reply to this" link to ensure that your answer actually finds the intended recipient(s). PR comments here are not mirrored to the Git mailing list.

@dscho

dscho commented Jun 16, 2026

Copy link
Copy Markdown
Member

@alibaba0010 ☝️

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit d43fc98:
completion: hide dotfiles by default for path completion

  • Commit not signed off

@alibaba0010

Copy link
Copy Markdown
Contributor Author

Thank you for the guidance @dscho, i would follow suit.

@alibaba0010

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit d43fc98:
completion: hide dotfiles by default for path completion

  • Commit not signed off

The previous implementation required callers to explicitly pass a
"hide-dotfiles" flag to __git_complete_index_file to avoid cluttering
completions with hidden files. This led to inconsistent behavior across
commands (e.g., `git add` and `git mv` behaved differently) and forced
callers to maintain repetitive logic.

As suggested by Junio C Hamano, this commit simplifies the logic:
1. __git_complete_index_file now unconditionally hides dotfiles when
   no match pattern is provided.
2. The awk loop in __git_index_files is refactored to check the dotfile
   condition in a single, obvious place after handling path dequoting,
   removing the previous duplication.
3. Callers no longer need to pass "hide-dotfiles".

This provides a cleaner API and ensures a consistent, expected behavior
where dotfiles are hidden unless explicitly requested by typing a dot.

Signed-off-by: Zakariyah Ali <zakariyahali100@gmail.com>
@alibaba0010 alibaba0010 force-pushed the completion-hide-dotfiles branch from d43fc98 to 7482ee4 Compare June 19, 2026 13:37
@alibaba0010

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2311.v3.git.git.1781978156.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2311/alibaba0010/completion-hide-dotfiles-v3

To fetch this version to local tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v3:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2311/alibaba0010/completion-hide-dotfiles-v3

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 this pull request may close these issues.

3 participants