diff

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL