fix: dont assume the remote name - #105
Open
teto wants to merge 1 commit into
Open
Conversation
Problem with the function get_head_branch is that it returns
"ref: refs/remotes/...."
===
return vim.iter(vim.fs.dir(remotes_dir))
:map(function(remote_subdir)
return read_line(vim.fs.joinpath(remotes_dir, remote_subdir, "HEAD"))
end)
:find(function(head_file_content)
return head_file_content:gsub("ref: refs/remotes/.+/", "")
end)
===
and then rocks tries to `git checkout ref: refs/remotes/...` which fails
The official way to get the default remote branch is to use
"ls-remote --symref <REMOTE> HEAD".
Since the problem is the default remote varies depending on user config,
I skipped it by passing the url:
The advantages are:
- it doesn't depend on user config or wether the user messed up with the repo (unlikely but I sometimes managed in the past to debug plugins in place).
- not implementation dependant
The drawback is that it's one more git call.
Alternatives considered:
- fix the current code. But it still wont know what remote to choose in
case there are several (it will follow vim.fs.dir order). It's
unlikely to be an issue so if that's the preferred solution I can do
it as well.
- trying to hardcode default upstream all the way. Can be annoying to implement ?
As for the tests, ideally we would run them against a real repo (ie, a
clone of https://github.com/lumen-oss/luarocks-stub.git) but
cloning this in a _spec.lua file might have been too slow so I didnt do
it ?
mrcjkb
requested changes
Aug 8, 2026
| :find(function(head_file_content) | ||
| return head_file_content:gsub("ref: refs/remotes/.+/", "") | ||
| end) | ||
| local args = { "ls-remote", "--symref", pkg.url, "HEAD" } |
Member
There was a problem hiding this comment.
issue: tests are failing in the nix flake check:
> Error → ...cz4-lua5.1-nvim-nio-1.10.0-1/share/lua/5.1/nio/tests.lua @ 66
> git Can get the remote HEAD branch
> ...cz4-lua5.1-nvim-nio-1.10.0-1/share/lua/5.1/nio/tests.lua:48: Test task failed with message:
> The coroutine failed with this message:
> spec/git_spec.lua:16: Expected objects to be the same.
> Passed in:
> (boolean) false
> Expected:
> (string) 'main'
> stack traceback:
> [C]: in function 'throw'
> ...f7ak-lua5.1-
We'll either have to implement a pure fallback mechanism or add --impure --option sandbox false to the CI run.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem with the function get_head_branch is that it returns "ref: refs/remotes/...."
and then rocks tries to
git checkout ref: refs/remotes/...which fails here.The official way to get the default remote branch is to use "ls-remote --symref HEAD".
Since the problem is the default remote varies depending on user config, I skipped it by passing the url:
The advantages are:
The drawback is that it's one more git call.
Alternatives considered:
git config get clone.defaultRemoteNamebut this value can be changed after a repo was cloned so not robust enough ()As for the tests, ideally we would run them against a real repo (ie, a clone of https://github.com/lumen-oss/luarocks-stub.git) but cloning this in a _spec.lua file might have been too slow so I didnt do it. Can restore in the test setup() call (a shallow clone)?