Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
dumux-repositories
dumux
Commits
a4d5cad8
Commit
a4d5cad8
authored
May 19, 2021
by
Dennis Gläser
Browse files
[bin] add script to detect modified files
parent
dce216a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/testing/getchangedfiles.py
0 → 100644
View file @
a4d5cad8
#!/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
()
os
.
chdir
(
os
.
path
.
abspath
(
gitFolder
))
root
=
getCommandOutput
([
'git'
,
'rev-parse'
,
'--show-toplevel'
]).
strip
(
'
\n
'
)
changedFiles
=
getCommandOutput
(
[
"git"
,
"diff-tree"
,
"-r"
,
"--name-only"
,
sourceTree
,
targetTree
],
).
splitlines
()
changedFiles
=
[
os
.
path
.
join
(
root
,
file
)
for
file
in
changedFiles
]
os
.
chdir
(
owd
)
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'
],
args
[
'source_tree'
],
args
[
'target_tree'
])
with
open
(
args
[
'outfile'
],
'w'
)
as
outFile
:
for
file
in
changedFiles
:
outFile
.
write
(
os
.
path
.
abspath
(
file
))
outFile
.
write
(
'
\n
'
)
Dennis Gläser
@DennisGlaeser
mentioned in commit
bffd84f3
·
Jun 02, 2021
mentioned in commit
bffd84f3
mentioned in commit bffd84f3e6ec5ada85159c7e22c9ac6906e7c60b
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment