Skip to content

Checkout new branch doesn't show current branch as option #327

@ascandella

Description

@ascandella

Description

Since #307 was merged, the behavior of b c now asks for a starting point for the new branch. However, on my machine, the current branch (e.g. master) is not presented as an option.

Neovim version

nvim --version
NVIM v0.7.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by [email protected]

Operating system and version

macOS 12.5

Steps to reproduce

:lua print(vim.inspect(require('neogit.lib.git.branch').get_all_branches()))
{ "remotes/origin/HEAD -> origin/master", "remotes/origin/master", "remotes/origin/thinkpad" }
$ git branch --list -a
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/thinkpad

Creating a new branch with b c

image
Note that master is not available, only origin/master

Creating a branch off of origin/master sets the upstream to origin/master which is somewhat dangerous, as pushing will push to origin/master not my branch:

image

However, if I'm on a non-master branch when I open the b c prompt:

Screen Shot 2022-08-03 at 9 53 51 AM

Select master as the base, then create a new branch, which doesn't have an upstream set (which is good):

Screen Shot 2022-08-03 at 9 54 11 AM

Expected behavior

Current branch (e.g. master or main) is a valid option to start branching from when creating a new branch

Actual behavior

Current branch not available, selecting the origin/ version sets the upstream to the branch from.

I think this is due to parse_branches using this regex: https://github.com/TimUntersberger/neogit/blob/d0731367918c840a850d55ce03398c6ce87a9eb7/lua/neogit/lib/git/branch.lua#L9

But this function has been around for a while, so I'm guessing there's some history as to why it ignores the current branch (with a * in front of it).

Minimal config

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup({
    {
      "wbthomason/packer.nvim",
      {
        "TimUntersberger/neogit",
        requires = {
          { "nvim-lua/plenary.nvim" },
          { "sindrets/diffview.nvim" },
        },
        config = function()
          print("loaded neogit")
          require("neogit").setup()
        end,
      },
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  })
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing neogit and dependencies.")
  vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path })
end
load_plugins()
require("packer").sync()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions