Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
feat: automates git add of diffs sampled with sample-git-diffs
Browse files Browse the repository at this point in the history
depreciates scripts/git-add_QC-sample.sh
  • Loading branch information
BobBorges committed Oct 18, 2023
1 parent 8b0aa72 commit 8827ac4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions scripts/git-add_diff-sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
"""
After creating a diff sample with e.g. sample-git-diffs, this script will `git add $f for f in sampled files`.
"""
import argparse, subprocess

def main(args):
changed_files = []
with open(args.diff_file, 'r') as inf:
rlines = inf.readlines()
lines = [_.strip() for _ in rlines if _.startswith('diff')]
[changed_files.append(_.split(' ')[-1][2:]) for _ in lines]


if args.dry_run:
[subprocess.call(['git', 'add', '-n', '--', _]) for _ in changed_files]
print(f"{len(changed_files)} files to be added")
else:
[subprocess.call(['git', 'add', '--', _]) for _ in changed_files]
print(f"{len(changed_files)} files added")

if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-d","--diff-file", required=True, help="Path to .diff file.")
parser.add_argument("-n", "--dry-run", action="store_true", help="== `git add --dry-run` : Don’t actually add the file(s), just show if they exist and/or will be ignored")
args = parser.parse_args()
main(args)

0 comments on commit 8827ac4

Please sign in to comment.