-
-
Notifications
You must be signed in to change notification settings - Fork 44
Trying to fix a non-existent HEAD #87
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
Conversation
|
Hi @EdmondFrank and thank for the help. Can you further explain when/how this does happen? As long as I know, the HEAD is not hardcoded anywhere in the code. If I remember correctly the repository HEAD symbolic reference is assigned on the first push (when the server receives the first PACK) and is specified by the client. What we could do is let the repository owner/admin change the default branch (HEAD) in the repository settings (like GitHub and GitLab do). |
| {:ok, stream} -> | ||
| with %GitRef{name: name} = | ||
| ref <- Enum.at(Stream.map(stream, &resolve_reference_peel!(&1, :undefined, handle)), 0), | ||
| :ok <- Git.repository_set_head(handle, "refs/heads/#{name}") do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is a good idea
I'd prefer to fix the issue upfront over implicitly updating the HEAD here.
| case Git.reference_resolve(handle, "HEAD") do | ||
| {:ok, name, shorthand, oid} -> | ||
| {:ok, resolve_reference({name, shorthand, :oid, oid})} | ||
| {:error, reason} -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of error are you getting here? And how doe it happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of error are you getting here? And how doe it happen?
Refer to the third paragraph of this comment: #87 (comment)
Reproduction steps:
- Create a new repository
Teston git.limo. - Create a local repository
Testwith only one branchmainas default branch. - Add git.limo
Testrepository as local repository's remote andgit push -u origin main. - Access
Testrepository at git.limo on web.
| } | ||
|
|
||
| ERL_NIF_TERM | ||
| geef_repository_set_head(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
We could use that for letting the repository owner/admin change the default branch in the repository settings.
Hi @redrabbit Thank you for your reply. According to the source code of libgit2, the Although we can provide the user with a global setting for the default branch of the initialized repository, there are still two problems: one, the setting cannot directly affect the existing repository, it can only take effect when the repository is initialized, and two, this global default branch is not always the same as the branch the user pushed for the first time. And when the branch pointed to by HEAD does not exist in the repository, we cannot access the repository through the front-end page and update default branch settings. |
This commit adds support for setting the default branch on a repository.
* Add :default_branch to GitGud.Repo schema.
* Add <form> field to templates/repo/{edit.html.eex, new.html.eex}.
* Refactor GitRekt.RepoStorage.init/2 to set initial_head accordingly.
* Ensure that HEAD is updated when :default_branch field changes.
* Add workaround for views relying on @Head (which can be nil).
See #87 for more details.
|
Hey @EdmondFrank. I've pushed a few changes for fixing the issue:
This allows for setting a custom default branch when creating/updating a repository.
This is still true but now the user can customize the default branch when creating the repository or update it later on. My preferred approach would be showing an alert in
I've fixed that (and a few other things). All views should be able to work even when |
|
I deployed the code to https://git.limo. |
Thanks @redrabbit . |
I think we're good, git.limo/apps/gitgud/lib/gitgud/schemas/repo.ex Lines 316 to 322 in b8b94d6
|
|
Closing this PR. Support for custom default branch has been added to |

Because the default branch of some recently new repository is
mainnow, but when you create a new repository and do the first push, the HEAD is still points to torefs/head/master.So when you access the repository on the page that was just pushed with the default branch of main, it will trigger an error that the
refs/heads/masterwas not found.This PR tries to fix the problem by setting the first branch in the branch list to HEAD if the current HEAD does not exist.