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

Setting environment variables for git command #95

Open
domeales-paloit opened this issue Oct 23, 2023 · 1 comment
Open

Setting environment variables for git command #95

domeales-paloit opened this issue Oct 23, 2023 · 1 comment

Comments

@domeales-paloit
Copy link

Hi there,

Is it possible to set the environment variables for the git commands?

I would like to set GIT_SSH_COMMAND like here: https://stackoverflow.com/a/29754018

Is this possible? Can you give me any example?

Thanks,
Dom

@janpecha
Copy link
Contributor

Hi, currently not, but you can prepare custom Runner https://github.com/czproject/git-php/blob/master/src/Runners/CliRunner.php and send PR :)

I think Runner can be very simple:

namespace CzProject\GitPhp\Runners;

use CzProject\GitPhp\IRunner;

class EnvironmentVarsRunner implements IRunner
{
  private $env;
  private $runner;

  public function __construct(array $env, IRunner $runner)
  {
    $this->env = $env;
    $this->runner = $runner;
  }

  public function run($cwd, array $args, array $env = NULL)
  {
     if ($env === NULL) {
        $env = $this->env;
     } else {
        $env = array_merge($this->env, $env);
     }

     return $this->runner->run($cwd, $args, $env);
  }
}

// usage:
$cliRunner = new CzProject\GitPhp\Runners\CliRunner;
$envRunner = new CzProject\GitPhp\Runners\EnvironmentVarsRunner([
  'GIT_SSH_COMMAND' => '...',
], $cliRunner);
$git = new CzProject\GitPhp\Git($envRunner);

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

No branches or pull requests

2 participants