Skip to content
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

feat: Spin out/off branch #676

Merged
merged 22 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
abb1f0f
feat: Spin off branch
morgsmccauley Jul 28, 2023
affcc98
feat: Spin out branch
morgsmccauley Jul 28, 2023
0765fa6
test: Spin out/off branch
morgsmccauley Jul 29, 2023
a3ef9e9
Merge branch 'master' into feat/spin-off-branch
CKolkey Jul 29, 2023
de63179
refactor: Extract dirty check to own function
morgsmccauley Jul 30, 2023
cdae697
fix: Remove unneeded dirty check from `spin_off`
morgsmccauley Jul 30, 2023
275d5ce
feat: Checkout spin out branch if uncommitted changes
morgsmccauley Jul 30, 2023
34cbffa
feat: Handle uncommitted changes during branch spin out
morgsmccauley Jul 30, 2023
408c6ae
feat: Handle uncommitted changes during branch spin off
morgsmccauley Jul 30, 2023
5ad234d
refactor: Use `git.branch` rather than repo state directly
morgsmccauley Jul 30, 2023
13bc72f
fix: Get branch name before spin out/off
morgsmccauley Jul 30, 2023
ffbe847
refactor: Move `status.is_dirty()` to lib
morgsmccauley Jul 31, 2023
d4f786d
Merge branch 'master' into feat/spin-off-branch
morgsmccauley Jul 31, 2023
3fa72e0
refactor: Extract spin out/off logic to common function
morgsmccauley Jul 31, 2023
d16bb74
refactor: Skip dirty check when checkout is intended
morgsmccauley Jul 31, 2023
aa12245
refactor: Make spin off branch reset async
morgsmccauley Jul 31, 2023
86a9dac
fix: Use correct module for `is_dirty()` check
morgsmccauley Aug 2, 2023
d608f35
refactor: Remove unused return values
morgsmccauley Aug 2, 2023
715c6cf
fix: Emit correct operation for spin out/off
morgsmccauley Aug 3, 2023
d339e3a
test: Spin out/off branch
morgsmccauley Aug 3, 2023
d98aca4
Merge remote-tracking branch 'origin/master' into feat/spin-off-branch
morgsmccauley Aug 3, 2023
5657ecf
fix: lint
morgsmccauley Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lua/neogit/popups/branch/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,40 @@ local function parse_remote_branch_name(ref)
return remote, branch_name
end

M.spin_off_branch = operation("spin_off_branch", function()
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved
if #git.repo.staged.items > 0 or #git.repo.unstaged.items > 0 then
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved
notif.create("Staying on current branch as there are uncommitted changes.", vim.log.levels.INFO)
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved
return
end

local name = git.branch.create()

local upstream = git.repo.upstream.ref
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved
if upstream then
git.cli.reset.hard.args(upstream).call_sync()
end

git.cli.checkout.branch(name).call_sync()
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved

status.refresh(true, "spin_off_branch")
end)

M.spin_out_branch = operation("spin_out_branch", function()
if #git.repo.staged.items > 0 or #git.repo.unstaged.items > 0 then
notif.create("Staying on current branch as there are uncommitted changes.", vim.log.levels.INFO)
return
end

git.branch.create()

local upstream = git.repo.upstream.ref
if upstream then
git.cli.reset.hard.args(upstream).call_sync()
end

status.refresh(true, "spin_out_branch")
end)

M.checkout_branch_revision = operation("checkout_branch_revision", function(popup)
local selected_branch = FuzzyFinderBuffer.new(git.branch.get_all_branches()):open_async()
if not selected_branch then
Expand Down
4 changes: 2 additions & 2 deletions lua/neogit/popups/branch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ function M.create()
:action("l", "local branch", actions.checkout_local_branch)
:new_action_group()
:action("c", "new branch", actions.checkout_create_branch)
:action("s", "new spin-off")
:action("s", "new spin-off", actions.spin_off_branch)
:action("w", "new worktree")
:new_action_group("Create")
:action("n", "new branch", actions.create_branch)
:action("S", "new spin-out")
:action("S", "new spin-out", actions.spin_out_branch)
:action("W", "new worktree")
:new_action_group("Do")
:action("C", "Configure...", actions.configure_branch)
Expand Down
20 changes: 20 additions & 0 deletions tests/specs/neogit/operations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,24 @@ describe("branch popup", function()
eq("branch-from-test", get_current_branch())
end)
)

it(
morgsmccauley marked this conversation as resolved.
Show resolved Hide resolved
"can spin off a branch",
in_prepared_repo(function()
input.value = "spin-off-branch"
act("bs<cr><cr>")
operations.wait("spin_off_branch")
eq("spin-off-branch", get_current_branch())
end)
)

it(
"can spin out a branch",
in_prepared_repo(function()
input.value = "spin-out-branch"
act("bS<cr><cr>")
operations.wait("spin_out_branch")
eq("master", get_current_branch())
end)
)
end)
Loading