Using GitPython and I want to call a function only if there is a change to local files after a pull. For example if I make a push on a separate computer. Then pull on the first computer it works as expected but does not provide any output. An ideal output is a list of files changed. Or alternatively just something that told me if the pull had an error, nothing pulled because the branch was up to date or a boolean that changes had happened. I believe I could scrape repo.git.status() but it seems crude. Looking around it looks like I could also compare branches for changes but it seems like a lot of extra code and remote calls. Is there a correct way using just the pull call?
while True:
repo = git.Repo()
o = repo.remotes.origin
o.pull()
changed = NOT_SURE
if changed:
do_something()
print(repo.git.status())
time.sleep(POLLING_RATE)
Update: This does work for checking if changes were made but does not give the files changes without extra remote calls
while True:
print(str(time.ctime())+": Checking for updates")
repo = git.Repo()
current_hash = repo.head.object.hexsha
o = repo.remotes.origin
o.pull()
pull_hash = repo.head.object.hexsha
if current_hash != pull_hash:
print("files have changed")
else:
print("no changes")
time.sleep(config.GIT_POLL_RATE)
git diff
. I can't tell you how to do that in GitPython, however. – Beadroll