diff --git a/pkg/commands/oscommands/cmd_obj_runner.go b/pkg/commands/oscommands/cmd_obj_runner.go index b964edce714..f7120910498 100644 --- a/pkg/commands/oscommands/cmd_obj_runner.go +++ b/pkg/commands/oscommands/cmd_obj_runner.go @@ -106,6 +106,10 @@ func (self *cmdObjRunner) RunWithOutputAux(cmdObj *CmdObj) (string, error) { t := time.Now() output, err := sanitisedCommandOutput(cmdObj.GetCmd().CombinedOutput()) + + // Filter out git warning lines that can appear in stderr and cause parsing issues + output = self.filterGitWarnings(output) + if err != nil { self.log.WithField("command", cmdObj.ToString()).Error(output) } @@ -196,6 +200,21 @@ func (self *cmdObjRunner) logCmdObj(cmdObj *CmdObj) { self.guiIO.logCommandFn(cmdObj.ToString(), true) } +// filterGitWarnings removes warning lines from git output that can interfere with parsing +// and logs them for debugging visibility +func (self *cmdObjRunner) filterGitWarnings(output string) string { + lines := strings.Split(output, "\n") + filtered := make([]string, 0, len(lines)) + for _, line := range lines { + if strings.HasPrefix(line, "warning:") { + self.log.Warnf("filtered git warning: %s", line) + } else { + filtered = append(filtered, line) + } + } + return strings.Join(filtered, "\n") +} + func sanitisedCommandOutput(output []byte, err error) (string, error) { outputString := string(output) if err != nil { diff --git a/pkg/integration/components/runner.go b/pkg/integration/components/runner.go index 83ddfe66d5c..5640c3e7044 100644 --- a/pkg/integration/components/runner.go +++ b/pkg/integration/components/runner.go @@ -246,7 +246,11 @@ func getLazygitCommand( cmdObj.AddEnvVars(fmt.Sprintf("GORACE=log_path=%s", raceDetectorLogsPath())) if test.ExtraEnvVars() != nil { for key, value := range test.ExtraEnvVars() { - cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, value)) + resolvedValue := utils.ResolvePlaceholderString(value, map[string]string{ + "actualPath": paths.Actual(), + "actualRepoPath": paths.ActualRepo(), + }) + cmdObj.AddEnvVars(fmt.Sprintf("%s=%s", key, resolvedValue)) } } diff --git a/pkg/integration/tests/misc/git_warning.go b/pkg/integration/tests/misc/git_warning.go new file mode 100644 index 00000000000..dedac849136 --- /dev/null +++ b/pkg/integration/tests/misc/git_warning.go @@ -0,0 +1,51 @@ +package misc + +import ( + "os" + "runtime" + + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var GitWarning = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Verify lazygit handles git warnings without crashing", + ExtraCmdArgs: []string{}, + ExtraEnvVars: map[string]string{ + "PATH": "{{actualRepoPath}}/bin:" + os.Getenv("PATH"), + }, + Skip: runtime.GOOS == "windows", // Shell wrapper won't work on Windows + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + // Create bin directory for our git wrapper + shell.CreateDir("bin") + + // Create a git wrapper that outputs the warning then calls real git + shell.CreateFile("bin/git", `#!/bin/sh +echo "warning: unhandled Platform key FamilyDisplayName" >&2 +exec /usr/bin/git "$@" +`) + shell.MakeExecutable("bin/git") + + // Create a simple repo with a commit + shell.CreateFileAndAdd("file.txt", "content"). + Commit("initial commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + // Simply verify lazygit opens and shows the files view without crashing + // The git wrapper outputs the warning on every git command + t.Views().Files().IsFocused() + + // Navigate to branches to trigger more git commands + t.Views().Branches().Focus() + t.Views().Branches().Lines( + Contains("master"), + ) + + // Navigate to commits to trigger git log + t.Views().Commits().Focus() + t.Views().Commits().Lines( + Contains("initial commit"), + ) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index 14072d866db..8da03d5db40 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -315,6 +315,7 @@ var tests = []*components.IntegrationTest{ misc.CopyConfirmationMessageToClipboard, misc.CopyToClipboard, misc.DisabledKeybindings, + misc.GitWarning, misc.InitialOpen, misc.RecentReposOnLaunch, patch_building.Apply,