diff --git a/internal/source/gitea/gitea.go b/internal/source/gitea/gitea.go index 99c96e3..ca32dbe 100644 --- a/internal/source/gitea/gitea.go +++ b/internal/source/gitea/gitea.go @@ -149,7 +149,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, *g.baseRef) + defer checkout(*wtree, *g.baseRef) g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) if err != nil { @@ -473,11 +473,16 @@ func GetPulls(ctx context.Context, url, owner, repo, password string) ([]*giteaP return pullsAll, nil } -func checkout(w *git.Worktree, ref plumbing.Reference) { +func checkout(w git.Worktree, ref plumbing.Reference) { ctx := context.Background() logger.Debug(ctx, fmt.Sprintf("Checkout: %s", ref.Name().Short())) - if err := w.Checkout(&git.CheckoutOptions{Hash: ref.Hash()}); err != nil { - logger.Fatal(ctx, fmt.Sprintf("failed to reset: %v", err)) + if err := w.Checkout(&git.CheckoutOptions{ + Branch: ref.Name(), + Create: false, + Force: true, + Keep: false, + }); err != nil { + logger.Error(ctx, fmt.Sprintf("failed to reset: %v", err)) } } diff --git a/internal/source/github/github.go b/internal/source/github/github.go index 9c15271..972457e 100644 --- a/internal/source/github/github.go +++ b/internal/source/github/github.go @@ -148,7 +148,7 @@ func (g *Github) RequestOpen(ctx context.Context, branch string, path string, mo if err != nil { logger.Fatal(ctx, fmt.Sprintf("failed to get worktree: %v", err)) } - defer checkout(wtree, *g.baseRef) + defer checkout(*wtree, *g.baseRef) g.pulls, err = GetPulls(ctx, g.URL, g.Owner, g.Repository, g.Password) if err != nil { @@ -376,11 +376,16 @@ func GetPulls(ctx context.Context, url, owner, repo, password string) ([]*github return pullsAll, nil } -func checkout(w *git.Worktree, ref plumbing.Reference) { +func checkout(w git.Worktree, ref plumbing.Reference) { ctx := context.Background() logger.Debug(ctx, fmt.Sprintf("Checkout: %s", ref.Name().Short())) - if err := w.Checkout(&git.CheckoutOptions{Hash: ref.Hash()}); err != nil { - logger.Fatal(ctx, fmt.Sprintf("failed to reset: %v", err)) + if err := w.Checkout(&git.CheckoutOptions{ + Branch: ref.Name(), + Create: false, + Force: true, + Keep: false, + }); err != nil { + logger.Error(ctx, fmt.Sprintf("failed to reset: %v", err)) } }