offsite 0.0.19 → 0.0.20

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.
@@ -4576,6 +4576,7 @@ const DIFF_LIMIT = 8e4;
4576
4576
  const UNTRACKED_LIMIT = 100;
4577
4577
  const NEW_FILE_LIMIT = 262144;
4578
4578
  const REPO_DEPTH = 3;
4579
+ const FETCH_TIMEOUT = 6e4;
4579
4580
  const run$1 = promisify(execFile);
4580
4581
  const PULL_REQUEST_INSTRUCTIONS = `You write GitHub pull requests as Markdown.
4581
4582
 
@@ -4638,9 +4639,44 @@ async function push$1(cwd) {
4638
4639
  ]);
4639
4640
  else await git(cwd, ["push"]);
4640
4641
  } catch (error) {
4641
- throw new Error((error instanceof Error ? error.message : String(error)).split("\n").filter((line) => line.trim() !== "" && !line.startsWith("hint:") && !line.startsWith("Command failed:")).join("\n"), { cause: error });
4642
+ throw gitError(error);
4642
4643
  }
4643
4644
  }
4645
+ async function sync(cwd) {
4646
+ if ((await gitStatus(cwd)).upstream === null) {
4647
+ await push$1(cwd);
4648
+ return;
4649
+ }
4650
+ try {
4651
+ await git(cwd, ["fetch"]);
4652
+ const status = await gitStatus(cwd);
4653
+ if (status.behind > 0 && status.ahead === 0) await git(cwd, [
4654
+ "merge",
4655
+ "--ff-only",
4656
+ "@{upstream}"
4657
+ ]);
4658
+ if (status.behind > 0 && status.ahead > 0) await rebaseOnUpstream(cwd);
4659
+ } catch (error) {
4660
+ throw gitError(error);
4661
+ }
4662
+ if ((await gitStatus(cwd)).ahead > 0) await push$1(cwd);
4663
+ }
4664
+ async function fetchProject(cwd) {
4665
+ await Promise.all((await projectRepos(cwd)).map(async (repo) => {
4666
+ try {
4667
+ await run$1("git", ["fetch"], {
4668
+ cwd: path.join(cwd, repo),
4669
+ env: {
4670
+ ...process.env,
4671
+ GIT_TERMINAL_PROMPT: "0"
4672
+ },
4673
+ timeout: FETCH_TIMEOUT
4674
+ });
4675
+ } catch (error) {
4676
+ throw gitError(error);
4677
+ }
4678
+ }));
4679
+ }
4644
4680
  async function localBranches(cwd) {
4645
4681
  return (await git(cwd, [
4646
4682
  "branch",
@@ -4796,6 +4832,7 @@ async function projectRepos(cwd) {
4796
4832
  }
4797
4833
  async function gitStatus(cwd) {
4798
4834
  const output = await git(cwd, [
4835
+ "--no-optional-locks",
4799
4836
  "status",
4800
4837
  "--porcelain=v2",
4801
4838
  "--branch"
@@ -4803,6 +4840,7 @@ async function gitStatus(cwd) {
4803
4840
  const status = {
4804
4841
  branch: null,
4805
4842
  upstream: null,
4843
+ remote: (await git(cwd, ["remote"])).stdout.trim() !== "",
4806
4844
  ahead: 0,
4807
4845
  behind: 0,
4808
4846
  changed: 0
@@ -4819,6 +4857,25 @@ async function gitStatus(cwd) {
4819
4857
  }
4820
4858
  return status;
4821
4859
  }
4860
+ async function rebaseOnUpstream(cwd) {
4861
+ try {
4862
+ await git(cwd, ["rebase", "@{upstream}"]);
4863
+ } catch (error) {
4864
+ const rebasing = await git(cwd, [
4865
+ "rev-parse",
4866
+ "--git-path",
4867
+ "rebase-merge"
4868
+ ]);
4869
+ if (existsSync(path.resolve(cwd, rebasing.stdout.trim()))) {
4870
+ await git(cwd, ["rebase", "--abort"]);
4871
+ throw new Error("Your commits conflict with the remote branch, so nothing was pulled or pushed. Resolve it in a terminal.", { cause: error });
4872
+ }
4873
+ throw error;
4874
+ }
4875
+ }
4876
+ function gitError(error) {
4877
+ return new Error((error instanceof Error ? error.message : String(error)).split("\n").filter((line) => line.trim() !== "" && !line.startsWith("hint:") && !line.startsWith("Command failed:")).join("\n"), { cause: error });
4878
+ }
4822
4879
  async function isRepo(cwd) {
4823
4880
  try {
4824
4881
  await git(cwd, ["rev-parse", "--is-inside-work-tree"]);
@@ -4880,8 +4937,10 @@ function newFilePatch(cwd, file, prefix) {
4880
4937
  const name = `${prefix}${file}`;
4881
4938
  const header = `diff --git a/${name} b/${name}\nnew file\n--- /dev/null\n+++ b/${name}\n`;
4882
4939
  const full = path.join(cwd, file);
4883
- if (lstatSync(full).isSymbolicLink()) return `${header}@@ -0,0 +1 @@\n+${readlinkSync(full)}\n`;
4884
- if (statSync(full).size > NEW_FILE_LIMIT) return `${header}Binary or large file\n`;
4940
+ const stats = lstatSync(full);
4941
+ if (stats.isSymbolicLink()) return `${header}@@ -0,0 +1 @@\n+${readlinkSync(full)}\n`;
4942
+ if (stats.isDirectory()) return `${header}Nested repository\n`;
4943
+ if (stats.size > NEW_FILE_LIMIT) return `${header}Binary or large file\n`;
4885
4944
  const content = readFileSync(full, "utf8");
4886
4945
  if (content.includes("\0")) return `${header}Binary or large file\n`;
4887
4946
  const lines = content.split("\n");
@@ -6112,6 +6171,14 @@ const handlers = {
6112
6171
  await push$1(path.join(projectPath(params.projectId), params.repo));
6113
6172
  return null;
6114
6173
  },
6174
+ "git.sync": async (params) => {
6175
+ await sync(path.join(projectPath(params.projectId), params.repo));
6176
+ return null;
6177
+ },
6178
+ "git.fetch": async (params) => {
6179
+ await fetchProject(projectPath(params.projectId));
6180
+ return null;
6181
+ },
6115
6182
  "git.branches": (params) => pullRequestBranches(path.join(projectPath(params.projectId), params.repo)),
6116
6183
  "git.localBranches": (params) => localBranches(path.join(projectPath(params.projectId), params.repo)),
6117
6184
  "git.switch": async (params) => {