Skip to content

Commit

Permalink
feat: prevent git from asking for credentials
Browse files Browse the repository at this point in the history
If you run a git command with GIT_TERMINAL_PROMPT=0, then git will throw
an error rather than prompt the user for a username or password. This is
the behavior that I want for the tool.

https://git-scm.com/docs/git#Documentation/git.txt-codeGITTERMINALPROMPTcode
  • Loading branch information
telemachus committed Nov 17, 2024
1 parent 1cb60c4 commit b2ea608
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/cli/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func (app *App) clone(repo Repo, ch chan<- result) {
}
args := []string{"clone", "--mirror", repo.URL, repo.Name}
cmd := exec.Command("git", args...)
noGitPrompt := "GIT_TERMINAL_PROMPT=0"
env := append(os.Environ(), noGitPrompt)
cmd.Env = env
cmd.Dir = filepath.Join(app.HomeDir, defaultStorage)
err := cmd.Run()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/cli/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"fmt"
"os"
"os/exec"
"path/filepath"

Expand Down Expand Up @@ -54,6 +55,9 @@ func (app *App) update(repo Repo, ch chan<- result) {

args := []string{"remote", "update"}
cmd := exec.Command("git", args...)
noGitPrompt := "GIT_TERMINAL_PROMPT=0"
env := append(os.Environ(), noGitPrompt)
cmd.Env = env
cmd.Dir = repoDir
err = cmd.Run()
if err != nil {
Expand Down

0 comments on commit b2ea608

Please sign in to comment.