Documentation
¶
Overview ¶
Package diff provides the command to show git diffs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DiffCmd = &cobra.Command{ Use: "diff", Example: ` contextvibes factory diff`, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr()) ctx := cmd.Context() presenter.Summary("Generating Git diff summary for %s.", fixedDiffOutputFile) workDir, err := os.Getwd() if err != nil { return fmt.Errorf("failed to get working directory: %w", err) } gitCfg := git.GitClientConfig{ Logger: globals.AppLogger, Executor: globals.ExecClient.UnderlyingExecutor(), } client, err := git.NewClient(ctx, workDir, gitCfg) if err != nil { presenter.Error("Failed git init: %v", err) return fmt.Errorf("failed to initialize git client: %w", err) } var outputBuffer bytes.Buffer var hasChanges bool stagedOut, _, stagedErr := client.GetDiffCached(ctx) if stagedErr != nil { return stagedErr } if strings.TrimSpace(stagedOut) != "" { hasChanges = true tools.AppendSectionHeader(&outputBuffer, "Staged Changes") tools.AppendFencedCodeBlock(&outputBuffer, stagedOut, "diff") } unstagedOut, _, unstagedErr := client.GetDiffUnstaged(ctx) if unstagedErr != nil { return unstagedErr } if strings.TrimSpace(unstagedOut) != "" { hasChanges = true tools.AppendSectionHeader(&outputBuffer, "Unstaged Changes") tools.AppendFencedCodeBlock(&outputBuffer, unstagedOut, "diff") } untrackedOut, _, untrackedErr := client.ListUntrackedFiles(ctx) if untrackedErr != nil { return untrackedErr } if strings.TrimSpace(untrackedOut) != "" { hasChanges = true tools.AppendSectionHeader(&outputBuffer, "Untracked Files") tools.AppendFencedCodeBlock(&outputBuffer, untrackedOut, "") } presenter.Newline() if !hasChanges { presenter.Info("No pending changes found.") } else { errWrite := tools.WriteBufferToFile(fixedDiffOutputFile, &outputBuffer) if errWrite != nil { return errWrite } } return nil }, }
DiffCmd represents the diff command.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.