staklink 0.3.13 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33608,6 +33608,33 @@ var Repo = class {
33608
33608
  `git checkout -f $(git remote show origin | sed -n '/HEAD branch/s/.*: //p')`
33609
33609
  );
33610
33610
  }
33611
+ async branchExists(branch) {
33612
+ try {
33613
+ const localCheck = await this.execCommand(`git show-ref --verify --quiet refs/heads/${branch}`).catch(() => null);
33614
+ if (localCheck !== null) {
33615
+ return true;
33616
+ }
33617
+ const remoteCheck = await this.execCommand(`git ls-remote --heads origin ${branch}`).catch(() => "");
33618
+ return remoteCheck.trim().length > 0;
33619
+ } catch (e) {
33620
+ return false;
33621
+ }
33622
+ }
33623
+ async generateUniqueBranchName(baseBranchName) {
33624
+ let branchName = baseBranchName;
33625
+ while (await this.branchExists(branchName)) {
33626
+ const parts = branchName.split("-");
33627
+ const lastPart = parts[parts.length - 1];
33628
+ const num = parseInt(lastPart, 10);
33629
+ if (!isNaN(num) && lastPart === num.toString()) {
33630
+ parts[parts.length - 1] = (num + 1).toString();
33631
+ branchName = parts.join("-");
33632
+ } else {
33633
+ branchName = `${branchName}-2`;
33634
+ }
33635
+ }
33636
+ return branchName;
33637
+ }
33611
33638
  async checkoutNew(branch) {
33612
33639
  return this.execCommand(`git checkout -b ${branch}`);
33613
33640
  }
@@ -80311,11 +80338,16 @@ async function startProxyServer() {
80311
80338
  const isOnMain = await repo.isOnMainBranch();
80312
80339
  const isOnBaseBranch = await repo.isOnBranch(r.base_branch);
80313
80340
  if (isOnMain || isOnBaseBranch) {
80314
- console.log(`=> CHECKOUT to new branch: ${r.branch_name}`);
80315
- await repo.checkoutNew(r.branch_name);
80341
+ const uniqueBranchName = await repo.generateUniqueBranchName(r.branch_name);
80342
+ if (uniqueBranchName !== r.branch_name) {
80343
+ console.log(`=> Branch ${r.branch_name} exists, using ${uniqueBranchName} instead`);
80344
+ }
80345
+ console.log(`=> CHECKOUT to new branch: ${uniqueBranchName}`);
80346
+ await repo.checkoutNew(uniqueBranchName);
80316
80347
  }
80317
80348
  await repo.addAll();
80318
- console.log(`=> COMMIT to ${r.url} on branch: ${r.branch_name}`);
80349
+ const currentBranch = (await repo.printCurrentBranch()).trim();
80350
+ console.log(`=> COMMIT to ${r.url} on branch: ${currentBranch}`);
80319
80351
  await repo.commitWithCredentials(r.commit_name, code.git_credentials);
80320
80352
  }
80321
80353
  console.log(`=> PUSH to ${r.url}`);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "staklink",
3
3
  "displayName": "staklink",
4
4
  "description": "staklink process manager",
5
- "version": "0.3.13",
5
+ "version": "0.3.14",
6
6
  "type": "module",
7
7
  "publisher": "stakwork",
8
8
  "engines": {