This repository has been archived by the owner on May 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: automates git add of diffs sampled with sample-git-diffs
depreciates scripts/git-add_QC-sample.sh
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |