* git working tree status @ 2008-10-26 21:54 Mike Clarke 2008-10-26 22:23 ` Miklos Vajna 0 siblings, 1 reply; 4+ messages in thread From: Mike Clarke @ 2008-10-26 21:54 UTC (permalink / raw) To: git Hi all, I'd like a way of getting a simple summary of the status of a working tree, for consumption by other programs rather than humans. Specifically, I'd like to know whether the working tree is: a) fully 'clean' -- i.e., all changes checked in, no stashes; b) all changes checked in, but there are some stashes; or c) 'dirty' in some way -- new files, uncommitted changes, etc. The logical way to do this seems to be via an exit code, but the exit code of git status is not currently rich enough. As a result, I'm considering the addition of an option to git status -- perhaps '--is-clean' -- that would provide the required information. My questions are: 1) Is there already some way of doing this that I've overlooked? 2) Would the preferred approach be an option (git status --is-clean) or a sub-command (git is-clean)? A sub-command would probably result in cleaner internal code, but would also clutter the interface. 3) Is a patch for such a feature likely to be accepted? Thanks, -- Mike Clarke ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: git working tree status 2008-10-26 21:54 git working tree status Mike Clarke @ 2008-10-26 22:23 ` Miklos Vajna 2008-10-26 22:26 ` Miklos Vajna [not found] ` <73f525b90810270412o234bc88by16c67df9df067649@mail.gmail.com> 0 siblings, 2 replies; 4+ messages in thread From: Miklos Vajna @ 2008-10-26 22:23 UTC (permalink / raw) To: Mike Clarke; +Cc: git [-- Attachment #1: Type: text/plain, Size: 1411 bytes --] On Sun, Oct 26, 2008 at 09:54:03PM +0000, Mike Clarke <clarkema@gmail.com> wrote: > a) fully 'clean' -- i.e., all changes checked in, no stashes; In case you want to ignore ignores: $ git ls-files -o otherwise: git ls-files -o --exclude-standard by 'stashes', I guess you mean those extra files, but using that term is confusing, given that stashes can be listed with git stash list and they are actually merge commits (so something totally different). > b) all changes checked in, but there are some stashes; or git update-index -q --refresh test -z "$(git diff-index --name-only HEAD --)" && echo "everything committed" > c) 'dirty' in some way -- new files, uncommitted changes, etc. git update-index -q --refresh test -z "$(git diff-index --name-only HEAD --)" && echo "dirty" see GIT-VERSION-GEN in git.git > 1) Is there already some way of doing this that I've overlooked? > 2) Would the preferred approach be an option (git status --is-clean) > or a sub-command (git is-clean)? A sub-command would probably result > in cleaner internal code, but would also clutter the interface. I guess you overlooked the fact that plumbing is supposed to be used from scripts and porcelain by the users. git status is porcelain, so in general just don't use it from scripts. > 3) Is a patch for such a feature likely to be accepted? I don't think so, see above. [-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: git working tree status 2008-10-26 22:23 ` Miklos Vajna @ 2008-10-26 22:26 ` Miklos Vajna [not found] ` <73f525b90810270412o234bc88by16c67df9df067649@mail.gmail.com> 1 sibling, 0 replies; 4+ messages in thread From: Miklos Vajna @ 2008-10-26 22:26 UTC (permalink / raw) To: Mike Clarke; +Cc: git [-- Attachment #1: Type: text/plain, Size: 307 bytes --] On Sun, Oct 26, 2008 at 11:23:35PM +0100, Miklos Vajna <vmiklos@frugalware.org> wrote: > > c) 'dirty' in some way -- new files, uncommitted changes, etc. > > git update-index -q --refresh > test -z "$(git diff-index --name-only HEAD --)" && echo "dirty" I wanted to write '|| echo "dirty"', sorry. [-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <73f525b90810270412o234bc88by16c67df9df067649@mail.gmail.com>]
* Re: git working tree status [not found] ` <73f525b90810270412o234bc88by16c67df9df067649@mail.gmail.com> @ 2008-10-27 11:37 ` Mike Clarke 0 siblings, 0 replies; 4+ messages in thread From: Mike Clarke @ 2008-10-27 11:37 UTC (permalink / raw) To: git On Sun, Oct 26, 2008 at 11:23 PM, Miklos Vajna <vmiklos@frugalware.org> wrote: > On Sun, Oct 26, 2008 at 09:54:03PM +0000, Mike Clarke <clarkema@gmail.com> wrote: >> b) all changes checked in, but there are some stashes; or > > git update-index -q --refresh > test -z "$(git diff-index --name-only HEAD --)" && echo "everything committed" > >> c) 'dirty' in some way -- new files, uncommitted changes, etc. > > git update-index -q --refresh > test -z "$(git diff-index --name-only HEAD --)" && echo "dirty" > > see GIT-VERSION-GEN in git.git > >> 1) Is there already some way of doing this that I've overlooked? >> 2) Would the preferred approach be an option (git status --is-clean) >> or a sub-command (git is-clean)? A sub-command would probably result >> in cleaner internal code, but would also clutter the interface. > > I guess you overlooked the fact that plumbing is supposed to be used > from scripts and porcelain by the users. git status is porcelain, so > in general just don't use it from scripts. > >> 3) Is a patch for such a feature likely to be accepted? > > I don't think so, see above. Thanks for the pointers! To add a bit of context to the original post, we deal with a lot of small project repositories at work, and we swap between them quite a lot. As a result, management of the repositories can be somewhat burdensome; it's easy to leave a tree in the middle of something, and then forget. To get around this, I'm writing a Perl script, called git-map, which a) can be used to apply a given git command (say, 'fetch') to a whole group of repositories b) gives you an overview of the state of all your repos. For example: 546 clarkema@swiss:~/git> git-map summary C /home/clarkema/git/apollo C /home/clarkema/git/cerebro C /home/clarkema/git/dionysus S /home/clarkema/git/dotfiles C /home/clarkema/git/packaging/eAccelerator.git C /home/clarkema/git/programmes/cleo-vc-doc-version-2_0 D /home/clarkema/git/programmes/cumbria-libraries/cumbria-libraries-version-1_0.git C /home/clarkema/git/services/cleo-service-loadbalancers.git C /home/clarkema/git/services/cleo-service-proxypac.git C /home/clarkema/git/services/cleo-service-vc.git C /home/clarkema/git/services/cleo-service-webgw.git C /home/clarkema/git/software/configutils.git C /home/clarkema/git/software/listbuilder.git C /home/clarkema/git/software/luns-sdp C /home/clarkema/git/software/proxy-pac.git C /home/clarkema/git/software/sgdsync.git D /home/clarkema/git/software/vc-billing C /home/clarkema/git/toybox/git-contrib-import This shows me that most of me repos are clean. 'dotfiles' has a stash on it, and two others have uncommitted changes. The code I'm currently using, based on the comments above, is: sub cmd_summary { foreach my $tree ( sort @trees ) { local $CWD = $tree; system( "$GIT update-index -q --refresh" ); # The redirection is somewhat dirty; but is designed to eat the error # message that occurs if there is no HEAD yet. system( "$GIT diff-index --quiet HEAD 2> /dev/null" ); if ( $CHILD_ERROR == -1 ) { print STDERR "Failed to execute $GIT: $OS_ERROR\n"; } elsif ( $CHILD_ERROR & 127 ) { printf STDERR "Child died with signal %d\n", ( $CHILD_ERROR & 127 ); } else { my $exit_code = $CHILD_ERROR >> 8; print " "; if ( $exit_code == 0 ) { if ( have_stash() ) { print colored ['yellow'], "S"; } else { print colored ['green'], "C"; } } elsif ( $exit_code == 1 ) { print colored ['red'], "D"; } else { print colored ['red'], "?"; } print " $tree\n"; } } } sub have_stash { my $ref_stash = 'refs/stash'; system( "$GIT rev-parse --verify $ref_stash > /dev/null 2>&1" ); if ( $CHILD_ERROR == -1 ) { print STDERR "Failed to execute $GIT: $OS_ERROR\n"; } elsif ( $CHILD_ERROR & 127 ) { printf STDERR "Child died with signal %d\n", ( $CHILD_ERROR & 127 ); } return ( $CHILD_ERROR >> 8 ) == 0; } Any comments or suggestions to improve the above would be gratefully received! Thanks, -- Mike Clarke ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-10-27 11:39 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-10-26 21:54 git working tree status Mike Clarke 2008-10-26 22:23 ` Miklos Vajna 2008-10-26 22:26 ` Miklos Vajna [not found] ` <73f525b90810270412o234bc88by16c67df9df067649@mail.gmail.com> 2008-10-27 11:37 ` Mike Clarke
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).