I have created a small script that aims on comparing two versions of a file by doing a git diff. Is there a better way to code it?
import subprocess
def diff_versions(file_to_be_compared, directory):
try:
out = subprocess.check_output(["git", "diff", "origin/master^", "origin/master", file_to_be_compared],
cwd = directory)
except subprocess.CalledProcessError as ex:
return ex.output
return out is None
def main():
result = diff_versions('file.txt', "some/directory")
if result is False:
raise Exception('diff found between the files')
else:
return 'files are identical'
if __name__ == "__main__":
main()
git
directly. – Etan Reisner Feb 4 '15 at 19:16