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

Add support for creating a registry repo with an initial branch other than master. #58

Conversation

tuckermcclure
Copy link

When an origin repo for a registry is created, it may use a branch name other than master (e.g., GitHub now defaults to main). When LocalRegistry creates a registry (e.g. in ~/.julia/registries/...), it may use an inconsistent initial branch name, leading to errors on the first attempt to push. This PR adds an option for the initial branch name.

I tested this by creating a local repo as my "origin" (git init --initial-branch=main --bare .) and then using LocalRegistry to create a new registry using main as the initial branch and file://... as the URL (create_registry("InitBranchTest5", "file:///Users/tucker/Dev/loreg/", branch = "main", push = true)). This pushed correctly and appears to have done the right thing.

It still needs CI testing, so this is a draft PR so folks can provide feedback.

Possible improvements:

  • The --initial-branch option will only work on git version 2.28.0, according to the same Stack Exchange. Perhaps this would be done after git init with git checkout -b $branch.
  • The default initial branch name could be pulled from the system's git config (git config --global init.defaultBranch is suggested by this Stack Exchange, but it doesn't appear to work on my machine, so I didn't add a feature for this.)

@codecov-commenter
Copy link

codecov-commenter commented Sep 12, 2022

Codecov Report

Merging #58 (3474df5) into master (fb3e916) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master      #58   +/-   ##
=======================================
  Coverage   96.57%   96.57%           
=======================================
  Files           1        1           
  Lines         263      263           
=======================================
  Hits          254      254           
  Misses          9        9           
Impacted Files Coverage Δ
src/LocalRegistry.jl 96.57% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@GunnarFarneback
Copy link
Owner

Thanks for looking into this.

If possible I would prefer not to have have a function argument for this. The best way to obtain the default branch from the remote repository should be to clone it and if it doesn't exist, in which case you should use push = false, the second best option would be to just run git init locally and rely on the user having set the init.defaultBranch config if he has preferences about the branch naming.

Versions of git might be an issue. The best solution to guarantee a sufficiently fresh git is #38, but the MacOS test failures are a blocker. I should probably rebase that PR and see if it fares better today, but I haven't heard about any progress in that area.

The way to go about testing this is to create a new test/create_registry.jl file. This could be similar to the start of https://github.com/GunnarFarneback/LocalRegistry.jl/blob/master/test/check_git_registry.jl but then just checking that the right branch has been created and/or pushed.

@GunnarFarneback
Copy link
Owner

Actually having a branch argument isn't a problem, but I'd prefer if the right thing happens without setting it, to the extent it's possible. Possibly the logic should be:

  1. If branch is set, use it.
  2. Otherwise if push is true, clone the remote repo to get a branch.
  3. Otherwise just run git init and use whatever branch that created.

@tuckermcclure
Copy link
Author

Hi Gunnar. I had a second to look at this again. Quick question: If push is true, why git init at all? Why not just clone the repo and skip the init step? And if cloning, then presumably we don't need to mess with picking the master branch. Something like this:

if push # Pushing presumes the existence of an empty remote.
        run(`$git clone $repo`)
else
    if isnothing(branch)
        run(`$git init -q`)
    else
        run(`$git init -q --initial-branch=$branch`)
    end
    run(`$git remote add origin $repo`)
end

# Now create the Registry.toml
...

# Add, commit, and push if requested.
if !isnothing(branch)
    run(`$git checkout -b $branch`)
end
run(`$git add Registry.toml`)
run(`$git commit -qm 'Create registry.'`)
if push
    run(`$git push -u origin HEAD`) # Already on the right branch, so HEAD will push that.
end

@GunnarFarneback
Copy link
Owner

The push option didn't exist initially, and I didn't redesign anything when I added it. I.e. basically for historical reasons.

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.

3 participants