This repository was archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 534
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
Hard reset leaves dirty worktree #923
Copy link
Copy link
Closed
Description
It seems for some cases hard reset is failing to do a hard reset. Here is a script to reproduce it:
package main
import (
"flag"
"gopkg.in/src-d/go-git.v4"
. "gopkg.in/src-d/go-git.v4/_examples"
"gopkg.in/src-d/go-git.v4/plumbing"
"os"
)
func main() {
cloneDirPtr := flag.String("clone-dir", os.Args[0], "Directory to clone")
cloneUrlPtr := flag.String("clone-url", "https://github.com/flutter/flutter", "URL to clone")
shaPtr := flag.String("sha", "", "sha to clone")
flag.Parse()
cloneOptions := git.CloneOptions{
URL: *cloneUrlPtr,
ReferenceName: plumbing.ReferenceName("refs/heads/master"),
SingleBranch: true,
Progress: os.Stdout,
Tags: git.NoTags,
}
repo, err := git.PlainClone(*cloneDirPtr, false, &cloneOptions)
CheckIfError(err)
reference, err := repo.Head()
CheckIfError(err)
Info("Cloned! Head at %s", reference)
workTree, err := repo.Worktree()
CheckIfError(err)
err = workTree.Reset(&git.ResetOptions{
Commit: plumbing.NewHash(*shaPtr),
Mode: git.HardReset,
})
CheckIfError(err)
Info("Hard reseted to %s", *shaPtr)
status, err := workTree.Status()
CheckIfError(err)
Info("Status after reset: %s", status)
}
Run it for flutter repository:
go run main.go --clone-dir=temp --clone-url=https://github.com/flutter/flutter --sha 393f9276ca079e15de5f97cf902d4ef8181e50c0
It prints:
Cloned! Head at 809721d0ee495ee555149b22679464e882b9fece refs/heads/master
Hard reseted to 393f9276ca079e15de5f97cf902d4ef8181e50c0
Status after reset:
Which indicates that it cloned and hard reseted. Worktree is clean.
But if you run cd temp && git status
you'll see:
On branch master
Your branch is behind 'origin/master' by 18 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: packages/flutter_tools/lib/src/android/gradle.dart
modified: packages/flutter_tools/test/android/android_sdk_test.dart
modified: packages/flutter_tools/test/android/android_workflow_test.dart
no changes added to commit (use "git add" and/or "git commit -a")
Which indicates that the worktree on FS is actually dirty: there are three modified files.
This is related to cirruslabs/cirrus-ci-docs#38
Metadata
Metadata
Assignees
Labels
No labels