Skip to content

Commit 87b886c

Browse files
authored
Merge pull request #17 from adamtheturtle/update-has-changes
Update index before diff-index to check if there are changes
2 parents 9d882e7 + 38ab68a commit 87b886c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

bin/main

+11-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,20 @@ _GIT = (
2626

2727

2828
def _has_changes(*, src_repo: str) -> bool:
29-
cmd = (
29+
# Without updating the index, diff-index may say that there
30+
# are changes when there are not.
31+
# For example, if a file has been written to but its contents
32+
# have not changed.
33+
update_index_cmd = (
34+
*_GIT, '-C', src_repo, 'update-index', '--refresh',
35+
)
36+
subprocess.call(update_index_cmd)
37+
38+
diff_index_cmd = (
3039
*_GIT, '-C', src_repo, 'diff-index',
3140
'--quiet', '--no-ext-diff', 'HEAD', '--',
3241
)
33-
return subprocess.call(cmd) == 1
42+
return subprocess.call(diff_index_cmd) == 1
3443

3544

3645
def _rev_parse(*, repo: str, ref: str) -> str:

0 commit comments

Comments
 (0)