Skip to content

Commit

Permalink
Merge pull request #17 from adamtheturtle/update-has-changes
Browse files Browse the repository at this point in the history
Update index before diff-index to check if there are changes
  • Loading branch information
asottile authored Sep 12, 2024
2 parents 9d882e7 + 38ab68a commit 87b886c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bin/main
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@ _GIT = (


def _has_changes(*, src_repo: str) -> bool:
cmd = (
# Without updating the index, diff-index may say that there
# are changes when there are not.
# For example, if a file has been written to but its contents
# have not changed.
update_index_cmd = (
*_GIT, '-C', src_repo, 'update-index', '--refresh',
)
subprocess.call(update_index_cmd)

diff_index_cmd = (
*_GIT, '-C', src_repo, 'diff-index',
'--quiet', '--no-ext-diff', 'HEAD', '--',
)
return subprocess.call(cmd) == 1
return subprocess.call(diff_index_cmd) == 1


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

0 comments on commit 87b886c

Please sign in to comment.