#8 fix checkout.

This commit is contained in:
Gorbunov Kirill Andreevich 2024-04-21 15:46:14 +03:00
parent cb209a6a7a
commit a5d39c23f8
2 changed files with 18 additions and 8 deletions

View File

@ -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))
}
}

View File

@ -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))
}
}