7
7
import static com .virtuslab .gitmachete .frontend .resourcebundles .GitMacheteBundle .getString ;
8
8
import static org .apache .commons .text .StringEscapeUtils .escapeHtml4 ;
9
9
10
+ import java .lang .reflect .Constructor ;
10
11
import java .lang .reflect .InvocationTargetException ;
11
12
import java .lang .reflect .Method ;
12
13
import java .util .Collections ;
13
14
14
15
import com .intellij .openapi .actionSystem .AnActionEvent ;
15
16
import com .intellij .openapi .application .ApplicationManager ;
17
+ import com .intellij .openapi .project .Project ;
16
18
import com .intellij .openapi .vcs .VcsNotifier ;
17
19
import git4idea .GitRemoteBranch ;
18
20
import git4idea .branch .GitNewBranchOptions ;
@@ -157,6 +159,7 @@ public void actionPerformed(AnActionEvent anActionEvent) {
157
159
}
158
160
159
161
@ ContinuesInBackground
162
+ @ SuppressWarnings ("KotlinInternalInJava" )
160
163
private Tuple2 <@ Nullable String , UiThreadUnsafeRunnable > getBranchNameAndPreSlideInRunnable (
161
164
GitRepository gitRepository ,
162
165
String startPoint ,
@@ -188,7 +191,26 @@ public void actionPerformed(AnActionEvent anActionEvent) {
188
191
189
192
if (remoteBranch == null ) {
190
193
return Tuple .of (branchName , () -> {
191
- val gitBranchCheckoutOperation = new GitBranchCheckoutOperation (project , Collections .singletonList (gitRepository ));
194
+ // TODO (#1938): replace with a non-reflective call once 2024.2 is no longer supported
195
+ Constructor constructor ;
196
+ try {
197
+ // Since 243.19420.21-EAP-SNAPSHOT
198
+ constructor = GitBranchCheckoutOperation .class .getConstructor (Project .class , java .util .Collection .class );
199
+ } catch (NoSuchMethodException e ) {
200
+ try {
201
+ // Before 243.19420.21-EAP-SNAPSHOT
202
+ constructor = GitBranchCheckoutOperation .class .getConstructor (Project .class , java .util .List .class );
203
+ } catch (NoSuchMethodException e1 ) {
204
+ throw new RuntimeException (e1 );
205
+ }
206
+ }
207
+ GitBranchCheckoutOperation gitBranchCheckoutOperation ;
208
+ try {
209
+ gitBranchCheckoutOperation = (GitBranchCheckoutOperation ) constructor .newInstance (project ,
210
+ Collections .singletonList (gitRepository ));
211
+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
212
+ throw new RuntimeException (e );
213
+ }
192
214
val git4IdeaOptions = options .toGit4IdeaOptions ();
193
215
try {
194
216
// Since 233.10527.20-EAP-SNAPSHOT
@@ -202,8 +224,8 @@ public void actionPerformed(AnActionEvent anActionEvent) {
202
224
throw new RuntimeException (e );
203
225
}
204
226
} catch (NoSuchMethodException e ) {
205
- // Before 233.10527.20-EAP-SNAPSHOT
206
227
try {
228
+ // Before 233.10527.20-EAP-SNAPSHOT
207
229
Method perform = GitBranchCheckoutOperation .class .getDeclaredMethod ("perform" , String .class ,
208
230
GitNewBranchOptions .class );
209
231
perform .invoke (gitBranchCheckoutOperation , startPoint , git4IdeaOptions );
0 commit comments