Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard Reset corrupts git directory if failed when cloned using git cli #878

Closed
rohitsakala opened this issue Oct 13, 2023 · 1 comment · Fixed by #1048
Closed

Hard Reset corrupts git directory if failed when cloned using git cli #878

rohitsakala opened this issue Oct 13, 2023 · 1 comment · Fixed by #1048

Comments

@rohitsakala
Copy link

rohitsakala commented Oct 13, 2023

Steps to Reproduce

       openOptions := git.PlainOpenOptions{
		DetectDotGit: false,
	}

	// git clone --depth 1 https://git.rancher.io/charts --branch dev-v2.8
	repo, err := git.PlainOpenWithOptions("/Users/RSAKALA/temp/charts", &openOptions)
	if err != nil {
		fmt.Println(err)
		return
	}

	// Ensure

	// Hard Reset to commit
	resetOpts := git.ResetOptions{
		Mode: git.HardReset,
	}
	resetOpts.Commit = plumbing.NewHash("6a2b15c6f6487b4db16f10d8ec69bb8bf91dcabd")

	// Validate hashCommit and reset options
	err = resetOpts.Validate(repo)
	if err != nil {
		fmt.Println("hardReset validation failure: %w", err)
	}

	// Open new worktree
	wt, err := repo.Worktree()
	if err != nil {
		fmt.Println("hardReset failure on WorkTree: %w", err)
	}

	// Reset
	err = wt.Reset(&resetOpts)
	if err != nil {
		fmt.Println("hardReset failure: %w", err)
	} else {
		fmt.Println("Hard Reset Worked")
		return
	}
  • Run git log

Output

fatal: bad object HEAD
@pjbgf
Copy link
Member

pjbgf commented Oct 13, 2023

@rohitsakala can you please share the error message you are getting? Please note that the code snippet above only gets the worktree and does not actually run the hard reset.

@rohitsakala rohitsakala changed the title Hard Reset doesn't work when cloned using git cli Hard Reset corrupts git directory if failed when cloned using git cli Oct 13, 2023
pjbgf added a commit to pjbgf/go-git that referenced this issue Mar 11, 2024
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
pjbgf added a commit to pjbgf/go-git that referenced this issue Mar 11, 2024
Signed-off-by: Paulo Gomes <paulo.gomes@suse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants