From 936c35af9a235e13adfcb316a56ef3a49f77866e Mon Sep 17 00:00:00 2001
From: Mac <mohammed.ali.chherawalla@gmail.com>
Date: Sat, 20 Aug 2022 16:26:12 +0530
Subject: [PATCH] fix: cannot find remote branch

---
 index.js      | 23 +++++++++++------------
 src/index.jsx | 23 +++++++++++------------
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/index.js b/index.js
index e45dc7b..f379a35 100644
--- a/index.js
+++ b/index.js
@@ -26275,34 +26275,33 @@ var main = async () => {
   const maxDepth = core.getInput("max_depth") || 9;
   const customFileColors = JSON.parse(core.getInput("file_colors") || "{}");
   const colorEncoding = core.getInput("color_encoding") || "type";
-  const commitMessage = core.getInput("commit_message") || "Repo visualizer: updated diagram";
+  const commitMessage = core.getInput("commit_message") || "Repo visualizer: update diagram";
   const excludedPathsString = core.getInput("excluded_paths") || "node_modules,bower_components,dist,out,build,eject,.next,.netlify,.yarn,.git,.vscode,package-lock.json,yarn.lock";
   const excludedPaths = excludedPathsString.split(",").map((str) => str.trim());
   const excludedGlobsString = core.getInput("excluded_globs") || "";
   const excludedGlobs = excludedGlobsString.split(";");
   const branch = core.getInput("branch");
   const data = await processDir(rootPath, excludedPaths, excludedGlobs);
-  const componentCodeString = import_server.default.renderToStaticMarkup(/* @__PURE__ */ import_react3.default.createElement(Tree, {
-    data,
-    maxDepth: +maxDepth,
-    colorEncoding,
-    customFileColors
-  }));
-  const outputFile = core.getInput("output_file") || "./diagram.svg";
-  core.setOutput("svg", componentCodeString);
-  await import_fs2.default.writeFileSync(outputFile, componentCodeString);
   let doesBranchExist = true;
   if (branch) {
     await (0, import_exec.exec)("git", ["fetch"]);
     try {
-      await (0, import_exec.exec)("git", ["rev-parse", "--verify", branch]);
-      await (0, import_exec.exec)("git", ["checkout", branch]);
+      await (0, import_exec.exec)("git", ["switch", "-c", branch, "--track", `origin/${branch}`]);
     } catch {
       doesBranchExist = false;
       core.info(`Branch ${branch} does not yet exist, creating ${branch}.`);
       await (0, import_exec.exec)("git", ["checkout", "-b", branch]);
     }
   }
+  const componentCodeString = import_server.default.renderToStaticMarkup(/* @__PURE__ */ import_react3.default.createElement(Tree, {
+    data,
+    maxDepth: +maxDepth,
+    colorEncoding,
+    customFileColors
+  }));
+  const outputFile = core.getInput("output_file") || "./diagram.svg";
+  core.setOutput("svg", componentCodeString);
+  await import_fs2.default.writeFileSync(outputFile, componentCodeString);
   await (0, import_exec.exec)("git", ["add", outputFile]);
   const diff = await execWithOutput("git", ["status", "--porcelain", outputFile]);
   core.info(`diff: ${diff}`);
diff --git a/src/index.jsx b/src/index.jsx
index d0ca9ae..fd348b1 100644
--- a/src/index.jsx
+++ b/src/index.jsx
@@ -38,30 +38,29 @@ const main = async () => {
   const branch = core.getInput("branch")
   const data = await processDir(rootPath, excludedPaths, excludedGlobs);
 
-  const componentCodeString = ReactDOMServer.renderToStaticMarkup(
-    <Tree data={data} maxDepth={+maxDepth} colorEncoding={colorEncoding} customFileColors={customFileColors}/>
-  );
-
-  const outputFile = core.getInput("output_file") || "./diagram.svg"
-
-  core.setOutput('svg', componentCodeString)
-
-  await fs.writeFileSync(outputFile, componentCodeString)
-
   let doesBranchExist = true
 
   if (branch) {
     await exec('git', ['fetch'])
 
     try {
-      await exec('git', ['rev-parse', '--verify', branch])
-      await exec('git', ['checkout', branch])
+      await exec('git', ['switch', '-c' , branch,'--track', `origin/${branch}`])
     } catch {
       doesBranchExist = false
       core.info(`Branch ${branch} does not yet exist, creating ${branch}.`)
       await exec('git', ['checkout', '-b', branch])
     }
   }
+  const componentCodeString = ReactDOMServer.renderToStaticMarkup(
+    <Tree data={data} maxDepth={+maxDepth} colorEncoding={colorEncoding} customFileColors={customFileColors}/>
+  );
+
+  const outputFile = core.getInput("output_file") || "./diagram.svg"
+
+  core.setOutput('svg', componentCodeString)
+
+  await fs.writeFileSync(outputFile, componentCodeString)
+
 
   await exec('git', ['add', outputFile])
   const diff = await execWithOutput('git', ['status', '--porcelain', outputFile])
