@@ -27,11 +27,13 @@ public partial class FormGerritPublish : FormGerritBase
27
27
28
28
private string _currentBranchRemote ;
29
29
private readonly GerritCapabilities _capabilities ;
30
+ private readonly bool _shouldTargetLocalBranch ;
30
31
31
- public FormGerritPublish ( IGitUICommands uiCommand , GerritCapabilities capabilities )
32
+ public FormGerritPublish ( IGitUICommands uiCommand , GerritCapabilities capabilities , bool shouldTargetLocalBranch )
32
33
: base ( uiCommand )
33
34
{
34
35
_capabilities = capabilities ;
36
+ _shouldTargetLocalBranch = shouldTargetLocalBranch ;
35
37
InitializeComponent ( ) ;
36
38
Publish . Image = Images . Push . AdaptLightness ( ) ;
37
39
InitializeComplete ( ) ;
@@ -137,18 +139,22 @@ private bool PublishChange(IWin32Window owner)
137
139
private string GetTopic ( string targetBranch )
138
140
{
139
141
string branchName = GetBranchName ( targetBranch ) ;
140
-
141
142
string [ ] branchParts = branchName . Split ( '/' ) ;
142
-
143
143
if ( branchParts . Length >= 3 && branchParts [ 0 ] == "review" )
144
144
{
145
145
branchName = string . Join ( "/" , branchParts . Skip ( 2 ) ) ;
146
146
147
147
// Don't use the Gerrit change number as a topic branch.
148
-
149
148
if ( int . TryParse ( branchName , out _ ) )
150
149
{
151
- branchName = null ;
150
+ return null ;
151
+ }
152
+
153
+ // check if patchset number is provided
154
+ branchParts = branchName . Split ( '/' ) ;
155
+ if ( branchParts . Length == 2 && int . TryParse ( branchParts . First ( ) , out _ ) && int . TryParse ( branchParts . Last ( ) , out _ ) )
156
+ {
157
+ return null ;
152
158
}
153
159
}
154
160
@@ -158,8 +164,7 @@ private string GetTopic(string targetBranch)
158
164
private string GetBranchName ( string targetBranch )
159
165
{
160
166
string branch = Module . GetSelectedBranch ( ) ;
161
-
162
- if ( string . IsNullOrWhiteSpace ( branch ) || branch . StartsWith ( "(no " ) )
167
+ if ( string . IsNullOrWhiteSpace ( branch ) || branch . StartsWith ( "(no " ) || branch . StartsWith ( "review/" ) )
163
168
{
164
169
return targetBranch ;
165
170
}
@@ -179,11 +184,15 @@ private void FormGerritPublishLoad(object sender, EventArgs e)
179
184
_NO_TRANSLATE_Branch . DataSource = Module . GetRefs ( RefsFilter . Remotes )
180
185
. Select ( branch => branch . LocalName )
181
186
. ToList ( ) ;
182
- _NO_TRANSLATE_Branch . Text = GetBranchName ( Settings . DefaultBranch ) ;
187
+ _NO_TRANSLATE_Branch . Text = Settings . DefaultBranch ;
183
188
184
- var branches = ( IList < string > ) _NO_TRANSLATE_Branch . DataSource ;
185
- int branchIndex = branches . IndexOf ( _NO_TRANSLATE_Branch . Text ) ;
186
- _NO_TRANSLATE_Branch . SelectedIndex = branchIndex >= 0 ? branchIndex : 0 ;
189
+ if ( _shouldTargetLocalBranch || string . IsNullOrEmpty ( _NO_TRANSLATE_Branch . Text ) )
190
+ {
191
+ _NO_TRANSLATE_Branch . Text = GetBranchName ( Settings . DefaultBranch ) ;
192
+ var branches = ( IList < string > ) _NO_TRANSLATE_Branch . DataSource ;
193
+ int branchIndex = branches . IndexOf ( _NO_TRANSLATE_Branch . Text ) ;
194
+ _NO_TRANSLATE_Branch . SelectedIndex = branchIndex >= 0 ? branchIndex : 0 ;
195
+ }
187
196
188
197
if ( ! string . IsNullOrEmpty ( _NO_TRANSLATE_Branch . Text ) )
189
198
{
@@ -195,7 +204,10 @@ private void FormGerritPublishLoad(object sender, EventArgs e)
195
204
_NO_TRANSLATE_Topic . Text = null ;
196
205
}
197
206
198
- _NO_TRANSLATE_Branch . Select ( ) ;
207
+ if ( _shouldTargetLocalBranch )
208
+ {
209
+ _NO_TRANSLATE_Branch . Select ( ) ;
210
+ }
199
211
200
212
Text = string . Concat ( _publishGerritChangeCaption . Text , " (" , Module . WorkingDir , ")" ) ;
201
213
}
0 commit comments