Created
October 24, 2018 05:20
-
-
Save mrlesmithjr/d04642ab94786065581465ea9f0170bc to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env python | |
import os | |
import datetime | |
import git | |
# Define files to commit when added or changed | |
FILES_TO_COMMIT = ['.gitignore'] | |
# Define repo directory | |
REPO_DIR = os.getcwd() | |
# Define files/folders to add to .gitignore | |
GITIGNORE = ['.DS_Store', '.env', '.venv', '.vscode/', '*.pyc', | |
'*.retry', 'ENV', 'env.bak/', 'env/', 'venv.bak/', 'venv/'] | |
try: | |
REPO = git.Repo(REPO_DIR) | |
except git.exc.InvalidGitRepositoryError: | |
REPO = git.Repo.init() | |
with open(os.path.join(REPO_DIR, '.gitignore'), 'w') as f: | |
for item in GITIGNORE: | |
f.write(item + '\n') | |
CURRENT_BRANCH = REPO.active_branch | |
INDEX = REPO.index.entries.items() | |
UNTRACKED_FILES = REPO.untracked_files | |
INDEX_DIFF = REPO.index.diff(None) | |
CHANGED_FILES = [] | |
for item in INDEX_DIFF: | |
CHANGED_FILES.append(item.a_path) | |
print 'Index: {}'.format(INDEX) | |
print 'Untracked files: {}'.format(UNTRACKED_FILES) | |
print 'Changed files: {}'.format(CHANGED_FILES) | |
try: | |
print 'Submodules: {}'.format(REPO.submodules) | |
except: | |
print 'Submodules: None' | |
for item in FILES_TO_COMMIT: | |
if item in UNTRACKED_FILES or item in CHANGED_FILES: | |
REPO.git.add(item) | |
commit_date = datetime.datetime.now().strftime( | |
'%Y-%m-%d-%H-%M-%S') | |
commit_msg = '{}-{}'.format( | |
CURRENT_BRANCH, commit_date) | |
REPO.git.commit('-m', '{}'.format(commit_msg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment