@hunan36/dsh-git-flow 0.4.1 → 0.4.2

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.
package/lib/index.js CHANGED
@@ -663,14 +663,16 @@ var GitFlow = class extends Service {
663
663
  async checkout(sessionId, name, force = false) {
664
664
  const repo = await this.resolveRepo(sessionId);
665
665
  assertBranchName(name);
666
+ const target = await this.unqualifiedName(repo, name);
666
667
  const args = ["switch"];
667
668
  if (force) args.push("--force");
668
- if (await this.hasLocalBranch(repo, name)) args.push(name);
669
+ if (await this.hasLocalBranch(repo, target)) args.push(target);
669
670
  else {
670
- const remotes = await this.remoteBranches(repo, name);
671
- if (remotes.length > 1) throw new GitError("git/invalid-input", `branch ${name} exists on multiple remotes: ${remotes.join(", ")}`);
672
- if (remotes.length === 1) args.push("-c", name, "--track", remotes[0]);
673
- else args.push(name);
671
+ const remotes = await this.remoteBranches(repo, target);
672
+ const tracking = remotes.includes(name) ? name : remotes.length === 1 ? remotes[0] : void 0;
673
+ if (tracking !== void 0) args.push("-c", target, "--track", tracking);
674
+ else if (remotes.length > 1) throw new GitError("git/invalid-input", `branch ${target} exists on multiple remotes: ${remotes.join(", ")}`);
675
+ else args.push(target);
674
676
  }
675
677
  await this.runSwitch(repo, args);
676
678
  return this.status(sessionId);
@@ -1202,6 +1204,20 @@ var GitFlow = class extends Service {
1202
1204
  `refs/heads/${name}`
1203
1205
  ])).exitCode === 0;
1204
1206
  }
1207
+ /**
1208
+ * Turn a branch row's name into something `git switch` accepts. Remote-only
1209
+ * rows are labelled `<remote>/<branch>` because that is their short refname,
1210
+ * but git refuses to switch to a remote ref directly; stripping the prefix
1211
+ * lets {@link checkout} create the local tracking branch instead. Only a
1212
+ * known remote is peeled off, and only when no real local branch has that
1213
+ * exact name.
1214
+ */
1215
+ async unqualifiedName(repo, name) {
1216
+ if (await this.hasLocalBranch(repo, name)) return name;
1217
+ const slash = name.indexOf("/");
1218
+ if (slash <= 0) return name;
1219
+ return (await this.git.runOk(repo, ["remote"])).stdout.split("\n").map((line) => line.trim()).filter(Boolean).includes(name.slice(0, slash)) ? name.slice(slash + 1) : name;
1220
+ }
1205
1221
  async remoteBranches(repo, name) {
1206
1222
  return (await this.git.runOk(repo, [
1207
1223
  "for-each-ref",
@@ -173,6 +173,15 @@ export declare class GitFlow extends Service {
173
173
  */
174
174
  private changedInIndex;
175
175
  private hasLocalBranch;
176
+ /**
177
+ * Turn a branch row's name into something `git switch` accepts. Remote-only
178
+ * rows are labelled `<remote>/<branch>` because that is their short refname,
179
+ * but git refuses to switch to a remote ref directly; stripping the prefix
180
+ * lets {@link checkout} create the local tracking branch instead. Only a
181
+ * known remote is peeled off, and only when no real local branch has that
182
+ * exact name.
183
+ */
184
+ private unqualifiedName;
176
185
  private remoteBranches;
177
186
  private runSwitch;
178
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hunan36/dsh-git-flow",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Workspace git branch switcher, commit composer with AI-written messages, and push for DeepSeek Harness",
5
5
  "keywords": [
6
6
  "dsh",