diff --git a/internal/git/service.go b/internal/git/service.go index 8163633..6acf1a9 100644 --- a/internal/git/service.go +++ b/internal/git/service.go @@ -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 @@ -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 diff --git a/main.go b/main.go index 16806ed..edea5d4 100644 --- a/main.go +++ b/main.go @@ -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)