zap-zsh / zap

:zap: Zap is a minimal zsh plugin manager
https://www.zapzsh.com/
GNU General Public License v3.0
942 stars 33 forks source link

Unable to checkout plugin on branch other than master/main #181

Closed mmorys closed 3 months ago

mmorys commented 3 months ago

Describe the bug

The documentation lists the ability to checkout a plugin from GitHub from a specific branch/commit:

# Example install of a plugin pinned to specifc commit or branch, just pass the git reference
plug "zsh-users/zsh-syntax-highlighting" "122dc46"

This ONLY works if the commit is on the master/main branch. If checking out a different branch by name, or a commit hash on a different branch this doesn't work.

Steps to reproduce

Add the following to your ~/.zshrc:

plug "zsh-users/zsh-autosuggestions" "develop"

and then source/open a new shell.

Expected behavior

Can use commit hashes and branches that are not on main/master

Screenshots and recordings

No response

OS / Linux distribution

Ubuntu 20.04

Zsh version

5.8

Zap version

release-v1/1.2.1

Terminal emulator

Gnome Terminal 3.36.2

If using WSL on Windows, which version of WSL

None

Additional context

This does not work because of the way git clone is performed...

  1. First a clone of depth 1 is made https://github.com/zap-zsh/zap/blob/aed067fe4a1732fe44e5cbf0f0b2b7f584023739/zap.zsh#L42
  2. Then before checkout unshallow is used https://github.com/zap-zsh/zap/blob/aed067fe4a1732fe44e5cbf0f0b2b7f584023739/zap.zsh#L46

The result is a local repo that contains the history of the master branch of the plugin, but no other branches are tracked. A fix is to make the following call before pulling with unshallow (see this StackOverflow).

git -C "$plugin_dir" remote set-branches origin '*' # <-- New command
git -C "$plugin_dir" pull --unshallow > /dev/null 2>&1

I will submit a PR to fix this issue