ganzua diff
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Compare two lockfiles.
The OLD and NEW arguments can be any of the following:
- file: use that path as the lockfile (e.g.
uv.lockorpoetry.lock) - directory: look for a lockfile in that directory
- git blob: a
<commit>:<path>identifying a lockfile in the Git history
Here's an example of using the Git feature to show non-committed changes in a lockfile:
ganzua diff HEAD:uv.lock uv.lock
Depending on whether --git, OLD, and NEW are present,
Lockfile data may be loaded from the Git history.
ganzua diff <lockfile> <lockfile>compares two lockfiles, each of which may be a file, directory, or Git blob as described above.ganzua diff [<path>]comparesINDEX:<path> <path>ganzua diff --git=<old> [<path>]compares<old>:<path> <path>ganzua diff --git=<old>...<new> [<path>]compares<old>:<path> <new>:<path>
If the <path> is absent, the lockfile path is located in the current directory,
as if . had been passed.
If an explicit --git option is passed, the positional argument must be a path,
not a git blob.
Options:
-
--filter LOCKFILE-FILTERInclude/exclude packages. [default: use all] -
--format [json|markdown]Choose the output format, e.g. Markdown. [default: json] -
--git COMMITGit commit to use for the diff. [default: INDEX]May be a single
<old>revision, or a<old>...<new>range. In addition togitrevisionsyntax, may useINDEXto name staged files. -
--no-gitDisable Git functionality. [default: enabled] -
--[no-]pypi-metadataLook up PyPI metadata for locked packages. [default: off]This will add warnings for yanked or vulnerable packages.
-
--helpShow this help message and exit.
Changed in Ganzua 0.5.0: renamed --name to --filter.
Output format
The ganzua diff command shows the package changes as JSON by default:
$ ganzua diff corpus/old-uv-project corpus/new-uv-project
{
"stat": {
"total": 2,
"added": 1,
"removed": 0,
"updated": 1
},
"packages": [
{
"name": "annotated-types",
"old": null,
"new": {
"name": "annotated-types",
"version": "0.7.0",
"source": "pypi"
}
},
{
"name": "typing-extensions",
"old": {
"name": "typing-extensions",
"version": "3.10.0.2",
"source": "pypi"
},
"new": {
"name": "typing-extensions",
"version": "4.14.1",
"source": "pypi"
},
"is_major_change": true
}
]
}
We can opt in to the Markdown format for the diff, which will show a table:
$ ganzua diff corpus/old-uv-project corpus/new-uv-project --format=markdown
2 changed packages (1 added, 1 updated)
| package | old | new | notes |
|-------------------|----------|--------|-------|
| annotated-types | - | 0.7.0 | |
| typing-extensions | 3.10.0.2 | 4.14.1 | (M) |
* (M) major change
Here's the same diff in reverse, which now shows a (D) downgrade notice:
$ ganzua diff corpus/new-uv-project corpus/old-uv-project --format=markdown
2 changed packages (1 updated, 1 removed)
| package | old | new | notes |
|-------------------|--------|----------|---------|
| annotated-types | 0.7.0 | - | |
| typing-extensions | 4.14.1 | 3.10.0.2 | (M) (D) |
* (M) major change
* (D) downgrade
Test cases for demonstrating how the (M)/is_major_change note works:
| package | old | new | notes |
|---|---|---|---|
| epoch-changed | 1.2.3 | 1!1.2.3 | (M) |
| epoch-zero | 1.2.3 | 0!1.2.3 | |
| existence-added | - | 1.2.3 | |
| existence-removed | 1.2.3 | - | |
| major | 1.2.3 | 2.1.0 | (M) |
| minor | 1.2.3 | 1.3.4 | |
| validity-invalid-to-invalid | foo | bar | (M) |
| validity-invalid-to-valid | foo | 1.2.3 | (M) |
| validity-valid-to-invalid | 1.2.3 | foo | (M) |
| zerover-change | 0.1.2 | 0.2.0 | (M) |
| zerover-same | 0.1.2 | 0.1.3 |
Test cases for demonstrating how the (D)/is_downgrade note works:
| package | old | new | notes |
|---|---|---|---|
| downgrade | 1.3.4 | 1.0.1 | (D) |
| upgrade | 1.0.1 | 1.3.4 |
The Markdown diff can show notices when the source of a package changes. When multiple entries have the same note, their IDs are deduplicated:
$ ganzua diff corpus/sources-poetry corpus/sources-uv --format=markdown
6 changed packages (1 added, 5 updated)
| package | old | new | notes |
|--------------------|-------|-------|-------|
| click | 8.3.0 | 8.3.0 | (S1) |
| click-example-repo | 1.0.0 | 1.0.0 | (S2) |
| colorama | 0.4.6 | 0.4.6 | (S1) |
| idna | 3.11 | 3.11 | (S1) |
| propcache | 0.4.1 | 0.4.1 | (S1) |
| sources-uv | - | 0.1.0 | |
* (S1) source changed from default to pypi
* (S2) source changed from <git+https://github.com/pallets/click.git@309ce9178707e1efaf994f191d062edbdffd5ce6#subdirectory=examples/repo> to <git+https://github.com/pallets/click.git@f67abc6fe7dd3d878879a4f004866bf5acefa9b4#subdirectory=examples/repo>
If there are no notes, the entire column is omitted:
$ ganzua diff --format=markdown corpus/new-uv-project corpus/minor-uv-project
1 changed packages (1 updated)
| package | old | new |
|-------------------|--------|--------|
| typing-extensions | 4.14.1 | 4.15.0 |
When a there are no changes, only the summary is shown. The Markdown output omits the table:
$ ganzua diff corpus/new-uv-project corpus/new-uv-project
{
"stat": {
"total": 0,
"added": 0,
"removed": 0,
"updated": 0
},
"packages": []
}
$ ganzua diff corpus/new-uv-project corpus/new-uv-project --format=markdown
0 changed packages
Diff arguments
A ganzua diff is always computed between two lockfiles or two versions of a lockfile.
This section describes the case that we want to compare two lockfiles in different locations.
The next section then discusses Git support.
The input paths may point to directories or lockfiles. The following invocations are all equivalent:
$ ganzua diff corpus/old-uv-project corpus/new-uv-project$ ganzua diff corpus/old-uv-project corpus/new-uv-project/uv.lock$ ganzua diff corpus/old-uv-project/uv.lock corpus/new-uv-project$ ganzua diff corpus/old-uv-project/uv.lock corpus/new-uv-project/uv.lock
output for the above commands
{
"stat": {
"total": 2,
"added": 1,
"removed": 0,
"updated": 1
},
"packages": [
{
"name": "annotated-types",
"old": null,
"new": {
"name": "annotated-types",
"version": "0.7.0",
"source": "pypi"
}
},
{
"name": "typing-extensions",
"old": {
"name": "typing-extensions",
"version": "3.10.0.2",
"source": "pypi"
},
"new": {
"name": "typing-extensions",
"version": "4.14.1",
"source": "pypi"
},
"is_major_change": true
}
]
}
Git support
A ganzua diff can compare lockfiles across Git versions.
For further details, see Git.
Note that there are two distinct invocation styles:
- 2 arguments: may be paths or git blob names of the form
<revision>:<path>. - 0 or 1 arguments: the argument must be a path (defaults to
.), but we may use the--gitargument to define Git versions.
setting up an example Git repo
$ git -C $EXAMPLE init .
Initialized empty Git repository in ${EXAMPLE}/.git/
Adding an initial lockfile and committing:
| name | version |
|---|---|
| initial | 1.2.3 |
$ git -C $EXAMPLE add uv.lock
$ git -C $EXAMPLE commit -m 'initial commit'
[main (root-commit) 0803229] initial commit
1 file changed, 8 insertions(+)
create mode 100644 uv.lock
Editing the lockfile and committing:
| name | version |
|---|---|
| initial | 1.2.3 |
| head | 2.3.4 |
$ git -C $EXAMPLE add uv.lock
$ git -C $EXAMPLE commit -m 'creating the HEAD commit'
[main 6185494] creating the HEAD commit
1 file changed, 5 insertions(+)
Editing the lockfile and staging (adding to the index) – but not committing:
| name | version |
|---|---|
| initial | 1.2.3 |
| head | 2.3.4 |
| staged | 3.4.5 |
$ git -C $EXAMPLE add uv.lock
Editing the lockfile yet again, without staging:
| name | version |
|---|---|
| initial | 1.2.3 |
| head | 2.3.4 |
| staged | 3.4.5 |
| dirty | 0.0.0 |
By default, a ganzua diff will compare the worktree to the index, just like git diff.
All of these invocations are equivalent:
$ env -C $EXAMPLE ganzua diff$ env -C $EXAMPLE ganzua diff .$ env -C $EXAMPLE ganzua diff uv.lock$ env -C $EXAMPLE ganzua diff INDEX:uv.lock .$ env -C $EXAMPLE ganzua diff INDEX:uv.lock uv.lock$ env -C $EXAMPLE ganzua diff --git=INDEX$ env -C $EXAMPLE ganzua diff --git=INDEX .
output for the above commands
{
"stat": {
"total": 1,
"added": 1,
"removed": 0,
"updated": 0
},
"packages": [
{
"name": "dirty",
"old": null,
"new": {
"name": "dirty",
"version": "0.0.0",
"source": "pypi"
}
}
]
}
We can also compare the working tree to the HEAD commit (@),
for example with any of the following commands:
$ env -C $EXAMPLE ganzua diff HEAD:uv.lock .$ env -C $EXAMPLE ganzua diff HEAD:uv.lock uv.lock$ env -C $EXAMPLE ganzua diff --git=HEAD$ env -C $EXAMPLE ganzua diff --git=HEAD uv.lock$ env -C $EXAMPLE ganzua diff @:uv.lock .$ env -C $EXAMPLE ganzua diff --git=@
output for the above commands
{
"stat": {
"total": 2,
"added": 2,
"removed": 0,
"updated": 0
},
"packages": [
{
"name": "dirty",
"old": null,
"new": {
"name": "dirty",
"version": "0.0.0",
"source": "pypi"
}
},
{
"name": "staged",
"old": null,
"new": {
"name": "staged",
"version": "3.4.5",
"source": "pypi"
}
}
]
}
We can compare two Git commits, which we'll name HEAD^ and HEAD here.
In a ... range, an empty side is interpreted as HEAD.
$ env -C $EXAMPLE ganzua diff HEAD^:uv.lock HEAD:uv.lock$ env -C $EXAMPLE ganzua diff --git=HEAD^...HEAD$ env -C $EXAMPLE ganzua diff --git=HEAD^...$ env -C $EXAMPLE ganzua diff --git=HEAD^... uv.lock
output for the above commands
{
"stat": {
"total": 1,
"added": 1,
"removed": 0,
"updated": 0
},
"packages": [
{
"name": "head",
"old": null,
"new": {
"name": "head",
"version": "2.3.4",
"source": "pypi"
}
}
]
}
Finally, we can compare commits to the staged files (index). Any of these are equivalent:
$ env -C $EXAMPLE ganzua diff HEAD^:uv.lock INDEX:uv.lock$ env -C $EXAMPLE ganzua diff --git=HEAD^...INDEX
output for the above commands
{
"stat": {
"total": 2,
"added": 2,
"removed": 0,
"updated": 0
},
"packages": [
{
"name": "head",
"old": null,
"new": {
"name": "head",
"version": "2.3.4",
"source": "pypi"
}
},
{
"name": "staged",
"old": null,
"new": {
"name": "staged",
"version": "3.4.5",
"source": "pypi"
}
}
]
}
Examples of some errors:
The two diff modes cannot be mixed.
$ env -C $EXAMPLE ganzua diff --git=HEAD uv.lock uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: Cannot use `--git` if both OLD and NEW were given
[command exited with status 2]
$ env -C $EXAMPLE ganzua diff --git=HEAD INDEX:uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: Could not read file from Git history: `HEAD:INDEX:uv.lock`
Note: Command `git cat-file blob HEAD:INDEX:uv.lock` exited with status 128
[command exited with status 2]
$ env -C $EXAMPLE ganzua diff --git=INDEX HEAD:uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: Could not read file from Git history: `:HEAD:uv.lock`
Note: Command `git cat-file blob :HEAD:uv.lock` exited with status 128
[command exited with status 2]
$ env -C $EXAMPLE ganzua diff HEAD:uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: Could not read file from Git history: `:HEAD:uv.lock`
Note: Command `git cat-file blob :HEAD:uv.lock` exited with status 128
[command exited with status 2]
$ env -C $EXAMPLE ganzua diff --git=HEAD uv.lock INDEX:uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: Cannot use `--git` if both OLD and NEW were given
[command exited with status 2]
Git mode can be disabled explicitly.
Under the --no-git mode, arguments are interpreted as ordinary paths.
$ env -C $EXAMPLE ganzua diff --no-git HEAD:uv.lock uv.lock
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: OLD: File `HEAD:uv.lock` does not exist.
[command exited with status 2]
Under the --no-git mode, explicitly using the --git option causes an error.
$ env -C $EXAMPLE ganzua diff --no-git --git=HEAD
Usage: ganzua diff [OPTIONS] [OLD] [NEW]
Try 'ganzua diff --help' for help.
Error: OLD: Cannot read `HEAD:uv.lock` because Git support was disabled.
[command exited with status 2]
Filters
Can filter the packages to be diffed by name. For more details, see the filter manual. Filtering was added in Ganzua 0.4.0.
$ ganzua diff $CORPUS/old-uv-project $CORPUS/new-uv-project --filter='typing*' --format=markdown
1 changed packages (1 updated)
| package | old | new | notes |
|-------------------|----------|--------|-------|
| typing-extensions | 3.10.0.2 | 4.14.1 | (M) |
* (M) major change
$ ganzua diff $CORPUS/old-uv-project $CORPUS/new-uv-project --filter='nonexistent' --format=markdown
0 changed packages
PyPI metadata
Using the --pypi-metadata flag will load package metadata from PyPI,
which can be used to audit for known-vulnerable or yanked packages,
and will also show project URLs in the JSON output.
See the PyPI metadata feature reference for examples and further details.
Other examples
Hidden features:
Unstable: there's a hidden --md-links option.
$ ganzua diff $CORPUS/old-uv-project $CORPUS/new-uv-project --format=markdown --md-links
2 changed packages (1 added, 1 updated)
| package | old | new | notes |
|-----------------------------------------------------------|----------|--------|-------|
| [annotated-types](https://pypi.org/p/annotated-types) | - | 0.7.0 | |
| [typing-extensions](https://pypi.org/p/typing-extensions) | 3.10.0.2 | 4.14.1 | (M) |
* (M) major change
JSON Schema
Download: schema.diff.json
Properties:
type DiffStat
Properties:
total: intadded: intremoved: intupdated: int
type DiffEntry
Properties:
-
name: string
Name of the package being diffed.Added in Ganzua 0.4.0: previously, the package name was implicit.
-
old: LockedPackageNoMeta | null -
new: LockedPackageNoMeta | null -
pypi_metadata?: PyPIMetadata
PyPI metadata for thenewversion, if any.This field will only be populated if metadata was explicitly requested via
--pypi-metadata, the package seems to have been installed from PyPI, and PyPI successfully provided metadata for the new version.Added in Ganzua 0.5.0.
-
is_major_change?: bool
True if there was a major version change.This doesn't literally mean "the SemVer-major version component changed", but is intended to highlight version changes that are likely to have breakage.
-
is_downgrade?: bool
True if the version was downgraded. -
is_source_change?: bool
True if the package source changed. -
is_yanked?: bool
True if the new version was yanked (perpypi_metadata).Added in Ganzua 0.5.0.
-
is_vulnerable?: bool
True if the new version has a known vulnerability (perpypi_metadata).For the purposes of this flag, withdrawn vulnerabilities are ignored.
Added in Ganzua 0.5.0.
type LockedPackageNoMeta
Properties:
-
name: string
Name of the package.Added in Ganzua 0.4.0: previously, the package name was implicit.
-
version: string -
source:pypi|default|other| SourceRegistry | SourceDirect
type SourceRegistry
The package is sourced from a third party registry.
Properties:
registry: string
URL or path to the registry.
type SourceDirect
The package is sourced from a specific URL or path, e.g. a Git repo or workspace path.
Properties:
direct: string
URL or path to the package (directory or archive).subdirectory?: string | null
Only allowed if the source points to an archive file.
type PyPIMetadata
Extra PyPI metadata that relates to a specific package version.
Added in Ganzua 0.5.0.
Properties:
-
yanked?: string
If this package version was yanked, the reason given.If no reason was given, a yanked package will use an empty string here.
-
vulnerabilities?: array(Vulnerability)
If this package version has vulnerabilities, details on those. -
project_urls?: mapping(string → string)
The project URLs declared in the package metadata (label → url).Well-known labels will have been replaced by their canonical name, e.g.
What's New?will be replaced bychangelog.Specifications:
type Vulnerability
Information about a known vulnerability for a specific package version.
Matches the PyPI JSON API exactly, which in turn is based on the Open Source Vulnerability format.
Properties:
id: stringsource: stringlink?: string | nullaliases?: array(string) | nulldetails?: string | nullsummary?: string | nullfixed_in?: array(string) | nullwithdrawn?: string | null