Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve informational printouts in update-all and update #37

Merged
merged 2 commits into from
Mar 23, 2023
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
26 changes: 12 additions & 14 deletions cmd/git-bundle-server/update-all.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"context"
"os"
"os/exec"
"fmt"
vdye marked this conversation as resolved.
Show resolved Hide resolved

"github.com/github/git-bundle-server/cmd/utils"
"github.com/github/git-bundle-server/internal/argparse"
"github.com/github/git-bundle-server/internal/cmd"
"github.com/github/git-bundle-server/internal/common"
"github.com/github/git-bundle-server/internal/core"
"github.com/github/git-bundle-server/internal/log"
)
Expand Down Expand Up @@ -37,13 +38,15 @@ func (u *updateAllCmd) Run(ctx context.Context, args []string) error {
parser.Parse(ctx, args)

repoProvider := utils.GetDependency[core.RepositoryProvider](ctx, u.container)
fileSystem := utils.GetDependency[common.FileSystem](ctx, u.container)
commandExecutor := utils.GetDependency[cmd.CommandExecutor](ctx, u.container)

repos, err := repoProvider.GetRepositories(ctx)
if err != nil {
return u.logger.Error(ctx, err)
}

exe, err := os.Executable()
exe, err := fileSystem.GetLocalExecutable("git-bundle-server")
if err != nil {
return u.logger.Errorf(ctx, "failed to get path to execuable: %w", err)
}
Expand All @@ -53,19 +56,14 @@ func (u *updateAllCmd) Run(ctx context.Context, args []string) error {

for route := range repos {
subargs[1] = route
cmd := exec.Command(exe, subargs...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

err := cmd.Start()
if err != nil {
return u.logger.Errorf(ctx, "git command failed to start: %w", err)
}

err = cmd.Wait()
fmt.Printf("*** Updating %s ***\n", route)
exitCode, err := commandExecutor.RunStdout(ctx, exe, subargs...)
if err != nil {
return u.logger.Errorf(ctx, "git command returned a failure: %w", err)
return u.logger.Error(ctx, err)
} else if exitCode != 0 {
return u.logger.Errorf(ctx, "git-bundle-server update exited with status %d", exitCode)
}
fmt.Print("\n")
}

return nil
Expand Down
8 changes: 5 additions & 3 deletions cmd/git-bundle-server/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,32 @@ func (u *updateCmd) Run(ctx context.Context, args []string) error {
return u.logger.Errorf(ctx, "failed to load bundle list: %w", err)
}

fmt.Printf("Creating new incremental bundle\n")
fmt.Printf("Checking for updates to %s\n", repo.Route)
bundle, err := bundleProvider.CreateIncrementalBundle(ctx, repo, list)
if err != nil {
return u.logger.Error(ctx, err)
}

// Nothing new!
if bundle == nil {
fmt.Printf("%s is up-to-date, no new bundles generated\n", repo.Route)
return nil
}

list.Bundles[bundle.CreationToken] = *bundle

fmt.Printf("Collapsing bundle list\n")
fmt.Println("Updating bundle list")
err = bundleProvider.CollapseList(ctx, repo, list)
if err != nil {
return u.logger.Error(ctx, err)
}

fmt.Printf("Writing updated bundle list\n")
fmt.Println("Writing updated bundle list")
listErr := bundleProvider.WriteBundleList(ctx, list, repo)
if listErr != nil {
return u.logger.Errorf(ctx, "failed to write bundle list: %w", listErr)
}

fmt.Println("Update complete")
return nil
}