Created
April 21, 2019 15:00
-
-
Save marskar/2363e468934ca74b3058d8ba429142fb to your computer and use it in GitHub Desktop.
ACM stands for git add && git commit --message
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
import git | |
repo = git.Repo() | |
untracked = repo.untracked_files | |
changed_file_lists = [ | |
[file.a_path | |
for file in repo.index.diff(None).iter_change_type(change_type)] | |
for change_type in ('D', 'M') | |
] | |
if any(untracked + changed_file_lists): | |
repo.git.add(untracked + changed_file_lists) | |
new = f"New files: {', '.join(untracked)}. " if untracked else "" | |
prefixes = "Deleted files:", "Modified files:" | |
deleted, modified = ( | |
f"{prefix} {', '.join(changed_files)}. " if changed_files else "" | |
for prefix, changed_files in zip(prefixes, changed_file_lists) | |
) | |
print(repo.git.commit(untracked + changed_file_lists, | |
message=new + deleted + modified)) | |
else: | |
print("There are no new, deleted, or modified files.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment