coc-git 2.7.11 → 2.7.12

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 (3) hide show
  1. package/history.md +4 -0
  2. package/lib/index.js +59 -46
  3. package/package.json +1 -1
package/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 2.7.12
2
+
3
+ - fix: address audited git workflow issues (eb6ee85)
4
+
1
5
  ## 2.7.11
2
6
 
3
7
  - add AGENTS.md (34ea156)
package/lib/index.js CHANGED
@@ -4757,6 +4757,16 @@ var Bcommits = class extends import_coc.BasicList {
4757
4757
  // src/lists/branches.ts
4758
4758
  var import_coc2 = require("coc.nvim");
4759
4759
  var import_safe = __toESM(require_safe());
4760
+ function parseBranchLine(line) {
4761
+ const name = line.slice(2);
4762
+ if (!name || name.includes(" -> ")) return void 0;
4763
+ const remote = name.startsWith("remotes/");
4764
+ return {
4765
+ current: line[0] == "*",
4766
+ branch: remote ? name.slice("remotes/".length) : name,
4767
+ remote
4768
+ };
4769
+ }
4760
4770
  var Branches = class {
4761
4771
  constructor(nvim, manager) {
4762
4772
  this.manager = manager;
@@ -4828,15 +4838,14 @@ var Branches = class {
4828
4838
  if (output == null) return;
4829
4839
  output = output.replace(/\s+$/, "");
4830
4840
  for (let line of output.split(/\r?\n/)) {
4831
- let remote = line.slice(2).startsWith("remotes/");
4841
+ const data = parseBranchLine(line);
4842
+ if (!data) continue;
4832
4843
  res.push({
4833
4844
  label: import_safe.default.yellow(line.slice(0, 2)) + line.slice(2),
4834
4845
  filterText: line.slice(2),
4835
4846
  data: {
4836
- current: line[0] == "*",
4837
4847
  root,
4838
- branch: remote ? line.slice(10) : line.slice(2),
4839
- remote
4848
+ ...data
4840
4849
  }
4841
4850
  });
4842
4851
  }
@@ -5092,14 +5101,12 @@ var Gfiles = class extends import_coc4.BasicList {
5092
5101
  this.detail = "Pass git sha as first command argument, when empty, HEAD is used.\nExample: :CocList gfiles 7b5c5cb";
5093
5102
  this.defaultAction = "edit";
5094
5103
  this.actions = [];
5095
- const preferences = import_coc4.workspace.getConfiguration("coc.preferences");
5096
- let jumpCommand = preferences.get("jumpCommand", "edit");
5097
5104
  for (let name of ["edit", "tabe", "vsplit", "split"]) {
5098
5105
  this.addAction(name, async (item, ctx) => {
5099
5106
  let { root, sha, filepath, branch } = item.data;
5100
5107
  if (!sha) return;
5101
5108
  if (branch == "HEAD") {
5102
- let cmd2 = name == "edit" ? jumpCommand : name;
5109
+ let cmd2 = name == "edit" ? import_coc4.workspace.getConfiguration("coc.preferences").get("jumpCommand", "edit") : name;
5103
5110
  if (ctx.options.position === "tab") cmd2 = "tabe";
5104
5111
  let fullpath = import_path.default.join(root, filepath);
5105
5112
  await import_coc4.workspace.jumpTo(import_coc4.Uri.file(fullpath).toString(), null, cmd2);
@@ -5107,7 +5114,7 @@ var Gfiles = class extends import_coc4.BasicList {
5107
5114
  }
5108
5115
  let content = (await this.manager.git.exec(root, ["cat-file", "-p", sha])).stdout;
5109
5116
  let lines = content.replace(/\n$/, "").split("\n");
5110
- let cmd = name == "edit" ? jumpCommand : name;
5117
+ let cmd = name == "edit" ? import_coc4.workspace.getConfiguration("coc.preferences").get("jumpCommand", "edit") : name;
5111
5118
  let bufferName = await nvim.call("fnameescape", [`(${branch}) ${filepath}`]);
5112
5119
  nvim.pauseNotification();
5113
5120
  nvim.command(`${cmd} ${bufferName}`, true);
@@ -5215,7 +5222,7 @@ function quoteGitPath(filepath) {
5215
5222
  }
5216
5223
  function createUnstagePatch(relpath, chunk) {
5217
5224
  if (chunk.remove.count == 0 && chunk.add.count == 0) return "";
5218
- let head = `@@ -${chunk.add.lnum},${chunk.add.count} +${chunk.add.lnum + 1 - chunk.add.count},${chunk.remove.count} @@`;
5225
+ let head = `@@ -${chunk.add.lnum},${chunk.add.count} +${chunk.remove.lnum},${chunk.remove.count} @@`;
5219
5226
  if (!head) return "";
5220
5227
  const from = quoteGitPath(`a/${relpath}`);
5221
5228
  const to = quoteGitPath(`b/${relpath}`);
@@ -5331,15 +5338,22 @@ function getUrl(fix, repoURL, name, filepath, lines) {
5331
5338
  }
5332
5339
  const encodePath = (value) => value.split("/").map(encodeURIComponent).join("/");
5333
5340
  let url = repoURL + "/blob/" + encodePath(name) + "/" + encodePath(filepath) + (anchor ? "#" + encodeURIComponent(anchor) : "");
5334
- let parts = fix.split("|");
5335
- if (parts.length < 2) return url;
5341
+ const separator = fix.lastIndexOf("|");
5342
+ if (separator === -1) return url;
5336
5343
  try {
5337
- let match = RegExp(parts[0]), result = parts[1];
5344
+ let match = RegExp(fix.slice(0, separator)), result = fix.slice(separator + 1);
5338
5345
  return url.replace(match, result);
5339
5346
  } catch (_e) {
5340
5347
  return url;
5341
5348
  }
5342
5349
  }
5350
+ async function feedTreeToggleKey(nvim, configuredKey) {
5351
+ let key = configuredKey;
5352
+ if (/^<[^"\\\r\n]+>$/.test(configuredKey)) {
5353
+ key = await nvim.call("eval", [`"\\${configuredKey}"`]);
5354
+ }
5355
+ await nvim.call("feedkeys", [key, "in"]);
5356
+ }
5343
5357
  function parseVersion(raw) {
5344
5358
  return raw.replace(/^git version /, "");
5345
5359
  }
@@ -5419,6 +5433,21 @@ function onceEvent(event) {
5419
5433
  }
5420
5434
 
5421
5435
  // src/lists/gstatus.ts
5436
+ async function commitWithFugitive(nvim, items) {
5437
+ let { root } = items[0].data;
5438
+ const cwd = await nvim.call("getcwd");
5439
+ let escapedRoot = await nvim.call("fnameescape", [root]);
5440
+ let escapedCwd = await nvim.call("fnameescape", [cwd]);
5441
+ await nvim.command(`lcd ${escapedRoot}`);
5442
+ try {
5443
+ let escapedFiles = await Promise.all(items.map((item) => nvim.call("fnameescape", [item.data.relative])));
5444
+ await nvim.command(`G commit -v -- ${escapedFiles.join(" ")}`);
5445
+ } catch (e) {
5446
+ import_coc6.window.showErrorMessage(`G commit command failed, make sure fugitive installed.`);
5447
+ } finally {
5448
+ await nvim.command(`lcd ${escapedCwd}`);
5449
+ }
5450
+ }
5422
5451
  var STATUS_MAP = {
5423
5452
  " ": " ",
5424
5453
  M: import_safe2.default.cyan("~"),
@@ -5454,15 +5483,7 @@ var GStatus = class extends import_coc6.BasicList {
5454
5483
  }]);
5455
5484
  });
5456
5485
  this.addMultipleAction("commit", async (items) => {
5457
- let { root } = items[0].data;
5458
- let escapedRoot = await nvim.call("fnameescape", [root]);
5459
- await nvim.command(`lcd ${escapedRoot}`);
5460
- let escapedFiles = await Promise.all(items.map((item) => nvim.call("fnameescape", [item.data.relative])));
5461
- try {
5462
- await nvim.command(`G commit -v -- ${escapedFiles.join(" ")}`);
5463
- } catch (e) {
5464
- import_coc6.window.showErrorMessage(`G commit command failed, make sure fugitive installed.`);
5465
- }
5486
+ await commitWithFugitive(nvim, items);
5466
5487
  });
5467
5488
  this.addAction("reset", async (item) => {
5468
5489
  let { staged, tree, relative, root } = item.data;
@@ -5604,20 +5625,20 @@ var GChunks = class extends import_coc7.BasicList {
5604
5625
  let stagedDiff = await buf.repo.getStagedChunks(relpath);
5605
5626
  let chunks = (_a = Object.values(stagedDiff)[0]) != null ? _a : [];
5606
5627
  if (chunks.length > 0) {
5607
- for (let diff of chunks) {
5628
+ for (let chunk of chunks) {
5608
5629
  let adjust = 0;
5609
5630
  let stagedSign = import_safe3.default.green("*");
5610
- let line = diff.add.lnum;
5611
- for (let diff2 of diffs) {
5612
- if (diff2.end >= line) {
5631
+ let line = chunk.add.lnum;
5632
+ for (let unstagedDiff of diffs) {
5633
+ if (unstagedDiff.end >= line) {
5613
5634
  break;
5614
5635
  }
5615
- adjust += diff2.added.count;
5616
- adjust -= diff2.removed.count;
5636
+ adjust += unstagedDiff.added.count;
5637
+ adjust -= unstagedDiff.removed.count;
5617
5638
  }
5618
5639
  line += adjust;
5619
5640
  res.push({
5620
- label: `${stagedSign} Line:${line} ${diff.lines[0]}`,
5641
+ label: `${stagedSign} Line:${line} ${chunk.lines[0]}`,
5621
5642
  data: {
5622
5643
  line
5623
5644
  }
@@ -5700,8 +5721,8 @@ var GitStatus = class {
5700
5721
  if (!this._enabled) this.setGitStatus("");
5701
5722
  this.scheduleRefresh(0);
5702
5723
  }, null, this.disposables);
5703
- import_coc9.events.on("BufEnter", this.refresh, this, this.disposables);
5704
- import_coc9.events.on("FocusGained", this.refresh, this, this.disposables);
5724
+ import_coc9.events.on("BufEnter", () => this.scheduleRefresh(100), this, this.disposables);
5725
+ import_coc9.events.on("FocusGained", () => this.scheduleRefresh(100), this, this.disposables);
5705
5726
  import_coc9.events.on("BufWritePost", () => this.scheduleRefresh(50), this, this.disposables);
5706
5727
  this.disposables.push({ dispose: () => this.clearTimer() });
5707
5728
  this.scheduleRefresh(300);
@@ -7342,14 +7363,7 @@ var GitBuffer = class {
7342
7363
  import_coc12.window.showErrorMessage("Not positioned in git chunk");
7343
7364
  return;
7344
7365
  }
7345
- let head;
7346
- if (diff.changeType === "add" /* Add */) {
7347
- head = `@@ -${diff.removed.start + 1},0 +${diff.removed.start + 1},${diff.added.count} @@`;
7348
- } else if (diff.changeType === "delete" /* Delete */) {
7349
- head = `@@ -${diff.removed.start},${diff.removed.count} +${diff.removed.start},0 @@`;
7350
- } else if (diff.changeType === "changed" /* Change */) {
7351
- head = `@@ -${diff.removed.start},${diff.removed.count} +${diff.removed.start},${diff.added.count} @@`;
7352
- }
7366
+ const head = diff.head;
7353
7367
  const from = quoteGitPath(`a/${relpath}`);
7354
7368
  const to = quoteGitPath(`b/${relpath}`);
7355
7369
  const lines = [
@@ -8546,6 +8560,9 @@ var GitService = class {
8546
8560
  var import_coc16 = require("coc.nvim");
8547
8561
  var import_safe5 = __toESM(require_safe());
8548
8562
  var import_url2 = require("url");
8563
+ function isIssuePage(value) {
8564
+ return Array.isArray(value);
8565
+ }
8549
8566
  function byteSlice(content, start, end) {
8550
8567
  let buf = Buffer.from(content, "utf8");
8551
8568
  return buf.slice(start, end).toString("utf8");
@@ -8640,7 +8657,7 @@ function addSource(context, service) {
8640
8657
  const pageUri = `${uri}&page=${pageIndex}`;
8641
8658
  pageIndex++;
8642
8659
  let info = await (0, import_coc16.fetch)(pageUri, { headers: { "Private-Token": token } });
8643
- if (!info.length) {
8660
+ if (!isIssuePage(info) || info.length === 0) {
8644
8661
  break;
8645
8662
  }
8646
8663
  for (let i = 0, len = info.length; i < len; i++) {
@@ -8677,7 +8694,7 @@ function addSource(context, service) {
8677
8694
  page_idx++;
8678
8695
  try {
8679
8696
  let info = await (0, import_coc16.fetch)(page_uri, { headers });
8680
- if (info.length == 0) {
8697
+ if (!isIssuePage(info) || info.length === 0) {
8681
8698
  break;
8682
8699
  }
8683
8700
  for (let i = 0, len = info.length; i < len; i++) {
@@ -9127,9 +9144,7 @@ var CommitFilesController = class {
9127
9144
  const element = node;
9128
9145
  if (element.kind !== "root" && element.kind !== "directory") return;
9129
9146
  const configuredKey = import_coc17.workspace.getConfiguration("tree").get("key.toggle", "t");
9130
- const key = configuredKey.startsWith("<") && configuredKey.endsWith(">") ? `\\${configuredKey}` : configuredKey;
9131
- const escaped = key.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
9132
- await import_coc17.workspace.nvim.call("eval", [`feedkeys("${escaped}", "in")`]);
9147
+ await feedTreeToggleKey(import_coc17.workspace.nvim, configuredKey);
9133
9148
  }
9134
9149
  async open(revision, requestedRoot, options = {}) {
9135
9150
  var _a;
@@ -9626,9 +9641,7 @@ var StatusFilesController = class {
9626
9641
  const element = node;
9627
9642
  if (element.kind !== "root" && element.kind !== "directory") return;
9628
9643
  const configuredKey = import_coc18.workspace.getConfiguration("tree").get("key.toggle", "t");
9629
- const key = configuredKey.startsWith("<") && configuredKey.endsWith(">") ? `\\${configuredKey}` : configuredKey;
9630
- const escaped = key.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
9631
- await import_coc18.workspace.nvim.call("eval", [`feedkeys("${escaped}", "in")`]);
9644
+ await feedTreeToggleKey(import_coc18.workspace.nvim, configuredKey);
9632
9645
  }
9633
9646
  async refresh() {
9634
9647
  const session = this.session;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coc-git",
3
- "version": "2.7.11",
3
+ "version": "2.7.12",
4
4
  "description": "Git extension for coc.nvim",
5
5
  "main": "lib/index.js",
6
6
  "publisher": "chemzqm",