Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions runtime/drivers/admin/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"time"

"github.com/bmatcuk/doublestar/v4"
"github.com/go-git/go-git/v5"
"github.com/rilldata/rill/cli/pkg/gitutil"
cligitutil "github.com/rilldata/rill/cli/pkg/gitutil"
adminv1 "github.com/rilldata/rill/proto/gen/rill/admin/v1"
"github.com/rilldata/rill/runtime/drivers"
"github.com/rilldata/rill/runtime/pkg/ctxsync"
"github.com/rilldata/rill/runtime/pkg/filewatcher"
"github.com/rilldata/rill/runtime/pkg/gitutil"
"go.uber.org/zap"
"golang.org/x/sync/singleflight"
"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -453,29 +453,25 @@ func (r *repo) Status(ctx context.Context, remoteBranch string) (*drivers.RepoSt
return &drivers.RepoStatus{}, nil
}

repo, err := git.PlainOpen(r.git.repoDir)
currentBranch, err := currentBranch(r.git.repoDir)
if err != nil {
return nil, err
}
head, err := repo.Head()
if err != nil {
return nil, err
}
branches := []string{head.Name().Short()}
branches := []string{currentBranch}

// If a remote branch was explicitly requested and it differs from the current branch, fetch it too
// so that ahead/behind counts in RunGitStatus have an up-to-date remote tracking ref to compare against.
if remoteBranch != "" && remoteBranch != branches[0] {
branches = append(branches, remoteBranch)
}

err = r.git.fetchBranch(ctx, repo, branches...)
err = gitutil.FetchBranches(ctx, r.git.repoDir, branches...)
if err != nil {
return nil, fmt.Errorf("failed to fetch branches %q: %w", branches, err)
}

// run git status
st, err := gitutil.RunGitStatus(r.git.repoDir, r.git.subpath, "origin", remoteBranch)
st, err := cligitutil.RunGitStatus(r.git.repoDir, r.git.subpath, "origin", remoteBranch)
if err != nil {
return nil, fmt.Errorf("failed to get Git status: %w", err)
}
Expand Down Expand Up @@ -505,11 +501,7 @@ func (r *repo) Commit(ctx context.Context, message string) (string, error) {
if !r.git.editable() {
return "", fmt.Errorf("repo is not editable")
}
repo, err := git.PlainOpen(r.git.repoDir)
if err != nil {
return "", err
}
return r.git.commitAll(repo, message)
return gitutil.CommitAll(ctx, r.git.repoDir, r.git.subpath, message, "Rill", "noreply@rilldata.com")
}

// Pull implements drivers.RepoStore.
Expand Down Expand Up @@ -564,7 +556,7 @@ func (r *repo) CommitHash(ctx context.Context) (string, error) {
if r.archive != nil {
return r.archive.archiveID, nil
}
return r.git.commitHash()
return r.git.commitHash(ctx)
}

// CommitTimestamp implements drivers.RepoStore.
Expand All @@ -578,7 +570,7 @@ func (r *repo) CommitTimestamp(ctx context.Context) (time.Time, error) {
if r.archive != nil {
return r.archive.archiveCreatedOn, nil
}
return r.git.commitTimestamp()
return r.git.commitTimestamp(ctx)
}

// close deletes the temporary directories used by the repo.
Expand Down Expand Up @@ -837,6 +829,11 @@ func (r *repo) checkHandshake(ctx context.Context, force bool) error {
if err != nil {
return fmt.Errorf("failed to get git data dir: %w", err)
}
// Resolve to an absolute path so that `git -C <repoDir>` does not depend on the process working directory.
repoDir, err = filepath.Abs(repoDir)
if err != nil {
return fmt.Errorf("failed to resolve git data dir: %w", err)
}
r.git = &gitRepo{
h: r.h,
repoDir: repoDir,
Expand Down
Loading
Loading