unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
@ 2025-01-04  0:00 Peter Seibel
  2025-01-04  7:52 ` Eli Zaretskii
  2025-01-04  7:54 ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Peter Seibel @ 2025-01-04  0:00 UTC (permalink / raw)
  To: 75336


[-- Attachment #1.1: Type: text/plain, Size: 482 bytes --]

I was going a bit crazy trying to figure out why tab completion in *shell*
wasn't working for git add when I was trying to add a new file to my repo.
Turns out pcomplete was only completing modified tracked files.This patch
changes it so after git add it also completes untracked non-ignored files.

I believe I long ago signed a Copyright assignment to the Emacs project but
I'm happy to do it again if that's still required. Cheers!


-- 
Peter Seibel
http://www.gigamonkeys.com/

[-- Attachment #1.2: Type: text/html, Size: 764 bytes --]

[-- Attachment #2: 0001-Allow-pcomplete-of-git-add-to-include-untracked-file.patch --]
[-- Type: application/octet-stream, Size: 1581 bytes --]

From 7890a230953c081d93c806c8a802aa69452d7e28 Mon Sep 17 00:00:00 2001
From: Peter Seibel <peter@gigamonkeys.com>
Date: Fri, 3 Jan 2025 15:56:01 -0800
Subject: [PATCH] Allow pcomplete of git add to include untracked files.

---
 lisp/pcmpl-git.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/pcmpl-git.el b/lisp/pcmpl-git.el
index f57c2d5470a..498918ac1c4 100644
--- a/lisp/pcmpl-git.el
+++ b/lisp/pcmpl-git.el
@@ -82,8 +82,18 @@ Files listed by `git ls-files ARGS' satisfy the predicate."
                   (pcomplete-from-help `(,vc-git-program "help" ,subcmd)
                                        :argument
                                        "-+\\(?:\\[no-\\]\\)?[a-z-]+=?"))))
+               ;; Complete modified tracked files and untracked files
+               ("add"
+                (pcomplete-here
+                 (pcomplete-entries
+                  nil (let ((modified (pcmpl-git--tracked-file-predicate "-m"))
+                            (untracked (pcmpl-git--tracked-file-predicate "-o" "--exclude-standard")))
+                        (lambda (file)
+                          (or
+                           (and modified (funcall modified file))
+                           (and untracked (funcall untracked file))))))))
                ;; Complete modified tracked files
-               ((or "add" "commit" "restore")
+               ((or "commit" "restore")
                 (pcomplete-here
                  (pcomplete-entries
                   nil (pcmpl-git--tracked-file-predicate "-m"))))
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
  2025-01-04  0:00 bug#75336: [PATCH] Allow pcomplete of git add to include untracked files Peter Seibel
@ 2025-01-04  7:52 ` Eli Zaretskii
  2025-01-04  7:54 ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2025-01-04  7:52 UTC (permalink / raw)
  To: Peter Seibel; +Cc: 75336

> From: Peter Seibel <peter@gigamonkeys.com>
> Date: Fri, 3 Jan 2025 16:00:27 -0800
> 
> I believe I long ago signed a Copyright assignment to the Emacs project but I'm happy to do it again if that's
> still required. Cheers!

Form sent off-list.

Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
  2025-01-04  0:00 bug#75336: [PATCH] Allow pcomplete of git add to include untracked files Peter Seibel
  2025-01-04  7:52 ` Eli Zaretskii
@ 2025-01-04  7:54 ` Eli Zaretskii
  2025-01-04 13:59   ` Peter Seibel
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2025-01-04  7:54 UTC (permalink / raw)
  To: Peter Seibel, Augusto Stoffel; +Cc: Stefan Monnier, 75336

> From: Peter Seibel <peter@gigamonkeys.com>
> Date: Fri, 3 Jan 2025 16:00:27 -0800
> 
> I was going a bit crazy trying to figure out why tab completion in *shell* wasn't working for git add when I was
> trying to add a new file to my repo. Turns out pcomplete was only completing modified tracked files.This
> patch changes it so after git add it also completes untracked non-ignored files.

Augusto and Stefan, any comments?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
  2025-01-04  7:54 ` Eli Zaretskii
@ 2025-01-04 13:59   ` Peter Seibel
  2025-01-04 15:04     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Seibel @ 2025-01-04 13:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Augusto Stoffel, Stefan Monnier, 75336


[-- Attachment #1.1: Type: text/plain, Size: 658 bytes --]

I just realized there's a better way to do this. New patch attached.

On Fri, Jan 3, 2025 at 11:54 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Peter Seibel <peter@gigamonkeys.com>
> > Date: Fri, 3 Jan 2025 16:00:27 -0800
> >
> > I was going a bit crazy trying to figure out why tab completion in
> *shell* wasn't working for git add when I was
> > trying to add a new file to my repo. Turns out pcomplete was only
> completing modified tracked files.This
> > patch changes it so after git add it also completes untracked
> non-ignored files.
>
> Augusto and Stefan, any comments?
>


-- 
Peter Seibel
http://www.gigamonkeys.com/

[-- Attachment #1.2: Type: text/html, Size: 1232 bytes --]

[-- Attachment #2: 0002-Simpler-way-to-get-list-of-addable-files.patch --]
[-- Type: application/octet-stream, Size: 1236 bytes --]

From ac98fdd494e7d025ae47cf45424d9cdaeef7f104 Mon Sep 17 00:00:00 2001
From: Peter Seibel <peter@gigamonkeys.com>
Date: Sat, 4 Jan 2025 05:54:31 -0800
Subject: [PATCH 2/2] Simpler way to get list of addable files.

---
 lisp/pcmpl-git.el | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/lisp/pcmpl-git.el b/lisp/pcmpl-git.el
index 498918ac1c4..ab5e3305865 100644
--- a/lisp/pcmpl-git.el
+++ b/lisp/pcmpl-git.el
@@ -86,12 +86,7 @@ Files listed by `git ls-files ARGS' satisfy the predicate."
                ("add"
                 (pcomplete-here
                  (pcomplete-entries
-                  nil (let ((modified (pcmpl-git--tracked-file-predicate "-m"))
-                            (untracked (pcmpl-git--tracked-file-predicate "-o" "--exclude-standard")))
-                        (lambda (file)
-                          (or
-                           (and modified (funcall modified file))
-                           (and untracked (funcall untracked file))))))))
+                  nil (pcmpl-git--tracked-file-predicate "-o" "--exclude-standard" "-m"))))
                ;; Complete modified tracked files
                ((or "commit" "restore")
                 (pcomplete-here
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
  2025-01-04 13:59   ` Peter Seibel
@ 2025-01-04 15:04     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2025-01-04 15:52       ` Peter Seibel
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2025-01-04 15:04 UTC (permalink / raw)
  To: Peter Seibel; +Cc: Eli Zaretskii, Augusto Stoffel, 75336

>> > I was going a bit crazy trying to figure out why tab completion in
>> > *shell* wasn't working for git add when I was trying to add a new
>> > file to my repo.  Turns out pcomplete was only completing modified
>> > tracked files.  This patch changes it so after git add it also
>> > completes untracked non-ignored files.
>> Augusto and Stefan, any comments?

The (new) patch looks good to me.

FWIW, it also makes sense occasionally to `git add` ignored files
(e.g. we could want to track a `.elc` file in the test suite inside the
Emacs repository to check how we handle specific old-format `.elc`
files).


        Stefan






^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#75336: [PATCH] Allow pcomplete of git add to include untracked files.
  2025-01-04 15:04     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2025-01-04 15:52       ` Peter Seibel
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Seibel @ 2025-01-04 15:52 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, Augusto Stoffel, 75336


[-- Attachment #1.1: Type: text/plain, Size: 967 bytes --]

Okay, here's an updated patch to also complete ignored files when -f or
--force is specified.

If you want I can rebase and make a single patch.

On Sat, Jan 4, 2025 at 7:04 AM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> >> > I was going a bit crazy trying to figure out why tab completion in
> >> > *shell* wasn't working for git add when I was trying to add a new
> >> > file to my repo.  Turns out pcomplete was only completing modified
> >> > tracked files.  This patch changes it so after git add it also
> >> > completes untracked non-ignored files.
> >> Augusto and Stefan, any comments?
>
> The (new) patch looks good to me.
>
> FWIW, it also makes sense occasionally to `git add` ignored files
> (e.g. we could want to track a `.elc` file in the test suite inside the
> Emacs repository to check how we handle specific old-format `.elc`
> files).
>
>
>         Stefan
>
>

-- 
Peter Seibel
http://www.gigamonkeys.com/

[-- Attachment #1.2: Type: text/html, Size: 1579 bytes --]

[-- Attachment #2: 0003-Complete-ignored-files-when-force-specified-in-git-a.patch --]
[-- Type: application/octet-stream, Size: 1570 bytes --]

From ec55556505a47ff61d38d6c8bc5e589b02def884 Mon Sep 17 00:00:00 2001
From: Peter Seibel <peter@gigamonkeys.com>
Date: Sat, 4 Jan 2025 07:48:09 -0800
Subject: [PATCH 3/3] Complete ignored files when force specified in git add.

---
 lisp/pcmpl-git.el | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/lisp/pcmpl-git.el b/lisp/pcmpl-git.el
index ab5e3305865..f23002df28b 100644
--- a/lisp/pcmpl-git.el
+++ b/lisp/pcmpl-git.el
@@ -82,11 +82,16 @@ Files listed by `git ls-files ARGS' satisfy the predicate."
                   (pcomplete-from-help `(,vc-git-program "help" ,subcmd)
                                        :argument
                                        "-+\\(?:\\[no-\\]\\)?[a-z-]+=?"))))
-               ;; Complete modified tracked files and untracked files
+               ;; Complete modified tracked files and untracked files and
+               ;; ignored files if -f or --force is specified.
                ("add"
                 (pcomplete-here
                  (pcomplete-entries
-                  nil (pcmpl-git--tracked-file-predicate "-o" "--exclude-standard" "-m"))))
+                  nil
+                  (let ((flags (list "-o" "-m")))
+                    (unless (or (member "-f" pcomplete-args) (member "--force" pcomplete-args))
+                      (push "--exclude-standard" flags))
+                    (apply #'pcmpl-git--tracked-file-predicate flags)))))
                ;; Complete modified tracked files
                ((or "commit" "restore")
                 (pcomplete-here
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-01-04 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-04  0:00 bug#75336: [PATCH] Allow pcomplete of git add to include untracked files Peter Seibel
2025-01-04  7:52 ` Eli Zaretskii
2025-01-04  7:54 ` Eli Zaretskii
2025-01-04 13:59   ` Peter Seibel
2025-01-04 15:04     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2025-01-04 15:52       ` Peter Seibel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).