bstack 1.2.1 → 1.3.0

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.
Files changed (2) hide show
  1. package/dist/bstack.mjs +20 -5
  2. package/package.json +1 -1
package/dist/bstack.mjs CHANGED
@@ -6,7 +6,7 @@ import * as v from "valibot";
6
6
  import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
7
7
  import { dirname } from "node:path";
8
8
  //#region package.json
9
- var version = "1.2.1";
9
+ var version = "1.3.0";
10
10
  //#endregion
11
11
  //#region src/command.ts
12
12
  var CommandError = class extends Error {
@@ -279,6 +279,7 @@ var GitCliRepository = class {
279
279
  remote,
280
280
  ...refspecs
281
281
  ]);
282
+ return branches.filter((branch) => existing.get(branch.name) !== branch.oid).map((branch) => branch.name);
282
283
  }
283
284
  statePath() {
284
285
  return this.git([
@@ -726,11 +727,13 @@ function syncStack(dependencies, options) {
726
727
  }
727
728
  }
728
729
  reporter.progress(`Pushing ${changes.length} remote branch${changes.length === 1 ? "" : "es"}`);
730
+ let pushedBranches = /* @__PURE__ */ new Set();
729
731
  try {
730
- repository.pushBranches(remote, changes.map((change) => ({
732
+ const updatedBranches = repository.pushBranches(remote, changes.map((change) => ({
731
733
  name: change.remoteBranch,
732
734
  oid: change.oid
733
735
  })));
736
+ pushedBranches = new Set(updatedBranches);
734
737
  } catch (error) {
735
738
  if (isReorder) restorePreviousStack(github, previous, base, remote, reporter, error);
736
739
  throw error;
@@ -744,6 +747,7 @@ function syncStack(dependencies, options) {
744
747
  reporter.progress(`Creating pull request: ${change.subject}`);
745
748
  return github.createPullRequest(change, pullRequestBase, options.draft);
746
749
  });
750
+ const createdBranches = new Set(changes.filter((_change, index) => existing[index] === void 0).map((change) => change.remoteBranch));
747
751
  if (changes.length === 1) {
748
752
  if (transition.kind === "partial") reporter.progress("Updating this down-stack prefix while preserving higher pull requests");
749
753
  const pullRequest = pullRequests[0];
@@ -809,10 +813,19 @@ function syncStack(dependencies, options) {
809
813
  rewritten,
810
814
  changes: changes.map((change, index) => ({
811
815
  ...change,
812
- pullRequest: pullRequests[index]
816
+ pullRequest: pullRequests[index],
817
+ outcome: changeOutcome(change, index, pullRequests[index], previous, changes, base, createdBranches, pushedBranches)
813
818
  }))
814
819
  };
815
820
  }
821
+ function changeOutcome(change, index, pullRequest, previous, changes, base, createdBranches, pushedBranches) {
822
+ if (createdBranches.has(change.remoteBranch)) return "created";
823
+ const previousIndex = previous?.changes.findIndex((candidate) => candidate.id === change.id);
824
+ const previousBase = previousIndex === void 0 || previousIndex < 0 ? void 0 : previousIndex === 0 ? previous.base : previous.changes[previousIndex - 1].remoteBranch;
825
+ const currentBase = index === 0 ? base : changes[index - 1].remoteBranch;
826
+ const metadataChanged = pullRequest.title !== change.subject || pullRequest.body !== change.body;
827
+ return pushedBranches.has(change.remoteBranch) || previousBase !== currentBase || metadataChanged ? "updated" : "unchanged";
828
+ }
816
829
  function restorePreviousStack(github, previous, base, remote, reporter, rebuildError) {
817
830
  const rebuildMessage = rebuildError instanceof Error ? rebuildError.message : String(rebuildError);
818
831
  reporter.progress("Rebuild failed; restoring the previous native GitHub stack");
@@ -926,10 +939,12 @@ function main() {
926
939
  draft: values.draft,
927
940
  dryRun: values["dry-run"]
928
941
  });
929
- console.log(`${values["dry-run"] ? "Would sync" : "Synced"} ${result.changes.length} change${result.changes.length === 1 ? "" : "s"} against ${result.base}:`);
942
+ const changeCount = `${result.changes.length} change${result.changes.length === 1 ? "" : "s"}`;
943
+ console.log(values["dry-run"] ? `Would sync ${changeCount} against ${result.base}:` : `Synced stack against ${result.base} (${changeCount}):`);
930
944
  for (const change of result.changes) {
945
+ const outcome = change.outcome ? `${change.outcome.padEnd(9)} ` : "";
931
946
  const destination = change.pullRequest ? ` ${change.pullRequest.url}` : "";
932
- console.log(` ${change.oid.slice(0, 8)} ${change.subject}${destination}`);
947
+ console.log(` ${outcome}${change.oid.slice(0, 8)} ${change.subject}${destination}`);
933
948
  }
934
949
  }
935
950
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bstack",
3
- "version": "1.2.1",
3
+ "version": "1.3.0",
4
4
  "description": "Create native GitHub stacked pull requests from a linear series of commits",
5
5
  "license": "MIT",
6
6
  "repository": {