jesseduffield / lazygit

simple terminal UI for git commands
MIT License
52.66k stars 1.84k forks source link

Git fast forward branch to remote fails when there's the same tag name #2625

Closed Neko-Box-Coder closed 2 months ago

Neko-Box-Coder commented 1 year ago

Describe the bug Git fast forward branch to remote fails when there's the same tag name because we didn't specify the fetch command to be a branch. This is pretty similar to #2546

It failed with

error: cannot update ref 'refs/head/<branch name>': trying to write non-commit object <tag hash with same branch name> to branch 'refs/heads/<branch name>'

To Reproduce Steps to reproduce the behavior:

  1. Create a tag that has the same name as the branch, and push it.
  2. Try to fast forward the branch with same name to upstream

Expected behavior The branch with the same name as the tag should be fast-forwarded successfully

Screenshots If applicable, add screenshots to help explain your problem.

Version info: lazygit --version: commit=v0.36.0, build date=2022-11-15T07:26:07Z, build source=binaryRelease, version=0.36.0, os=linux, arch=amd64, git version=2.38.1 git --version: git version 2.38.1

jesseduffield commented 1 year ago

Sounds like an easy fix: Just a matter of updating pkg/commands/git_commands/sync.go FastForward, similar to what we did here.

I'll chuck a 'good-first-issue' label on this. Do you feel up to the task @Neko-Box-Coder ?

Neko-Box-Coder commented 1 year ago

@jesseduffield This is slightly different from before because git fetch doesn't have a branch specifier/option afaik

That's why I didn't suggest a change this time because the only way I can think of to get it work is to do a full reference so something like

git fetch "origin" "refs/heads/<branch name>":"<branch name>"

If that works, then do we want to change most if not all the branch/tag reference strings in other places to be using "refs/heads/" or "refs/tags/" to prevent any future issues that are related to this?

What do you think? I am fine picking up the task if it is only changing sync.go but might not be suitable for changing all reference strings if you want to change all the reference strings.

jesseduffield commented 1 year ago

I'm happy for us to change just this one place for now.

Neko-Box-Coder commented 1 year ago

Yeah no problem, I will create a PR for it.