Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when updating repos with branch named "main" instead of "master" #86

Closed
sunjon opened this issue Nov 8, 2020 · 7 comments
Closed

Comments

@sunjon
Copy link
Contributor

sunjon commented Nov 8, 2020

Github allows users to change the default branch name from master. Packer doesn't currently support main as a branch name:

 ✗ Failed to update jamessan/vim-gnupg
  Errors:
    fatal: invalid reference: master
    fatal: invalid reference: master
    90b86c5
@wbthomason
Copy link
Owner

So, you can work around this by using packer's "branch" feature, e.g. use {'jamessan/vim-gnupg', branch = 'main'} should work. But that is a lot of extra noise if you have many plugin repos which use main (or something else) as their default branch name.

Do you think it would be helpful to provide a new setting for the default "default branch name"? Other than that, I'm not sure there's a way to get around specifying the branch name plugin-by-plugin.

@timbedard
Copy link

Do you think it would be helpful to provide a new setting for the default "default branch name"? Other than that, I'm not sure there's a way to get around specifying the branch name plugin-by-plugin.

Why not make the inclusion of a specific branch (ref, etc) on the clone command conditional based on whether or not a branch is provided? If there's not a specified branch, don't clone a specific branch. I'm looking through vim-plug and that seems to be the approach there. There are probably some side effects in terms of how updates would need to work, but this seems like the more future-proof approach. Especially considering the rising adoption of main.

@wbthomason
Copy link
Owner

@timbedard Ok, that seems like a reasonable solution. The trick will be in detecting what to check out if a plugin spec changes branches, e.g. if a user initially specifies use {'foo/bar', branch = 'baz'}, but later changes their spec to use {'foo/bar'}. That's the main place packer uses master as the "default" branch name.

It looks like vim-plug handles this by reading ${GIT_DIR}/refs/remotes/origin/HEAD; this is probably the right thing to do.

@wbthomason
Copy link
Owner

@sunjon and others: this should be fixed now, but please let me know if you still encounter errors (or encounter new errors this change may have introduced). Thanks!

@timbedard
Copy link

@wbthomason Nicely (and quickly) done! Working great. Thanks!

lewis6991 added a commit to lewis6991/gitsigns.nvim that referenced this issue Aug 7, 2021
@lukamanitta
Copy link

getting this issue with https://github.com/kdheepak/lazygit.nvim
Error is:

Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.
9bceeab

They may have changed from 'master' -> 'main'? I'm happy to use branch = 'main' for now, but thought I'd drop this here anyway.

justin-f-perez added a commit to justin-f-perez/NvChad that referenced this issue Apr 9, 2022
By default packer tries to use "master" for the branch of any plugin that doesn't have a branch explicitly defined. However, the bufferline authors recently renamed their default branch from "master" to main. Thus, packer will work fine with bufferline for any new clones, but it will fail to update for anyone who had the old branch name "master" set.

See also: wbthomason/packer.nvim#86
@justin-f-perez
Copy link

justin-f-perez commented Apr 9, 2022

I just had the same problem. I never specified a branch explicitly in my configuration; but the authors of bufferline.nvim seem to have deleted master/renamed the master branch to main. See: NvChad/NvChad#940

@wbthomason I might suggest that when no branch is explicitly defined and there's an error related to a non-existent remote branch, Packer should fall back to the remote head. Unfortunately I'm not skilled in lua, but this is how you could get that information from the commandline:

❯ git remote show origin | grep HEAD | sed 's/^.*: \(.*$\)/\1/'

example:

cd /tmp
❯ git clone https://github.com/akinsho/bufferline.nvim
❯ cd bufferline.nvim/
❯ git remote show origin | grep HEAD | sed 's/^.*: \(.*$\)/\1/'
main

It's also probably worth noting: I don't expect this problem to go away. There are still a lot of repos around with the remote head set to "master". Whether or not folks buy into "'master' is a non-inclusive name and we should stop using it", as "main" becomes the de facto standard due to "main" being default on all major hosting platform, I expect more and more folks changing branch names at least to avoid annoying errors from "main" vs "master" muscle memory.

See also:
https://sfconservancy.org/news/2020/jun/23/gitbranchname/
https://about.gitlab.com/blog/2021/03/10/new-git-default-branch-name/
https://bitbucket.org/blog/moving-away-from-master-as-the-default-name-for-branches-in-git
https://github.blog/changelog/2020-10-01-the-default-branch-for-newly-created-repositories-is-now-main/

siduck pushed a commit to NvChad/NvChad that referenced this issue Apr 10, 2022
By default packer tries to use "master" for the branch of any plugin that doesn't have a branch explicitly defined. However, the bufferline authors recently renamed their default branch from "master" to main. Thus, packer will work fine with bufferline for any new clones, but it will fail to update for anyone who had the old branch name "master" set.

See also: wbthomason/packer.nvim#86
jtzero pushed a commit to jtzero/NvChad that referenced this issue Apr 14, 2022
By default packer tries to use "master" for the branch of any plugin that doesn't have a branch explicitly defined. However, the bufferline authors recently renamed their default branch from "master" to main. Thus, packer will work fine with bufferline for any new clones, but it will fail to update for anyone who had the old branch name "master" set.

See also: wbthomason/packer.nvim#86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants