()
| 587 | } |
| 588 | |
| 589 | func (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 | |
| 640 | func (a *App) quitCmd() error { |
| 641 | fmt.Println("Bye.") |
nothing calls this directly
no test coverage detected