spin icon indicating copy to clipboard operation
spin copied to clipboard

Spin new with a fork template

Open fouteox opened this issue 11 months ago • 0 comments

Current Behavior

Forking an existing template, such as laravel's, will cause an error when spin tries to retrieve it.

This is because the api call to github to check the default branch will return "default_branch" multiple times at multiple levels, which causes "main" to be assigned multiple times to the "branch" variable.

Spin will then not be able to continue its installation process.

Expected Behavior

In /lib/functions.sh, the "github_default_branch" function should always make sure to only read the "default_branch" api response located at the root and not the others (e.g. "parent" referring to the project the fork came from).

Steps To Reproduce

Fork the base laravel template and try installing from there.

Environment

Spin Version: 
v3.0.2 [stable] (User Installed)

Operating System Version: 
ProductName:		macOS
ProductVersion:		15.2
BuildVersion:		24C101

Anything else?

I'm not a bash expert but this seems to work.

github_default_branch() {
  local repo="$1"
  local branch=""
  
  branch=$(curl --silent "https://api.github.com/repos/$repo" | grep -E '^\s*"default_branch":' | head -n 1 | sed -E 's/.*"([^"]+)".*/\1/')

  echo "$branch"
}

fouteox avatar Jan 24 '25 21:01 fouteox