Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/commands/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ _create_resolve_from_ref() {
from_ref=$(get_current_branch)
if [ -z "$from_ref" ] || [ "$from_ref" = "HEAD" ]; then
log_warn "Currently in detached HEAD state - falling back to default branch"
from_ref=$(resolve_default_branch "$repo_root")
from_ref="origin/$(resolve_default_branch "$repo_root")"
else
log_info "Creating from current branch: $from_ref"
fi
else
from_ref=$(resolve_default_branch "$repo_root")
from_ref="origin/$(resolve_default_branch "$repo_root")"
Comment on lines +76 to +81
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Avoid unconditional origin/ prefixing for default branch values.

On Line 76 and Line 81, if resolve_default_branch already returns origin/main (from existing config), this becomes origin/origin/main and ref resolution can fail. Normalize the value before prefixing.

Proposed fix
 _create_resolve_from_ref() {
   local from_ref="$1" from_current="$2" repo_root="$3"
+  local default_branch

   if [ -z "$from_ref" ]; then
     if [ "$from_current" -eq 1 ]; then
       from_ref=$(get_current_branch)
       if [ -z "$from_ref" ] || [ "$from_ref" = "HEAD" ]; then
         log_warn "Currently in detached HEAD state - falling back to default branch"
-        from_ref="origin/$(resolve_default_branch "$repo_root")"
+        default_branch=$(resolve_default_branch "$repo_root")
+        case "$default_branch" in
+          origin/*) from_ref="$default_branch" ;;
+          refs/remotes/origin/*) from_ref="${default_branch#refs/remotes/}" ;;
+          *) from_ref="origin/$default_branch" ;;
+        esac
       else
         log_info "Creating from current branch: $from_ref"
       fi
     else
-      from_ref="origin/$(resolve_default_branch "$repo_root")"
+      default_branch=$(resolve_default_branch "$repo_root")
+      case "$default_branch" in
+        origin/*) from_ref="$default_branch" ;;
+        refs/remotes/origin/*) from_ref="${default_branch#refs/remotes/}" ;;
+        *) from_ref="origin/$default_branch" ;;
+      esac
     fi
   fi

   printf "%s" "$from_ref"
 }

As per coding guidelines, "Maintain backwards compatibility with existing configs in shell scripts."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from_ref="origin/$(resolve_default_branch "$repo_root")"
else
log_info "Creating from current branch: $from_ref"
fi
else
from_ref=$(resolve_default_branch "$repo_root")
from_ref="origin/$(resolve_default_branch "$repo_root")"
default_branch=$(resolve_default_branch "$repo_root")
case "$default_branch" in
origin/*) from_ref="$default_branch" ;;
refs/remotes/origin/*) from_ref="${default_branch#refs/remotes/}" ;;
*) from_ref="origin/$default_branch" ;;
esac
else
log_info "Creating from current branch: $from_ref"
fi
else
default_branch=$(resolve_default_branch "$repo_root")
case "$default_branch" in
origin/*) from_ref="$default_branch" ;;
refs/remotes/origin/*) from_ref="${default_branch#refs/remotes/}" ;;
*) from_ref="origin/$default_branch" ;;
esac
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/commands/create.sh` around lines 76 - 81, The code unconditionally
prefixes origin/ onto the value returned by resolve_default_branch which can
produce origin/origin/main; update the logic around from_ref assignment in
create.sh to normalize the resolved branch: check the string returned by
resolve_default_branch (used where from_ref is set) and if it already starts
with "origin/" (or a full ref like "refs/heads/"), use it as-is, otherwise
prepend "origin/"; apply this normalization in both places where from_ref is
assigned so existing configs like "origin/main" remain unchanged and new values
get the correct prefix.

fi
fi

Expand Down