MCPcopy Create free account
hub / github.com/cwarden/git-add--interactive / diffCmd

Method diffCmd

internal/ui/app.go:589–638  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

587}
588
589func (a *App) diffCmd() error {
590 files, err := a.repo.ListModified("index-only")
591 if err != nil {
592 return err
593 }
594
595 var nonBinaryFiles []interface{}
596 for _, file := range files {
597 if !file.Binary {
598 nonBinaryFiles = append(nonBinaryFiles, file)
599 }
600 }
601
602 if len(nonBinaryFiles) == 0 {
603 return nil
604 }
605
606 fmt.Printf(a.colored(a.colors.HeaderColor, "%12s %12s %s\n"), "staged", "unstaged", "path")
607 chosen, err := a.listAndChoose("Review diff", nonBinaryFiles, false, true)
608 if err != nil {
609 return err
610 }
611
612 if len(chosen) > 0 {
613 var paths []string
614 for _, item := range chosen {
615 file := item.(git.FileStatus)
616 paths = append(paths, file.Path)
617 }
618
619 reference := "HEAD"
620 if a.repo.IsInitialCommit() {
621 emptyTree, err := a.repo.GetEmptyTree()
622 if err != nil {
623 return err
624 }
625 reference = emptyTree
626 }
627
628 args := append([]string{"diff", "-p", "--cached", reference, "--"}, paths...)
629 output, err := a.repo.RunCommand(args...)
630 if err != nil {
631 return err
632 }
633
634 fmt.Print(string(output))
635 }
636
637 return nil
638}
639
640func (a *App) quitCmd() error {
641 fmt.Println("Bye.")

Callers

nothing calls this directly

Calls 6

coloredMethod · 0.95
listAndChooseMethod · 0.95
ListModifiedMethod · 0.80
IsInitialCommitMethod · 0.80
GetEmptyTreeMethod · 0.80
RunCommandMethod · 0.80

Tested by

no test coverage detected