Re: determine if the tree is dirty

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: determine if the tree is dirty

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:39

Adam Mercer [off-list ref] 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.

Re: determine if the tree is dirty

From: Adam Mercer <hidden>
Date: 2016-06-15 22:47:39

On Tue, Nov 3, 2009 at 13:06, Jeff Epler [off-list ref] 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 [off-list ref] 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help