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

Statamic does not find git binary #3392

Closed
morhi opened this issue Mar 18, 2021 · 3 comments
Closed

Statamic does not find git binary #3392

morhi opened this issue Mar 18, 2021 · 3 comments
Labels

Comments

@morhi
Copy link
Contributor

morhi commented Mar 18, 2021

Bug Description

I have installed Statamic in a shared hosting package with Git installed, which works as usual by typing git in the Shell. However when Git is enabled in Statamic I get the error git: not found.

How to Reproduce

I cannot really say how to reproduce, because it seems to be an environment specific issue with this shared hosting. The PHP process runs with the same user as the shell user, which has a working git command. However, setting an absolute path to the binary (like /usr/local/bin/git) in the Statamic Core (Git.php) helps to fix this problem.

Extra Detail

production.ERROR: The provided cwd "exec: git: not found/" does not exist. {"userId":"0000","exception":"[object] (Symfony\\Component\\Process\\Exception\\RuntimeException(code: 0): The provided cwd \"exec: git: not found/\" does not exist. at vendor/symfony/process/Process.php:344)

Environment

Statamic 3.0.46 Pro
Laravel 8.32.1
PHP 7.4.16

Install method (choose one):

  • Fresh install from statamic/statamic
@jesseleite
Copy link
Member

Solved by #3393.

@sbrow
Copy link

sbrow commented Mar 20, 2024

This fix (#3393) doesn't seem to work in nix environments. In order to get things working with my git flake, I had to update the default git commands to include the git binary config.

Without these changes, I get

[2024-03-20 15:58:47] local.ERROR: Process Class: Git
Command: git add /home/spencer/github.com/cyberspace-place/content /home/spencer/github.com/cyberspace-place/users /home/spencer/github.com/cyberspace-place/resources/blueprints /home/spencer/github.com/cyberspace-place/resources/users /home/spencer/github.com/cyberspace-place/resources/preferences.yaml /home/spencer/github.com/cyberspace-place/public/assets

P.S. It should be noted that commands like php please git:commit worked fine, but making edits through the Control Panel did not.

Example (Removing some fields for brevity):
// config/statamic/git.php
<?php

$binary = env('STATAMIC_GIT_BINARY', 'git');

return [
    // ...

    /*
    |--------------------------------------------------------------------------
    | Git Binary
    |--------------------------------------------------------------------------
    |
    | By default, Statamic will try to use the "git" command, but you can set
    | an absolute path to the git binary if necessary for your environment.
    |
    */
    'binary' => $binary,

    /*
    |--------------------------------------------------------------------------
    | Commands
    |--------------------------------------------------------------------------
    |
    | Define a list commands to be run when Statamic is ready to `git add`
    | and `git commit` your changes. These commands will be run once
    | per repo, attempting to consolidate commits where possible.
    |
    | https://statamic.dev/git-automation#customizing-commits
    |
    */
    'commands' => [
        "$binary add {{ paths }}",
        $binary.' -c "user.name={{ name }}" -c "user.email={{ email }}" commit -m "{{ message }}"',
    ],

    // ...
];
# .env

# ...
STATAMIC_GIT_ENABLED=true
# realpath $(which git)
STATAMIC_GIT_BINARY=/nix/store/zrs710jpfn7ngy5z4c6rrwwjq33b2a0y-git-2.42.0/bin/git
# ...
# flake.nix
{
  description = "Testing statamic";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/23.11";

    sbrow.url = "github:sbrow/nix";

    flake-parts.url = "github:hercules-ci/flake-parts";
    process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
  };

  outputs = inputs@{ self, flake-parts, nixpkgs, process-compose-flake, sbrow }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.process-compose-flake.flakeModule
      ];
      systems = [ "x86_64-linux" ];

      perSystem = { pkgs, system, ... }:
      {
        formatter = pkgs.nixpkgs-fmt;

        # See process-compose.yaml for details
        process-compose.default.settings = {
          processes = {
            web.command = "sudo ${pkgs.caddy}/bin/caddy run";
            php.command = "${pkgs.php}/bin/php-fpm -F -y php-fpm.conf";
          };
        };

        devShells.default = pkgs.mkShell
          {
            buildInputs = with pkgs; [
              caddy
              php
              yarn
              process-compose
              git
            ] ++ (with phpPackages; [
              composer
            ]);
          };
      };
    };
}

@duncanmcclean
Copy link
Member

This issue is over 3 years old. To avoid past participants being notified, are you able to open a new issue instead? Feel free to reference this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants