Skip to content
Merged
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
15 changes: 15 additions & 0 deletions cmd/input.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import "strings"

// isUnifiedDiff reports whether the input looks like a git unified-diff stream
// (the format the TUI is built to render).
//
// `git diff` and `git show` produce unified diffs that always contain at least
// one `diff --git ` header line, regardless of which dialect of the diff
// command was invoked. Summary forms (`--stat`, `--shortstat`, `--name-only`,
// `--name-status`) and metadata-only commands (`git log` with no patch) emit
// other shapes that the renderer cannot consume.
func isUnifiedDiff(input string) bool {
return strings.Contains(input, "diff --git ")
}
82 changes: 82 additions & 0 deletions cmd/input_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package cmd

import "testing"

func TestIsUnifiedDiff(t *testing.T) {
cases := []struct {
name string
input string
want bool
}{
{
name: "git diff (unified)",
input: "diff --git a/foo.go b/foo.go\n" +
"index 1234567..89abcde 100644\n" +
"--- a/foo.go\n" +
"+++ b/foo.go\n" +
"@@ -1,3 +1,4 @@\n" +
" package foo\n" +
"+\n" +
" func A() {}\n",
want: true,
},
{
name: "git show (preamble + unified)",
input: "commit abc1234567890\n" +
"Author: Someone <s@example.com>\n" +
"Date: Mon Jan 1 00:00:00 2026 +0000\n" +
"\n" +
" subject\n" +
"\n" +
"diff --git a/foo.go b/foo.go\n" +
"@@ -1 +1,2 @@\n" +
" a\n+b\n",
want: true,
},
{
name: "git diff --stat",
input: " main.go | 5 ++---\n" +
" foo.go | 1 +\n" +
" 2 files changed, 3 insertions(+), 3 deletions(-)\n",
want: false,
},
{
name: "git diff --shortstat",
input: " 2 files changed, 3 insertions(+), 3 deletions(-)\n",
want: false,
},
{
name: "git diff --name-only",
input: "main.go\nfoo.go\n",
want: false,
},
{
name: "git diff --name-status",
input: "M\tmain.go\nA\tfoo.go\n",
want: false,
},
{
name: "git log (no patch)",
input: "commit abc1234567890\n" +
"Author: Someone <s@example.com>\n" +
"Date: Mon Jan 1 00:00:00 2026 +0000\n" +
"\n" +
" subject\n",
want: false,
},
{
name: "empty",
input: "",
want: false,
},
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := isUnifiedDiff(tc.input)
if got != tc.want {
t.Fatalf("isUnifiedDiff(%q) = %v, want %v", tc.name, got, tc.want)
}
})
}
}
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ func init() {
fmt.Println("No input provided, exiting")
os.Exit(0)
}

if !isUnifiedDiff(input) {
fmt.Print(input)
if !strings.HasSuffix(input, "\n") {
fmt.Println()
}
os.Exit(0)
}
}

cfg := config.Load()
Expand Down
Loading