【架构优化】合并 gitwork/workbranch.go 中 push/pull 重复的默认提交身份注入为 withFallbackIdentity

Ouverte
#488 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@fx-kurumi y travaille déjà.

Depuis le 13/11/2026.

  • #489 par @fx-kurumi — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
40/100
Type d'issue
Refactorisation
Clarté
Clairement spécifiée
Activité
Active
Stack technique
go
Domaine
devtools

Piste de recherche

Both copies live in internal/gitwork/workbranch.go: one in pushWorkBranch before the commit args are built, one in pullWorkBranch before the rebase args. Add package-level withFallbackIdentity(ctx, workspace, args) beside them and swap both call sites without changing argument order. Add a test file using a real temp repository for the configured and unconfigured cases, then run gofmt, go vet ./internal/gitwork/ and go test ./internal/gitwork/. PR #489 already touches this file, so check it before starting.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

现状问题

internal/gitwork/workbranch.go 里有两处一模一样的“仓库没配 user.email 时补默认提交身份”的代码:

  • pushWorkBranch:拼 commit 参数前
  • pullWorkBranch:拼 rebase 参数前
if email, _ := C(ctx, workspace, "config", "user.email"); strings.TrimSpace(email) == "" {
	args = append([]string{"-c", "user.name=LoopForge", "-c", "user.email=loopforge@local"}, args...)
}

两份代码都写死了 LoopForge / loopforge@local,以后改了一处容易漏掉另一处。

重构方案

在 workbranch.go 里新增包内函数 withFallbackIdentity(ctx, workspace, args) []string:仓库没配 user.email 时,在 args 前加上 -c user.name=LoopForge -c user.email=loopforge@local,配了就原样返回。两处调用改用这个函数,其余逻辑不动。

影响范围

  • 只改 internal/gitwork/workbranch.go 一个文件,另加一个测试文件;
  • 不改导出函数,不改 git 命令参数和执行顺序,行为不变;
  • 和 PR #452(同文件、verifyOffWorkBranch)改的不是同一段代码。

验证方式

  • 新增单元测试:用真实临时仓库验证“没配身份时加前缀”和“已配身份时原样返回”两种情况;
  • gofmt、go vet ./internal/gitwork/、go test ./internal/gitwork/ 全部通过。
Langage dominant
Go
Étoiles
141
Forks
28
Merge moyen
1 j 15 h
PR mergées (30 j)
113

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de Tencent/LoopForge

Toutes les issues de Tencent/LoopForge

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.