Skip to content

Commit

Permalink
fix: correct update bug when no package manager ⚓ (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx authored Sep 24, 2024
1 parent 2518709 commit c32950f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
9 changes: 3 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,18 @@
};

# Things needed only at compile-time.
nativeBuildInputs = with pkgs; [
packages = with pkgs; [
golines
go_1_22
];

# Things needed at runtime.
buildInputs = with pkgs; [ ];
in
with pkgs;
{
devShells.default = mkShell {
# To make CGO and the debugger delve work.
# https://nixos.wiki/wiki/Go#Using_cgo_on_NixOS
hardeningDisable = [ "fortify" ];

inherit buildInputs nativeBuildInputs;
inherit packages;
};
}
);
Expand Down
4 changes: 2 additions & 2 deletions githooks/cmd/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func runInstallDispatched(
// Only do an update if enabled and we either have
// given the update flag or its an auto-update
// call.
doUpdate := updates.Enabled && args.Update && status.IsUpdateAvailable
doUpdate := updates.UpdateEnabled && args.Update && status.IsUpdateAvailable

tag := ""
commit := ""
Expand Down Expand Up @@ -1282,7 +1282,7 @@ func runInstaller(
args.DryRun,
uiSettings)

if updates.Enabled {
if updates.UpdateEnabled {
setupAutomaticUpdateChecks(log, gitx, args.NonInteractive, args.DryRun, uiSettings.PromptCtx)
}

Expand Down
2 changes: 1 addition & 1 deletion githooks/updates/update-enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import "github.com/gabyx/githooks/githooks/common"

const (
// Only allow update if not using a package manager.
Enabled = !common.PackageManagerEnabled
UpdateEnabled = !common.PackageManagerEnabled
)
25 changes: 15 additions & 10 deletions githooks/updates/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func FetchUpdates(
return
}
}
remoteBranch := DefaultRemote + "/" + branch

// Set the url/branch back...
if setGitConfig {
Expand All @@ -256,12 +257,17 @@ func FetchUpdates(
}
}

// We reset local branch
// to the matching current release tag descending from HEAD.
// Remote stays and might trigger a direct update.
branchFrom := "HEAD"
if !UpdateEnabled {
// When updates disabled we do the check onto the remote branch.
branchFrom = remoteBranch
}

// Check if current tag is reachable from HEAD.
reachable, e := git.IsRefReachable(gitx, "HEAD", tag)
// We reset local branch to the matching
// current release tag descending from the HEAD branch.
// Remote stays and might trigger a direct update.
// Check if current tag is reachable from the remote branch.
reachable, e := git.IsRefReachable(gitx, branchFrom, tag)
if e != nil || !reachable {
err = cm.CombineErrors(
cm.ErrorF("Current version tag '%v' could not be found on branch '%s'",
Expand All @@ -280,7 +286,6 @@ func FetchUpdates(
}

resetRemoteTo := ""
remoteBranch := DefaultRemote + "/" + branch
status, err = getStatus(gitx, url, DefaultRemote, branch, remoteBranch, usePreRelease)

status.IsNewClone = isNewClone
Expand Down Expand Up @@ -541,7 +546,7 @@ func FormatUpdateText(status *ReleaseStatus, withUpdateHint bool) (versionText s

versionText = "There is a new Githooks update available:"

if Enabled {
if UpdateEnabled {
cmd := "git hooks update"
if strs.IsNotEmpty(status.UpdateVersion.Prerelease()) {
cmd += " --use-pre-release"
Expand Down Expand Up @@ -590,7 +595,7 @@ func DefaultAcceptUpdateCallback(
promptDefault = "y/N"
}

if Enabled && promptx != nil {
if UpdateEnabled && promptx != nil {
question := versionText + "\n" +
"Would you like to install it now?"

Expand All @@ -609,7 +614,7 @@ func DefaultAcceptUpdateCallback(
} else {
log.InfoF("There is a new Githooks update available:\n%s", versionText)

if Enabled {
if UpdateEnabled {
if acceptNonInteractive == AcceptNonInteractiveAll ||
(!isMajorUpdate && acceptNonInteractive == AcceptNonInteractiveOnlyNonMajor) {
log.InfoF("Going to install version: '%s'.", status.UpdateVersion.String())
Expand All @@ -633,7 +638,7 @@ func RunUpdateOverExecutable(
pipeSetup cm.PipeSetupFunc,
args ...string) error {

if !Enabled {
if !UpdateEnabled {
return cm.Error("Updates have been disabled in this build of Githooks.")
}

Expand Down

0 comments on commit c32950f

Please sign in to comment.