mirror of
https://github.com/schpet/linear-cli.git
synced 2026-09-14 14:26:50 +08:00
eb6f07499a
When no team can be determined, issue mine (and its list alias) now uses the same message as issue query — 'No default team configured and no team scope provided' — instead of the inaccurate 'Could not determine team key from directory name or team flag' (the team only ever comes from the --team flag, LINEAR_TEAM_ID, or team_id config; directory names are not consulted). The error now carries a suggestion: always offer --team <key>, and when run inside a git work tree, also point at linear config, which links the repository to a team by generating .linear.toml. Repo detection is a new best-effort isInsideGitRepo() helper: any git failure (not a repo, dubious ownership) counts as false so the optional hint can never turn the team error into a git crash. The same stale message remains in cycle-list, cycle-view, team-states, and team-members; those are deferred so they can adopt the helper in a follow-up.
120 lines
3.4 KiB
TypeScript
120 lines
3.4 KiB
TypeScript
import { assertEquals, assertRejects } from "@std/assert"
|
|
import {
|
|
getCurrentBranch,
|
|
getRepoDir,
|
|
isInsideGitRepo,
|
|
} from "../../src/utils/git.ts"
|
|
import { CliError } from "../../src/utils/errors.ts"
|
|
|
|
Deno.test("getCurrentBranch - handles errors when not in a git repository", async () => {
|
|
// Create a temporary directory that's not a git repo
|
|
const tempDir = await Deno.makeTempDir()
|
|
const originalCwd = Deno.cwd()
|
|
|
|
try {
|
|
Deno.chdir(tempDir)
|
|
await assertRejects(
|
|
async () => await getCurrentBranch(),
|
|
CliError,
|
|
"Failed to get current branch",
|
|
)
|
|
} finally {
|
|
Deno.chdir(originalCwd)
|
|
await Deno.remove(tempDir, { recursive: true })
|
|
}
|
|
})
|
|
|
|
Deno.test("getRepoDir - handles errors when not in a git repository", async () => {
|
|
// Create a temporary directory that's not a git repo
|
|
const tempDir = await Deno.makeTempDir()
|
|
const originalCwd = Deno.cwd()
|
|
|
|
try {
|
|
Deno.chdir(tempDir)
|
|
await assertRejects(
|
|
async () => await getRepoDir(),
|
|
CliError,
|
|
"Failed to get repository directory",
|
|
)
|
|
} finally {
|
|
Deno.chdir(originalCwd)
|
|
await Deno.remove(tempDir, { recursive: true })
|
|
}
|
|
})
|
|
|
|
Deno.test("getCurrentBranch - returns null for detached HEAD", async () => {
|
|
// Create a temporary git repository
|
|
const tempDir = await Deno.makeTempDir()
|
|
const originalCwd = Deno.cwd()
|
|
|
|
try {
|
|
Deno.chdir(tempDir)
|
|
|
|
// Initialize git repo
|
|
await new Deno.Command("git", { args: ["init"] }).output()
|
|
await new Deno.Command("git", {
|
|
args: ["config", "user.email", "test@example.com"],
|
|
}).output()
|
|
await new Deno.Command("git", {
|
|
args: ["config", "user.name", "Test User"],
|
|
}).output()
|
|
|
|
// Create a commit
|
|
await Deno.writeTextFile("test.txt", "test")
|
|
await new Deno.Command("git", { args: ["add", "test.txt"] }).output()
|
|
await new Deno.Command("git", {
|
|
args: ["commit", "-m", "initial commit"],
|
|
}).output()
|
|
|
|
// Get the commit hash
|
|
const { stdout } = await new Deno.Command("git", {
|
|
args: ["rev-parse", "HEAD"],
|
|
}).output()
|
|
const commitHash = new TextDecoder().decode(stdout).trim()
|
|
|
|
// Checkout the commit to create detached HEAD
|
|
await new Deno.Command("git", {
|
|
args: ["checkout", commitHash],
|
|
}).output()
|
|
|
|
// getCurrentBranch should return null for detached HEAD
|
|
const branch = await getCurrentBranch()
|
|
assertEquals(branch, null)
|
|
} finally {
|
|
Deno.chdir(originalCwd)
|
|
await Deno.remove(tempDir, { recursive: true })
|
|
}
|
|
})
|
|
|
|
Deno.test("isInsideGitRepo - false in a non-repository directory", async () => {
|
|
const tempDir = await Deno.makeTempDir()
|
|
const originalCwd = Deno.cwd()
|
|
|
|
try {
|
|
Deno.chdir(tempDir)
|
|
assertEquals(await isInsideGitRepo(), false)
|
|
} finally {
|
|
Deno.chdir(originalCwd)
|
|
await Deno.remove(tempDir, { recursive: true })
|
|
}
|
|
})
|
|
|
|
Deno.test("isInsideGitRepo - true inside a git repository, including nested directories", async () => {
|
|
const tempDir = await Deno.makeTempDir()
|
|
const originalCwd = Deno.cwd()
|
|
|
|
try {
|
|
Deno.chdir(tempDir)
|
|
await new Deno.Command("git", { args: ["init"] }).output()
|
|
assertEquals(await isInsideGitRepo(), true)
|
|
|
|
const nested = `${tempDir}/nested/dir`
|
|
await Deno.mkdir(nested, { recursive: true })
|
|
Deno.chdir(nested)
|
|
assertEquals(await isInsideGitRepo(), true)
|
|
} finally {
|
|
Deno.chdir(originalCwd)
|
|
await Deno.remove(tempDir, { recursive: true })
|
|
}
|
|
})
|