# [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository

5 messages from 2005-07-23 to 2005-07-25. Participants: Ryan Anderson, Linus Torvalds, Junio C Hamano.
Thread: https://gitlist.dev/t/1318

## Ryan Anderson, 2005-07-23 07:42

Subject: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
Message-ID: <20050723074219.GB3255@mythryan2.michonline.com>
URL: https://gitlist.dev/e/20050723074219.GB3255%40mythryan2.michonline.com

```
Add git-find-new-files to find files that are in the tree, but not checked into the repository.

Most users will probably want to "make clean" before using this for real
significant changes, as it does such a good job that it finds binaries that
just got built.

Signed-off-by: Ryan Anderson <ryan@michonline.com>
---

 Makefile           |    2 +-
 git-find-new-files |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 1 deletions(-)
 create mode 100755 git-find-new-files

028b21ae78dba3edab5e9b1a24cdf68011e42ab7
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -36,7 +36,7 @@ SCRIPTS=git git-apply-patch-script git-m
 	git-reset-script git-add-script git-checkout-script git-clone-script \
 	gitk git-cherry git-rebase-script git-relink-script git-repack-script \
 	git-format-patch-script git-sh-setup-script git-push-script \
-	git-branch-script git-parse-remote
+	git-branch-script git-parse-remote git-find-new-files
 
 PROG=   git-update-cache git-diff-files git-init-db git-write-tree \
 	git-read-tree git-commit-tree git-cat-file git-fsck-cache \
diff --git a/git-find-new-files b/git-find-new-files
new file mode 100755
--- /dev/null
+++ b/git-find-new-files
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+#
+# A simple script to take a look at all the files git knows about and compare
+# that to the files that we actually see in teh source tree, and output a
+# listing of the difference between them.
+#
+# The original command that did this is below, but a pure-Perl version can skip
+# the temp files.
+#
+#	find . -name .git -type d -prune -o -type f -print \
+#		| grep -v -e .tree1 -e .tree2 \
+#		| sed -e "s/^\.\///" \
+#		| sort >.tree1
+#	git-ls-files | grep -v -e .tree1 -e .tree2 \
+#		| sort >.tree2
+#	diff -u .tree1 .tree2
+
+use warnings;
+use strict;
+
+# Since we're using NUL (ASCII value of 0) to terminate strings,
+# set the field separator to that:
+$/ = "\0";
+
+my (%actual,%git);
+
+open(F,"-|","find . -name .git -type d -prune -o -type f -print0")
+	or die "Failed to open pipe from find: " . $!;
+
+while(<F>) {
+	chomp;
+	s#^\./##;
+	$actual{$_}++;
+}
+close(F);
+
+open(F,"-|","git-ls-files -z")
+	or die "Failed to open pipe from git-ls-files: " . $!;
+
+while(<F>) {
+	chomp;
+	delete $actual{$_};
+}
+close(F);
+
+foreach my $f (sort keys %actual) {
+	printf("A\t%s\n",$f);
+}
-- 

Ryan Anderson
  sometimes Pug Majere

```

## Linus Torvalds, 2005-07-23 17:43

Subject: Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
Message-ID: <Pine.LNX.4.58.0507231039290.6074@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0507231039290.6074%40g5.osdl.org
In-Reply-To: <20050723074219.GB3255@mythryan2.michonline.com>

```


On Sat, 23 Jul 2005, Ryan Anderson wrote:
>
> Add git-find-new-files to find files that are in the tree, but not checked into the repository.
> 
> Most users will probably want to "make clean" before using this for real
> significant changes, as it does such a good job that it finds binaries that
> just got built.

You really want to run "file" on the files. We almost certainly don't want 
to add binary executables, object files etc etc to the tree, so why even 
show them?

You should also filter the list by the "ignore" file. And I'd suggest
ignoring dot-files by default, for example (maybe add a "-a" flag to 
disable that, the same way "ls" does).

		Linus

```

## Linus Torvalds, 2005-07-23 17:48

Subject: Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
Message-ID: <Pine.LNX.4.58.0507231043330.6074@g5.osdl.org>
URL: https://gitlist.dev/e/Pine.LNX.4.58.0507231043330.6074%40g5.osdl.org
In-Reply-To: <Pine.LNX.4.58.0507231039290.6074@g5.osdl.org>

```


On Sat, 23 Jul 2005, Linus Torvalds wrote:

> 
> 
> On Sat, 23 Jul 2005, Ryan Anderson wrote:
> >
> > Add git-find-new-files to find files that are in the tree, but not checked into the repository.
> > 
> > Most users will probably want to "make clean" before using this for real
> > significant changes, as it does such a good job that it finds binaries that
> > just got built.
> 
> You really want to run "file" on the files. We almost certainly don't want 
> to add binary executables, object files etc etc to the tree, so why even 
> show them?
> 
> You should also filter the list by the "ignore" file. And I'd suggest
> ignoring dot-files by default, for example (maybe add a "-a" flag to 
> disable that, the same way "ls" does).

Oh, and btw, maybe you didn't realize that "git-ls-files --others" already 
basically does what your script does? Without any filtering - it was meant 
to be run from a script, so something like

	for i in $(git-ls-files --others)
	do
		if [ ! match_ignore "$i" ]; then
			case $(file -b $i)
			ELF*)
				;;
			*)
				echo $i
				;;
			esac
		fi
	done

was what I was thinking of.

		Linus

```

## Junio C Hamano, 2005-07-23 20:44

Subject: Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
Message-ID: <7vsly5qmkd.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vsly5qmkd.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20050723074219.GB3255@mythryan2.michonline.com>

```
Ryan Anderson <ryan@michonline.com> writes:

> Add git-find-new-files to find files that are in the tree, but
> not checked into the repository.

You _ought_ to be able to just say:

 $ git-ls-files --others --exclude-from=<exclude pattern file>

and be done with it.  Also please see the thread about Cogito
and StGIT's use of .gitignore and .git/exclude files.

The current implementation of "git-ls-files" exclude mechanism
may have rooms for improvements; the last time I checked, it
only did the matching of patterns against filename without
leading directories).  The world will be a better place if
somebody extends it, instead of working around its limitation.

I may be tempted to doing it myself, but I'm in the middle of
something else, so ...

> +#	find . -name .git -type d -prune -o -type f -print \
> +#		| grep -v -e .tree1 -e .tree2 \
> +#		| sed -e "s/^\.\///" \
> +#		| sort >.tree1
> +#	git-ls-files | grep -v -e .tree1 -e .tree2 \
> +#		| sort >.tree2
> +#	diff -u .tree1 .tree2

It does not matter since the above is just an example and I
think you should be able to just use "ls-files --others", but
just FYI, you could have written "comm -23 .tree1 .tree2" above
instead of "diff -u".

```

## Ryan Anderson, 2005-07-25 06:00

Subject: Re: [PATCH] Add git-find-new-files to spot files added to the tree, but not the repository
Message-ID: <20050725060029.GC6098@mythryan2.michonline.com>
URL: https://gitlist.dev/e/20050725060029.GC6098%40mythryan2.michonline.com
In-Reply-To: <Pine.LNX.4.58.0507231043330.6074@g5.osdl.org>

```
On Sat, Jul 23, 2005 at 10:48:39AM -0700, Linus Torvalds wrote:
> 
> Oh, and btw, maybe you didn't realize that "git-ls-files --others" already 
> basically does what your script does? Without any filtering - it was meant 
> to be run from a script, so something like

That's exactly what I was missing.

The usage on a lot of the commands is very, well, "terse".

I totally missed "others" and I'm not sure I would have caught the
significance right away, anyway.

I was going to start a patch series to pull the man pages into each
program - but then I just decided it'd be easier to install the man
pages.

-- 

Ryan Anderson
  sometimes Pug Majere

```
