[mike@mwxm4]

This commit is contained in:
2026-08-11 11:40:32 +02:00
parent 113527f220
commit 39f5b48d94
14 changed files with 719 additions and 39 deletions
+21 -7
View File
@@ -43,13 +43,23 @@ type Config struct {
// `remote.<name>.<field>` block. Name doubles as the git remote name created in
// the repository, so several targets can coexist side by side.
type RemoteTarget struct {
Name string
URL string
Key string
Type string // "gitea"|"github"|"gitlab" (auto-detected when empty)
Vis string // "private" (default) | "public"
Name string
URL string
Key string
Type string // "gitea"|"github"|"gitlab" (auto-detected when empty)
Vis string // "private" (default) | "public"
Active string // falsy -> taken along only when named (default: on)
}
// isActive reports whether the target takes part in a command that was given no
// target of its own — `pushremote`, `release`, an auto-mirroring `push`. An
// inactive one is not disabled, it is merely off the automatic path: naming it
// (`pushremote @gitea`) uses it as it always did.
//
// Unset means active. The setting exists to take a server *out* of the default
// set, so a configuration written before it existed must keep behaving.
func (t RemoteTarget) isActive() bool { return !falsy(t.Active) }
// legacyRemoteName is the target the pre-4.1 flat remoteurl/remotekey settings
// are migrated to. It matches the git remote those versions created, so a
// converted configuration keeps pushing to the same place.
@@ -441,7 +451,7 @@ func foldLegacyRemoteKeys(m map[string]string) map[string]string {
}
// remoteFieldRe matches a named mirror target setting: remote.<name>.<field>.
var remoteFieldRe = regexp.MustCompile(`^remote\.([a-z0-9_.-]+)\.(url|key|type|visibility)$`)
var remoteFieldRe = regexp.MustCompile(`^remote\.([a-z0-9_.-]+)\.(url|key|type|visibility|active)$`)
// applyRemoteTargets merges `remote.<name>.<field>` settings into c.Remotes.
// An already known target is updated field by field, so a project .mgshrc can
@@ -472,6 +482,8 @@ func applyRemoteTargets(c *Config, m map[string]string) {
t.Type = v
case "visibility":
t.Vis = v
case "active":
t.Active = v
}
}
}
@@ -510,7 +522,7 @@ func applyEnv(c *Config) {
}
// remoteFields are the settings a mirror target is made of.
var remoteFields = []string{"url", "key", "type", "visibility"}
var remoteFields = []string{"url", "key", "type", "visibility", "active"}
// applyRemoteEnv reads MGSH_REMOTE_<NAME>_<FIELD>, the environment spelling of
// a remote.<name>.<field> setting — MGSH_REMOTE_GITLAB_KEY for
@@ -552,6 +564,8 @@ func applyRemoteEnv(c *Config) {
t.Type = value
case "visibility":
t.Vis = value
case "active":
t.Active = value
}
}
}