Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify user of noteworthy lineage changes #2558

Merged
merged 5 commits into from Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions features/kill/current_branch/features/parent_branch.feature
Expand Up @@ -22,6 +22,10 @@ Feature: delete a branch within a branch chain
| | git commit -m "WIP on beta" |
| | git checkout alpha |
| alpha | git branch -D beta |
And it prints:
"""
branch "gamma" is now a child of "alpha"
"""
And the current branch is now "alpha"
And no uncommitted files exist
And the branches are now
Expand Down
4 changes: 4 additions & 0 deletions features/ship/current_branch/features/parent_branch.feature
Expand Up @@ -23,6 +23,10 @@ Feature: ship a parent branch
| | git commit -m "parent done" |
| | git push |
| | git branch -D parent |
And it prints:
"""
branch "child" is now a child of "main"
"""
And the current branch is now "main"
And now these commits exist
| BRANCH | LOCATION | MESSAGE |
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/append.go
Expand Up @@ -181,7 +181,7 @@ func appendSteps(config *appendConfig) steps.List {
})
}
list.Add(&step.CreateBranch{Branch: config.targetBranch, StartingPoint: config.parentBranch.Location()})
list.Add(&step.SetParent{Branch: config.targetBranch, ParentBranch: config.parentBranch})
list.Add(&step.SetParent{Branch: config.targetBranch, Parent: config.parentBranch})
list.Add(&step.Checkout{Branch: config.targetBranch})
if config.remotes.HasOrigin() && config.shouldNewBranchPush && !config.isOffline {
list.Add(&step.CreateTrackingBranch{Branch: config.targetBranch, NoPushHook: !config.pushHook})
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/kill.go
Expand Up @@ -198,7 +198,7 @@ func killFeatureBranch(list *steps.List, finalUndoList *steps.List, config killC
func removeBranchFromLineage(args removeBranchFromLineageArgs) {
childBranches := args.lineage.Children(args.branch)
for _, child := range childBranches {
args.list.Add(&step.SetParent{Branch: child, ParentBranch: args.parent})
args.list.Add(&step.ChangeParent{Branch: child, Parent: args.parent})
}
args.list.Add(&step.DeleteParentBranch{Branch: args.branch})
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/prepend.go
Expand Up @@ -182,8 +182,8 @@ func prependSteps(config *prependConfig) steps.List {
})
}
list.Add(&step.CreateBranch{Branch: config.targetBranch, StartingPoint: config.parentBranch.Location()})
list.Add(&step.SetParent{Branch: config.targetBranch, ParentBranch: config.parentBranch})
list.Add(&step.SetParent{Branch: config.branches.Initial, ParentBranch: config.targetBranch})
list.Add(&step.SetParent{Branch: config.targetBranch, Parent: config.parentBranch})
list.Add(&step.SetParent{Branch: config.branches.Initial, Parent: config.targetBranch})
list.Add(&step.Checkout{Branch: config.targetBranch})
if config.remotes.HasOrigin() && config.shouldNewBranchPush && !config.isOffline {
list.Add(&step.CreateTrackingBranch{Branch: config.targetBranch, NoPushHook: !config.pushHook})
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/rename_branch.go
Expand Up @@ -175,10 +175,10 @@ func renameBranchSteps(config *renameBranchConfig) steps.List {
} else {
lineage := config.lineage
result.Add(&step.DeleteParentBranch{Branch: config.oldBranch.LocalName})
result.Add(&step.SetParent{Branch: config.newBranch, ParentBranch: lineage.Parent(config.oldBranch.LocalName)})
result.Add(&step.SetParent{Branch: config.newBranch, Parent: lineage.Parent(config.oldBranch.LocalName)})
}
for _, child := range config.lineage.Children(config.oldBranch.LocalName) {
result.Add(&step.SetParent{Branch: child, ParentBranch: config.newBranch})
result.Add(&step.SetParent{Branch: child, Parent: config.newBranch})
}
if config.oldBranch.HasTrackingBranch() && !config.isOffline {
result.Add(&step.CreateTrackingBranch{Branch: config.newBranch, NoPushHook: config.noPushHook})
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ship.go
Expand Up @@ -364,7 +364,7 @@ func shipSteps(config *shipConfig, commitMessage string) steps.List {
list.Add(&step.DeleteLocalBranch{Branch: config.branchToShip.LocalName, Parent: config.mainBranch.Location(), Force: false})
list.Add(&step.DeleteParentBranch{Branch: config.branchToShip.LocalName})
for _, child := range config.childBranches {
list.Add(&step.SetParent{Branch: child, ParentBranch: config.targetBranch.LocalName})
list.Add(&step.ChangeParent{Branch: child, Parent: config.targetBranch.LocalName})
}
if !config.isShippingInitialBranch {
list.Add(&step.Checkout{Branch: config.branches.Initial})
Expand Down
1 change: 1 addition & 0 deletions src/messages/en.go
Expand Up @@ -16,6 +16,7 @@ const (
BranchHasWrongSHA = "cannot reset branch %q to %q because it received additional commits in the meantime. It should have SHA %q but has %q"
BranchLocalSHAProblem = "cannot determine SHA of local branch %q: %w"
BranchLocalProblem = "cannot determine whether the local branch %q exists: %w"
BranchParentChanged = "branch %q is now a child of %q"
BrowserOpen = "Please open in a browser: %s\n"
CacheUnitialized = "using a cached value before initialization"
CommandsRun = "Ran %d shell commands."
Expand Down
17 changes: 14 additions & 3 deletions src/persistence/save_load_test.go
Expand Up @@ -43,6 +43,10 @@ func TestLoadSave(t *testing.T) {
&step.AbortMerge{},
&step.AbortRebase{},
&step.AddToPerennialBranches{Branch: domain.NewLocalBranchName("branch")},
&step.ChangeParent{
Branch: domain.NewLocalBranchName("branch"),
Parent: domain.NewLocalBranchName("parent"),
},
&step.Checkout{Branch: domain.NewLocalBranchName("branch")},
&step.CommitOpenChanges{},
&step.ConnectorMergeProposal{
Expand Down Expand Up @@ -132,8 +136,8 @@ func TestLoadSave(t *testing.T) {
Value: "1",
},
&step.SetParent{
Branch: domain.NewLocalBranchName("branch"),
ParentBranch: domain.NewLocalBranchName("parent"),
Branch: domain.NewLocalBranchName("branch"),
Parent: domain.NewLocalBranchName("parent"),
},
&step.SkipCurrentBranch{},
&step.SquashMerge{
Expand Down Expand Up @@ -179,6 +183,13 @@ func TestLoadSave(t *testing.T) {
},
"type": "AddToPerennialBranches"
},
{
"data": {
"Branch": "branch",
"Parent": "parent"
},
"type": "ChangeParent"
},
{
"data": {
"Branch": "branch"
Expand Down Expand Up @@ -371,7 +382,7 @@ func TestLoadSave(t *testing.T) {
{
"data": {
"Branch": "branch",
"ParentBranch": "parent"
"Parent": "parent"
},
"type": "SetParent"
},
Expand Down
25 changes: 25 additions & 0 deletions src/step/change_parent.go
@@ -0,0 +1,25 @@
package step

import (
"fmt"

"github.com/git-town/git-town/v9/src/domain"
"github.com/git-town/git-town/v9/src/messages"
)

// ChangeParent changes the parent of the given branch to the given parent.
// Use SetParent to set the parent if no parent existed before.
type ChangeParent struct {
Branch domain.LocalBranchName
Parent domain.LocalBranchName
Empty
}

func (step *ChangeParent) Run(args RunArgs) error {
err := args.Runner.Config.SetParent(step.Branch, step.Parent)
if err != nil {
return err
}
args.Runner.FinalMessages.Add(fmt.Sprintf(messages.BranchParentChanged, step.Branch, step.Parent))
return nil
}
19 changes: 19 additions & 0 deletions src/step/set_parent.go
@@ -0,0 +1,19 @@
package step

import "github.com/git-town/git-town/v9/src/domain"

// SetParent sets the given parent branch as the parent of the given branch.
// Use ChangeParent to change an existing parent.
type SetParent struct {
Branch domain.LocalBranchName
Parent domain.LocalBranchName
Empty
}

func (step *SetParent) Run(args RunArgs) error {
err := args.Runner.Config.SetParent(step.Branch, step.Parent)
if err != nil {
return err
}
return nil
}
17 changes: 0 additions & 17 deletions src/step/set_parent_branch.go

This file was deleted.

2 changes: 2 additions & 0 deletions src/steps/json.go
Expand Up @@ -49,6 +49,8 @@ func DetermineStep(stepType string) step.Step { //nolint:ireturn
return &step.AbortRebase{}
case "AddToPerennialBranches":
return &step.AddToPerennialBranches{}
case "ChangeParent":
return &step.ChangeParent{}
case "Checkout":
return &step.Checkout{}
case "CheckoutIfExists":
Expand Down