Staged area modified after cross branch checkout
未关闭
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 1.7k
- 派生
- 408
- 平均合并
- 2 天 57 分钟
- 30 天内合并 PR
- 7
描述
I created two branches with commits like this:
Then I call checkout to switch the branch from old_master to master. Somehow, the cached area is updated after checkout:
Here's the code toe reproduce
import pathlib
import pygit2
def test_checkout(tmp_path: pathlib.Path):
repo_dir = tmp_path
git_author = pygit2.Signature(name="foo", email="foo@bar.com")
repo = pygit2.init_repository(str(repo_dir))
workdir = pathlib.Path(repo.workdir)
readme = workdir / "README.md"
readme.write_text("commit0")
index = repo.index
index.add(readme.relative_to(workdir).as_posix())
index.write()
tree = index.write_tree()
commit0 = repo.create_commit("HEAD", git_author, git_author, "commit0", tree, [])
master_branch = repo.branches.local["master"]
old_master_branch = repo.branches.local.create("old_master", master_branch.peel())
readme.write_text("commit1")
index = repo.index
index.add(readme.relative_to(workdir).as_posix())
index.write()
tree = index.write_tree()
repo.create_commit(repo.head.name, git_author, git_author, "commit1", tree, [commit0])
repo.checkout(old_master_branch)
readme.write_text("commit2")
index = repo.index
index.add(readme.relative_to(workdir).as_posix())
index.write()
tree = index.write_tree()
repo.create_commit(repo.head.name, git_author, git_author, "commit2", tree, [commit0])
repo.checkout(master_branch)
# the staged area should be empty after checkout
assert not list(repo.index)
I tried it with git checkout master and it works fine without changing the staged area.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先运行提供的 test_checkout 复现程序,并检查两次分支切换期间 repo.checkout 和 repo.index 的行为。返回 master 后,将已暂存的 index 与预期的空状态进行比较,并根据所描述的 git checkout 行为验证结果。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- git, python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100