@@ -27,11 +27,13 @@ public partial class FormGerritPublish : FormGerritBase
2727
2828 private string _currentBranchRemote ;
2929 private readonly GerritCapabilities _capabilities ;
30+ private readonly bool _shouldTargetLocalBranch ;
3031
31- public FormGerritPublish ( IGitUICommands uiCommand , GerritCapabilities capabilities )
32+ public FormGerritPublish ( IGitUICommands uiCommand , GerritCapabilities capabilities , bool shouldTargetLocalBranch )
3233 : base ( uiCommand )
3334 {
3435 _capabilities = capabilities ;
36+ _shouldTargetLocalBranch = shouldTargetLocalBranch ;
3537 InitializeComponent ( ) ;
3638 Publish . Image = Images . Push . AdaptLightness ( ) ;
3739 InitializeComplete ( ) ;
@@ -137,18 +139,22 @@ private bool PublishChange(IWin32Window owner)
137139 private string GetTopic ( string targetBranch )
138140 {
139141 string branchName = GetBranchName ( targetBranch ) ;
140-
141142 string [ ] branchParts = branchName . Split ( '/' ) ;
142-
143143 if ( branchParts . Length >= 3 && branchParts [ 0 ] == "review" )
144144 {
145145 branchName = string . Join ( "/" , branchParts . Skip ( 2 ) ) ;
146146
147147 // Don't use the Gerrit change number as a topic branch.
148-
149148 if ( int . TryParse ( branchName , out _ ) )
150149 {
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 ;
152158 }
153159 }
154160
@@ -158,8 +164,7 @@ private string GetTopic(string targetBranch)
158164 private string GetBranchName ( string targetBranch )
159165 {
160166 string branch = Module . GetSelectedBranch ( ) ;
161-
162- if ( string . IsNullOrWhiteSpace ( branch ) || branch . StartsWith ( "(no " ) )
167+ if ( string . IsNullOrWhiteSpace ( branch ) || branch . StartsWith ( "(no " ) || branch . StartsWith ( "review/" ) )
163168 {
164169 return targetBranch ;
165170 }
@@ -179,11 +184,15 @@ private void FormGerritPublishLoad(object sender, EventArgs e)
179184 _NO_TRANSLATE_Branch . DataSource = Module . GetRefs ( RefsFilter . Remotes )
180185 . Select ( branch => branch . LocalName )
181186 . ToList ( ) ;
182- _NO_TRANSLATE_Branch . Text = GetBranchName ( Settings . DefaultBranch ) ;
187+ _NO_TRANSLATE_Branch . Text = Settings . DefaultBranch ;
183188
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+ }
187196
188197 if ( ! string . IsNullOrEmpty ( _NO_TRANSLATE_Branch . Text ) )
189198 {
@@ -195,7 +204,10 @@ private void FormGerritPublishLoad(object sender, EventArgs e)
195204 _NO_TRANSLATE_Topic . Text = null ;
196205 }
197206
198- _NO_TRANSLATE_Branch . Select ( ) ;
207+ if ( _shouldTargetLocalBranch )
208+ {
209+ _NO_TRANSLATE_Branch . Select ( ) ;
210+ }
199211
200212 Text = string . Concat ( _publishGerritChangeCaption . Text , " (" , Module . WorkingDir , ")" ) ;
201213 }
0 commit comments