mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-30 11:52:04 +00:00
fix(desktop): clarify branch convert actions
Open checked-out branches, switch the primary checkout for the default branch, and create linked worktrees only for non-trunk free branches.
This commit is contained in:
parent
9f3aa1685c
commit
19ca295a84
13 changed files with 433 additions and 187 deletions
|
|
@ -108,14 +108,36 @@ test('listBranches: lists locals and flags the checked-out branch', async () =>
|
|||
assert.deepEqual(names, [current, 'feature'].sort())
|
||||
// The repo's own checkout is flagged; the unused branch is convertible.
|
||||
assert.equal(branches.find(b => b.name === current).checkedOut, true)
|
||||
assert.equal(branches.find(b => b.name === current).isDefault, true)
|
||||
assert.equal(fs.realpathSync(branches.find(b => b.name === current).worktreePath), fs.realpathSync(dir))
|
||||
assert.equal(branches.find(b => b.name === 'feature').checkedOut, false)
|
||||
assert.equal(branches.find(b => b.name === 'feature').isDefault, false)
|
||||
assert.equal(branches.find(b => b.name === 'feature').worktreePath, null)
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('listBranches: flags a free default branch as default, not checked out', async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-branches-default-'))
|
||||
const git = (...args) => execFileSync('git', args, { cwd: dir }).toString().trim()
|
||||
|
||||
try {
|
||||
await ensureGitRepo('git', dir)
|
||||
const trunk = git('branch', '--show-current')
|
||||
execFileSync('git', ['switch', '-c', 'rawr'], { cwd: dir })
|
||||
|
||||
const branches = await listBranches(dir, 'git')
|
||||
const defaultBranch = branches.find(b => b.name === trunk)
|
||||
|
||||
assert.equal(defaultBranch.checkedOut, false)
|
||||
assert.equal(defaultBranch.isDefault, true)
|
||||
assert.equal(defaultBranch.worktreePath, null)
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('listBranches: a branch claimed by a worktree is flagged checked out', async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-branches-wt-'))
|
||||
|
||||
|
|
@ -170,3 +192,23 @@ test('addWorktree: existingBranch checks the branch out without a new branch', a
|
|||
fs.rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test('addWorktree: existing default branch switches the main checkout, not .worktrees/main', async () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'hermes-convert-default-'))
|
||||
const git = (...args) => execFileSync('git', args, { cwd: dir }).toString().trim()
|
||||
|
||||
try {
|
||||
await ensureGitRepo('git', dir)
|
||||
const trunk = git('branch', '--show-current')
|
||||
execFileSync('git', ['switch', '-c', 'rawr'], { cwd: dir })
|
||||
|
||||
const result = await addWorktree(dir, { existingBranch: trunk }, 'git')
|
||||
|
||||
assert.equal(result.branch, trunk)
|
||||
assert.equal(fs.realpathSync(result.path), fs.realpathSync(dir))
|
||||
assert.equal(git('branch', '--show-current'), trunk)
|
||||
assert.equal(fs.existsSync(path.join(dir, '.worktrees', trunk)), false)
|
||||
} finally {
|
||||
fs.rmSync(dir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue