Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/commands/oscommands/cmd_obj_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 5 additions & 1 deletion pkg/integration/components/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
51 changes: 51 additions & 0 deletions pkg/integration/tests/misc/git_warning.go
Original file line number Diff line number Diff line change
@@ -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"),
)
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ var tests = []*components.IntegrationTest{
misc.CopyConfirmationMessageToClipboard,
misc.CopyToClipboard,
misc.DisabledKeybindings,
misc.GitWarning,
misc.InitialOpen,
misc.RecentReposOnLaunch,
patch_building.Apply,
Expand Down