Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
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)
$(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
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
29 changes: 17 additions & 12 deletions composer-lock-diff
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ if (! $opts['only-prod']) {
}

if ($opts['json']) {
$json_opts = ($opts['pretty']) ? JSON_PRETTY_PRINT : 0;
print json_encode($changes, $json_opts);
$json_opts = ($opts['pretty']) ? JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT : 0;
echo json_encode($changes, $json_opts), PHP_EOL;
return;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -462,14 +462,14 @@ function parseOpts() {
);
}

function usage() {
function usage($status = 0) {
$vcses = implode(', ', getVcses());
print <<<EOF
$help = <<<EOF
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)
Expand All @@ -480,11 +480,16 @@ Options:
--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 ($vcses). Default: attempt to auto-detect

--vcs Force VCS ($vcses). Default: attempt to auto-detect
EOF;

exit(0);
if ($status) {
error_log($help);
} else {
echo $help, "\n";
}

exit($status);
}
# vim: ff=unix ts=4 ss=4 sr et

5 changes: 3 additions & 2 deletions test-svn.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/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; }

trap cleanup INT ERR

function cleanup() {
cd "$DIR/test-data"
cd "$DIR/test-data" || exit
rm -rf proj proj-working svnrepo
}

Expand Down