From 5b85fba0df0663520a1f0012fdb1f5ec8cb74866 Mon Sep 17 00:00:00 2001 From: Abdur Rehman Date: Fri, 30 Mar 2018 18:12:57 +0500 Subject: [PATCH] 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 --- kas/repos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kas/repos.py b/kas/repos.py index 4b94499..c5d1ce3 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -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']