Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
【架构优化】合并 workbranch.go 中重复的默认提交身份注入为 withFallbackIdentity (#489)
fx-kurumi5d9fa25f8afa
diff --git a/internal/gitwork/workbranch.go b/internal/gitwork/workbranch.goindex 6d4d96af..43249341 100644--- a/internal/gitwork/workbranch.go+++ b/internal/gitwork/workbranch.go@@ -46,10 +46,7 @@ func pushWorkBranch(ctx context.Context, workspace, branch, message string, requreturn "", err}if exec.Command("git", "-C", workspace, "diff", "--cached", "--quiet").Run() != nil {- args := []string{"commit", "--no-verify", "-q", "-m", message}- if email, _ := C(ctx, workspace, "config", "user.email"); strings.TrimSpace(email) == "" {- args = append([]string{"-c", "user.name=LoopForge", "-c", "user.email=loopforge@local"}, args...)- }+ args := withFallbackIdentity(ctx, workspace, []string{"commit", "--no-verify", "-q", "-m", message})if _, err := C(ctx, workspace, args...); err != nil {return "", fmt.Errorf("commit work branch: %w", err)}@@ -163,10 +160,7 @@ func pullWorkBranch(ctx context.Context, workspace, branch string, requireExisti}return remote, nil}- args := []string{"rebase", "-q", "--autostash", trackingRef}- if email, _ := C(ctx, workspace, "config", "user.email"); strings.TrimSpace(email) == "" {- args = append([]string{"-c", "user.name=LoopForge", "-c", "user.email=loopforge@local"}, args...)- }+ args := withFallbackIdentity(ctx, workspace, []string{"rebase", "-q", "--autostash", trackingRef})if _, err := C(ctx, workspace, args...); err != nil {_, _ = C(ctx, workspace, "rebase", "--abort")return "", fmt.Errorf("远程工作分支 %s 与本机工作区已分叉且无法自动变基,拒绝覆盖(请检查是否有人手动推送过该分支): %w", branch, err)@@ -195,6 +189,16 @@ func verifyOffWorkBranch(ctx context.Context, workspace, branch string, requireEreturn nil}+// withFallbackIdentity prefixes args with the LoopForge commit identity when+// the checkout has no user.email configured, so commits and rebases made on+// the work branch never fail for a missing author.+func withFallbackIdentity(ctx context.Context, workspace string, args []string) []string {+ if email, _ := C(ctx, workspace, "config", "user.email"); strings.TrimSpace(email) == "" {+ return append([]string{"-c", "user.name=LoopForge", "-c", "user.email=loopforge@local"}, args...)+ }+ return args+}+// fetchExistingWorkBranch fetches only refs/heads, never a same-named tag.// It validates the current remote even if a stale tracking ref already exists.func fetchExistingWorkBranch(ctx context.Context, workspace, branch string) (string, error) {diff --git a/internal/gitwork/workbranch_identity_test.go b/internal/gitwork/workbranch_identity_test.gonew file mode 100644index 00000000..777dd2b1--- /dev/null+++ b/internal/gitwork/workbranch_identity_test.go@@ -0,0 +1,41 @@+package gitwork++import (+ "context"+ "slices"+ "testing"+)++func TestWithFallbackIdentity(t *testing.T) {+ ctx := context.Background()+ args := []string{"commit", "-q", "-m", "msg"}++ t.Run("missing identity gets LoopForge prefix", func(t *testing.T) {+ workspace := t.TempDir()+ t.Setenv("HOME", t.TempDir())+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())+ t.Setenv("GIT_CONFIG_NOSYSTEM", "1")+ if _, err := C(ctx, workspace, "init", "-q"); err != nil {+ t.Fatal(err)+ }+ got := withFallbackIdentity(ctx, workspace, args)+ want := append([]string{"-c", "user.name=LoopForge", "-c", "user.email=loopforge@local"}, args...)+ if !slices.Equal(got, want) {+ t.Fatalf("withFallbackIdentity() = %q, want %q", got, want)+ }+ })++ t.Run("configured identity is left untouched", func(t *testing.T) {+ workspace := t.TempDir()+ if _, err := C(ctx, workspace, "init", "-q"); err != nil {+ t.Fatal(err)+ }+ if _, err := C(ctx, workspace, "config", "user.email", "[email protected]"); err != nil {+ t.Fatal(err)+ }+ got := withFallbackIdentity(ctx, workspace, args)+ if !slices.Equal(got, args) {+ t.Fatalf("withFallbackIdentity() = %q, want %q", got, args)+ }+ })+}