gitflow

package
v0.0.0-...-e1d77ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 5, 2019 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MasterBranchKey  = "gitflow.branch.master"
	DevBranchKey     = "gitflow.branch.develop"
	FeaturePrefixKey = "gitflow.prefix.feature"
	ReleasePrefixKey = "gitflow.prefix.release"
	HotfixPrefixKey  = "gitflow.prefix.hotfix"
	SupportPrefixKey = "gitflow.prefix.support"
	VersiontagKey    = "gitflow.prefix.versiontag"
)

Variables

View Source
var (
	DefaultBranchMaster      = Option{MasterBranchKey, "master"}
	DefaultBranchDevelopment = Option{DevBranchKey, "dev"}
	DefaultPrefixFeature     = Option{FeaturePrefixKey, "feature"}
	DefaultPrefixRelease     = Option{ReleasePrefixKey, "release"}
	DefaultPrefixHotfix      = Option{HotfixPrefixKey, "hotfix"}
	DefaultPrefixSupport     = Option{SupportPrefixKey, "support"}
	DefaultPrefixVersiontag  = Option{VersiontagKey, "v"}
)
View Source
var (
	DefaultMasterSuggestions = []string{
		"master", "prod", "production", "main",
	}
	DefaultDevSuggestions = []string{
		"develop", "dev", "development", "master",
	}
	DefaultBranches = []Option{
		DefaultBranchDevelopment,
		DefaultBranchMaster,
	}
	DefaultPrefixes = []Option{
		DefaultPrefixFeature,
		DefaultPrefixHotfix,
		DefaultPrefixRelease,
		DefaultPrefixSupport,
	}
	DefaultTags = []Option{
		DefaultPrefixVersiontag,
	}
)
View Source
var (
	ErrAlreadyInitialized                  = errors.New("Gitflow is already initialized; use -f to force reinit")
	ErrUnstagedChanges                     = errors.New("There are unstaged changes in your working directory")
	ErrIndexUncommitted                    = errors.New("There are uncommitted changes in your index")
	ErrHeadlessRepo                        = errors.New("Unable to initialize in a bare repo")
	ErrProdDoesntExist                     = errors.New("The branch you have selected does not exist")
	ErrUnableToConfigure                   = errors.New("Unable to configure the repo")
	ErrProductionMustDifferFromDevelopment = errors.New("The production branch must differ from the development branch")
	ErrCannotDetermineCurrentBranch        = errors.New("Cannot determine the current branch")
)
View Source
var (
	// https://stackoverflow.com/a/12093994
	// https://regex101.com/r/E2TCqU/3/tests
	GitReferenceRestrictionsPattern = regexp.MustCompile(`/\.|\.\.|\/\/+|[\000-\037\177 \\~^:?*[]+|(.(lock)?|/)$|^[^/]+$`)
	GitReferenceNotAt               = regexp.MustCompile(`^@$`)
	GitReferenceNoLeadingDots       = regexp.MustCompile(`^\.`)
	GitReferenceNoAtBracket         = regexp.MustCompile(`@\{`)
	GitReferenceNoSlashDot          = regexp.MustCompile(`/\.`)
	GitReferenceNoMultipleDot       = regexp.MustCompile(`\.\.+`)
	GitReferenceNoMultipleSlash     = regexp.MustCompile(`//+`)
	GitReferenceNoSpecialChars      = regexp.MustCompile(`[\000-\037\177 \~^:?*[]+`)
	GitReferenceNoDotLockEnd        = regexp.MustCompile(`\.(lock)?$`)
	GitReferenceNoSlashEnd          = regexp.MustCompile(`/$`)
	GitReferenceMustContainSlash    = regexp.MustCompile(`^[^/]+$`)
)
View Source
var (
	GitBranchPattern        = regexp.MustCompile(`(?m)^.*?(\w.*)\s*?`)
	GitCurrentBranchPattern = regexp.MustCompile(`(?m)^\s*\*\s*?(\w.*)\s*?$`)
)
View Source
var Defaults bool
View Source
var FeatureCmd = &cobra.Command{
	Use:              "feature",
	TraverseChildren: true,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		Repo.Prefix = GitConfig.GetWithDefault(FeaturePrefixKey, DefaultPrefixFeature.Value)
		Repo.HumanPrefix = strings.TrimSuffix(Repo.Prefix, "/")
	},
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Println("wat")
	},
}
View Source
var FeatureListAction = &cobra.Command{
	Use:              "list",
	TraverseChildren: true,
	Run: func(cmd *cobra.Command, args []string) {
		branches := PassthroughThroughPrefixedBranchesWithErrorMessage(false)
		logrus.Trace("message")
		var width int
		if 0 < VerbosityFlagValue {
			for _, branch := range branches {
				width = MaxInt(width, len(branch))
			}
			width += 3
		}
		for _, branch := range branches {
			branchFullname := fmt.Sprintf("%s%s", Repo.Prefix, branch)
			if Repo.CurrentBranch() == branchFullname {
				fmt.Printf("* ")
			} else {
				fmt.Printf("  ")
			}
			if 0 < VerbosityFlagValue {
				devBranch := GitConfig.Get(DevBranchKey)
				base := MergeBase(branchFullname, devBranch)
				devSha := RevParseArgs(devBranch)
				branchSha := RevParseArgs(branchFullname)
				fmt.Printf(fmt.Sprintf("%%-%ds", width), branch)
				switch {
				case branchSha == devSha:
					fmt.Printf("(sha is identical to dev)")
				case base == branchSha:
					fmt.Printf("(may ff to dev)")
				case base == devSha:
					fmt.Printf("(identical to latest dev")
				default:
					fmt.Printf("may be rebased")
				}

			} else {
				fmt.Printf("%s", branch)
			}
			fmt.Println()
		}
	},
}
View Source
var Force bool
View Source
var (
	GitConfig = &GitConfigHelper{}
)
View Source
var InitCmd = &cobra.Command{
	Use:              "init",
	TraverseChildren: true,
	Run: func(cmd *cobra.Command, args []string) {
		InitProcedural()
	},
}
View Source
var PackageCmd = &cobra.Command{
	Use:              "git-flow",
	TraverseChildren: true,
	Version:          PackageVersion,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		BootstrapLogger(VerbosityFlagValue)
	},
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
	},
}
View Source
var PackageVersion = "0.0.0"
View Source
var (
	Repo = &Repository{}
)
View Source
var VerbosityFlagValue int

Functions

func AreMasterAndDevTheSameValue

func AreMasterAndDevTheSameValue() bool

func ArePrefixesConfigured

func ArePrefixesConfigured() bool

func BootstrapLogger

func BootstrapLogger(verbosityLevel int)

func CheckErr

func CheckErr(err error)

func CheckExistence

func CheckExistence(branchName string, newName string)

func GetKeyFromRef

func GetKeyFromRef(branch string) string

func GetValueFromRef

func GetValueFromRef(branch string) string

func InitProcedural

func InitProcedural()

func IsBranchConfigured

func IsBranchConfigured(name string) bool

func IsDevConfigured

func IsDevConfigured() bool

func IsGitFlowInitialized

func IsGitFlowInitialized() bool

func IsMasterConfigured

func IsMasterConfigured() bool

func IsWorkingTreeClean

func IsWorkingTreeClean() bool

func MaxInt

func MaxInt(x int, y int) int

func ParsePrefix

func ParsePrefix(prefixKey string, defaultValue string) error

func PassthroughThroughPrefixedBranchesWithErrorMessage

func PassthroughThroughPrefixedBranchesWithErrorMessage(remote bool) []string

func PrefixValidator

func PrefixValidator(refName string) error

func PromptForInput

func PromptForInput(inputType ValidationTarget, promptMessage string, defaultValue string) string

func PromptMessageFromBranch

func PromptMessageFromBranch(branchName string, suggestion string) string

func SharedPrep

func SharedPrep(branchName string) error

func ValidateBranchName

func ValidateBranchName(refName string) error

func ValidatePrefixName

func ValidatePrefixName(refName string) error

func ValidateRefName

func ValidateRefName(refName string) error

func ValidateTagPrefix

func ValidateTagPrefix(tagPrefix string) error

Types

type CommandResponse

type CommandResponse struct {
	// contains filtered or unexported fields
}

func BranchNoColor

func BranchNoColor(remote bool) CommandResponse

func ExecCmd

func ExecCmd(args ...string) CommandResponse

func GitInit

func GitInit() CommandResponse

func MergeBase

func MergeBase(firstBranch string, secondBranch string) CommandResponse

func RevParseAbbrevRefHead

func RevParseAbbrevRefHead() CommandResponse

func RevParseArgs

func RevParseArgs(arguments ...string) CommandResponse

func RevParseGitDir

func RevParseGitDir() CommandResponse

func RevParseQuietVerifyHead

func RevParseQuietVerifyHead() CommandResponse

func (CommandResponse) Bool

func (c CommandResponse) Bool() bool

func (CommandResponse) String

func (c CommandResponse) String() string

func (CommandResponse) Succeeded

func (c CommandResponse) Succeeded() bool

type GitConfigHelper

type GitConfigHelper struct {
}

func (*GitConfigHelper) Get

func (g *GitConfigHelper) Get(key string) string

func (*GitConfigHelper) GetWithDefault

func (g *GitConfigHelper) GetWithDefault(key string, defaultValue string) string

func (*GitConfigHelper) Write

func (g *GitConfigHelper) Write(key string, value string) CommandResponse

type Option

type Option struct {
	Key   string
	Value string
}

type Repository

type Repository struct {
	Prefix      string
	HumanPrefix string
}

func (*Repository) CurrentBranch

func (r *Repository) CurrentBranch() string

func (*Repository) HasLocalBranch

func (r *Repository) HasLocalBranch(needle string) bool

func (*Repository) HasRemoteBranch

func (r *Repository) HasRemoteBranch(needle string) bool

func (*Repository) LocalBranches

func (r *Repository) LocalBranches() []string

func (*Repository) PickGoodDevSuggestion

func (r *Repository) PickGoodDevSuggestion() string

func (*Repository) PickGoodMasterSuggestion

func (r *Repository) PickGoodMasterSuggestion() string

func (*Repository) PickGoodSuggestion

func (r *Repository) PickGoodSuggestion(branchName string) string

func (*Repository) RemoteBranches

func (r *Repository) RemoteBranches() []string

func (*Repository) SpecificBranches

func (r *Repository) SpecificBranches(remote bool) []string

func (*Repository) SpecificPrefixBranches

func (r *Repository) SpecificPrefixBranches(remote bool) []string

type ValidationTarget

type ValidationTarget int
const (
	RefNameValidation ValidationTarget = iota
	PrefixNameValidation
	TagNameValidation
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL