Skip to content

Commit

Permalink
Merge pull request #156 from wi1dcard/master
Browse files Browse the repository at this point in the history
Fix a bug on windows
  • Loading branch information
TomasVotruba committed Jul 18, 2018
2 parents 64aeb9e + 5ac12af commit 0ea6f3c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/GitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ public function getCommandLine()

$command = array_merge([$this->getCommand()], $this->buildOptions(), $this->args);

return array_filter($command);
return array_filter($command, 'strlen');
}
}
40 changes: 26 additions & 14 deletions src/GitProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,18 @@ public function __construct(GitWrapper $gitWrapper, GitCommand $gitCommand, ?str
$this->gitCommand = $gitCommand;

// Build the command line options, flags, and arguments.
$gitCommandLine = $gitCommand->getCommandLine();
$commandLine = array_merge([$gitWrapper->getGitBinary()], (array) $gitCommandLine);

// Support for executing an arbitrary git command.
if (is_string($gitCommandLine)) {
$commandLine = implode(' ', $commandLine);
$commandLine = $gitCommand->getCommandLine();
$gitBinary = $gitWrapper->getGitBinary();
if (is_string($commandLine)) {
// Support for executing an arbitrary git command.
$commandLine = '"' . $gitBinary . '" ' . $commandLine;
} else {
array_unshift($commandLine, $gitBinary);
}

// Resolve the working directory of the Git process. Use the directory
// in the command object if it exists.
if ($cwd === null) {
$directory = $gitCommand->getDirectory();
if ($directory !== null) {
if (! $cwd = realpath($directory)) {
throw new GitException('Path to working directory could not be resolved: ' . $directory);
}
}
}
$cwd = $this->resolveWorkingDirectory($cwd, $gitCommand);

// Finalize the environment variables, an empty array is converted
// to null which enherits the environment of the PHP process.
Expand Down Expand Up @@ -103,4 +97,22 @@ private function dispatchGitEvent(string $eventName): void
new GitEvent($this->gitWrapper, $this, $this->gitCommand)
);
}

private function resolveWorkingDirectory(?string $cwd, GitCommand $gitCommand): ?string
{
if ($cwd !== null) {
return $cwd;
}

$directory = $gitCommand->getDirectory();
if ($directory === null) {
return $cwd;
}

if (! $cwd = realpath($directory)) {
throw new GitException('Path to working directory could not be resolved: ' . $directory);
}

return $cwd;
}
}
2 changes: 1 addition & 1 deletion src/GitWorkingCopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function run(string $command, array $argsAndOptions = [], bool $setDirect
*/
public function getStatus(): string
{
return $this->gitWrapper->git('status -s', $this->directory);
return $this->run('status', ['-s']);
}

/**
Expand Down

0 comments on commit 0ea6f3c

Please sign in to comment.