Skip to content

Commit d5461c2

Browse files
committed
✨ feat (diff): Add interactive staging for untracked files
1 parent e325c29 commit d5461c2

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lua/commit-ai/utils.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@ local log = require("commit-ai.log")
22
local M = {}
33

44
function M.get_git_diff()
5+
local status_lines = vim.fn.systemlist('git status --porcelain')
6+
local untracked_files = vim.tbl_filter(function(line)
7+
return line:match("^%?%?")
8+
end, status_lines)
9+
10+
if #untracked_files > 0 then
11+
for _, line in ipairs(untracked_files) do
12+
local file = line:sub(4)
13+
log.info("‼️ Untracked file: " .. file)
14+
end
15+
local answer = vim.fn.input("Do you want to add them to the staging area? (y/n) ")
16+
if answer:lower() == "y" then
17+
for _, line in ipairs(untracked_files) do
18+
local file = line:sub(4)
19+
vim.fn.system("git add " .. file)
20+
log.info("📝 Added " .. file .. " to the staging area")
21+
end
22+
else
23+
log.error("Aborting")
24+
return nil
25+
end
26+
return nil
27+
end
528
local staged_diff = vim.fn.system('git diff --cached --no-color')
629
if staged_diff == "" then
730
staged_diff = vim.fn.system('git diff --no-color')

0 commit comments

Comments
 (0)