Re: How to check repository/working tree status from a script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Tue, 19 May 2009, Linus Torvalds wrote:
> 
> And if what you want to know about is whether there are _new_ files you 
> might want to check, then you need a third check: 'git ls-files'. You 
> won't see it in the error code, but you can do
> 
> 	others=$(git ls-files -o --exclude-standard)
> 
> and then check it 'others' is empty or not.

Actually, you can use 'git ls-files' to also list files that are changed 
wrt the index, so then you can drop the 'git diff' thing.

IOW, something like this:

	# any staged changes (ready to commit)
	git diff --quiet --staged || echo Staged changes

	# any changes wrt the index (not staged)
	others=$(git ls-files --exclude-standard -o -d -m -u)
	[ -z "$others" ] || echo "Other changes"

should do it.

If you want more specificity wrt the "Other changes", you can add the "-t" 
flag to git ls-files and parse the output to see whether the listed files 
were just unknown (ie new files): '?', changed: 'C', removed: 'R' or need 
to be merged: 'M'

Of course, 'git diff [--staged]' is needed if you actually want to know 
some "deeper" patterns about _how_ things were changed. IOW, if you want 
to know about renames/copies, you need to use 'git diff -M/C' to get that 
kind of information.

			Linus
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]