#8 reset branch before return.

This commit is contained in:
Gorbunov Kirill Andreevich
2024-04-04 23:57:32 +03:00
parent 92075a8145
commit d055412753
2 changed files with 17 additions and 1 deletions

View File

@@ -140,6 +140,7 @@ func (g *Gitea) RequestOpen(ctx context.Context, branch string, path string, mod
if err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err))
}
defer checkout(wtree, *headRef)
g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password)
if err != nil && err != ErrPRNotExist {
@@ -462,3 +463,10 @@ func GetPulls(ctx context.Context, url, owner, repo, password string) ([]*giteaP
return pullsAll, nil
}
func checkout(w *git.Worktree, ref plumbing.Reference) {
ctx := context.Background()
if err := w.Reset(&git.ResetOptions{Commit: ref.Hash(), Mode: git.HardReset}); err != nil {
logger.Fatal(ctx, fmt.Sprintf("failed to reset: %v", err))
}
}