Skip to content
Snippets Groups Projects
Commit 9ecda465 authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[bin][getchangedfiles] prefer subprocess' cwd over chdir

parent 65f3548b
No related branches found
No related tags found
1 merge request!2626feature/refactor-test-selection
......@@ -9,23 +9,24 @@ import subprocess
from argparse import ArgumentParser
def getCommandOutput(command):
return subprocess.check_output(command, encoding='ascii')
def getCommandOutput(command, cwd=None):
return subprocess.check_output(command, encoding='ascii', cwd=cwd)
# get the files that differ between two trees in a git repo
def getChangedFiles(gitFolder, sourceTree, targetTree):
owd = os.getcwd()
os.chdir(os.path.abspath(gitFolder))
root = getCommandOutput(['git', 'rev-parse', '--show-toplevel']).strip('\n')
gitFolder = os.path.abspath(gitFolder)
root = getCommandOutput(
command=['git', 'rev-parse', '--show-toplevel'],
cwd=gitFolder
).strip('\n')
changedFiles = getCommandOutput(
["git", "diff-tree", "-r", "--name-only", sourceTree, targetTree],
command=["git", "diff-tree", "-r", "--name-only", sourceTree, targetTree],
cwd=gitFolder
).splitlines()
changedFiles = [os.path.join(root, file) for file in changedFiles]
os.chdir(owd)
return changedFiles
return [os.path.join(root, file) for file in changedFiles]
if __name__ == '__main__':
......@@ -54,5 +55,4 @@ if __name__ == '__main__':
with open(args['outfile'], 'w') as outFile:
for file in changedFiles:
outFile.write(os.path.abspath(file))
outFile.write('\n')
outFile.write(f"{os.path.abspath(file)}\n")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment