Skip to content

Create MR branch logic does not include remote branches #296

@levouh

Description

@levouh

Prerequsities

  • I'm on the latest version of the plugin
  • I've installed the required dependencies
  • I've run :h gitlab.nvim.troubleshooting and followed the steps there

Bug Description

get_all_merge_targets -> get_all_remote_branches -> branches calls git branch, which is seemingly incorrect if we are trying to fetch remote branches - should use git branch --remotes or git branch --all.

I have thrown in some debug printing strings to enumerate the issue, as follows:

# Listing the current branch
[user] -- DBGSTR [git.lua:52-7] current_branch=test-branchy

# Output from `git branch` as called by M.branches()
[user] -- DBGSTR [git.lua:69-9] all_branches=master
[user] * test-branchy

# Parsing of string to Lua table
[user] -- DBGSTR [git.lua:79-10] lines={ "master", "* test-branchy" }

Then the following code:

  return List.new(lines)
    :map(function(line)
      -- Trim "origin/"
      return line:match("origin/(%S+)")
    end)
    :filter(function(branch)
      -- Don't include the HEAD pointer
      return not branch:match("^HEAD$")
    end)

is obviously going to skip all of these lines, as none of them match the patterns (the first filter filters out all branches, and the second pattern has nothing to match against).

If I change the call to be git branch --remotes, it looks more like this:

# Listing the current branch
[user] -- DBGSTR [git.lua:54-8] remotes={ { "master", "test-branchy" } }

# Output from `git branch` as called by M.branches() (with --remotes)
[user] -- DBGSTR [git.lua:69-9] all_branches=master
[user] * test-branchy
[user]   remotes/origin/master
[user]   remotes/origin/test-branchy

# Parsing of string to Lua table
[user] -- DBGSTR [git.lua:79-10] lines={ "master", "* test-branchy", "  remotes/origin/master", "  remotes/origin/test-branchy" }

# Comparisons later on which show that some branches actually get returned (above no branches were returned)
[user] -- DBGSTR [git.lua:57-5] branch=master
[user] -- DBGSTR [git.lua:58-6] current_branch=test-branchy
[user] -- DBGSTR [git.lua:57-5] branch=test-branchy
[user] -- DBGSTR [git.lua:58-6] current_branch=test-branchy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions