Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Aug 23, 2022

@ghost
Copy link
Author

ghost commented Aug 23, 2022

make default branch configurable

@effigies
Copy link
Contributor

Thanks! Thinking about this, I think we need to consider these use cases:

  1. New repository with no remote. Probably want the current branch, as you're unlikely to be branching yet.
  2. Self-owned repository where you work with just one remote (typically origin)
  3. Contributing repository where you refer to a canonical fork (generally upstream or origin, depending on local convention)

I would probably use the following preference order:

  1. git rev-parse --abbrev-ref upstream/HEAD
  2. git rev-parse --abbrev-ref origin/HEAD
  3. git rev-parse --abbrev-ref HEAD
  4. git config init.defaultBranch
  5. "master" (git too old to have init.defaultBranch)

This value should be computed on installation, not git_pieces_from_vcs(), and set in the configuration. We do VCS-specific installation steps in https://github.com/python-versioneer/python-versioneer/blob/master/src/git/install.py.

In git_pieces_from_vcs() we should use the configuration variable in place of hard-coded "master".

Now, this is just to get the default branch, which only needs to be done once at installation. When we actually use it, we should use the config variable, since that will be more reliable than each user of the repository naming their remotes the same thing.

SAMPLE_CONFIG = """
# See the docstring in versioneer.py for instructions. Note that you must
# re-run 'versioneer.py setup' after changing this section, and commit the
# resulting files.
[versioneer]
#VCS = git
#style = pep440
#versionfile_source =
#versionfile_build =
#tag_prefix =
#parentdir_prefix =
"""

We could consider making it default_branch = {default_branch}, which would make it easy to detect whether it has been set before or if we should run the inference above.

@ghost
Copy link
Author

ghost commented Sep 5, 2022

cool, will work on the above comment.

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

Successfully merging this pull request may close these issues.

2 participants