From 84e8cff4e0ff8733b913ea2c12dcec789eb98013 Mon Sep 17 00:00:00 2001 From: Valentin Kiselev Date: Tue, 23 Jul 2024 10:42:14 +0300 Subject: [PATCH] chore: small cosmetic changes --- cmd/commands_no_self_update.go | 2 +- internal/updater/updater.go | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmd/commands_no_self_update.go b/cmd/commands_no_self_update.go index 7c6a591e..56daa0d5 100644 --- a/cmd/commands_no_self_update.go +++ b/cmd/commands_no_self_update.go @@ -9,7 +9,7 @@ import ( ) type command interface { - add(*lefthook.Options) *cobra.Command + New(*lefthook.Options) *cobra.Command } var commands = [...]command{ diff --git a/internal/updater/updater.go b/internal/updater/updater.go index d178c6c9..a9f6ed72 100644 --- a/internal/updater/updater.go +++ b/internal/updater/updater.go @@ -77,7 +77,7 @@ func (u *Updater) SelfUpdate(ctx context.Context, yes, force bool) error { latestVersion := strings.TrimPrefix(rel.TagName, "v") if latestVersion == version.Version(false) && !force { - log.Infof("Already installed the latest version: %s\n", latestVersion) + log.Infof("Up to date: %s\n", latestVersion) return nil } @@ -140,7 +140,6 @@ func (u *Updater) SelfUpdate(ctx context.Context, yes, force bool) error { destPath := lefthookExePath + "." + latestVersion defer os.Remove(destPath) - log.Debugf("Downloading to %s", destPath) ok, err := u.download(ctx, wantedAsset, downloadURL, checksumURL, destPath) if err != nil { return err @@ -152,12 +151,12 @@ func (u *Updater) SelfUpdate(ctx context.Context, yes, force bool) error { backupPath := lefthookExePath + ".bak" defer os.Remove(backupPath) - log.Debugf("Renaming %s -> %s", lefthookExePath, backupPath) + log.Debugf("mv %s %s", lefthookExePath, backupPath) if err = os.Rename(lefthookExePath, backupPath); err != nil { return fmt.Errorf("failed to backup lefthook executable: %w", err) } - log.Debugf("Renaming %s -> %s", destPath, lefthookExePath) + log.Debugf("mv %s %s", destPath, lefthookExePath) err = os.Rename(destPath, lefthookExePath) if err != nil { log.Errorf("Failed to replace the lefthook executable: %s\n", err) @@ -168,7 +167,7 @@ func (u *Updater) SelfUpdate(ctx context.Context, yes, force bool) error { return nil } - log.Debugf("Making file %s executable", lefthookExePath) + log.Debugf("chmod +x %s", lefthookExePath) if err = os.Chmod(lefthookExePath, modExecutable); err != nil { return fmt.Errorf("failed to set mod executable: %w", err) } @@ -199,6 +198,8 @@ func (u *Updater) fetchLatestRelease(ctx context.Context) (*release, error) { } func (u *Updater) download(ctx context.Context, name, fileURL, checksumURL, path string) (bool, error) { + log.Debugf("Downloading %s to %s", fileURL, path) + filereq, err := http.NewRequestWithContext(ctx, http.MethodGet, fileURL, nil) if err != nil { return false, fmt.Errorf("failed to build download request: %w", err)