Adds git method

This commit is contained in:
Michel Fedde 2025-02-18 00:53:46 +01:00
parent b7da3ade1c
commit d34742c3bd
7 changed files with 87 additions and 10 deletions

View file

@ -0,0 +1,13 @@
local git = require("functions.git")
local enabledGit = os.getenv("ENABLE_GIT_SETUP") or false
if not enabledGit then
return
end
vim.api.nvim_create_user_command("GitPush", function()
git.push()
end, {})
vim.api.nvim_create_user_command("GitPull", function()
git.pull()
end, {})

View file

@ -23,6 +23,7 @@ vim.api.nvim_create_autocmd("VimLeavePre", {
return
end
git.commitRest()
git.push()
end,
})

View file

@ -6,7 +6,7 @@ function git.commitFile(filepath)
return vim.fn.fnamemodify(file, ":t:r")
end
local commitMessage = get_file_name(filepath) .. "-" .. os.date("%m_%B_%Y")
local commitMessage = get_file_name(filepath) .. "-" .. os.date("%d_%B_%Y")
os.execute('git add "' .. filepath .. '"')
local commitCommand = 'git commit -m "' .. commitMessage .. '" &> /dev/null'
@ -25,6 +25,26 @@ function git.commitFile(filepath)
end
end
function git.commitRest()
local commitMessage = "Files changed since last commit-" .. os.date("%d_%B_%Y")
os.execute("git add .")
local commitCommand = 'git commit -m "' .. commitMessage .. '" &> /dev/null'
local commitResult = os.execute(commitCommand)
print("Commiting... " .. commitMessage)
if commitResult == 256 then
print("Nothing to commit")
return
elseif commitResult == 0 then
print("Commit complete")
else
print("Unknown Error " .. commitResult)
print(commitCommand)
return
end
end
function git.push()
print("Pushing changes...")
-- Push twice, in case the credentials expired. Ugly hack, but it works

View file

@ -1,7 +1,3 @@
if true then
return {}
end
return {
"shortcuts/no-neck-pain.nvim",
version = "*",
@ -9,7 +5,6 @@ return {
require("no-neck-pain").setup({
width = 125,
autocmds = {
enableOnVimEnter = true,
skipEnteringNoNeckPainBuffer = true,
},
})