Skip to content

Commit

Permalink
Add --join (fixes #437)
Browse files Browse the repository at this point in the history
Co-authored-by: Michel Grootjans <[email protected]>
Co-authored-by: Tom Scholz <[email protected]>
Co-authored-by: Bertram Vogel <[email protected]>
Co-authored-by: Niklas Rueber <[email protected]>
Co-authored-by: Mirjam Aulbach <[email protected]>
Co-authored-by: Benjamin Hugot <[email protected]>
Co-authored-by: Alexander Klump <[email protected]>
  • Loading branch information
8 people committed Aug 24, 2024
1 parent e4ded45 commit f36fb1c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 4 additions & 1 deletion configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand Down
20 changes: 20 additions & 0 deletions configuration/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions help/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Basic Commands with Options:
[--include-uncommitted-changes|-i] Move uncommitted changes to wip branch
[--branch|-b <branch-postfix>] Set wip branch to 'mob/<base-branch>` + configuration.WipBranchQualifierSeparator + `<branch-postfix>'
[--create] Create the remote branch
[--join|-j] Join existing wip branch
[--room <room-name>] Set room name for timer.mob.sh once
next
[--stay|-s] Stay on wip branch (default)
Expand Down
5 changes: 5 additions & 0 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 8 additions & 0 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit f36fb1c

Please sign in to comment.