From 7f0628e377cf6876ce2a1cc3b5c026de0abafa7c Mon Sep 17 00:00:00 2001 From: bochard Date: Sun, 6 Jul 2025 11:42:38 +0800 Subject: [PATCH] updated sync-works.sh to use git clone --- sync-works.sh | 59 +++++++++++++++++++++----------------------------- works-list.txt | 12 ++++++++++ 2 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 works-list.txt diff --git a/sync-works.sh b/sync-works.sh index 10ae025..a75e64f 100755 --- a/sync-works.sh +++ b/sync-works.sh @@ -1,52 +1,43 @@ #!/bin/bash -declare -A submodules=( - ['roman-numeral-converter']='git@github.com:b0chard/roman-numeral-converter.git' - ['palindrome-checker']='git@github.com:b0chard/palindrome-checker.git' - ['temperature-converter']='git@github.com:b0chard/temperature-converter.git' - ['drum-ka-dum']='git@github.com:b0chard/drum-ka-dum.git' - ['tick-clock']='git@github.com:b0chard/tick-clock.git' - ['simple-cash-register']='git@github.com:b0chard/simple-cash-register.git' - ['circle']='git@github.com:b0chard/circle.git' - ['basic-calc']='git@github.com:b0chard/basic-calc.git' - ['signup-login-system']='git@github.com:b0chard/signup-login-system.git' - ['number-guessing-game-in-c']='git@github.com:b0chard/number-guessing-game-in-c.git' - ['rock-paper-scissors-in-c']='git@github.com:b0chard/rock-paper-scissors-in-c.git' - ['atm-program-in-c']='git@github.com:b0chard/atm-program-in-c.git' -) +declare -A works + +echo "Reading works-list.txt file..."; +while IFS=' ' read name url || [ -n "$name" ]; do + works[$name]="$url" +done < works-list.txt tmpBase='works-tmp' worksBase='works' - mkdir -p "$tmpBase" "$worksBase" -echo "Checking and adding missing submodules in $tmpBase..." -for submodule in "${!submodules[@]}"; do - tmpPath="$tmpBase/$submodule" - destPath="$worksBase/$submodule" +echo "Cloning or updating repos in $tmpBase..." +for work in "${!works[@]}"; do + tmpPath="$tmpBase/$work" + destPath="$worksBase/$work" if [ ! -d "$tmpPath" ]; then - echo "Adding submodule $submodule to $tmpBase..." - git submodule add -f "${submodules[$submodule]}" "$tmpPath" - echo "Submodule $submodule added successfully to $tmpPath." + echo "Cloning $work to $tmpBase..." + git clone "${works[$work]}" "$tmpPath" + echo "$work cloned successfully to $tmpPath." else - echo "Submodule $submodule already exists in $tmpBase." + echo "$work already exists in $tmpBase. Fetching and resetting to latest remote commit..." + branch=$(git -C "$tmpPath" rev-parse --abbrev-ref HEAD) + git -C "$tmpPath" fetch origin + git -C "$tmpPath" reset --hard "origin/$branch" + echo "$work updated to latest commit on $branch." fi done -echo "Uploading all submodules in $tmpBase to latest remote commits..." -git submodule update --remote --merge -echo "Submodules has been successfully updated to latest remote commits." - -echo "Synchronizing submodules content from $tmpBase to $worksBase..." -for submodule in "${!submodules[@]}"; do - src="$tmpBase/$submodule" - dest="$worksBase/$submodule" +echo "Synchronizing content from $tmpBase to $worksBase..." +for work in "${!works[@]}"; do + src="$tmpBase/$work" + dest="$worksBase/$work" if [ -d "$src" ]; then mkdir -p "$dest" rsync -av --delete --exclude='.git' "$src/" "$dest/" - echo "Synchronized submodule $submodule successfully." + echo "Synchronized $work successfully." else echo "Warning: $src does not exist, skipping synchronization!" fi @@ -55,7 +46,7 @@ done echo "Staging changes in $worksBase..." git add "$worksBase/" -echo "Committing changes..." -git commit -m "Sync latest updates from submodules to works/ directory." || echo "Nothing to commit." +# echo "Committing changes..." +# git commit -m "Sync latest updates from $tmpBase to $worksBase directory." || echo "Nothing to commit." echo "done." \ No newline at end of file diff --git a/works-list.txt b/works-list.txt new file mode 100644 index 0000000..5baa390 --- /dev/null +++ b/works-list.txt @@ -0,0 +1,12 @@ +roman-numeral-converter git@github.com:b0chard/roman-numeral-converter.git +palindrome-checker git@github.com:b0chard/palindrome-checker.git +temperature-converter git@github.com:b0chard/temperature-converter.git +drum-ka-dum git@github.com:b0chard/drum-ka-dum.git +tick-clock git@github.com:b0chard/tick-clock.git +simple-cash-register git@github.com:b0chard/simple-cash-register.git +circle git@github.com:b0chard/circle.git +basic-calc git@github.com:b0chard/basic-calc.git +signup-login-system git@github.com:b0chard/signup-login-system.git +number-guessing-game-in-c git@github.com:b0chard/number-guessing-game-in-c.git +rock-paper-scissors-in-c git@github.com:b0chard/rock-paper-scissors-in-c.git +atm-program-in-c git@github.com:b0chard/atm-program-in-c.git \ No newline at end of file -- 2.39.5