* determine if the tree is dirty
@ 2009-11-03 18:57 Adam Mercer
2009-11-03 19:06 ` Jeff Epler
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Adam Mercer @ 2009-11-03 18:57 UTC (permalink / raw)
To: git
Hi
As part of a python script I need to determine if a tree has any
uncommitted changes, so far I am been using:
# determine tree status
status_cmd = 'git status'
status_output = run_external_command(status_cmd,
honour_ret_code=False)[1].strip()
if status_output.endswith('no changes added to commit (use "git add"
and/or "git commit -a")'):
git_status = 'UNCLEAN: Some modifications not committed'
else:
git_status = 'CLEAN: All modifications committed'
but I feel that this relies to heavily on the porcelain and that there
should be a better way to accomplish this without relying on parsing
the output of git-status.
Does anyone know of a better way to accomplish this?
Cheers
Adam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: determine if the tree is dirty
2009-11-03 18:57 determine if the tree is dirty Adam Mercer
@ 2009-11-03 19:06 ` Jeff Epler
2009-11-03 19:19 ` Junio C Hamano
2009-11-03 21:07 ` Markus Hitter
2 siblings, 0 replies; 5+ messages in thread
From: Jeff Epler @ 2009-11-03 19:06 UTC (permalink / raw)
To: Adam Mercer; +Cc: git
On Tue, Nov 03, 2009 at 12:57:37PM -0600, Adam Mercer wrote:
> As part of a python script I need to determine if a tree has any
> uncommitted changes
GIT-VERSION-GEN uses something like this (shell script):
git update-index -q --refresh
test -z "$(git diff-index --name-only HEAD --)" || VN="$VN-dirty" ;;
Jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: determine if the tree is dirty
2009-11-03 18:57 determine if the tree is dirty Adam Mercer
2009-11-03 19:06 ` Jeff Epler
@ 2009-11-03 19:19 ` Junio C Hamano
2009-11-03 19:30 ` Adam Mercer
2009-11-03 21:07 ` Markus Hitter
2 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-11-03 19:19 UTC (permalink / raw)
To: Adam Mercer; +Cc: git
Adam Mercer <ramercer@gmail.com> writes:
> As part of a python script I need to determine if a tree has any
> uncommitted changes, so far I am been using:
>
> # determine tree status
> status_cmd = 'git status'
> status_output = run_external_command(status_cmd,
> honour_ret_code=False)[1].strip()
> if status_output.endswith('no changes added to commit (use "git add"
> and/or "git commit -a")'):
> git_status = 'UNCLEAN: Some modifications not committed'
> else:
> git_status = 'CLEAN: All modifications committed'
>
> but I feel that this relies to heavily on the porcelain and that there
> should be a better way to accomplish this without relying on parsing
> the output of git-status.
>
> Does anyone know of a better way to accomplish this?
Use plumbing commands.
"git diff-files" will show changes you have in the work tree compared to
the index.
"git diff-index HEAD" will show changes you have in the work tree compared
to the HEAD.
"git diff-index --cached HEAD" will show changes you have in the index
compared to the HEAD.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: determine if the tree is dirty
2009-11-03 19:19 ` Junio C Hamano
@ 2009-11-03 19:30 ` Adam Mercer
0 siblings, 0 replies; 5+ messages in thread
From: Adam Mercer @ 2009-11-03 19:30 UTC (permalink / raw)
To: Junio C Hamano, jepler; +Cc: git
On Tue, Nov 3, 2009 at 13:06, Jeff Epler <jepler@unpythonic.net> wrote:
> GIT-VERSION-GEN uses something like this (shell script):
> git update-index -q --refresh
> test -z "$(git diff-index --name-only HEAD --)" || VN="$VN-dirty" ;;
On Tue, Nov 3, 2009 at 13:19, Junio C Hamano <gitster@pobox.com> wrote:
> Use plumbing commands.
>
> "git diff-files" will show changes you have in the work tree compared to
> the index.
>
> "git diff-index HEAD" will show changes you have in the work tree compared
> to the HEAD.
>
> "git diff-index --cached HEAD" will show changes you have in the index
> compared to the HEAD.
Fantastic, this is exactly what I was after! Thanks!
Cheers
Adam
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: determine if the tree is dirty
2009-11-03 18:57 determine if the tree is dirty Adam Mercer
2009-11-03 19:06 ` Jeff Epler
2009-11-03 19:19 ` Junio C Hamano
@ 2009-11-03 21:07 ` Markus Hitter
2 siblings, 0 replies; 5+ messages in thread
From: Markus Hitter @ 2009-11-03 21:07 UTC (permalink / raw)
To: Adam Mercer; +Cc: git
Am 03.11.2009 um 19:57 schrieb Adam Mercer:
> As part of a python script I need to determine if a tree has any
> uncommitted changes, so far I am been using:
> [...]
> Does anyone know of a better way to accomplish this?
I'm using
git ls-files -m -o -d --exclude-standard
If it returns anything, your repo is dirty.
Markus
- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-11-03 21:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-03 18:57 determine if the tree is dirty Adam Mercer
2009-11-03 19:06 ` Jeff Epler
2009-11-03 19:19 ` Junio C Hamano
2009-11-03 19:30 ` Adam Mercer
2009-11-03 21:07 ` Markus Hitter
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).