From f36fb1c24c5078416687d7ae5d20d6dab393fdcf Mon Sep 17 00:00:00 2001 From: Simon Harrer Date: Sat, 24 Aug 2024 12:21:28 +0200 Subject: [PATCH] Add --join (fixes #437) Co-authored-by: Michel Grootjans Co-authored-by: Tom Scholz Co-authored-by: Bertram Vogel Co-authored-by: Niklas Rueber Co-authored-by: Mirjam Aulbach Co-authored-by: Benjamin Hugot Co-authored-by: Alexander Klump --- CHANGELOG.md | 4 ++++ configuration/configuration.go | 5 ++++- configuration/configuration_test.go | 20 ++++++++++++++++++++ help/help.go | 1 + mob.go | 5 +++++ mob_test.go | 8 ++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee7374e..f592121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 5.1.0 +- Feature: Adds new flag `--join` for `mob start` to join an existing session + `mob start --join` (#437) + # 5.0.1 - Fix: The configuration option `MOB_SKIP_CI_PUSH_OPTION_ENABLED` now works correctly diff --git a/configuration/configuration.go b/configuration/configuration.go index 4c10f79..2533b1c 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -29,7 +29,8 @@ type Configuration struct { NotifyMessage string // override with MOB_NOTIFY_MESSAGE NextStay bool // override with MOB_NEXT_STAY StartIncludeUncommittedChanges bool - StartCreate bool // override with MOB_START_CREATE variable + StartCreate bool // override with MOB_START_CREATE variable + StartJoin bool StashName string // override with MOB_STASH_NAME WipBranchQualifier string // override with MOB_WIP_BRANCH_QUALIFIER WipBranchQualifierSeparator string // override with MOB_WIP_BRANCH_QUALIFIER_SEPARATOR @@ -143,6 +144,8 @@ func ParseArgs(args []string, configuration Configuration) (command string, para newConfiguration.DoneSquash = SquashWip case "--create": newConfiguration.StartCreate = true + case "--join", "-j": + newConfiguration.StartJoin = true case "--delete-remote-wip-branch": newConfiguration.ResetDeleteRemoteWipBranch = true case "--room": diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index 844aec0..683f997 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -39,6 +39,26 @@ func TestParseArgsStartCreate(t *testing.T) { test.Equals(t, true, configuration.StartCreate) } +func TestParseArgsStartJoin(t *testing.T) { + configuration := GetDefaultConfiguration() + + command, parameters, configuration := ParseArgs([]string{"mob", "start", "--join"}, configuration) + + test.Equals(t, "start", command) + test.Equals(t, "", strings.Join(parameters, "")) + test.Equals(t, true, configuration.StartJoin) +} + +func TestParseArgsStartJoinShort(t *testing.T) { + configuration := GetDefaultConfiguration() + + command, parameters, configuration := ParseArgs([]string{"mob", "start", "-j"}, configuration) + + test.Equals(t, "start", command) + test.Equals(t, "", strings.Join(parameters, "")) + test.Equals(t, true, configuration.StartJoin) +} + func TestParseArgsDoneNoSquash(t *testing.T) { configuration := GetDefaultConfiguration() test.Equals(t, Squash, configuration.DoneSquash) diff --git a/help/help.go b/help/help.go index 2b6c049..0a6c8dc 100644 --- a/help/help.go +++ b/help/help.go @@ -20,6 +20,7 @@ Basic Commands with Options: [--include-uncommitted-changes|-i] Move uncommitted changes to wip branch [--branch|-b ] Set wip branch to 'mob/` + configuration.WipBranchQualifierSeparator + `' [--create] Create the remote branch + [--join|-j] Join existing wip branch [--room ] Set room name for timer.mob.sh once next [--stay|-s] Stay on wip branch (default) diff --git a/mob.go b/mob.go index 3834614..7adc4f5 100644 --- a/mob.go +++ b/mob.go @@ -538,6 +538,11 @@ func start(configuration config.Configuration) error { git("fetch", configuration.RemoteName, "--prune") currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration) + if !currentWipBranch.hasRemoteBranch(configuration) && configuration.StartJoin { + say.Error("Remote wip branch " + currentWipBranch.remote(configuration).String() + " is missing") + return errors.New("remote wip branch is missing") + } + if !currentBaseBranch.hasRemoteBranch(configuration) && !configuration.StartCreate { say.Error("Remote branch " + currentBaseBranch.remote(configuration).String() + " is missing") say.Fix("To start and create the remote branch", "mob start --create") diff --git a/mob_test.go b/mob_test.go index 0252dd6..8a52992 100644 --- a/mob_test.go +++ b/mob_test.go @@ -390,6 +390,14 @@ func TestStartWithPushDefaultTracking(t *testing.T) { assertMobSessionBranches(t, configuration, "mob-session") } +func TestStartWithJoiningNonExistingSession(t *testing.T) { + _, configuration := setup(t) + assertOnBranch(t, "master") + configuration.StartJoin = true + start(configuration) + assertOnBranch(t, "master") +} + func TestReset(t *testing.T) { output, configuration := setup(t)