mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-05 01:28:34 +00:00
Fix locale-dependent git repo detection (#1099)
Fixes #1089 ## Root cause `tea clone` initializes the command context by probing the current directory with `git rev-parse --show-toplevel`. `classifyRepoError` recognizes the "not a git repository" case by matching the English stderr text. When git emits localized errors (for example with `LANG=de_DE.UTF-8`), that match fails, and the otherwise harmless "no repo here" error is returned as fatal before cloning. ## Fix Pin the locale of git subprocesses to `C` by overriding `LC_ALL`, `LANG`, and `LANGUAGE` in `runGitCommand`. This keeps all git output stable for parsing while leaving the parent process locale untouched. ## Tests Added a regression test using a fake git executable that emits a German "not a repository" error unless the locale is forced to `C`, and verifies `ErrRepositoryNotExists` is returned. Reviewed-on: https://gitea.com/gitea/tea/pulls/1099 Reviewed-by: Zettat123 <39446+zettat123@noreply.gitea.com>
This commit is contained in:
@@ -258,6 +258,21 @@ func (e *gitCommandError) Unwrap() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func gitCommandEnv(authEnv []string) []string {
|
||||
baseEnv := os.Environ()
|
||||
env := make([]string, 0, len(baseEnv)+len(authEnv)+3)
|
||||
for _, value := range baseEnv {
|
||||
if strings.HasPrefix(value, "LC_ALL=") ||
|
||||
strings.HasPrefix(value, "LANG=") ||
|
||||
strings.HasPrefix(value, "LANGUAGE=") {
|
||||
continue
|
||||
}
|
||||
env = append(env, value)
|
||||
}
|
||||
env = append(env, authEnv...)
|
||||
return append(env, "LC_ALL=C", "LANG=C", "LANGUAGE=C")
|
||||
}
|
||||
|
||||
func runGitCommand(dir string, auth *AuthMethod, extraConfigs []string, args ...string) (string, error) {
|
||||
authConfigs, authEnv, cleanup, err := prepareCLIAuth(auth)
|
||||
if err != nil {
|
||||
@@ -278,7 +293,7 @@ func runGitCommand(dir string, auth *AuthMethod, extraConfigs []string, args ...
|
||||
if dir != "" {
|
||||
cmd.Dir = dir
|
||||
}
|
||||
cmd.Env = append(os.Environ(), authEnv...)
|
||||
cmd.Env = gitCommandEnv(authEnv)
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
Reference in New Issue
Block a user