Skip to contentSkip to conversation

Add "--only-untracked" flag to status commands.

PATCH In review Väinö Järvelä 7 participants 21 messages Jun 15, 2016 1 message not in the archive Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Add "--only-untracked" flag to status commands.

With this flag, the user can choose to filter untracked files from the status output. This can be used to either speed up the status output, as the untracked files are not fetched at all, or to just cleanup the output without using gitignore.

---
 builtin-runstatus.c |    4 +++-
 git-commit.sh       |   11 +++++++++--
 wt-status.c         |    8 +++++++-
 wt-status.h         |    1 +
 4 files changed, 20 insertions(+), 4 deletions(-)
builtin-runstatus.c +3 -1
index 2db25c8..2121762 100644
@@ -5,7 +5,7 @@
 extern int wt_status_use_color;
 
 static const char runstatus_usage[] =
-"git-runstatus [--color|--nocolor] [--amend] [--verbose] [--untracked]";
+"git-runstatus [--color|--nocolor] [--amend] [--verbose] [--untracked]" "[--only-tracked]";
 
 int cmd_runstatus(int argc, const char **argv, const char *prefix)
 {
@@ -28,6 +28,8 @@ int cmd_runstatus(int argc, const char **argv, const char *prefix)
 			s.verbose = 1;
 		else if (!strcmp(argv[i], "--untracked"))
 			s.untracked = 1;
+		else if (!strcmp(argv[i], "--only-tracked"))
+			s.only_tracked = 1;
 		else
 			usage(runstatus_usage);
 	}
git-commit.sh +9 -2
index d7e7028..0ef50d9 100755
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2006 Junio C Hamano
 
-USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [[-i | -o] <path>...]'
+USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [--template <file>] [--only-tracked] [[-i | -o] <path>...]'
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
 require_work_tree
@@ -56,7 +56,8 @@ run_status () {
 	git runstatus ${color} \
 		${verbose:+--verbose} \
 		${amend:+--amend} \
-		${untracked_files:+--untracked}
+		${untracked_files:+--untracked} \
+		${only_tracked:+--only-tracked}
 }
 
 trap '
@@ -87,6 +88,7 @@ signoff=
 force_author=
 only_include_assumed=
 untracked_files=
+only_tracked=
 templatefile="`git config commit.template`"
 while case "$#" in 0) break;; esac
 do
@@ -269,6 +271,11 @@ $1"
 		untracked_files=t
 		shift
 		;;
+    --only-|--only-t|--only-tr|--only-tra|--only-trac|--only-track|\
+    --only-tracke|--only-tracked)
+        only_tracked=t
+        shift
+        ;;
 	--)
 		shift
 		break
wt-status.c +7 -1
index 5205420..7c2c468 100644
@@ -331,7 +331,13 @@ void wt_status_print(struct wt_status *s)
 	}
 
 	wt_status_print_changed(s);
-	wt_status_print_untracked(s);
+
+	if (!s->only_tracked) {
+		wt_status_print_untracked(s);
+	}
+	else {
+		printf("# Untracked files were filtered by \"--only-tracked\"\n");
+	}
 
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
wt-status.h +1 -0
index cfea4ae..45b7e09 100644
@@ -15,6 +15,7 @@ struct wt_status {
 	int verbose;
 	int amend;
 	int untracked;
+	int only_tracked;
 	/* These are computed during processing of the individual sections */
 	int commitable;
 	int workdir_dirty;
Signature · 1 line
1.5.3.rc6.17.g1911-dirty
#1 lore raw

PATCH 2/2 Documented "--only-untracked" flag.

Also moved a paragraph about git-status options from description section, to options section. Which makes it easier to quickly search for git-status options without reading the description, even though the description for options forwards to git-commit manual.

---
 Documentation/git-runstatus.txt |    4 +++-
 Documentation/git-status.txt    |   17 ++++++++++++-----
 2 files changed, 15 insertions(+), 6 deletions(-)
Documentation/git-runstatus.txt +3 -1
index dee5d0d..56af1c1 100644
@@ -8,7 +8,7 @@ git-runstatus - A helper for git-status and git-commit
 
 SYNOPSIS
 --------
-'git-runstatus' [--color|--nocolor] [--amend] [--verbose] [--untracked]
+'git-runstatus' [--color|--nocolor] [--amend] [--verbose] [--untracked] [--only-tracked]
 
 
 DESCRIPTION
@@ -47,6 +47,8 @@ OPTIONS
 	option only its name and a trailing slash are displayed
 	for each untracked directory.
 
+--only-tracked:
+	Hide untracked files from the output.
 
 OUTPUT
 ------
Documentation/git-status.txt +12 -5
index 8fd0fc6..de9f5ff 100644
@@ -8,7 +8,7 @@ git-status - Show the working tree status
 
 SYNOPSIS
 --------
-'git-status' <options>...
+'git-status' [--only-tracked] <options>...
 
 DESCRIPTION
 -----------
@@ -23,10 +23,6 @@ If there is no path that is different between the index file and
 the current HEAD commit, the command exits with non-zero
 status.
 
-The command takes the same set of options as `git-commit`; it
-shows what would be committed if the same options are given to
-`git-commit`.
-
 If any paths have been touched in the working tree (that is,
 their modification times have changed) but their contents and
 permissions are identical to those in the index file, the command
@@ -35,6 +31,17 @@ subsequent operations such as `git-diff` if the working tree
 contains many paths that have been touched but not modified.
 
 
+OPTIONS
+-------
+--only-tracked::
+	Hide untracked files from the output.
+
+<options>::
+	The command takes the same set of options as `git-commit`; it
+	shows what would be committed if the same options are given to
+	`git-commit`.
+
+
 OUTPUT
 ------
 The output from this command is designed to be used as a commit
Signature · 1 line
1.5.3.rc6.17.g1911-dirty
#3 lore raw
In reply to a message not in the archive

Väinö Järvelä, Thu, Aug 23, 2007 21:58:31 +0200:

Quoted 4 lines

With this flag, the user can choose to filter untracked files from the status output. This can be used to either speed up the status output, as the untracked files are not fetched at all, or to just cleanup the output without using gitignore.

"git diff -r --name-status; git diff --cached -r --name-status" is not enough?

#4 lore raw
Quoted 10 lines · Alex Riesen

Väinö Järvelä, Thu, Aug 23, 2007 21:58:31 +0200:

Quoted 6 lines

With this flag, the user can choose to filter untracked files from the
status output. This can be used to either speed up the status output, as
the untracked files are not fetched at all, or to just cleanup the output without using gitignore.

"git diff -r --name-status; git diff --cached -r --name-status" is not enough?

That line will result in duplicate entries, if files are staged, and the output of git-status is neater (but longer) in my opinion.

"""
M Makefile
M Makefile
"""
vs.
"""
# On branch entity_class
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: Makefile
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: Makefile
#
# Untracked files were filtered by "--only-tracked" """

Sure you could remove duplicate entries with "sort|uniq", or something, but just running "git status --only-tracked", is cleaner, and more user friendly.

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

--
Väinö

#5 lore raw

Väinö Järvelä, Fri, Aug 24, 2007 08:35:13 +0200:

Quoted 10 lines · Alex Riesen
Quoted 9 lines

Väinö Järvelä, Thu, Aug 23, 2007 21:58:31 +0200:

Quoted 6 lines

With this flag, the user can choose to filter untracked files from the
status output. This can be used to either speed up the status output, as
the untracked files are not fetched at all, or to just cleanup the output without using gitignore.

Quoted 5 lines
Quoted 2 lines

"git diff -r --name-status; git diff --cached -r --name-status" is not enough?

That line will result in duplicate entries, if files are staged, and the output of git-status is neater (but longer) in my opinion.

That is because it _is_ two times different: between working directory and the index, and between index and HEAD. git-status _will_ show you the same for the same reason.

Besides, why do you want to hide this "duplication"? It shows how the matters really are.

Besides, it looks like you are using "friendly" where you actually wanted to say "I consider you too dumb to know what happens". Someone may feel offended

#6 lore raw
Quoted 17 lines · Alex Riesen

Väinö Järvelä, Fri, Aug 24, 2007 08:35:13 +0200:

Quoted 10 lines · Alex Riesen
Quoted 9 lines

Väinö Järvelä, Thu, Aug 23, 2007 21:58:31 +0200:

Quoted 6 lines

With this flag, the user can choose to filter untracked files from the
status output. This can be used to either speed up the status output, as
the untracked files are not fetched at all, or to just cleanup the output without using gitignore.

Quoted 5 lines
Quoted 2 lines

"git diff -r --name-status; git diff --cached -r --name-status" is not enough?

That line will result in duplicate entries, if files are staged, and the output of git-status is neater (but longer) in my opinion.

Quoted 6 lines

That is because it _is_ two times different: between working directory and the index, and between index and HEAD. git-status _will_ show you the same for the same reason.

Besides, why do you want to hide this "duplication"? It shows how the matters really are.

git status --only-tracked, does not hide the fact that there are files staged for commit, and modified files relative to the index. The difference is, that it shows them in a clean way. Sure you could make a script like:

echo "Changes to be committed:"; git diff --cached -r --name-status; echo "Changed but not updates:"; git diff -r --name-status

But that is quite long, for a quick look at the state, without any untracked files.

Quoted 4 lines

Besides, it looks like you are using "friendly" where you actually wanted to say "I consider you too dumb to know what happens". Someone may feel offended

I don't see where I consider users dumb, but hey, I'm sorry if I made someone feel offended.

--
Väinö

#7 lore raw
Quoted 11 lines · Väinö Järvelä
Quoted 9 lines · Alex Riesen
Quoted 2 lines

That line will result in duplicate entries, if files are staged, and the output of git-status is neater (but longer) in my opinion.

That is because it _is_ two times different: between working directory and the index, and between index and HEAD. git-status _will_ show you the same for the same reason.

Besides, why do you want to hide this "duplication"? It shows how the matters really are.

The whole argument of "two entries are dups" is showing that you might be repeating past mistake of Cogito where hiding the index from the user would make git somehow more user friendly. It was a laudable attempt, but did not really fly well in practice.

But the --only-tracked has a bigger issue.

Letting the user know about untracked files that should be tracked is really important to avoid mistakes. If the status output is so cluttered for you to want an option like this, it is hard to spot such a file. I do not think disabling the untracked output is a solution to the real problem.

You earlier said that you may not be able to add certain untracked files to .gitignore --- can you elaborate?

I do not think the reason is you are too lazy to do so, nor you are incompetent to understand the ignore pattern. There is something else, which might show that the current ignore facility needs to become easier to use for _your_ use of _your_ repository. I still do not see in the thread what it is yet.

For example, maybe the reason why you do not want to place them in the .gitignore file is because the clutter are your random wip temporary files, whose naming convention is personal to you and does not apply to others. Naturally, you do not want to put such patterns to the tracked .gitignore file, which is for all participants of the project. In such a case, you would want a facility to allow you to specify your personal ignore patterns that is used in addition to the .gitignore file [*1*].

The particular example use case above is covered by an existing facility, but there might be other valid reasons that you cannot express your ignore patterns easily with existing facilities. In which case, we need to know that, so that you and people in similar situation as you are in can express the necessary ignore patterns more easily, in order to reduce the risk of forgetting to add new files.

[Footnote]

*1* Which already exists. Put them in .git/info/exclude file.

#8 lore raw
In reply to Väinö Järvelä
Quoted 3 lines · Väinö Järvelä

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

Why?

Just set up .gitignore once then (1) you do not have to worry about them ever again, and (2) you _will_ still be able to notice if you accidentally added more cruft, or more importantly, if you forgot to tell an important file to git.

I think the latter is more important point. If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice. Mistake to forget "git add" a new file before commiting will bound to happen.

#9 lore raw
Quoted 13 lines · Junio C Hamano
Quoted 3 lines · Väinö Järvelä

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

Why?

Just set up .gitignore once then (1) you do not have to worry about them ever again, and (2) you _will_ still be able to notice if you accidentally added more cruft, or more importantly, if you forgot to tell an important file to git.

Quoted 4 lines

I think the latter is more important point. If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice. Mistake to forget "git add" a new file before commiting will bound to happen.

I also think that maintaining a proper .gitignore is imporant, and more productive than using --only-tracked instead. But when I have cruft that can't be put in .gitignore, or it would ignore files that are supposed to be shown and tracked, I use --only-tracked.

It's true though, that the user might forget to add a file if he always uses --only-tracked, that's why I added the note in the status that the untracked files were filtered out. The flag is supposed to be a helper for situations where .gitignore wouldn't work, not a way to work always. Maybe if this flag is accepted, the manual should say that in most cases it's better to use .gitignore.

--
Väinö

#10 lore raw

Hi,

Quoted 20 lines · V?in? J?rvel
Quoted 13 lines · Junio C Hamano
Quoted 3 lines · V?in? J?rvel?

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

Why?

Just set up .gitignore once then (1) you do not have to worry about them ever again, and (2) you _will_ still be able to notice if you accidentally added more cruft, or more importantly, if you forgot to tell an important file to git.

Quoted 4 lines

I think the latter is more important point. If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice. Mistake to forget "git add" a new file before commiting will bound to happen.

Quoted 4 lines

I also think that maintaining a proper .gitignore is imporant, and more productive than using --only-tracked instead. But when I have cruft that can't be put in .gitignore, or it would ignore files that are supposed to be shown and tracked, I use --only-tracked.

Would it not be better to imitate the "-x" and "-X" options of ls-files, then? You could achieve the effect you desire by "git status -x \*" then.

Ciao,
Dscho

#11 lore raw
Quoted 9 lines · Johannes Schindelin
Quoted 7 lines · V?in? J?rvel

I also think that maintaining a proper .gitignore is imporant, and more
productive than using --only-tracked instead. But when I have cruft that can't
be put in .gitignore, or it would ignore files that are supposed to be shown
and tracked, I use --only-tracked.

Quoted 7 lines

Would it not be better to imitate the "-x" and "-X" options of ls- files,
then? You could achieve the effect you desire by "git status -x \*" then.

Ciao,
Dscho

I haven't used that option, do I understand correctly, that with that option, you should provide another exclusion file? That would remove the dynamic ability of --only-tracked.

--
Väinö

#12 lore raw

Hi,

Quoted 7 lines · V?in? J?rvel
Quoted 6 lines · Johannes Schindelin
Quoted 4 lines · V?in? J?rvel

I also think that maintaining a proper .gitignore is imporant, and more productive than using --only-tracked instead. But when I have cruft that can't be put in .gitignore, or it would ignore files that are supposed to be shown and tracked, I use --only-tracked.

Quoted 7 lines
Quoted 3 lines

Would it not be better to imitate the "-x" and "-X" options of ls-files, then? You could achieve the effect you desire by "git status -x \*" then.

I haven't used that option, do I understand correctly, that with that option, you should provide another exclusion file? That would remove the dynamic ability of --only-tracked.

-X takes a filename, -x a pattern.

Hth,
Dscho

#13 lore raw
In reply to Johannes Schindelin
Quoted 3 lines · Johannes Schindelin

Would it not be better to imitate the "-x" and "-X" options of ls-files, then? You could achieve the effect you desire by "git status -x \*" then.

That's equivalent feature-wise, but a bit slower performance-wise (the proposed patch skips file listing totally). But since the use-case for it is not the common case, it probably doesn't matter (and in case, it's possible to hardcode an optimisation if the pattern is "*").

Signature · 1 line
Matthieu
#14 lore raw
In reply to Junio C Hamano
Quoted 4 lines · Junio C Hamano

I think the latter is more important point.  If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice.  Mistake to forget "git add" a new file before commiting will bound to happen.

If it won't acquire short version, nor tab completion, mosts users when confronted with such a mothful of option-name wouldn't use it unless necessary, I think...

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#15 lore raw
Quoted 10 lines · Jakub Narebski
Quoted 4 lines · Junio C Hamano

I think the latter is more important point.  If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice.  Mistake to forget "git add" a new file before commiting will bound to happen.

If it won't acquire short version, nor tab completion, mosts users when confronted with such a mothful of option-name wouldn't use it unless necessary, I think...

Yeah, but if we accept that --only-tracked patch, I know from the past experience that people would send a "shorter synonym" patch, arguing that the capability is already there.

I really think we should resist temptation to add misfeatures that would encourage bad workflows and new user mistakes.

#16 lore raw
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · Jakub Narebski
Quoted 4 lines · Junio C Hamano

I think the latter is more important point. If you train a naive user to use --only-tracked to ignore "Untracked" list, you are doing him or her a great disservice. Mistake to forget "git add" a new file before commiting will bound to happen.

If it won't acquire short version, nor tab completion, mosts users when
confronted with such a mothful of option-name wouldn't use it unless necessary, I think...

Quoted 6 lines

Yeah, but if we accept that --only-tracked patch, I know from the past experience that people would send a "shorter synonym" patch, arguing that the capability is already there.

I really think we should resist temptation to add misfeatures that would encourage bad workflows and new user mistakes.

I really do think that there is a use case for this patch. But this assumes that the testing is done in the source tree, but maybe that in itself can be considered a bad workflow.

An example would be in game development, where I have a directory full of images, and I wish to try out different images in the place of one. I usually create different versions of the images with different names, filling up the image directory under VCS. This usually results in tens of images that will not be tracked (unless they replace the original images), but because of my bad habit of creating the files inside the source tree, which results in a little bit faster workflow for me. With all these untracked files, git- status will obscure the actual contents of the status I wish to see.

I cannot put those files inside .gitignore, as there would have to be some kind of exclusion pattern for them that won't match the tracked files. Sure I could prefix all of my test images with 'test_' or something similiar. Or I could just add '*' to .gitignore, and force adds. The latter seems like a bad habit for me, the other seems to include a lot of manual labor, especially when someone else sends test files for me.

So the end result for me is, that it's easier to use --only-tracked

Fringe case? Maybe. Workflow could be better, sure. But --only- tracked even works for the less technical folk, which might be scared of forcing the changes, or annoyed by having to name the files with a magic prefix.

--
Väinö

#17 lore raw

Hi,

Quoted 4 lines · V?in? J?rvel

An example would be in game development, where I have a directory full of images, and I wish to try out different images in the place of one. I usually create different versions of the images with different names, filling up the image directory under VCS.

I have a similar use case, funnily enough also with images. I created a tmp/ directory and put the images there, cp'ing or ln -s'ing the current one into the cwd. Then, "/tmp/" is put into .gitignore and all is well.

Especially the fact that I no longer forget to check in the images that I _do_ want to track.

Ciao,
Dscho

#18 lore raw
In reply to Väinö Järvelä
Quoted 3 lines · Väinö Järvelä

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

I like it.

Signature · 3 lines
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
#20 lore raw
In reply to Väinö Järvelä
Quoted 1 line · Väinö Järvelä

Subject: Re: [PATCH 1/2] Add "--only-untracked" flag to status commands.

                                       ^^

I suppose you meant --only-tracked.

Quoted 4 lines

static const char runstatus_usage[] =
-"git-runstatus [--color|--nocolor] [--amend] [--verbose] [--untracked]"; +"git-runstatus [--color|--nocolor] [--amend] [--verbose] [--untracked]" "[--only-tracked]";

               ^^^

The compiler will concatenate the strings, but won't add a space. That results in "... [--untracked][--only-tracked]".

Otherwise, the patch sounds fine to me. Not /terribly/ usefull, but why not.

Signature · 1 line
Matthieu
#21 lore raw
Quoted 7 lines · Matthieu Moy
Quoted 2 lines · Väinö Järvelä

Subject: Re: [PATCH 1/2] Add "--only-untracked" flag to status commands.

                                       ^^

I suppose you meant --only-tracked.

Yes, a stupid typo. It should be --only-tracked.

Quoted 9 lines
Quoted 5 lines

static const char runstatus_usage[] =
-"git-runstatus [--color|--nocolor] [--amend] [--verbose] [-- untracked]";
+"git-runstatus [--color|--nocolor] [--amend] [--verbose] [--untracked]" "[--only-tracked]";

               ^^^

The compiler will concatenate the strings, but won't add a space. That results in "... [--untracked][--only-tracked]".

Should have checked it more properly, sorry about that.

Quoted 3 lines

Otherwise, the patch sounds fine to me. Not /terribly/ usefull, but why not.

This is something that has come up many times on our project, there might be a lot of temporary files that are used inside the project tree, to test the code, and the user just wants to see the modifications to tracked files without using a pager. One could use gitignore, but in our case, it would be hard to create a gitignore which would ignore all of the test files, and none of the actual project files, so it's quite convenient to use --only-tracked.

A better behavior might be to test outside of the project tree.

Quoted 3 lines
Signature · 2 lines
-- 
Matthieu

--
Väinö

#19 lore raw
In reply to Jakub Narebski
Quoted 6 lines · Jakub Narebski
Quoted 1 line · Väinö Järvelä

The way I see the flag used is: A user runs "git status", sees that there is too much untracked files and not enough scrollback, so he runs "git status --only-tracked" to filter the results.

I like it.

Ack on that. It's happened to me a bunch of times, usually followed by <identical command> | sed '/Untracked/,$d'

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231