Skip to content

Commit ec35479

Browse files
committed
fix(auto-session): block save/restore during git rebase
1 parent 88d4d92 commit ec35479

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

lua/lib/git.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ M.repo_status = function(callback, cwd)
8585
end)
8686
end
8787

88+
M.is_rebasing = function()
89+
local handle = io.popen("git rev-parse --git-path rebase-merge 2>/dev/null", "r")
90+
if handle then
91+
local result = handle:read("*a"):gsub("%s+", "")
92+
handle:close()
93+
if result ~= "" and vim.uv.fs_stat(result) then
94+
return true
95+
end
96+
end
97+
98+
handle = io.popen("git rev-parse --git-path rebase-apply 2>/dev/null", "r")
99+
if handle then
100+
local result = handle:read("*a"):gsub("%s+", "")
101+
handle:close()
102+
if result ~= "" and vim.uv.fs_stat(result) then
103+
return true
104+
end
105+
end
106+
107+
return false
108+
end
109+
88110
M.remote_status = function(callback, cwd)
89111
cwd = cwd or vim.fn.getcwd()
90112

lua/plugins/auto-session.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
-- Session management
22
-- https://github.com/rmagatti/auto-session
33

4+
local is_rebasing = require("lib.git").is_rebasing
5+
46
return {
57
"rmagatti/auto-session",
68
event = "VimEnter",
@@ -9,6 +11,20 @@ return {
911
git_auto_restore_on_branch_change = true,
1012
git_use_branch_name = true,
1113
purge_after_minutes = 14400,
14+
pre_save_cmds = {
15+
function()
16+
if is_rebasing() then
17+
return false
18+
end
19+
end,
20+
},
21+
pre_restore_cmds = {
22+
function()
23+
if is_rebasing() then
24+
return false
25+
end
26+
end,
27+
},
1228
save_extra_cmds = {
1329
-- Save and restore the quickfix list
1430
function()

0 commit comments

Comments
 (0)