Skip to content

Commit

Permalink
Git synk iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhomer committed Sep 23, 2023
1 parent b0850fc commit 274d596
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions bin/git-synk
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
# Synchronise a local git repository with remote
#

import datetime
import os
import re
from subprocess import call, getoutput, STDOUT

fetch_window = 600


def is_git_repo(path):
return os.path.isdir(path) and (
Expand All @@ -34,10 +37,32 @@ def synk(path):
f"Directory {path} is not a git repository and can not be synked"
)
os.chdir(path)
print(path)
print("synching")
repository_name = os.path.basename(path)
branch = get_branch_name()
print(f"Branch {branch}")
changes = int(getoutput("git status --porcelain | wc -l"))
auto_commit = getoutput("git config core.autocommit") == "true"
original_url = getoutput("git config --get remote.origin.url")

if changes > 0:
if auto_commit:
os.system("git add -A ; git commit --quiet -m sync")
else:
print(f"∷ ◉ {repository_name} - set autocommit with git synk -a to commit local")
return
print("▻ ", end="")

dated_file = f"{path}/.git/FETCH_HEAD"
if not os.path.exists(dated_file):
dated_file = f"{path}/.git/HEAD"
last_modified = datetime.datetime.fromtimestamp(os.path.getmtime(dated_file))
now = datetime.datetime.now()
if last_modified + datetime.timedelta(seconds=fetch_window) < now:
print(".", end="")
print(".", end="")
else:
print("∷ ", end="")

print("")


def run():
Expand Down

0 comments on commit 274d596

Please sign in to comment.