-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
bugSomething isn't workingSomething isn't working
Description
本地的 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
的实现,但貌似有问题没有生效
hok/crates/libscoop/src/internal/git.rs
Lines 59 to 83 in 24421ea
// 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
Labels
bugSomething isn't workingSomething isn't working