diff options
Diffstat (limited to 'internal/gitaly/service/repository/fullpath.go')
-rw-r--r-- | internal/gitaly/service/repository/fullpath.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/fullpath.go b/internal/gitaly/service/repository/fullpath.go new file mode 100644 index 000000000..9fdf70c99 --- /dev/null +++ b/internal/gitaly/service/repository/fullpath.go @@ -0,0 +1,43 @@ +package repository + +import ( + "context" + "fmt" + + "gitlab.com/gitlab-org/gitaly/v14/internal/git" + "gitlab.com/gitlab-org/gitaly/v14/internal/helper" + "gitlab.com/gitlab-org/gitaly/v14/proto/go/gitalypb" +) + +const fullPathKey = "gitlab.fullpath" + +// SetFullPath writes the provided path value into the repository's gitconfig under the +// "gitlab.fullpath" key. +func (s *server) SetFullPath( + ctx context.Context, + request *gitalypb.SetFullPathRequest, +) (*gitalypb.SetFullPathResponse, error) { + if request.GetRepository() == nil { + return nil, helper.ErrInvalidArgumentf("empty Repository") + } + + if len(request.GetPath()) == 0 { + return nil, helper.ErrInvalidArgumentf("no path provided") + } + + repo := s.localrepo(request.GetRepository()) + + if err := s.voteOnConfig(ctx, request.GetRepository()); err != nil { + return nil, helper.ErrInternal(fmt.Errorf("preimage vote on config: %w", err)) + } + + if err := repo.Config().Add(ctx, fullPathKey, request.GetPath(), git.ConfigAddOpts{}); err != nil { + return nil, helper.ErrInternal(fmt.Errorf("writing config: %w", err)) + } + + if err := s.voteOnConfig(ctx, request.GetRepository()); err != nil { + return nil, helper.ErrInternal(fmt.Errorf("postimage vote on config: %w", err)) + } + + return &gitalypb.SetFullPathResponse{}, nil +} |