Merge pull request #827 from johnmanjiro13/show-current-branch

add --show-current option to dolt branch
This commit is contained in:
Zach Musgrave
2020-08-11 12:53:05 -07:00
committed by GitHub
+9
View File
@@ -68,6 +68,7 @@ const (
verboseFlag = "verbose"
allFlag = "all"
remoteFlag = "remote"
showCurrentFlag = "show-current"
)
type BranchCmd struct{}
@@ -100,6 +101,7 @@ func (cmd BranchCmd) createArgParser() *argparser.ArgParser {
ap.SupportsFlag(verboseFlag, "v", "When in list mode, show the hash and commit subject line for each head")
ap.SupportsFlag(allFlag, "a", "When in list mode, shows remote tracked branches")
ap.SupportsFlag(remoteFlag, "r", "When in list mode, show only remote tracked branches. When with -d, delete a remote tracking branch.")
ap.SupportsFlag(showCurrentFlag, "", "Print the name of the current branch")
return ap
}
@@ -125,6 +127,8 @@ func (cmd BranchCmd) Exec(ctx context.Context, commandStr string, args []string,
return deleteForceBranches(ctx, dEnv, apr, usage)
case apr.Contains(listFlag):
return printBranches(ctx, dEnv, apr, usage)
case apr.Contains(showCurrentFlag):
return printCurrentBranch(dEnv)
case apr.NArg() > 0:
return createBranch(ctx, dEnv, apr, usage)
default:
@@ -202,6 +206,11 @@ func printBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
return 0
}
func printCurrentBranch(dEnv *env.DoltEnv) int {
cli.Println(dEnv.RepoState.CWBHeadRef().GetPath())
return 0
}
func moveBranch(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgParseResults, usage cli.UsagePrinter) int {
if apr.NArg() != 2 {
usage()