{"thread":{"id":"12029","subject":"Suggestion: git status --untracked","startedAt":"2008-02-11T09:46:25Z","lastAt":"2008-02-11T10:56:26Z","messageCount":5,"participants":["Rafael Garcia-Suarez","Matthieu Moy","Jeff King","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"68351","messageId":"b77c1dce0802110146o708e26a7lef56683f6b823365@mail.gmail.com","threadId":"12029","inReplyTo":null,"subject":"Suggestion: git status --untracked","fromName":"Rafael Garcia-Suarez","fromEmail":"rgarciasuarez@gmail.com","sentAt":"2008-02-11T09:46:25Z","receivedAt":"2008-02-11T09:46:25Z","isPatch":false,"sender":{"key":"rgarciasuarez@gmail.com","avatar":null},"body":"I find myself wanting sometimes to filter out the output of\ngit-status, to feed it to another command (for example, git-add, or\nrm, or cat >> .gitignore). However it's not currently very easy to\nparse in a one-liner.\n\nI'm suggesting to add options to control this behaviour. My suggestion\nwould be (for a start) to add an option --untracked that will list all\nuntracked files on stdout, without a leading \"#\\t\", and without\nlisting the added / modified / removed files.\n\nI'm willing to implement it, but I'd like to have some discussion\nabout the interface first. Is that a good idea at all, and how could\nit be improved interface-wise?\n"},{"id":"68359","messageId":"vpq63wvztqc.fsf@bauges.imag.fr","threadId":"12029","inReplyTo":"b77c1dce0802110146o708e26a7lef56683f6b823365@mail.gmail.com","subject":"Re: Suggestion: git status --untracked","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2008-02-11T10:13:15Z","receivedAt":"2008-02-11T10:13:15Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"\"Rafael Garcia-Suarez\" <rgarciasuarez@gmail.com> writes:\n\n> I find myself wanting sometimes to filter out the output of\n> git-status, to feed it to another command (for example, git-add, or\n> rm, or cat >> .gitignore). However it's not currently very easy to\n> parse in a one-liner.\n>\n> I'm suggesting to add options to control this behaviour. My suggestion\n> would be (for a start) to add an option --untracked that will list all\n> untracked files on stdout, without a leading \"#\\t\", and without\n> listing the added / modified / removed files.\n\nActually, it's already available (since a few weeks in master IIRC,\nnot sure whether it's in the latest release), as\n\n  git ls-files --exclude-standard -o\n\nThe --exclude-standard tells git ls-files to read .gitignore and\nfriends as most commands do, and -o means \"show 'other' files\".\n\nOlder gits didn't have the --exclude-standard, so you had to say\n--exclude-from=.git/info/exclude --exclude-per-directory=.gitignore\n(or stg like that) instead.\n\n-- \nMatthieu\n"},{"id":"68364","messageId":"20080211102359.GA5916@coredump.intra.peff.net","threadId":"12029","inReplyTo":"b77c1dce0802110146o708e26a7lef56683f6b823365@mail.gmail.com","subject":"Re: Suggestion: git status --untracked","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-02-11T10:23:59Z","receivedAt":"2008-02-11T10:23:59Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Feb 11, 2008 at 10:46:25AM +0100, Rafael Garcia-Suarez wrote:\n\n> I find myself wanting sometimes to filter out the output of\n> git-status, to feed it to another command (for example, git-add, or\n> rm, or cat >> .gitignore). However it's not currently very easy to\n> parse in a one-liner.\n\nHere's a one-liner:\n\n  git status | sed -ne '/^# Untracked/,${s/#\\t//p}'\n\nUnfortunately it is both specific to GNU sed as well as horribly\nunreadable.\n\n> I'm suggesting to add options to control this behaviour. My suggestion\n> would be (for a start) to add an option --untracked that will list all\n> untracked files on stdout, without a leading \"#\\t\", and without\n> listing the added / modified / removed files.\n\nThe problem you are running into is that \"git status\" has a specific\npurpose: generating the commit message template. Fortunately, it is\nbuilt on top of plumbing that is much easier to parse:\n\n  git ls-files -o --exclude-standard\n\nshould produce the results you want. It even has a '-z' option to do\nthings safely in the face of filenames with newlines, and can limit\nitself to partial paths.\n\n-Peff\n"},{"id":"68369","messageId":"b77c1dce0802110254g724d4218l7219c9d9f9ec8027@mail.gmail.com","threadId":"12029","inReplyTo":"vpq63wvztqc.fsf@bauges.imag.fr","subject":"Re: Suggestion: git status --untracked","fromName":"Rafael Garcia-Suarez","fromEmail":"rgarciasuarez@gmail.com","sentAt":"2008-02-11T10:54:27Z","receivedAt":"2008-02-11T10:54:27Z","isPatch":false,"sender":{"key":"rgarciasuarez@gmail.com","avatar":null},"body":"On 11/02/2008, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:\n> Actually, it's already available (since a few weeks in master IIRC,\n> not sure whether it's in the latest release), as\n>\n>   git ls-files --exclude-standard -o\n>\n> The --exclude-standard tells git ls-files to read .gitignore and\n> friends as most commands do, and -o means \"show 'other' files\".\n\nAh, many thanks. (Still not familiar with the plumbing.) I'm already\nadding an alias for that command in my config!\n"},{"id":"68370","messageId":"m3bq6ng3sb.fsf@localhost.localdomain","threadId":"12029","inReplyTo":"b77c1dce0802110146o708e26a7lef56683f6b823365@mail.gmail.com","subject":"Re: Suggestion: git status --untracked","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-02-11T10:56:26Z","receivedAt":"2008-02-11T10:56:26Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Rafael Garcia-Suarez\" <rgarciasuarez@gmail.com> writes:\n\n> I find myself wanting sometimes to filter out the output of\n> git-status, to feed it to another command (for example, git-add, or\n> rm, or cat >> .gitignore). However it's not currently very easy to\n> parse in a one-liner.\n\nProbably because git-status is porcelain, and is meant to be used by\nend user, not in scripts.\n \n> I'm suggesting to add options to control this behaviour. My suggestion\n> would be (for a start) to add an option --untracked that will list all\n> untracked files on stdout, without a leading \"#\\t\", and without\n> listing the added / modified / removed files.\n> \n> I'm willing to implement it, but I'd like to have some discussion\n> about the interface first. Is that a good idea at all, and how could\n> it be improved interface-wise?\n\nTo list all untracked files you can use plumbing command, namely\n\"git ls-files --others\" (Show other files in the output), or perhaps\n\"git ls-files -o --directory --no-empty-directory --exclude-standard\"\n\nIf you want to use git command in script, it is better to find\nappropriate plumbing command to do what you want, for example\ngit-ls-files instead of git-status to list untracked files,\ngit-symbolic-ref instead of git-branch to get current branch name,\netc.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}