makecindy / makecindy/cindy

bug: Worktree 创建后残留全局 safe.directory 配置

Open
#2,627 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
2.7k
Forks
401
Avg merge
21h 40m
Merged PRs (30d)
805

Description

**提交人**: 匿名
**客户端版本**: 0.1.46

---

## 现象

Cindy Desktop 创建 Git worktree(工作树)后,会无条件执行:

```text
git config --global --add safe.directory
```

该操作不依赖 Git 是否实际返回过 `dubious ownership`。底层 Git 执行器在检测到该错误时也会按需写入相同配置,因此某些路径可能被重复添加。

删除或归档 worktree 后,对应的 `safe.directory` 条目不会被清理,导致用户全局 Git 配置中长期残留已不存在的绝对路径。

这不是安全漏洞,而是全局配置污染和 worktree 生命周期清理问题。

## 复现步骤

1. 在 Cindy Desktop 中为一个 Git 仓库启用 worktree 会话。
2. 创建一个 worktree。
3. 检查全局 Git 配置:

```bash
git config --global --get-all safe.directory
```

4. 即使创建过程中没有出现 `dubious ownership`,也能看到新 worktree 路径。
5. 删除或归档该 worktree。
6. 再次检查配置,已删除的 worktree 路径仍然存在。

使用临时 `GIT_CONFIG_GLOBAL` 文件进行隔离验证时,同一路径重复执行 `--add` 会产生重复记录;执行 `git worktree remove` 不会自动移除这些记录。

## 期望行为

- 正常创建同一用户拥有的 worktree 时,不修改全局 Git 配置。
- 只有 Git 实际返回 `dubious ownership` 时,才添加对应的精确路径并重试一次。
- 删除或归档 worktree 时,清理由 Cindy 添加的 `safe.directory`。
- 不重复添加,也不删除用户原本手动配置的同一路径。

## 相关代码

- `apps/desktop/src/main/worktree/WorktreeManager.ts`:创建成功后无条件添加 `safe.directory`
- `apps/desktop/src/main/worktree/gitExec.ts`:检测到 `dubious ownership` 后按需添加并重试
- worktree 删除流程没有对应的 `safe.directory` 清理逻辑

## 已尝试

已通过源码检查和隔离 Git 配置探针确认该行为;目前没有修改源码。
---
**版本区域**: CN
**OS**: darwin arm64 (24.6.0)
**界面语言**: zh-CN

Contributor guide

Open the contributing guide

Research direction

Start with apps/desktop/src/main/worktree/WorktreeManager.ts and gitExec.ts, then trace the worktree deletion and archive flows for their configuration handling. Reproduce with an isolated GIT_CONFIG_GLOBAL file and inspect the existing safe.directory entries before and after creation and removal. Done means conditional, non-duplicating entries are cleaned up without removing matching paths that were already user-configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, typescript
Domain
desktop, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.