Skip to content

feat: added ignore-detached-head command line flag #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/common_opts/opts.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package common_opts

var Workdir = ""
var IgnoreDetachedHead = false
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func main() {
func init() {
rootCmd.PersistentFlags().StringVarP(&common_opts.Workdir, "workdir", "w", ".", "Working directory to use")
rootCmd.PersistentFlags().String("log-level", logger.DEFAULT_LOG_LEVEL.String(), "panic | fatal | error | warn | info | debug | trace")
rootCmd.PersistentFlags().BoolVar(&common_opts.IgnoreDetachedHead, "ignore-detached-head", false, "Specifies to ignore detached head errors")
}

func processLogLevelFlag(cmd *cobra.Command) {
Expand Down
6 changes: 4 additions & 2 deletions cli/next/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ var Command = cobra.Command{
Run: func(cmd *cobra.Command, args []string) {

nextVersion, err := next.Next(next.NextOptions{
Workdir: common_opts.Workdir,
Stable: stable,
Workdir: common_opts.Workdir,
IgnoreDetachedHead: common_opts.IgnoreDetachedHead,
Stable: stable,
MajorVersionFilter: majorVersionFilter,
PreReleaseOptions: semver.PreReleaseOptions{
Label: preReleaseTag,
Expand All @@ -44,4 +45,5 @@ func init() {
Command.Flags().IntVar(&majorVersionFilter, "major-version", -1, "Only consider tags with this specific major version.")
Command.Flags().StringVar(&preReleaseTag, "pre-release-tag", "", "Specifies a pre-release tag which should be appended to the next version.")
Command.Flags().BoolVar(&appendPreReleaseCounter, "pre-release-counter", false, "Specifies if there should be a counter appended to the pre-release tag. It will increase automatically depending on previous pre-releases for the same version.")

}
3 changes: 2 additions & 1 deletion next/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type NextOptions struct {
Stable bool
MajorVersionFilter int
PreReleaseOptions semver.PreReleaseOptions
IgnoreDetachedHead bool
}

func Next(options NextOptions) (*semver.Version, error) {
Expand All @@ -41,7 +42,7 @@ func Next(options NextOptions) (*semver.Version, error) {
return nil, errors.WithMessage(err, "Error while trying to find latest release version tag")
}

if latestReleaseVersionTag != nil {
if latestReleaseVersionTag != nil && !options.IgnoreDetachedHead {
if err = git_utils.AssertRefIsReachable(repo, latestReleaseVersionTag, headRef, "Latest tag is not on HEAD. This is necessary as the next version is calculated based on the commits since the latest version tag."); err != nil {
return nil, err
}
Expand Down