neogit icon indicating copy to clipboard operation
neogit copied to clipboard

Doesn't respect git credential caching setting

Open mortezadadgar opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. I have configured git to cache my credential for 2hrs like this in my .gitconfig:

[credential]
	helper = cache --timeout=3600

therefore I don't have to enter my password every moment for pushing just quickly checked out the magit; it does save password just like git.

Describe the solution you'd like respect git config credential config

Describe alternatives you've considered there's none.

Additional context not needed.

mortezadadgar avatar Dec 14 '23 09:12 mortezadadgar

@CKolkey I come up with a hacky solution which checks credential-cache--daemon is running using pgrep and start it in background I would like to find a cross platform way to list running processes

diff --git a/lua/neogit/lib/git/cli.lua b/lua/neogit/lib/git/cli.lua
index 2260942a..ebd42cf7 100644
--- a/lua/neogit/lib/git/cli.lua
+++ b/lua/neogit/lib/git/cli.lua
@@ -724,6 +724,11 @@ local mt_builder = {
 ---@param p Process
 ---@param line string
 local function handle_interactive_password_questions(p, line)
+  local out = vim.fn.system("pgrep -f 'credential-cache--daemon'")
+  if vim.v.shell_error ~= 0 and out == "" then
+    vim.fn.jobstart("git credential-cache--daemon ~/.git-credential-cache/socket")
+  end
+
   process.hide_preview_buffers()
   logger.debug(string.format("Matching interactive cmd output: '%s'", line))
   if vim.startswith(line, "Are you sure you want to continue connecting ") then

If I'm reading it right magit doesn't check for git credential being enabled in gitconfig either ref: https://github.com/magit/magit/blob/eac5c51fe002d8d1415b8ad97cb5b543c2051b15/lisp/magit-process.el#L958

a cleaner way would be to spawn prcesses using plenary.Job which has a flag to let child processes being detached(though I'm not familiar with api): https://github.com/nvim-lua/plenary.nvim/blob/55d9fe89e33efd26f532ef20223e5f9430c8b0c0/lua/plenary/job.lua#L12

mortezadadgar avatar Dec 15 '23 09:12 mortezadadgar