repos: use git diff-index to check if repo is dirty

is_dirty_cmd() uses `git diff --shortstat` to see if the repo can be
safely checked out. This only checks for the modified files and does
not take the cached(staged) files into account.

There can be cases where the cached changes could be overwritten by a
checkout. In this case, the git checkout command aborts with an error
message telling the user to commit or stash their changes.

Use `git diff-index HEAD --shortstat` to determine if there are any
changes in the tracked files, whether cached or not.

https://git-scm.com/docs/git-diff-index

Signed-off-by: Abdur Rehman <abdur_rehman@mentor.com>
This commit is contained in:
Abdur Rehman 2018-03-30 18:12:57 +05:00 committed by Daniel Wagner
parent 4be43c7bf6
commit 5b85fba0df

View File

@ -293,7 +293,7 @@ class GitRepo(RepoImpl):
return ['git', 'fetch', '--all']
def is_dirty_cmd(self):
return ['git', 'diff', '--shortstat']
return ['git', 'diff-index', 'HEAD', '--shortstat']
def current_rev_cmd(self):
return ['git', 'rev-parse', '--verify', 'HEAD']