Skip to content

hok update 无法正确处理 git 冲突 #31

@xrgzs

Description

@xrgzs

本地的 commit 和远端不一致时,hok 无法正确实现 git reset --hard origin/HEAD 的效果

问题截图

使用 hok update,无法强制更新:

使用 git reset --hard origin/HEAD,可以看到本地的 commit 被 reset 了:

问题复现

# 切换到一个具有远端地址的 bucket
Set-Location "$env:USERPROFILE\scoop\buckets\main"

# 创建若干个 commit
"aaa" > 1.txt
git add 1.txt
git commit -m "local1"
"bbb" > 2.txt
git add 2.txt
git commit -m "local2"

# 使用 hok 更新 buckets
hok update

# 查看 commit 是否被重置
git status

相关代码

git reset --hard origin/HEAD 的实现,但貌似有问题没有生效

// NOTE: this will discard all local changes.
pub fn reset_head<P, S>(path: P, proxy: Option<S>) -> Fallible<()>
where
P: AsRef<Path>,
S: AsRef<str>,
{
let proxy = proxy.as_ref().map(|s| s.as_ref());
let repo = Repository::open(path.as_ref())?;
let mut origin = repo.find_remote("origin")?;
// fetch all refs
origin.fetch(
&["refs/heads/*:refs/heads/*"],
Some(&mut fetch_options(proxy)),
None,
)?;
let head = repo.head()?.target().unwrap();
let obj = repo.find_object(head, None)?;
repo.reset(&obj, git2::ResetType::Hard, None)?;
Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions