diff --git a/.circleci/config.yml b/.circleci/config.yml index 15c06aa1..09b31cc1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,7 +12,7 @@ jobs: default: "test-alpine" type: string machine: - image: ubuntu-2004:202010-01 + image: ubuntu-2204:current steps: - checkout - run: bash tests/<>.sh @@ -30,12 +30,15 @@ jobs: executor: size: medium name: win/server-2022 - version: 2023.11.1 + version: current steps: - checkout - run: no_output_timeout: 30m - command: "& 'C:/Program Files/Git/bin/bash.exe' -c 'tests/<>.sh --seq <>'" + command: < + & 'C:/Program Files/Git/bin/bash.exe' + -c 'tests/<>.sh + --seq <>' workflows: version: 2 diff --git a/flake.lock b/flake.lock index 736c73d5..6e347518 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1726560853, + "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1702312524, - "narHash": "sha256-gkZJRDBUCpTPBvQk25G0B7vfbpEYM5s5OZqghkjZsnE=", + "lastModified": 1726463316, + "narHash": "sha256-gI9kkaH0ZjakJOKrdjaI/VbaMEo9qBbSUl93DnU7f4c=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a9bf124c46ef298113270b1f84a164865987a91c", + "rev": "99dc8785f6a0adac95f5e2ab05cc2e1bf666d172", "type": "github" }, "original": { @@ -36,11 +36,11 @@ }, "nixpkgsStable": { "locked": { - "lastModified": 1702233072, - "narHash": "sha256-H5G2wgbim2Ku6G6w+NSaQaauv6B6DlPhY9fMvArKqRo=", + "lastModified": 1720535198, + "narHash": "sha256-zwVvxrdIzralnSbcpghA92tWu2DV2lwv89xZc8MTrbg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "781e2a9797ecf0f146e81425c822dca69fe4a348", + "rev": "205fd4226592cc83fd4c0885a3e4c9c400efabb5", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index af39704a..a8bdee4c 100644 --- a/flake.nix +++ b/flake.nix @@ -27,41 +27,44 @@ flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { - self, - nixpkgs, - nixpkgsStable, - flake-utils, - ... - } @ inputs: + outputs = + { + self, + nixpkgs, + nixpkgsStable, + flake-utils, + ... + }@inputs: flake-utils.lib.eachDefaultSystem - # Creates an attribute map `{ devShells..default = ...}` - # by calling this function: - ( - system: let - overlays = []; + # Creates an attribute map `{ devShells..default = ...}` + # by calling this function: + ( + system: + let + overlays = [ ]; - # Import nixpkgs and load it into pkgs. - pkgs = import nixpkgs { - inherit system overlays; - }; + # Import nixpkgs and load it into pkgs. + pkgs = import nixpkgs { + inherit system overlays; + }; - # Things needed only at compile-time. - nativeBuildInputs = with pkgs; [ - go_1_21 - ]; + # Things needed only at compile-time. + nativeBuildInputs = with pkgs; [ + go_1_22 + ]; - # Things needed at runtime. - buildInputs = with pkgs; []; - in - with pkgs; { + # 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"]; + hardeningDisable = [ "fortify" ]; inherit buildInputs nativeBuildInputs; }; } - ); + ); } diff --git a/githooks/apps/runner/runner.go b/githooks/apps/runner/runner.go index efef839c..cc1e5e9c 100644 --- a/githooks/apps/runner/runner.go +++ b/githooks/apps/runner/runner.go @@ -57,7 +57,13 @@ func mainRun() (exitCode int) { cwd = filepath.ToSlash(cwd) settings, uiSettings := setupSettings(cwd) - assertRegistered(settings.GitX, settings.InstallDir) + + if settings.HookName != "reference-transaction" { + // Git 2.46.x apparently runs `reference-transaction` on `git init` + // where different commands fail like `git config ...` since + // the repo is not yet properly initialized (?). + assertRegistered(settings.GitX, settings.InstallDir) + } checksums, err := hooks.GetChecksumStorage(settings.GitDirWorktree) log.AssertNoErrorF(err, "Errors while loading checksum store.") @@ -140,6 +146,9 @@ func setupSettings(repoPath string) (HookSettings, UISettings) { // General execution context, in currenct working dir. execx := cm.ExecContext{Env: os.Environ()} + log.DebugF("Arguments: '%q'", os.Args) + log.DebugF("Env: '%q'", os.Environ()) + // Current git context, in current working dir. gitx := git.NewCtxAt(repoPath) log.AssertNoErrorF(gitx.InitConfigCache(nil), diff --git a/githooks/git/gitcommon.go b/githooks/git/gitcommon.go index a5d9c5b8..3d93fb34 100644 --- a/githooks/git/gitcommon.go +++ b/githooks/git/gitcommon.go @@ -84,13 +84,22 @@ func (c *Context) GetMainWorktree() (string, error) { // GetGitDirCommon returns the common Git directory. // For normal repos this points to the `.git` directory. // For worktrees this points to the main worktrees git dir. -// The env. variable GIT_COMMON_DIR has especiall +// The env. variable GIT_COMMON_DIR has especially // be introduced for multiple worktrees, see: // https://github.com/git/git/commit/c7b3a3d2fe2688a30ddb8d516ed000eeda13c24e func (c *Context) GetGitDirCommon() (gitDir string, err error) { - gitDir, err = c.Get("rev-parse", "--git-common-dir") - if err != nil { - return + // Git 2.46.x apparently runs `reference-transaction` on `git init` + // where `rev-parse` fails despite the documentation saying it reports `$GIT_COMMON_DIR` if set + // (it is set!) -> Bug was reported. + gitDir = os.Getenv("GIT_COMMON_DIR") + if strs.IsEmpty(gitDir) { + gitDir = os.Getenv("GIT_DIR") + if strs.IsEmpty(gitDir) { + gitDir, err = c.Get("rev-parse", "--git-common-dir") + if err != nil { + return + } + } } if !filepath.IsAbs(gitDir) { @@ -111,9 +120,15 @@ func (c *Context) GetGitDirCommon() (gitDir string, err error) { // For normal repos this points to the `.git` directory. // For worktrees this points to the actual worktrees git dir `.git/worktrees/<....>/`. func (c *Context) GetGitDirWorktree() (gitDir string, err error) { - gitDir, err = c.Get("rev-parse", "--absolute-git-dir") - if err != nil { - return + // Git 2.46.x apparently runs `reference-transaction` on `git init` + // where `rev-parse` fails despite the documentation saying it reports `$GIT_DIR` if set + // (it is set!) -> Bug was reported. + gitDir = os.Getenv("GIT_DIR") + if strs.IsEmpty(gitDir) { + gitDir, err = c.Get("rev-parse", "--absolute-git-dir") + if err != nil { + return + } } gitDir = filepath.ToSlash(gitDir) diff --git a/githooks/go.mod b/githooks/go.mod index 78922639..3448aa11 100644 --- a/githooks/go.mod +++ b/githooks/go.mod @@ -1,6 +1,6 @@ module github.com/gabyx/githooks/githooks -go 1.21 +go 1.22 require ( code.gitea.io/sdk/gitea v0.15.0 diff --git a/tests/steps/step-006.sh b/tests/steps/step-006.sh index 8fbfba5f..1d2ddc16 100755 --- a/tests/steps/step-006.sh +++ b/tests/steps/step-006.sh @@ -61,5 +61,8 @@ mkdir -p "$GH_TEST_TMP/test6" && check_local_install_run_wrappers # Reinstall and check again. -"$GH_INSTALL_BIN_DIR/githooks-cli" install +"$GH_INSTALL_BIN_DIR/githooks-cli" install || { + echo "! Reinstall failed." + exit 1 +} check_local_install_run_wrappers diff --git a/tests/test-alpine-nolfs.sh b/tests/test-alpine-nolfs.sh index 63350b54..64989271 100755 --- a/tests/test-alpine-nolfs.sh +++ b/tests/test-alpine-nolfs.sh @@ -11,7 +11,7 @@ TEST_DIR="$ROOT_DIR/tests" cd "$ROOT_DIR" cat <