Documentation
¶
Overview ¶
Package commit provides the command to commit changes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var CommitCmd = &cobra.Command{ Use: "commit -m <message>", Example: ` contextvibes factory commit -m "feat(auth): Implement OTP login"`, Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _ []string) error { presenter := ui.NewPresenter(cmd.OutOrStdout(), cmd.ErrOrStderr()) ctx := cmd.Context() if strings.TrimSpace(commitMessageFlag) == "" { return errors.New("commit message is required via -m flag") } validationRule := globals.LoadedAppConfig.Validation.CommitMessage validationEnabled := validationRule.Enable == nil || *validationRule.Enable if validationEnabled { pattern := validationRule.Pattern if pattern == "" { pattern = config.DefaultCommitMessagePattern } re, err := regexp.Compile(pattern) if err != nil { return errors.New("invalid commit message validation regex") } if !re.MatchString(commitMessageFlag) { presenter.Error("Invalid commit message format.") presenter.Advice("Message must match pattern: %s", pattern) return errors.New("invalid commit message format") } } gitCfg := git.GitClientConfig{ Logger: globals.AppLogger, DefaultRemoteName: globals.LoadedAppConfig.Git.DefaultRemote, DefaultMainBranchName: globals.LoadedAppConfig.Git.DefaultMainBranch, Executor: globals.ExecClient.UnderlyingExecutor(), } client, err := git.NewClient(ctx, ".", gitCfg) if err != nil { return fmt.Errorf("failed to initialize git client: %w", err) } err = client.AddAll(ctx) if err != nil { return fmt.Errorf("failed to stage changes: %w", err) } hasStaged, err := client.HasStagedChanges(ctx) if err != nil { return fmt.Errorf("failed to check staged changes: %w", err) } if !hasStaged { presenter.Info("No changes were staged for commit.") return nil } currentBranch, _ := client.GetCurrentBranchName(ctx) statusOutput, _, _ := client.GetStatusShort(ctx) presenter.InfoPrefixOnly() fmt.Fprintf(presenter.Out(), " Branch: %s\n", currentBranch) fmt.Fprintf(presenter.Out(), " Commit Message: %s\n", commitMessageFlag) fmt.Fprintf(presenter.Out(), " Staged Changes:\n%s\n", statusOutput) if !globals.AssumeYes { confirmed, err := presenter.PromptForConfirmation("Proceed?") if err != nil || !confirmed { return errors.New("commit aborted") } } return client.Commit(ctx, commitMessageFlag) }, }
CommitCmd represents the commit command.
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.