Commit a4d5cad8 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[bin] add script to detect modified files

parent dce216a4
#!/usr/bin/env python3
Get the names of the files that differ between two git trees
import os
import subprocess
from argparse import ArgumentParser
def getCommandOutput(command):
return subprocess.check_output(command, encoding='ascii')
# get the files that differ between two trees in a git repo
def getChangedFiles(gitFolder, sourceTree, targetTree):
owd = os.getcwd()
root = getCommandOutput(['git', 'rev-parse', '--show-toplevel']).strip('\n')
changedFiles = getCommandOutput(
["git", "diff-tree", "-r", "--name-only", sourceTree, targetTree],
changedFiles = [os.path.join(root, file) for file in changedFiles]
return changedFiles
if __name__ == '__main__':
# parse input arguments
parser = ArgumentParser(
description='Get the files that differ between two git-trees'
parser.add_argument('-f', '--folder',
required=False, default='.',
help='The path to a folder within the git repository')
parser.add_argument('-s', '--source-tree',
required=False, default='HEAD',
help='The source tree (default: `HEAD`)')
parser.add_argument('-t', '--target-tree',
required=False, default='master',
help='The tree to compare against (default: `master`)')
parser.add_argument('-o', '--outfile',
required=False, default='changedfiles.txt',
help='The file in which to write the changed files')
args = vars(parser.parse_args())
changedFiles = getChangedFiles(args['folder'],
with open(args['outfile'], 'w') as outFile:
for file in changedFiles:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment