From 824bbf425f04259a58b287b8880c2c5a4e4212b5 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Wed, 11 Dec 2024 15:13:44 +0100 Subject: [PATCH 1/8] Makefile PHP parameter Ease testing with different PHP versions on make invocations. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1375841..d7d7838 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ OPTS ?= "" +PHP = php all: test md no-links only-dev only-prod json json-pretty test: - php ./composer-lock-diff --from test-data/composer.from.lock --to test-data/composer.to.lock $(OPTS) + $(PHP) ./composer-lock-diff --from test-data/composer.from.lock --to test-data/composer.to.lock $(OPTS) md: $(MAKE) test OPTS=--md From 32b77531ec40e2d1a5dfef97736fa8089d6e42e4 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Fri, 6 Dec 2024 09:08:54 +0100 Subject: [PATCH 2/8] Safeguard prefix directory operations in SVN testing Given for some unforeseen error situation DIR is empty, the trap wouldn't operate on the prefix but root. We don't want that under any circumstances und prefer to exit in error. Similarly, we don't want the `cd` operation to take CDPATH into account. --- test-svn.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test-svn.sh b/test-svn.sh index 63694fa..0d614ed 100755 --- a/test-svn.sh +++ b/test-svn.sh @@ -1,6 +1,7 @@ #!/bin/bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +DIR="$( CDPATH='' cd -- "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +[ "$DIR" ] || exit svn --help > /dev/null || { echo "Fail: could not find 'svn' executable"; exit 1; } svnadmin --help > /dev/null || { echo "Fail: could not find 'svnadmin' executable"; exit 1; } @@ -8,7 +9,7 @@ svnadmin --help > /dev/null || { echo "Fail: could not find 'svnadmin' executabl trap cleanup INT ERR function cleanup() { - cd "$DIR/test-data" + cd "$DIR/test-data" || exit rm -rf proj proj-working svnrepo } From d8da920a572bc728b4f2b20e922e8a86a78a0d52 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Fri, 6 Dec 2024 09:29:04 +0100 Subject: [PATCH 3/8] Remove superfluous isset() check --- composer-lock-diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer-lock-diff b/composer-lock-diff index 2d4a213..2c50b82 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -69,7 +69,7 @@ function diff($key, $data_from, $data_to) { function version($pkg) { - if((substr($pkg->version,0,4) == 'dev-' || '-dev' === substr($pkg->version, -4)) && isset($pkg->source) && isset($pkg->source->reference)) { + if((substr($pkg->version,0,4) == 'dev-' || '-dev' === substr($pkg->version, -4)) && isset($pkg->source->reference)) { $version = substr($pkg->source->reference,0,7) ?: ''; } else { $version = (string) $pkg->version; From cbd58aa35ca1de7ac5d0e81fc91b2cde49a67301 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Wed, 11 Dec 2024 15:53:22 +0100 Subject: [PATCH 4/8] Terminate JSON Text output --- composer-lock-diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer-lock-diff b/composer-lock-diff index 2c50b82..c33c961 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -17,7 +17,7 @@ if (! $opts['only-prod']) { if ($opts['json']) { $json_opts = ($opts['pretty']) ? JSON_PRETTY_PRINT : 0; - print json_encode($changes, $json_opts); + echo json_encode($changes, $json_opts), PHP_EOL; return; } From 1740925a15016ec98103e21f394c4825471b8997 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Wed, 11 Dec 2024 15:56:51 +0100 Subject: [PATCH 5/8] Pretty JSON Text with JSON_UNESCAPED_SLASHES --- composer-lock-diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer-lock-diff b/composer-lock-diff index c33c961..c35fd2a 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -16,7 +16,7 @@ if (! $opts['only-prod']) { } if ($opts['json']) { - $json_opts = ($opts['pretty']) ? JSON_PRETTY_PRINT : 0; + $json_opts = ($opts['pretty']) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : 0; echo json_encode($changes, $json_opts), PHP_EOL; return; } From 9a1bab84f152b968e4dc23042d61aba2ae16b550 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Fri, 6 Dec 2024 09:20:23 +0100 Subject: [PATCH 6/8] Fix usage short, long options in usage --- composer-lock-diff | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer-lock-diff b/composer-lock-diff index c35fd2a..1361cac 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -468,8 +468,8 @@ function usage() { Usage: composer-lock-diff [options] Options: - -h --help Print this message - --path, -p Base to with which to prefix paths. Default "./" + -h, --help Print this message + -p, --path Base to with which to prefix paths. Default "./" E.g. `-p app` would look for HEAD:app/composer.lock and app/composer.lock --from The file, git ref, or git ref with filename to compare from (git: HEAD:composer.lock, svn: composer.lock@BASE) From cbf69a5aae0c3e7cd5272d80a50a9210c86f1ad9 Mon Sep 17 00:00:00 2001 From: "Hans Krentel (hakre)" Date: Fri, 6 Dec 2024 09:26:29 +0100 Subject: [PATCH 7/8] Exit in error if VCS cannot be forced --- Makefile | 8 +++++++- composer-lock-diff | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d7d7838..4fbccc8 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,17 @@ OPTS ?= "" PHP = php -all: test md no-links only-dev only-prod json json-pretty +all: test test-help test-help-vcs-error md no-links only-dev only-prod json json-pretty test: $(PHP) ./composer-lock-diff --from test-data/composer.from.lock --to test-data/composer.to.lock $(OPTS) +test-help: + $(PHP) ./composer-lock-diff --help + +test-help-vcs-error: + $(PHP) ./composer-lock-diff --vcs UNKNOWN ; test $$? -eq 1 + md: $(MAKE) test OPTS=--md diff --git a/composer-lock-diff b/composer-lock-diff index 1361cac..45ceb9c 100755 --- a/composer-lock-diff +++ b/composer-lock-diff @@ -444,8 +444,8 @@ function parseOpts() { $vcs = array_key_exists('vcs', $given) ? $given['vcs'] : ''; if ($vcs && !function_exists('vcsLoad' . ucfirst($vcs))) { - error_log("Unsupported vcs '$vcs'\n"); - usage(); + error_log(sprintf("Unsupported VCS '$vcs'; supported are: '%s'\n", implode("', '", getVcses()))); + usage(1); } return array( @@ -462,9 +462,9 @@ function parseOpts() { ); } -function usage() { +function usage($status = 0) { $vcses = implode(', ', getVcses()); - print << Date: Wed, 11 Dec 2024 16:18:47 +0100 Subject: [PATCH 8/8] Update Read Me Options section To align it with recent and older changes in `--help` output. --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a3f9702..7e7b488 100644 --- a/README.md +++ b/README.md @@ -38,16 +38,18 @@ Or from vim, to insert the output into the commit message, type `:r!composer-loc ### Options -- `--path, -p`: Base to with which to prefix paths. Default "./" -- `--from`: The file^, git ref, or git ref with filename to compare from (HEAD:composer.lock) +- `-h, --help`: Print this message +- `-p, --path`: Base to with which to prefix paths. Default "./" + E.g. `-p app` would look for HEAD:app/composer.lock and app/composer.lock +- `--from`: The file^, git ref, or git ref with filename to compare from (git: HEAD:composer.lock, svn: composer.lock@BASE) - `--to`: The file^, git ref, or git ref with filename to compare to (composer.lock) -- `--md`: Markdown table output -- `--json`: json output -- `--pretty`: pretty output when combined with `--json` (>=5.4 only) +- `--json`: Format output as JSON +- `--pretty`: Pretty print JSON output (PHP >= 5.4.0) +- `--md`: Use markdown instead of plain text - `--no-links`: Don't include Compare links in plain text or any links in markdown - `--only-prod`: Only include changes from `packages` - `--only-dev`: Only include changes from `packages-dev` -- `--vcs`: Force vcs (git, svn, ...). Default auto-detect from path +- `--vcs`: Force vcs (git, svn, ...). Default: attempt to auto-detect ^ File includes anything available as a [protocol stream wrapper](http://php.net/manual/en/wrappers.php) such as URLs.