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

nbgv install should create a version.json file, observing the default branch name #717

Open
AArnott opened this issue Jan 25, 2022 · 5 comments

Comments

@AArnott
Copy link
Collaborator

AArnott commented Jan 25, 2022

In new git repos, the default branch name may be main (or develop, etc) but nbgv install will create a version.json file whose publicReleaseRefSpec makes master the first public release branch regardless of the name of the default branch.

@AArnott AArnott added the bug label Jan 25, 2022
@KalleOlaviNiemitalo
Copy link

Do you mean it should use the init.defaultBranch setting from git config?

@AArnott
Copy link
Collaborator Author

AArnott commented Jan 25, 2022

Maybe. I hadn't figured out yet how it would be accomplished.

@AArnott
Copy link
Collaborator Author

AArnott commented Jan 25, 2022

I guess for a git repo with no remotes, there is no "default" branch. It's just a bunch of branches. When it was new, there was only one branch, of course, but if there is more than one branch I guess it's impossible to say for sure. So perhaps an algorithm like this:

  1. If the upstream remote exists, use this technique to ascertain the default branch.
  2. If the origin remote exists, use the same technique.
  3. If any remote exists, pick one arbitrarily and use the same technique.
  4. If only one local branch exists, use that one.
  5. Use git config init.defaultBranch if the named branch exists locally.
  6. Use the name of the first local branch that exists from this ordered list: master, main, develop.

@KalleOlaviNiemitalo
Copy link

If the repo has remotes already then the refs/remotes/origin/HEAD symbolic ref seems likely to be more reliable for this purpose than either HEAD (which might point to a temporary branch for adding nb.gv) or init.defaultBranch (which is used for new repositories but might not match old ones, and is unlikely to be set per repository). Except the name of the remote might not be origin.

@AArnott
Copy link
Collaborator Author

AArnott commented Jan 25, 2022

Ultimately the remote's default branch should win, but you gotta pick the right one. By convention upstream would typically trump origin, which is why I ordered the steps above as I did.

And you're right, my algorithm isn't fool proof. I just updated it based on your feedback but at the end of the day, it's a best effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants