diff --git a/repo_watcher.sh b/repo_watcher.sh index 9252b12..1d83d49 100644 --- a/repo_watcher.sh +++ b/repo_watcher.sh @@ -18,8 +18,16 @@ process_repo() { fi cd "$REPO_DIR" || exit + # Detect the default branch dynamically + DEFAULT_BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}') + + # Check if an upstream is configured; if not, set it + if ! git rev-parse @{u} > /dev/null 2>&1; then + git branch --set-upstream-to=origin/$DEFAULT_BRANCH $DEFAULT_BRANCH + fi + # Fetch the latest changes - git fetch origin main > /dev/null 2>&1 + git fetch origin $DEFAULT_BRANCH > /dev/null 2>&1 # Check if the local repository is behind the remote LOCAL=$(git rev-parse @) @@ -27,7 +35,7 @@ process_repo() { if [ "$LOCAL" != "$REMOTE" ]; then curl -d "Updating: $CLEAN_REPO_URL" $NTFY_URL - git pull origin main > /dev/null 2>&1 + git pull origin $DEFAULT_BRANCH > /dev/null 2>&1 rsync -av --delete --exclude '.git/' ./ "$DESTINATION" > /dev/null 2>&1 fi } @@ -48,6 +56,6 @@ while true; do process_repo "$REPO_URL" "$DESTINATION" done - # Wait for 5 seconds before the next iteration - sleep 5 -done + # Wait for 30 seconds before the next iteration + sleep 30 +done \ No newline at end of file