Skip to content

Commit fdf9726

Browse files
EliasA5stefanhaller
authored andcommitted
Use branchPrefix on moving commits to a new branch
Signed-off-by: Elias Assaf <[email protected]>
1 parent 816d0c0 commit fdf9726

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

pkg/gui/controllers/helpers/refs_helper.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,21 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
396396
return err
397397
}
398398

399-
withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) {
399+
withNewBranchNamePrompt := func(baseBranchName string, f func(string, string) error) error {
400400
prompt := utils.ResolvePlaceholderString(
401401
self.c.Tr.NewBranchNameBranchOff,
402402
map[string]string{
403403
"branchName": baseBranchName,
404404
},
405405
)
406+
suggestedBranchName, err := self.getSuggestedBranchName()
407+
if err != nil {
408+
return err
409+
}
406410

407411
self.c.Prompt(types.PromptOpts{
408-
Title: prompt,
412+
Title: prompt,
413+
InitialContent: suggestedBranchName,
409414
HandleConfirm: func(response string) error {
410415
self.c.LogAction(self.c.Tr.MoveCommitsToNewBranch)
411416
newBranchName := SanitizedBranchName(response)
@@ -414,6 +419,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
414419
})
415420
},
416421
})
422+
return nil
417423
}
418424

419425
isMainBranch := lo.Contains(self.c.UserConfig().Git.MainBranches, currentBranch.Name)
@@ -428,8 +434,7 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
428434
Title: self.c.Tr.MoveCommitsToNewBranch,
429435
Prompt: prompt,
430436
HandleConfirm: func() error {
431-
withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
432-
return nil
437+
return withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
433438
},
434439
})
435440
return nil
@@ -449,17 +454,15 @@ func (self *RefsHelper) MoveCommitsToNewBranch() error {
449454
{
450455
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchFromBaseItem, shortBaseBranchName),
451456
OnPress: func() error {
452-
withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error {
457+
return withNewBranchNamePrompt(shortBaseBranchName, func(currentBranch string, newBranchName string) error {
453458
return self.moveCommitsToNewBranchOffOfMainBranch(currentBranch, newBranchName, baseBranchRef)
454459
})
455-
return nil
456460
},
457461
},
458462
{
459463
Label: fmt.Sprintf(self.c.Tr.MoveCommitsToNewBranchStackedItem, currentBranch.Name),
460464
OnPress: func() error {
461-
withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
462-
return nil
465+
return withNewBranchNamePrompt(currentBranch.Name, self.moveCommitsToNewBranchStackedOnCurrentBranch)
463466
},
464467
},
465468
},

pkg/integration/tests/branch/move_commits_to_new_branch_keep_stacked.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ var MoveCommitsToNewBranchKeepStacked = NewIntegrationTest(NewIntegrationTestArg
99
Description: "Create a new branch from the commits that you accidentally made on the wrong branch; choosing stacked on current branch",
1010
ExtraCmdArgs: []string{},
1111
Skip: false,
12-
SetupConfig: func(config *config.AppConfig) {},
12+
SetupConfig: func(config *config.AppConfig) {
13+
config.GetUserConfig().Git.BranchPrefix = "myprefix/"
14+
},
1315
SetupRepo: func(shell *Shell) {
1416
shell.EmptyCommit("initial commit")
1517
shell.CloneIntoRemote("origin")
@@ -42,12 +44,13 @@ var MoveCommitsToNewBranchKeepStacked = NewIntegrationTest(NewIntegrationTestArg
4244

4345
t.ExpectPopup().Prompt().
4446
Title(Equals("New branch name (branch is off of 'feature')")).
47+
InitialText(Equals("myprefix/")).
4548
Type("new branch").
4649
Confirm()
4750

4851
t.Views().Branches().
4952
Lines(
50-
Contains("new-branch").DoesNotContain("↑").IsSelected(),
53+
Contains("myprefix/new-branch").DoesNotContain("↑").IsSelected(),
5154
Contains("feature ✓"),
5255
Contains("master ✓"),
5356
)

0 commit comments

Comments
 (0)