Skip to content

Commit 50531ef

Browse files
committed
feature: support to choose the start point of git-flow topic branch (#2538)
Signed-off-by: leo <longshuang@msn.cn>
1 parent d70e4f4 commit 50531ef

3 files changed

Lines changed: 41 additions & 15 deletions

File tree

‎src/Commands/GitFlow.cs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,32 @@ public async Task<bool> InitAsync(string production, string develop, string feat
4747
return await ExecAsync().ConfigureAwait(false);
4848
}
4949

50-
public async Task<bool> StartAsync(Models.GitFlowBranchType type, string name)
50+
public async Task<bool> StartAsync(Models.GitFlowBranchType type, string name, Models.Branch based)
5151
{
52+
var builder = new StringBuilder();
53+
builder.Append("flow ");
54+
5255
switch (type)
5356
{
5457
case Models.GitFlowBranchType.Feature:
55-
Args = $"flow feature start {name}";
58+
builder.Append("feature");
5659
break;
5760
case Models.GitFlowBranchType.Release:
58-
Args = $"flow release start {name}";
61+
builder.Append("release");
5962
break;
6063
case Models.GitFlowBranchType.Hotfix:
61-
Args = $"flow hotfix start {name}";
64+
builder.Append("hotfix");
6265
break;
6366
default:
6467
RaiseException("Bad git-flow branch type!!!");
6568
return false;
6669
}
6770

71+
builder.Append(" start ").Append(name);
72+
if (based != null)
73+
builder.Append(' ').Append(based.Name);
74+
75+
Args = builder.ToString();
6876
return await ExecAsync().ConfigureAwait(false);
6977
}
7078

‎src/ViewModels/GitFlowStart.cs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System.ComponentModel.DataAnnotations;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel.DataAnnotations;
24
using System.Threading.Tasks;
35

46
namespace SourceGit.ViewModels
@@ -11,12 +13,18 @@ public Models.GitFlowBranchType Type
1113
private set;
1214
}
1315

14-
public string StartPoint
16+
public List<Models.Branch> LocalBranches
1517
{
1618
get;
1719
private set;
1820
}
1921

22+
public Models.Branch StartPoint
23+
{
24+
get => _startPoint;
25+
set => SetProperty(ref _startPoint, value);
26+
}
27+
2028
public string Prefix
2129
{
2230
get;
@@ -38,11 +46,21 @@ public GitFlowStart(Repository repo, Models.GitFlowBranchType type)
3846

3947
Type = type;
4048
Prefix = _repo.GitFlow.GetPrefix(type);
41-
StartPoint = type switch
49+
LocalBranches = new List<Models.Branch>();
50+
51+
foreach (var b in _repo.Branches)
52+
{
53+
if (b.IsLocal && !b.IsDetachedHead)
54+
LocalBranches.Add(b);
55+
}
56+
57+
var defBranch = type switch
4258
{
4359
Models.GitFlowBranchType.Hotfix => _repo.GitFlow.ProductionBranch,
4460
_ => _repo.GitFlow.DevelopmentBranch,
4561
};
62+
63+
StartPoint = LocalBranches.Find(b => b.Name.Equals(defBranch, StringComparison.Ordinal));
4664
}
4765

4866
public static ValidationResult ValidateBranchName(string name, ValidationContext ctx)
@@ -70,13 +88,14 @@ public override async Task<bool> Sure()
7088

7189
var succ = await new Commands.GitFlow(_repo.FullPath)
7290
.Use(log)
73-
.StartAsync(Type, _name);
91+
.StartAsync(Type, _name, _startPoint);
7492

7593
log.Complete();
7694
return succ;
7795
}
7896

7997
private readonly Repository _repo;
8098
private string _name = null;
99+
private Models.Branch _startPoint = null;
81100
}
82101
}

‎src/Views/GitFlowStart.axaml‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@
3333
HorizontalAlignment="Right" VerticalAlignment="Center"
3434
Margin="0,0,8,0"
3535
Text="{DynamicResource Text.GitFlow.StartAt}"/>
36-
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
37-
<Path Width="14" Height="14"
38-
Data="{StaticResource Icons.Branch}"/>
39-
<TextBlock Margin="8,0,0,0"
40-
VerticalAlignment="Center"
41-
Text="{Binding StartPoint, Mode=OneWay}"/>
42-
</StackPanel>
36+
<v:BranchSelector Grid.Row="0" Grid.Column="1"
37+
Height="28"
38+
VerticalAlignment="Center"
39+
Branches="{Binding LocalBranches, Mode=OneWay}"
40+
SelectedBranch="{Binding StartPoint, Mode=TwoWay}"
41+
UsePureName="True"/>
4342

4443
<TextBlock Grid.Row="1" Grid.Column="0"
4544
HorizontalAlignment="Right" VerticalAlignment="Center"

0 commit comments

Comments
 (0)