From 9ecda46501cf319c8ce7bf20576611f1d571fae8 Mon Sep 17 00:00:00 2001 From: Dennis <dennis.glaeser@iws.uni-stuttgart.de> Date: Thu, 20 May 2021 16:18:17 +0200 Subject: [PATCH] [bin][getchangedfiles] prefer subprocess' cwd over chdir --- bin/testing/getchangedfiles.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/testing/getchangedfiles.py b/bin/testing/getchangedfiles.py index 7d4cb2d2a4..69651b7c2b 100644 --- a/bin/testing/getchangedfiles.py +++ b/bin/testing/getchangedfiles.py @@ -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") -- GitLab