Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrisch committed Nov 22, 2024
1 parent fd3a369 commit c9acfa9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 40 deletions.
3 changes: 2 additions & 1 deletion scripts/git/auto_rebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ async function rebaseBranch(baseBranch, targetBranch) {

return true;
} catch (error) {
if (error.message.includes("CONFLICT")) {
const status = await git.status();
if (status.conflicts.length > 0) {
console.error(
`Conflicts occurred while rebasing ${targetBranch} onto ${baseBranch}`
);
Expand Down
66 changes: 27 additions & 39 deletions scripts/git/cherry-pick-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ async function cherryPickCommits() {
min: 1,
});

if (!selectedCommits || selectedCommits.length === 0) {
console.log("No commits selected. Exiting.");
return;
}

commitsToCherryPick = commitList.filter((commit) =>
selectedCommits.includes(commit.hash)
);
Expand Down Expand Up @@ -115,13 +120,27 @@ async function cherryPickCommits() {
}
}

function executeCommand(command, args) {
function executeCommand(command, args, options = { captureOutput: false }) {
return new Promise((resolve, reject) => {
const cmd = spawn(command, args, { stdio: "inherit", shell: true });
let output = "";
const spawnOptions = options.captureOutput
? { shell: true }
: { stdio: "inherit", shell: true };
const cmd = spawn(command, args, spawnOptions);

if (options.captureOutput) {
cmd.stdout.on("data", (data) => {
output += data.toString();
});

cmd.stderr.on("data", (data) => {
output += data.toString();
});
}

cmd.on("close", (code) => {
if (code === 0) {
resolve();
resolve(output.trim());
} else {
reject(
new Error(
Expand All @@ -139,11 +158,11 @@ function executeCommand(command, args) {

async function getCommitsNotInTarget(sourceBranch, targetBranch) {
// Get commits in sourceBranch not in targetBranch
const commitsOutput = await executeGitCommand([
"log",
`${targetBranch}..${sourceBranch}`,
"--pretty=format:%H %s",
]);
const commitsOutput = await executeCommand(
"git",
["log", `${targetBranch}..${sourceBranch}`, "--pretty=format:%H %s"],
{ captureOutput: true }
);

const commits = commitsOutput
.split("\n")
Expand All @@ -156,35 +175,4 @@ async function getCommitsNotInTarget(sourceBranch, targetBranch) {
return commits;
}

function executeGitCommand(args) {
return new Promise((resolve, reject) => {
let output = "";
const cmd = spawn("git", args, { shell: true });

cmd.stdout.on("data", (data) => {
output += data.toString();
});

cmd.stderr.on("data", (data) => {
output += data.toString();
});

cmd.on("close", (code) => {
if (code === 0) {
resolve(output.trim());
} else {
reject(
new Error(
`Git command "git ${args.join(" ")}" exited with code ${code}`
)
);
}
});

cmd.on("error", (error) => {
reject(error);
});
});
}

cherryPickCommits();

0 comments on commit c9acfa9

Please sign in to comment.