Skip to content

Commit

Permalink
added support to process diff files
Browse files Browse the repository at this point in the history
  • Loading branch information
nrctkno committed Jan 27, 2021
1 parent a12f8ac commit b21a294
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ If we're auditing text, then we want to keep the text, right? This script that t
- From your browser: Access to `http://localhost/git_diff_renderer/git_diff_renderer.php?path=path/to/your/git/repo/folder`. Replace `localhost` by a valid host.
- From command line: `php -f git_diff_renderer.php path=path/to/your/git/repo/folder > output.html`

You can also process a diff file (a file with the output of a previous `git diff` execution) passing the file path instead of a directory.


![screenshot](screenshot.png)


Expand All @@ -29,20 +32,3 @@ _Why inline styles?_

_What about Composer?_
- This library isn't conceived to be used as part of a project (please don't). So composer.. nope.


```
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@.....................@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@.............. @@@@................@@@@@@@@@@@@
@@@@@@@@...................@@@@......................@@@@@@@
@@@@@........@@@@@@@@@@ .. @@@@@@@@@ ...@@@@@@@@@ ......@@@@
@@...........@@@ ****@@@@ @@@@ ***@@@@ @@@ ****@@@@ ......@@
@...........@@@@......@@@ @@@ ... @@@..@@@..... @@@ ......@@
@.......... @@@ ... @@@@ @@@@.... @@@ @@@ ... @@@@ .......@@
@@.........@@@@@@@@@@....@@@ ... @@@..@@@@@@@@@..........@@@
@@@@...... @@@ ......................@@@ ...............@@@@
@@@@@@@... ...................... ............@@@@@@@
@@@@@@@@@@@....................................@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@...................@@@@@@@@@@@@@@@@@@@@@@@
```
23 changes: 20 additions & 3 deletions git_diff_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ public static function formattedOutput(array $lines): void

}

class GitDiffCommand
class GitDiffCommandReader
{

public static function run($path): array
{
$output = [];
$retcode = [];
$retcode = null;

chdir($path);
exec('git diff', $output, $retcode);
Expand All @@ -190,6 +190,16 @@ public static function run($path): array

}

class FileReader
{

public static function run($path): array
{
return ['path' => $path, 'output' => file($path), 'retcode' => 0];
}

}

class GitDiffRenderer
{

Expand All @@ -198,7 +208,14 @@ class GitDiffRenderer
static function execute(\Request $request): array
{
$path = $request->getParam('path', null, self::PATH_NOT_SET_MSG);
return GitDiffCommand::run($path);

if (is_file($path)) {
return FileReader::run($path);
} elseif (is_dir($path)) {
return GitDiffCommandReader::run($path);
} else {
die('Specified path is not a directory of a file.');
}
}

}
Expand Down

0 comments on commit b21a294

Please sign in to comment.