Skip to content

Commit

Permalink
Merge pull request #1379 from fnune/fnune/add-initial-branch-name-fea…
Browse files Browse the repository at this point in the history
…ture
  • Loading branch information
CKolkey authored Oct 21, 2024
2 parents e862967 + d1a3b99 commit 24726da
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ neogit.setup {
-- Flag description: https://git-scm.com/docs/git-branch#Documentation/git-branch.txt---sortltkeygt
-- Sorting keys: https://git-scm.com/docs/git-for-each-ref#_options
sort_branches = "-committerdate",
-- Default for new branch name prompts
initial_branch_name = "",
-- Change the default way of opening neogit
kind = "tab",
-- Disable line numbers and relative line numbers
Expand Down
1 change: 1 addition & 0 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ TODO: Detail what these do
fetch_after_checkout = false,
auto_refresh = true,
sort_branches = "-committerdate",
initial_branch_name = "",
kind = "tab",
disable_line_numbers = true,
-- The time after which an output console is shown for slow running commands
Expand Down
3 changes: 3 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ end
---@field use_per_project_settings? boolean Scope persisted settings on a per-project basis
---@field remember_settings? boolean Whether neogit should persist flags from popups, e.g. git push flags
---@field sort_branches? string Value used for `--sort` for the `git branch` command
---@field initial_branch_name? string Default for new branch name prompts
---@field kind? WindowKind The default type of window neogit should open in
---@field disable_line_numbers? boolean Whether to disable line numbers
---@field disable_relative_line_numbers? boolean Whether to disable line numbers
Expand Down Expand Up @@ -359,6 +360,7 @@ function M.get_default_values()
fetch_after_checkout = false,
sort_branches = "-committerdate",
kind = "tab",
initial_branch_name = "",
disable_line_numbers = true,
disable_relative_line_numbers = true,
-- The time after which an output console is shown for slow running commands
Expand Down Expand Up @@ -1087,6 +1089,7 @@ function M.validate_config()
validate_type(config.use_per_project_settings, "use_per_project_settings", "boolean")
validate_type(config.remember_settings, "remember_settings", "boolean")
validate_type(config.sort_branches, "sort_branches", "string")
validate_type(config.initial_branch_name, "initial_branch_name", "string")
validate_type(config.notification_icon, "notification_icon", "string")
validate_type(config.console_timeout, "console_timeout", "number")
validate_kind(config.kind, "kind")
Expand Down
10 changes: 7 additions & 3 deletions lua/neogit/popups/branch/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ local function checkout_branch(target, args)
end
end

local function get_branch_name_user_input(prompt, default)
default = default or config.values.initial_branch_name
return input.get_user_input(prompt, { strip_spaces = true, default = default })
end

local function spin_off_branch(checkout)
if git.status.is_dirty() and not checkout then
notification.info("Staying on HEAD due to uncommitted changes")
checkout = true
end

local name =
input.get_user_input(("%s branch"):format(checkout and "Spin-off" or "Spin-out"), { strip_spaces = true })
local name = get_branch_name_user_input(("%s branch"):format(checkout and "Spin-off" or "Spin-out"))
if not name then
return
end
Expand Down Expand Up @@ -215,7 +219,7 @@ function M.rename_branch()
return
end

local new_name = input.get_user_input(("Rename '%s' to"):format(selected_branch), { strip_spaces = true })
local new_name = get_branch_name_user_input(("Rename '%s' to"):format(selected_branch))
if not new_name then
return
end
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/neogit/config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe("Neogit config", function()
assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0)
end)

it("should return invalid when initial_branch_name isn't a string", function()
config.values.initial_branch_name = false
assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0)
end)

it("should return invalid when kind isn't a string", function()
config.values.kind = true
assert.True(vim.tbl_count(require("neogit.config").validate_config()) ~= 0)
Expand Down

0 comments on commit 24726da

Please sign in to comment.