Skip to content

Commit

Permalink
✨ allow git synk fetch window from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhomer committed Dec 24, 2023
1 parent f72db57 commit 1f26bc6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
15 changes: 10 additions & 5 deletions bin/git-synk
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
# Synchronise a local git repository with remote
#

import argparse
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 Down Expand Up @@ -44,7 +43,7 @@ def printf(message):
print(message, end="")


def synk(path):
def synk(path, fetch_window: int):
if not is_git_repo(path):
raise Exception(
f"Directory {path} is not a git repository and can not be synked"
Expand Down Expand Up @@ -116,18 +115,24 @@ def synk(path):


def run():
parser = argparse.ArgumentParser(description="Git synk")
parser.add_argument("--window", "-w", help="fetch window in seconds", default=600)
args = parser.parse_args()

fetch_window = int(args.window)

cwd = os.getcwd()
match = re.search("projects/things", cwd)
if not match:
raise Exception("Can only sync in project/things directory")

if is_git_repo(cwd):
synk(cwd)
synk(cwd, fetch_window=fetch_window)
else:
for child in os.listdir(cwd):
directory = os.path.join(cwd, child)
if is_git_repo(directory):
synk(directory)
synk(directory, fetch_window=fetch_window)


run()
16 changes: 14 additions & 2 deletions bin/things-sync
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ is-connected || (echo "Not connected, no sync" ; exit 1)

FETCH_WINDOW=600
EXTRA_ARGS=""
while getopts "cw:" o; do case "$o" in
c) EXTRA_ARGS="-c" ;;
while getopts "chw:" o; do case "$o" in
h) HELP=y ;;
w) FETCH_WINDOW=$OPTARG ;;
esac done

help() {
cat << EOF
-h this help
-w 600 set fetch window in seconds
EOF
}

if [ "$HELP" == "y" ] ; then
help
exit 1
fi

cd $THINGS_DIR
git synk -w $FETCH_WINDOW $EXTRA_ARGS

Expand Down

0 comments on commit 1f26bc6

Please sign in to comment.