Browse Source

Only fetch if not checked out

bryan 3 days ago
parent
commit
d28f2e8c31
1 changed files with 8 additions and 7 deletions
  1. 8 7
      openwrtbuilder

+ 8 - 7
openwrtbuilder

@@ -500,16 +500,16 @@ from_source() {
 
   # Determine commit-ish for git worktree
   case "$RELEASE" in
-    snapshot)
-      wt_commit="main"
-      ;;
+    snapshot) wt_commit="main" ;;
     [0-9][0-9].[0-9][0-9].*)
       branch="openwrt-${RELEASE%.*}"
       tag="v$RELEASE"
       if ask_ok "Use $branch branch HEAD (y, recommended) or $tag tag (n)?"; then
         wt_commit="$branch"
-        # Always fetch latest branch from origin
-        execute git -C "$SRC_DIR" fetch origin "$branch:$branch"
+        # Only fetch if branch is NOT checked out in any worktree
+        if ! git -C "$SRC_DIR" worktree list | grep -q "$branch"; then
+          execute git -C "$SRC_DIR" fetch origin "$branch:$branch"
+        fi
       else
         wt_commit="$tag"
       fi
@@ -517,9 +517,10 @@ from_source() {
     *)
       debug "Passing '$RELEASE' commit-ish to git worktree"
       wt_commit="$RELEASE"
-      # If it's a branch, fetch latest
       if execute git -C "$SRC_DIR" show-ref --verify --quiet "refs/heads/$wt_commit"; then
-        execute git -C "$SRC_DIR" fetch origin "$wt_commit:$wt_commit"
+        if ! git -C "$SRC_DIR" worktree list | grep -q "$wt_commit"; then
+          execute git -C "$SRC_DIR" fetch origin "$wt_commit:$wt_commit"
+        fi
       fi
       ;;
   esac