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

View File

@ -138,6 +138,7 @@ func (g *Gitlab) 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, *headRef)
g.pulls, err = GetPulls(ctx, g.URL, g.RepositoryId, branch, g.Password)
if err != nil && err != ErrPRNotExist {
@ -159,7 +160,7 @@ func (g *Gitlab) RequestOpen(ctx context.Context, branch string, path string, mo
logger.Info(ctx, "reset worktree")
if err = wtree.Reset(&git.ResetOptions{Commit: headRef.Hash(), Mode: git.HardReset}); err != nil {
logger.Error(ctx, fmt.Sprintf("failed to reset repo branch: %v", err))
} //вроде меняем ветку todo вроде можно удалить
}
if err = wtree.PullContext(ctx, &git.PullOptions{
Auth: &httpauth.BasicAuth{Username: g.Username, Password: g.Password},
@ -446,3 +447,10 @@ func GetPulls(ctx context.Context, url, projectId, branch, password string) ([]*
return nil, fmt.Errorf("unknown error: %s", buf)
}
}
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))
}
}