This is an automated email from the ASF dual-hosted git repository.

thiagoelg pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 311d9cae1e4 kie-issues#408: KIE Sandbox Quarkus Accelerators will 
wrongly initializate in branch different than "main" (#2299)
311d9cae1e4 is described below

commit 311d9cae1e48923f730cce449eeafa692aa7fbba
Author: Kbowers <[email protected]>
AuthorDate: Fri May 10 14:45:06 2024 +0200

    kie-issues#408: KIE Sandbox Quarkus Accelerators will wrongly initializate 
in branch different than "main" (#2299)
---
 .../src/accelerators/AcceleratorsHooks.tsx         | 48 +++++++++++-----------
 packages/online-editor/src/accelerators/test.dmn   |  0
 2 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/packages/online-editor/src/accelerators/AcceleratorsHooks.tsx 
b/packages/online-editor/src/accelerators/AcceleratorsHooks.tsx
index d3624a807a6..534a2749c96 100644
--- a/packages/online-editor/src/accelerators/AcceleratorsHooks.tsx
+++ b/packages/online-editor/src/accelerators/AcceleratorsHooks.tsx
@@ -41,10 +41,7 @@ import { useCancelableEffect } from 
"@kie-tools-core/react-hooks/dist/useCancela
 import { useAuthSession } from "../authSessions/AuthSessionsContext";
 import { ActiveWorkspace } from 
"@kie-tools-core/workspaces-git-fs/dist/model/ActiveWorkspace";
 import { useWorkspaceFilePromise } from 
"@kie-tools-core/workspaces-git-fs/dist/hooks/WorkspaceFileHooks";
-import {
-  GIT_DEFAULT_BRANCH,
-  GIT_ORIGIN_REMOTE_NAME,
-} from "@kie-tools-core/workspaces-git-fs/dist/constants/GitConstants";
+import { GIT_ORIGIN_REMOTE_NAME } from 
"@kie-tools-core/workspaces-git-fs/dist/constants/GitConstants";
 import { isOfKind } from 
"@kie-tools-core/workspaces-git-fs/dist/constants/ExtensionHelper";
 
 const TEMP_ACCELERATOR_REMOTE_NAME = "__kie-sandbox__accelerator-remote";
@@ -70,7 +67,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
   const { i18n } = useOnlineI18n();
   const { gitConfig } = useAuthSession(workspace.descriptor.gitAuthSessionId);
 
-  const apllyingAcceleratorAlert = useGlobalAlert(
+  const applyingAcceleratorAlert = useGlobalAlert(
     useCallback(
       (_, staticArgs: { acceleratorName: string }) => (
         <Alert
@@ -132,7 +129,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
 
   const applyAcceleratorToWorkspace = useCallback(
     async (accelerator: AcceleratorConfig, currentFile: WorkspaceFile) => {
-      apllyingAcceleratorAlert.show({ acceleratorName: accelerator.name });
+      applyingAcceleratorAlert.show({ acceleratorName: accelerator.name });
 
       const workspaceId = workspace.descriptor.workspaceId;
 
@@ -163,25 +160,17 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
 
         const workspaceFiles = await workspaces.getFiles({ workspaceId });
 
-        // Create new temporary branch with current files, but stay on main
+        // Create new temporary branch with current files, but stay on current 
branch
         await workspaces.branch({ workspaceId, name: BACKUP_BRANCH_NAME, 
checkout: false });
 
-        // Commit moved files to moved files branch (this commit will never be 
pushed, as this branch will be deleted)
+        // Commit files to backup branch (this commit will never be pushed, as 
this branch will be deleted)
         await workspaces.commit({
           workspaceId,
           commitMessage: `${env.KIE_SANDBOX_APP_NAME}: Backup files before 
applying ${accelerator.name} Accelerator`,
           targetBranch: BACKUP_BRANCH_NAME,
         });
-
-        // Create new temporary branch for moved files, but stay on main
-        await workspaces.branch({ workspaceId, name: MOVED_FILES_BRANCH_NAME, 
checkout: false });
-
-        // Checkout to moved files branch
-        await workspaces.checkout({
-          workspaceId,
-          ref: MOVED_FILES_BRANCH_NAME,
-          remote: GIT_ORIGIN_REMOTE_NAME,
-        });
+        // Create and checkout new temporary branch for moved files
+        await workspaces.branch({ workspaceId, name: MOVED_FILES_BRANCH_NAME, 
checkout: true });
 
         // Move files
         let currentFileAfterAccelerator: WorkspaceFile | undefined;
@@ -224,8 +213,12 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
           targetBranch: MOVED_FILES_BRANCH_NAME,
         });
 
-        // Go back to main
-        await workspaces.checkout({ workspaceId, ref: GIT_DEFAULT_BRANCH, 
remote: GIT_ORIGIN_REMOTE_NAME });
+        // Go back to original branch
+        await workspaces.checkout({
+          workspaceId,
+          ref: workspace.descriptor.origin.branch,
+          remote: GIT_ORIGIN_REMOTE_NAME,
+        });
 
         // Add Accelerator remote and fetch it
         await workspaces.addRemote({
@@ -311,7 +304,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
           forceHasChanges: true,
         });
 
-        apllyingAcceleratorAlert.close();
+        applyingAcceleratorAlert.close();
 
         applyAcceleratorSuccessAlert.show({ acceleratorName: accelerator.name 
});
 
@@ -325,7 +318,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
           }),
         });
       } catch (e) {
-        apllyingAcceleratorAlert.close();
+        applyingAcceleratorAlert.close();
         applyAcceleratorFailAlert.show({ acceleratorName: accelerator.name });
 
         console.error(e);
@@ -335,8 +328,12 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
           await workspaces.deleteFile({ file: configFile });
         }
 
-        // Return to main
-        await workspaces.checkout({ workspaceId, ref: GIT_DEFAULT_BRANCH, 
remote: GIT_ORIGIN_REMOTE_NAME });
+        // Return to original branch
+        await workspaces.checkout({
+          workspaceId,
+          ref: workspace.descriptor.origin.branch,
+          remote: GIT_ORIGIN_REMOTE_NAME,
+        });
 
         // Revert repo
         await workspaces.checkoutFilesFromLocalHead({
@@ -367,7 +364,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
       }
     },
     [
-      apllyingAcceleratorAlert,
+      applyingAcceleratorAlert,
       applyAcceleratorFailAlert,
       applyAcceleratorSuccessAlert,
       attemptToDeleteTemporaryBranches,
@@ -376,6 +373,7 @@ export function useAcceleratorsDispatch(workspace: 
ActiveWorkspace) {
       history,
       i18n.accelerators,
       routes.workspaceWithFilePath,
+      workspace.descriptor.origin.branch,
       workspace.descriptor.workspaceId,
       workspaces,
     ]
diff --git a/packages/online-editor/src/accelerators/test.dmn 
b/packages/online-editor/src/accelerators/test.dmn
new file mode 100644
index 00000000000..e69de29bb2d


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to