blob: 9c32070eefb6a436c01153db68ce0daa4505f31c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package localrepo
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"gitlab.com/gitlab-org/gitaly/v15/internal/archive"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/v15/internal/structerr"
)
// GetCustomHooks writes the git hooks for a repository to out. The hooks are
// written in a tar archive containing a `custom_hooks` directory. If no hooks
// are present in the repository, the response will have no data.
func (repo *Repo) GetCustomHooks(ctx context.Context, out io.Writer) error {
repoPath, err := repo.locator.GetRepoPath(repo)
if err != nil {
return fmt.Errorf("getting repo path: %w", err)
}
if _, err := os.Lstat(filepath.Join(repoPath, hook.CustomHooksDir)); os.IsNotExist(err) {
return nil
}
if err := archive.WriteTarball(ctx, out, repoPath, hook.CustomHooksDir); err != nil {
return structerr.NewInternal("archiving hooks: %w", err)
}
return nil
}
|