mob
mob copied to clipboard
Feature Request: Create new base branch
My git repo is setup such that writing directly to main is not allowed. Instead we have to create a new branch, mob start on that, do our work on it, and then submit a PR to merge that branch into main.
We felt like it would be useful to have a new mob command to handle the creation of that new base branch for us. I actually ended up forking mob tool to add this functionality in myself
https://github.com/jason-cannon/mob
I added a command called mob create that creates a new base branch, switches to it, and then executes mob start on that branch. Mob Create might not be the best name in the world for it, but it did what we needed.
func create(branchName string, configuration Configuration) {
git("fetch", configuration.RemoteName)
if (hasLocalBranch(branchName) || hasRemoteBranch(branchName, configuration)) {
sayError(fmt.Sprintf("Branch by the name of %s already exists", branchName))
} else {
git("pull")
git("checkout", "-b", branchName)
git("push","-u",configuration.RemoteName, branchName)
start(configuration)
}
}
I don't know GO but adding this was simple thanks to the solid foundation you already built.
I think something like this might be useful for others. It's not that many commands to type in, but it's been convenient for us to be able to do the one command and go. I even use this to create branches that I solo work on for the ease of creating branches and the easy squash of commits.
Simon suggested that the name mob create might be too generic, and I can definitely agree with that.
What do you think about a solution, where you first create a new branch x from main, then start using this branch x as your main branch? So you run mob start on x. Once you are finished, you mob done on x. And then you create a PR from x to main.
Sorry if that wasn't clear, but that is exactly what this command I created does. We don't keep long running branches (squash and commit after PR) so I built a shortcut so instead of having to type
git fetch && git pull && git checkout -b mob-Feature-#WorkItem && git push -u origin mob-Feature-#WorkItem && mob start
I can just type
mob create mob-Feature-#WorkItem
It's a small QOL improvement that my team has been using for the last 6 months and I feel like it could be useful to other users of the mob tool.
So we're just searching for a better name?
How about mob fork {branchname} or mob feature {branchname} or mob from {branchname}
More or less. I implemented this functionality on my own fork but didn't take the time to write unit tests or anything or else I'd just offer a pull request of this functionality. Of those three I think I personally like mob feature
This is similar to https://github.com/remotemobprogramming/mob/issues/185 so perhaps @lamalex might be interested in this, as well.
An alternative would be to use mob start --feature {branchname} instead, making it more obvious that a mob start is happening here.
Love the idea. --feature feels like your enabling some mob-specific feature-flag - which I guess you kind of are, but the term is overloaded by git feature branches (which I imagine is where the flag name was derived from?)
I do like using a flag on mob start to keep that UI consistent.
mob start --create [<branchname>]? Where branchname is optional and defaults to current branch?
I think this might be the way to go. It enables two functions users asked for. Push a locally created feature branch or create and push a feature branch.
So if all developers in the mob start from mainline, but they want to derive the mob branch from a newly created sub-branch, so they use mob start --create [<branchname>]. Doesn't this mean that every developer will have to use mob start --create [<branchname>] at every rotation, then?
Alex: mob start --create new
Alex: mob next
Paula: mob start --create new
Paula: mob next
Isn't this cumbersome? Was thinking of a solution where you had to run it only once:
Alex: mob from new
Paula: mob from new
Alex: mob start
Alex: mob next
Paula: mob start
Paula: mob next
The first mob start might require some parameters like --branch or --create, but the second one can just be mob start.
Example:
# SCENARIO
# Carola
main $ mob start --create feature1
# git fetch
# git checkout -b feature1
# git push
# mob start
mob/feature1 $ mob next
mob/feature1 $
# Maria
main $ mob start --create feature1
# git fetch
# git checkout feature1
# mob start
mob/feature1 $ mob next
mob/feature1 $
# Carola
mob/feature1 $ mob start # already works
mob/feature1 $ mob next
mob/feature1 $
The cool thing of making the name optional would be something like
# SCENARIO
# Carola
main $ git checkout -b feature1
feature1 $ mob start --create
# git fetch
# git push # NEW ONE, helps when you did the local branch creation by yourself, and this fixes the lacking remote one automatically
# mob start
mob/feature1 $ mob next
mob/feature1 $
# Maria
main $ mob start --create feature1
# git fetch
# git checkout feature1
# mob start
mob/feature1 $ mob next
mob/feature1 $
# Carola
mob/feature1 $ mob start # already works
mob/feature1 $ mob next
mob/feature1 $
Does this make sense?
This is dead-on how I saw it working in my head. Seems very natural.
A push is missing in the 2nd example though, right?
main $ mob start --create feature1
# git fetch
# git checkout -b feature1
# git push origin feature1
# mob start
mob/feature1 $ mob next
mob/feature1 $
# Carola
mob/feature1 $ mob start # already works
mob/feature1 $ mob next
mob/feature1 $
Not sure what you mean. Can you elaborate?
Another aspect is on naming: we would now have a mob start --create and a mob start --branch flag. This feels somewhat bad. Any ideas on better names for both features?
Not sure what you mean. Can you elaborate?
--create has to push a remote branch, right? In your --create feature1 example there is no git push in the # <git command> "unrolling" of the mob start --create (unlike in the --create) case example
The first user, in this case Carola, creates the remote branch for feature1. So on Maria's turn, the remote branch has already been pushed. So no need to do any push in this case. Or do we misunderstand each other?
Ah yes I misunderstood. I was reading these as 2 distinct sessions, not 2 individuals mobbing together.
I think Maria running --create feature1 is confusing after Carola having run it. Is --create on a branch that already exists in the remote isomorphic to --branch then?
The idea is that you shouldn’t care whether the branch already exists or not. Tell, don’t ask.
The branch flag is orthogonal to the create flag. You can combine them if you want.
Do we need --create ?
What if start did the push anyhow in case the branch didn't exist
remotely.
It's not really required, @gregorriegler , however, it heavily violates the design principles of the mob tool. The mob tool owns only the mob branches, not anything else. I'd like the user to explicitly enable such behavior instead of something happening unexpectedly. The --create option will probably only be shown as a fix hint to the user when a mob start fails.
git checkout -b test
mob start # fails, but shows that the failure can be used with mob start --create
mob start --create # works
Maybe some user stories/defined AC would help? Here is my first shot. Please iterate.
User Story: As a mob user I want mob to create my remote branch So that starting a new mob-flow is more seamless
AC:
WHEN I mob start
AND <current branch> does not exist in the remote
THEN mob start fails
AND mob issues a --create suggestion
WHEN I mob start --create
AND <current branch> does not exist in the remote
THEN mob start --create creates a remote branch
AND mob start begins a new mob session on <current branch>/<mob branch>
WHEN I mob start --create
AND <current branch> exists in the remote
THEN mob start begins a new mob session on <current branch>/<mob branch>
WHEN I mob start --create <new branch name>
AND <new branch name> does not exist in the remote
THEN mob start --create creates a remote branch named <new branch name>
AND mob start begins a new mob session on <new branch name>/<mob branch>
WHEN I mob start --create <new branch name>
AND <new branch name> exists in the remote
THEN mob start begins a new mob session on <new branch name>/<mob branch>
@simonharrer ?
Thanks for your patience. Yes, makes sense. We, however, have to be careful as there may be
I think we should go forward with this.
I suggest adding the flag --create to automatically create the remote branch, and add a TODO when mob start fails because the remote branch is missing.
After we got this change in, we can think about whether we want to proceed with the second and more complicated part that might also creates a new local branch.
Anyone wants to have a try to implement this?
The first step is now in main. How do we want to continue here?
I would suggest we go small steps, and ship the create feature you did, and create a new issue for the second step. So that we can collect feedback on this initial change, and discuss how or whether to proceed