1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-22 07:43:03 +00:00

prepare-release: improve handling of release from non-master branch

The final push command now states the correct branch to push.
This commit is contained in:
Michael Eischer 2024-11-01 16:22:32 +01:00
parent ded9fc7690
commit bcf5fbe498

View file

@ -31,7 +31,7 @@ var opts = struct {
var versionRegex = regexp.MustCompile(`^\d+\.\d+\.\d+$`) var versionRegex = regexp.MustCompile(`^\d+\.\d+\.\d+$`)
func init() { func init() {
pflag.BoolVar(&opts.IgnoreBranchName, "ignore-branch-name", false, "allow releasing from other branches as 'master'") pflag.BoolVar(&opts.IgnoreBranchName, "ignore-branch-name", false, "allow releasing from other branches than 'master'")
pflag.BoolVar(&opts.IgnoreUncommittedChanges, "ignore-uncommitted-changes", false, "allow uncommitted changes") pflag.BoolVar(&opts.IgnoreUncommittedChanges, "ignore-uncommitted-changes", false, "allow uncommitted changes")
pflag.BoolVar(&opts.IgnoreChangelogVersion, "ignore-changelog-version", false, "ignore missing entry in CHANGELOG.md") pflag.BoolVar(&opts.IgnoreChangelogVersion, "ignore-changelog-version", false, "ignore missing entry in CHANGELOG.md")
pflag.BoolVar(&opts.IgnoreChangelogReleaseDate, "ignore-changelog-release-date", false, "ignore missing subdir with date in changelog/") pflag.BoolVar(&opts.IgnoreChangelogReleaseDate, "ignore-changelog-release-date", false, "ignore missing subdir with date in changelog/")
@ -128,17 +128,22 @@ func uncommittedChanges(dirs ...string) string {
return string(changes) return string(changes)
} }
func preCheckBranchMaster() { func getBranchName() string {
if opts.IgnoreBranchName {
return
}
branch, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output() branch, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()
if err != nil { if err != nil {
die("error running 'git': %v", err) die("error running 'git': %v", err)
} }
if strings.TrimSpace(string(branch)) != "master" { return strings.TrimSpace(string(branch))
}
func preCheckBranchMaster() {
if opts.IgnoreBranchName {
return
}
branch := getBranchName()
if branch != "master" {
die("wrong branch: %s", branch) die("wrong branch: %s", branch)
} }
} }
@ -449,6 +454,7 @@ func main() {
} }
preCheckBranchMaster() preCheckBranchMaster()
branch := getBranchName()
preCheckUncommittedChanges() preCheckUncommittedChanges()
preCheckVersionExists() preCheckVersionExists()
preCheckDockerBuilderGoVersion() preCheckDockerBuilderGoVersion()
@ -485,5 +491,5 @@ func main() {
msg("done, output dir is %v", opts.OutputDir) msg("done, output dir is %v", opts.OutputDir)
msg("now run:\n\ngit push --tags origin master\n%s\n\nrm -rf %q", dockerCmds, sourceDir) msg("now run:\n\ngit push --tags origin %s\n%s\n\nrm -rf %q", branch, dockerCmds, sourceDir)
} }