git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Suggestion: git status --untracked
@ 2008-02-11  9:46 Rafael Garcia-Suarez
  2008-02-11 10:13 ` Matthieu Moy
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Rafael Garcia-Suarez @ 2008-02-11  9:46 UTC (permalink / raw)
  To: Git Mailing List

I find myself wanting sometimes to filter out the output of
git-status, to feed it to another command (for example, git-add, or
rm, or cat >> .gitignore). However it's not currently very easy to
parse in a one-liner.

I'm suggesting to add options to control this behaviour. My suggestion
would be (for a start) to add an option --untracked that will list all
untracked files on stdout, without a leading "#\t", and without
listing the added / modified / removed files.

I'm willing to implement it, but I'd like to have some discussion
about the interface first. Is that a good idea at all, and how could
it be improved interface-wise?

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

* Re: Suggestion: git status --untracked
  2008-02-11  9:46 Suggestion: git status --untracked Rafael Garcia-Suarez
@ 2008-02-11 10:13 ` Matthieu Moy
  2008-02-11 10:54   ` Rafael Garcia-Suarez
  2008-02-11 10:23 ` Jeff King
  2008-02-11 10:56 ` Jakub Narebski
  2 siblings, 1 reply; 5+ messages in thread
From: Matthieu Moy @ 2008-02-11 10:13 UTC (permalink / raw)
  To: Rafael Garcia-Suarez; +Cc: Git Mailing List

"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com> writes:

> I find myself wanting sometimes to filter out the output of
> git-status, to feed it to another command (for example, git-add, or
> rm, or cat >> .gitignore). However it's not currently very easy to
> parse in a one-liner.
>
> I'm suggesting to add options to control this behaviour. My suggestion
> would be (for a start) to add an option --untracked that will list all
> untracked files on stdout, without a leading "#\t", and without
> listing the added / modified / removed files.

Actually, it's already available (since a few weeks in master IIRC,
not sure whether it's in the latest release), as

  git ls-files --exclude-standard -o

The --exclude-standard tells git ls-files to read .gitignore and
friends as most commands do, and -o means "show 'other' files".

Older gits didn't have the --exclude-standard, so you had to say
--exclude-from=.git/info/exclude --exclude-per-directory=.gitignore
(or stg like that) instead.

-- 
Matthieu

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

* Re: Suggestion: git status --untracked
  2008-02-11  9:46 Suggestion: git status --untracked Rafael Garcia-Suarez
  2008-02-11 10:13 ` Matthieu Moy
@ 2008-02-11 10:23 ` Jeff King
  2008-02-11 10:56 ` Jakub Narebski
  2 siblings, 0 replies; 5+ messages in thread
From: Jeff King @ 2008-02-11 10:23 UTC (permalink / raw)
  To: Rafael Garcia-Suarez; +Cc: Git Mailing List

On Mon, Feb 11, 2008 at 10:46:25AM +0100, Rafael Garcia-Suarez wrote:

> I find myself wanting sometimes to filter out the output of
> git-status, to feed it to another command (for example, git-add, or
> rm, or cat >> .gitignore). However it's not currently very easy to
> parse in a one-liner.

Here's a one-liner:

  git status | sed -ne '/^# Untracked/,${s/#\t//p}'

Unfortunately it is both specific to GNU sed as well as horribly
unreadable.

> I'm suggesting to add options to control this behaviour. My suggestion
> would be (for a start) to add an option --untracked that will list all
> untracked files on stdout, without a leading "#\t", and without
> listing the added / modified / removed files.

The problem you are running into is that "git status" has a specific
purpose: generating the commit message template. Fortunately, it is
built on top of plumbing that is much easier to parse:

  git ls-files -o --exclude-standard

should produce the results you want. It even has a '-z' option to do
things safely in the face of filenames with newlines, and can limit
itself to partial paths.

-Peff

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

* Re: Suggestion: git status --untracked
  2008-02-11 10:13 ` Matthieu Moy
@ 2008-02-11 10:54   ` Rafael Garcia-Suarez
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael Garcia-Suarez @ 2008-02-11 10:54 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Git Mailing List

On 11/02/2008, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> Actually, it's already available (since a few weeks in master IIRC,
> not sure whether it's in the latest release), as
>
>   git ls-files --exclude-standard -o
>
> The --exclude-standard tells git ls-files to read .gitignore and
> friends as most commands do, and -o means "show 'other' files".

Ah, many thanks. (Still not familiar with the plumbing.) I'm already
adding an alias for that command in my config!

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

* Re: Suggestion: git status --untracked
  2008-02-11  9:46 Suggestion: git status --untracked Rafael Garcia-Suarez
  2008-02-11 10:13 ` Matthieu Moy
  2008-02-11 10:23 ` Jeff King
@ 2008-02-11 10:56 ` Jakub Narebski
  2 siblings, 0 replies; 5+ messages in thread
From: Jakub Narebski @ 2008-02-11 10:56 UTC (permalink / raw)
  To: Rafael Garcia-Suarez; +Cc: Git Mailing List

"Rafael Garcia-Suarez" <rgarciasuarez@gmail.com> writes:

> I find myself wanting sometimes to filter out the output of
> git-status, to feed it to another command (for example, git-add, or
> rm, or cat >> .gitignore). However it's not currently very easy to
> parse in a one-liner.

Probably because git-status is porcelain, and is meant to be used by
end user, not in scripts.
 
> I'm suggesting to add options to control this behaviour. My suggestion
> would be (for a start) to add an option --untracked that will list all
> untracked files on stdout, without a leading "#\t", and without
> listing the added / modified / removed files.
> 
> I'm willing to implement it, but I'd like to have some discussion
> about the interface first. Is that a good idea at all, and how could
> it be improved interface-wise?

To list all untracked files you can use plumbing command, namely
"git ls-files --others" (Show other files in the output), or perhaps
"git ls-files -o --directory --no-empty-directory --exclude-standard"

If you want to use git command in script, it is better to find
appropriate plumbing command to do what you want, for example
git-ls-files instead of git-status to list untracked files,
git-symbolic-ref instead of git-branch to get current branch name,
etc.

-- 
Jakub Narebski
Poland
ShadeHawk on #git

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

end of thread, other threads:[~2008-02-11 10:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-11  9:46 Suggestion: git status --untracked Rafael Garcia-Suarez
2008-02-11 10:13 ` Matthieu Moy
2008-02-11 10:54   ` Rafael Garcia-Suarez
2008-02-11 10:23 ` Jeff King
2008-02-11 10:56 ` Jakub Narebski

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 NNTP newsgroup(s).