LocalRegistry.jl
LocalRegistry.jl copied to clipboard
Add support for creating a registry repo with an initial branch other than master.
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 aftergit init
withgit 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 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.
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.
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:
- If
branch
is set, use it. - Otherwise if
push
is true, clone the remote repo to get a branch. - Otherwise just run
git init
and use whatever branch that created.
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
The push
option didn't exist initially, and I didn't redesign anything when I added it. I.e. basically for historical reasons.