Skip to content

Commit

Permalink
Merge pull request #413 from remotemobprogramming/410-status-time
Browse files Browse the repository at this point in the history
#410: added duration to latest commit for a remote branch to mob status
  • Loading branch information
hollesse authored Apr 5, 2024
2 parents fe9c42f + b9c023a commit 3a717b8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 56 deletions.
25 changes: 1 addition & 24 deletions mob.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
versionNumber = "4.5.0"
versionNumber = "4.5.1"
minimumGitVersion = "2.13.0"
)

Expand Down Expand Up @@ -887,16 +887,6 @@ func warnForActiveWipBranches(configuration config.Configuration, currentBaseBra
}
}

func showActiveMobSessions(configuration config.Configuration, currentBaseBranch Branch) {
existingWipBranches := getWipBranchesForBaseBranch(currentBaseBranch, configuration)
if len(existingWipBranches) > 0 {
say.Info("remote wip branches detected:")
for _, wipBranch := range existingWipBranches {
say.WithPrefix(wipBranch, " - ")
}
}
}

func sayUntrackedFilesInfo() {
untrackedFiles := getUntrackedFiles()
hasUntrackedFiles := len(untrackedFiles) > 0
Expand Down Expand Up @@ -1190,19 +1180,6 @@ func squashOrCommit(configuration config.Configuration) string {
}
}

func status(configuration config.Configuration) {
if isMobProgramming(configuration) {
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
say.Info("you are on wip branch " + currentWipBranch.String() + " (base branch " + currentBaseBranch.String() + ")")

sayLastCommitsList(currentBaseBranch.String(), currentWipBranch.String())
} else {
currentBaseBranch, _ := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
say.Info("you are on base branch '" + currentBaseBranch.String() + "'")
showActiveMobSessions(configuration, currentBaseBranch)
}
}

func sayLastCommitsList(currentBaseBranch string, currentWipBranch string) {
commitsBaseWipBranch := currentBaseBranch + ".." + currentWipBranch
log := silentgit("--no-pager", "log", commitsBaseWipBranch, "--pretty=format:%h %cr <%an>", "--abbrev-commit")
Expand Down
32 changes: 0 additions & 32 deletions mob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,38 +177,6 @@ func TestDoneNotMobProgramming(t *testing.T) {
assertOutputContains(t, output, "to start working together")
}

func TestStatusMobProgramming(t *testing.T) {
output, configuration := setup(t)
start(configuration)

status(configuration)

assertOutputContains(t, output, "you are on wip branch mob-session")
}

func TestStatusWithMoreThan5LinesOfLog(t *testing.T) {
output, configuration := setup(t)
configuration.NextStay = true
start(configuration)

for i := 0; i < 6; i++ {
createFile(t, "test"+strconv.Itoa(i)+".txt", "contentIrrelevant")
next(configuration)
}

status(configuration)
// 6 wip commits + 1 start commit
assertOutputContains(t, output, "wip branch 'mob-session' contains 7 commits.")
}

func TestExecuteKicksOffStatus(t *testing.T) {
output, _ := setup(t)

execute("status", []string{}, config.GetDefaultConfiguration())

assertOutputContains(t, output, "you are on base branch 'master'")
}

func TestExecuteInvalidCommandKicksOffHelp(t *testing.T) {
output, _ := setup(t)

Expand Down
32 changes: 32 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
config "github.com/remotemobprogramming/mob/v4/configuration"
"github.com/remotemobprogramming/mob/v4/say"
)

func status(configuration config.Configuration) {
if isMobProgramming(configuration) {
currentBaseBranch, currentWipBranch := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
say.Info("you are on wip branch " + currentWipBranch.String() + " (base branch " + currentBaseBranch.String() + ")")

sayLastCommitsList(currentBaseBranch.String(), currentWipBranch.String())
} else {
currentBaseBranch, _ := determineBranches(gitCurrentBranch(), gitBranches(), configuration)
say.Info("you are on base branch '" + currentBaseBranch.String() + "'")
showActiveMobSessions(configuration, currentBaseBranch)
}
}

func showActiveMobSessions(configuration config.Configuration, currentBaseBranch Branch) {
existingWipBranches := getWipBranchesForBaseBranch(currentBaseBranch, configuration)
if len(existingWipBranches) > 0 {
say.Info("remote wip branches detected:")
for _, wipBranch := range existingWipBranches {
time := silentgit("log", "-1", "--pretty=format:(%ar)", wipBranch)
say.WithPrefix(wipBranch+" "+time, " - ")
}
} else {
say.Info("no remote wip branches detected!")
}
}
53 changes: 53 additions & 0 deletions status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
config "github.com/remotemobprogramming/mob/v4/configuration"
"strconv"
"testing"
)

func TestExecuteKicksOffStatus(t *testing.T) {
output, _ := setup(t)

execute("status", []string{}, config.GetDefaultConfiguration())

assertOutputContains(t, output, "you are on base branch 'master'")
}

func TestStatusMobProgramming(t *testing.T) {
output, configuration := setup(t)
start(configuration)

status(configuration)

assertOutputContains(t, output, "you are on wip branch mob-session")
}

func TestStatusWithMoreThan5LinesOfLog(t *testing.T) {
output, configuration := setup(t)
configuration.NextStay = true
start(configuration)

for i := 0; i < 6; i++ {
createFile(t, "test"+strconv.Itoa(i)+".txt", "contentIrrelevant")
next(configuration)
}

status(configuration)
// 6 wip commits + 1 start commit
assertOutputContains(t, output, "wip branch 'mob-session' contains 7 commits.")
}

func TestStatusDetectsWipBranches(t *testing.T) {
output, configuration := setup(t)
start(configuration)
createFile(t, "test.txt", "contentIrrelevant")
next(configuration)
git("checkout", "master")

status(configuration)

assertOutputContains(t, output, "remote wip branches detected:\n - origin/mob-session")
assertOutputContains(t, output, " second")
assertOutputContains(t, output, " ago)")
}

0 comments on commit 3a717b8

Please sign in to comment.