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
28 changes: 20 additions & 8 deletions internal/git/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import (
"strings"
)

type Service struct{}
type Service struct{
diffTarget string
}

func NewService() *Service {
return &Service{}
}

// SetDiffTarget sets the target for git diff (e.g., "main", "HEAD~1", commit hash)
func (s *Service) SetDiffTarget(target string) {
s.diffTarget = target
}

// GetDiff retrieves the git diff with optional context lines (default: 3)
func (s *Service) GetDiff(diffType DiffType, contextLines ...int) (*DiffResult, error) {
context := 3
Expand All @@ -22,13 +29,18 @@ func (s *Service) GetDiff(diffType DiffType, contextLines ...int) (*DiffResult,

var args []string

switch diffType {
case DiffTypeStaged:
args = []string{"diff", "--cached", "--no-color", "--no-ext-diff"}
case DiffTypeUnstaged:
args = []string{"diff", "--no-color", "--no-ext-diff"}
default:
args = []string{"diff", "HEAD", "--no-color", "--no-ext-diff"}
// If a diff target is specified, use it instead of the default behavior
if s.diffTarget != "" {
args = []string{"diff", s.diffTarget, "--no-color", "--no-ext-diff"}
} else {
switch diffType {
case DiffTypeStaged:
args = []string{"diff", "--cached", "--no-color", "--no-ext-diff"}
case DiffTypeUnstaged:
args = []string{"diff", "--no-color", "--no-ext-diff"}
default:
args = []string{"diff", "HEAD", "--no-color", "--no-ext-diff"}
}
}

// Add context parameter
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,16 @@ func main() {
os.Setenv("VIBEDIFF_DEBUG", "true")
}

// Get diff target from positional argument
var target string
if flag.NArg() > 0 {
target = flag.Arg(0)
}

reviewStore := review.NewStore()

gitService := git.NewService()
gitService.SetDiffTarget(target)
handler := handlers.NewHandler(gitService, reviewStore)
handler.SetFormat(*format)

Expand Down