Skip to content

Commit f36fb1c

Browse files
simonharrermichelgrootjansqotsa2002bertoverflowBadWinniePooh
committed
Add --join (fixes #437)
Co-authored-by: Michel Grootjans <michel.grootjans@gmail.com> Co-authored-by: Tom Scholz <tom.scholz@gmx.de> Co-authored-by: Bertram Vogel <bertoverflow@posteo.de> Co-authored-by: Niklas Rueber <niklas@rueber.cloud> Co-authored-by: Mirjam Aulbach <me@programmiri.rocks> Co-authored-by: Benjamin Hugot <bhugot@gmail.com> Co-authored-by: Alexander Klump <alexander.klump@tngtech.com>
1 parent e4ded45 commit f36fb1c

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 5.1.0
2+
- Feature: Adds new flag `--join` for `mob start` to join an existing session
3+
`mob start --join` (#437)
4+
15
# 5.0.1
26
- Fix: The configuration option `MOB_SKIP_CI_PUSH_OPTION_ENABLED` now works correctly
37

configuration/configuration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ type Configuration struct {
2929
NotifyMessage string // override with MOB_NOTIFY_MESSAGE
3030
NextStay bool // override with MOB_NEXT_STAY
3131
StartIncludeUncommittedChanges bool
32-
StartCreate bool // override with MOB_START_CREATE variable
32+
StartCreate bool // override with MOB_START_CREATE variable
33+
StartJoin bool
3334
StashName string // override with MOB_STASH_NAME
3435
WipBranchQualifier string // override with MOB_WIP_BRANCH_QUALIFIER
3536
WipBranchQualifierSeparator string // override with MOB_WIP_BRANCH_QUALIFIER_SEPARATOR
@@ -143,6 +144,8 @@ func ParseArgs(args []string, configuration Configuration) (command string, para
143144
newConfiguration.DoneSquash = SquashWip
144145
case "--create":
145146
newConfiguration.StartCreate = true
147+
case "--join", "-j":
148+
newConfiguration.StartJoin = true
146149
case "--delete-remote-wip-branch":
147150
newConfiguration.ResetDeleteRemoteWipBranch = true
148151
case "--room":

configuration/configuration_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ func TestParseArgsStartCreate(t *testing.T) {
3939
test.Equals(t, true, configuration.StartCreate)
4040
}
4141

42+
func TestParseArgsStartJoin(t *testing.T) {
43+
configuration := GetDefaultConfiguration()
44+
45+
command, parameters, configuration := ParseArgs([]string{"mob", "start", "--join"}, configuration)
46+
47+
test.Equals(t, "start", command)
48+
test.Equals(t, "", strings.Join(parameters, ""))
49+
test.Equals(t, true, configuration.StartJoin)
50+
}
51+
52+
func TestParseArgsStartJoinShort(t *testing.T) {
53+
configuration := GetDefaultConfiguration()
54+
55+
command, parameters, configuration := ParseArgs([]string{"mob", "start", "-j"}, configuration)
56+
57+
test.Equals(t, "start", command)
58+
test.Equals(t, "", strings.Join(parameters, ""))
59+
test.Equals(t, true, configuration.StartJoin)
60+
}
61+
4262
func TestParseArgsDoneNoSquash(t *testing.T) {
4363
configuration := GetDefaultConfiguration()
4464
test.Equals(t, Squash, configuration.DoneSquash)

help/help.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Basic Commands with Options:
2020
[--include-uncommitted-changes|-i] Move uncommitted changes to wip branch
2121
[--branch|-b <branch-postfix>] Set wip branch to 'mob/<base-branch>` + configuration.WipBranchQualifierSeparator + `<branch-postfix>'
2222
[--create] Create the remote branch
23+
[--join|-j] Join existing wip branch
2324
[--room <room-name>] Set room name for timer.mob.sh once
2425
next
2526
[--stay|-s] Stay on wip branch (default)

mob.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,11 @@ func start(configuration config.Configuration) error {
538538
git("fetch", configuration.RemoteName, "--prune")
539539
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
540540

541+
if !currentWipBranch.hasRemoteBranch(configuration) && configuration.StartJoin {
542+
say.Error("Remote wip branch " + currentWipBranch.remote(configuration).String() + " is missing")
543+
return errors.New("remote wip branch is missing")
544+
}
545+
541546
if !currentBaseBranch.hasRemoteBranch(configuration) && !configuration.StartCreate {
542547
say.Error("Remote branch " + currentBaseBranch.remote(configuration).String() + " is missing")
543548
say.Fix("To start and create the remote branch", "mob start --create")

mob_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ func TestStartWithPushDefaultTracking(t *testing.T) {
390390
assertMobSessionBranches(t, configuration, "mob-session")
391391
}
392392

393+
func TestStartWithJoiningNonExistingSession(t *testing.T) {
394+
_, configuration := setup(t)
395+
assertOnBranch(t, "master")
396+
configuration.StartJoin = true
397+
start(configuration)
398+
assertOnBranch(t, "master")
399+
}
400+
393401
func TestReset(t *testing.T) {
394402
output, configuration := setup(t)
395403

0 commit comments

Comments
 (0)