From 7f0867986f60493d8af56526d727a411dbd96ffd Mon Sep 17 00:00:00 2001 From: Mark Randall Havens Date: Fri, 30 May 2025 08:04:33 -0500 Subject: [PATCH] test5 --- .radicle-push-state | 1 + .test5 | 0 gitfield-radicle | 52 ++++++++++++++++++++++----------------------- 3 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 .radicle-push-state create mode 100644 .test5 diff --git a/.radicle-push-state b/.radicle-push-state new file mode 100644 index 0000000..07384f3 --- /dev/null +++ b/.radicle-push-state @@ -0,0 +1 @@ +7a86f69629e6970f3901b93cf50c234f5e04c1c2 diff --git a/.test5 b/.test5 new file mode 100644 index 0000000..e69de29 diff --git a/gitfield-radicle b/gitfield-radicle index 2a6ac0c..975532f 100755 --- a/gitfield-radicle +++ b/gitfield-radicle @@ -15,17 +15,17 @@ RAD_KEYS="$RAD_HOME/keys.json" RAD_BACKUP=".radicle-backup/keys.json" RAD_PATH_LINE='export PATH="$HOME/.radicle/bin:$PATH"' PROFILE_FILE="$HOME/.bashrc" -RAD_PUSH_FILE=".radicle-push-done" +PUSH_STATE_FILE=".radicle-push-state" # ╭───────────────────────────────╮ -# │ Logging │ +# │ Logging Utils │ # ╰───────────────────────────────╯ info() { echo -e "\e[1;34m[INFO]\e[0m $*"; } warn() { echo -e "\e[1;33m[WARN]\e[0m $*"; } error() { echo -e "\e[1;31m[ERROR]\e[0m $*" >&2; exit 1; } # ╭───────────────────────────────╮ -# │ Git + Tools Precheck │ +# │ Git + Tools Precheck │ # ╰───────────────────────────────╯ info "Checking Git..." command -v git >/dev/null || { @@ -44,7 +44,7 @@ EMAIL=$(git config --global user.email || true) info "Git identity: $(git config --global user.name) <$(git config --global user.email)>" # ╭───────────────────────────────╮ -# │ Install Radicle CLI │ +# │ Radicle CLI Setup │ # ╰───────────────────────────────╯ if [ ! -x "$RAD_BIN" ]; then info "Installing Radicle CLI..." @@ -52,19 +52,14 @@ if [ ! -x "$RAD_BIN" ]; then curl -sSf https://radicle.xyz/install | sh || error "Radicle install failed" fi -# ─ PATH Setup (Temporary + Persistent) -if ! command -v rad &>/dev/null; then - export PATH="$HOME/.radicle/bin:$PATH" - info "→ Temporarily patched PATH for this session" -fi - +export PATH="$HOME/.radicle/bin:$PATH" if ! grep -Fxq "$RAD_PATH_LINE" "$PROFILE_FILE"; then echo "$RAD_PATH_LINE" >> "$PROFILE_FILE" info "→ Added PATH to $PROFILE_FILE" - warn "→ Run 'source $PROFILE_FILE' to make 'rad' persistent" + warn "→ Run 'source $PROFILE_FILE' to make Radicle CLI persistent" fi -command -v rad >/dev/null || error "Radicle CLI still unavailable. Try restarting your terminal." +command -v rad >/dev/null || error "Radicle CLI still unavailable. Try restarting terminal." info "Radicle CLI ready: $(rad --version)" @@ -86,16 +81,16 @@ else fi # ╭───────────────────────────────╮ -# │ Start Rad Node │ +# │ Start Rad Node │ # ╰───────────────────────────────╯ -pgrep -f "rad node start" &>/dev/null || { +pgrep -f "rad node start" >/dev/null || { info "Starting Radicle node..." nohup rad node start > /dev/null 2>&1 & sleep 3 } # ╭───────────────────────────────╮ -# │ Initialize Git Repo │ +# │ Git Repo Initialization │ # ╰───────────────────────────────╯ if [ ! -d .git ]; then git init @@ -106,7 +101,7 @@ else fi # ╭───────────────────────────────╮ -# │ Register Radicle Project │ +# │ Radicle Project Registration│ # ╰───────────────────────────────╯ if ! rad projects | grep -q "$PROJECT_NAME"; then info "Registering Radicle project '$PROJECT_NAME'..." @@ -116,23 +111,26 @@ else fi # ╭───────────────────────────────╮ -# │ Push Current Branch │ +# │ Push Current Commit Logic │ # ╰───────────────────────────────╯ CURRENT_BRANCH=$(git symbolic-ref --short HEAD) -if [ ! -f "$RAD_PUSH_FILE" ]; then - info "Pushing branch '$CURRENT_BRANCH' to Radicle..." - if git push rad "$CURRENT_BRANCH"; then - touch "$RAD_PUSH_FILE" - info "✓ Branch '$CURRENT_BRANCH' replicated successfully" - else - warn "Radicle push failed or already synced" - fi +CURRENT_COMMIT=$(git rev-parse HEAD) +LAST_PUSHED_COMMIT=$(cat "$PUSH_STATE_FILE" 2>/dev/null || echo "none") + +if [[ "$CURRENT_COMMIT" == "$LAST_PUSHED_COMMIT" ]]; then + info "✓ Already pushed commit: $CURRENT_COMMIT" else - info "Push previously completed. Skipping." + info "Pushing commit '$CURRENT_COMMIT' on branch '$CURRENT_BRANCH'..." + if git push rad "$CURRENT_BRANCH"; then + echo "$CURRENT_COMMIT" > "$PUSH_STATE_FILE" + info "✓ Pushed to Radicle successfully" + else + warn "Push may have failed — check 'rad sync status'" + fi fi # ╭───────────────────────────────╮ -# │ Final Output │ +# │ Final Output Block │ # ╰───────────────────────────────╯ PROJECT_ID=$(rad self | grep 'Project ID' | awk '{print $NF}' || true) PEER_ID=$(rad self | grep 'Peer ID' | awk '{print $NF}' || true)