Skip to content

Releases

v2.0.0

Choose a tag to compare

@lyrixx lyrixx released this 10 Nov 14:10

Changes since v1.6.0. To upgrade, fix the deprecations of 1.7 first, then see UPGRADE-2.0.md.

Breaking changes

  • Run every git operation through a driver (Gitonomy\Git\Driver): the domain objects call a Driver\RepositoryDriverInterface, typed (hashes, enums, value objects of Driver\Data), instead of building processes and parsing their output. A failing operation always throws, a missing revision or object a ReferenceNotFoundException, a timeout a ProcessTimedOutException; dates are \DateTimeImmutable; names in diffs and trees are UTF-8; references are read again after every write gitlib makes, and peel annotated tags; the diff of a merge commit is against its first parent; blame lines and logs are typed objects; the subject of a message is its first paragraph. See UPGRADE-2.0.md for every change. (#253)
  • Return the dates of commits and tags at the UTC offset of their author, committer or tagger, like git log shows them, instead of in UTC: the instant doesn't change, but format() returns their local time. (#254)
  • Require PHP 8.4 or later, and symfony/process ^6.4.33, ^7.4.5 or ^8.1: most classes are final (some readonly), and every method has native types. (#238)
  • Remove Gitonomy\Git\Util\StringHelper, replaced by symfony/string, and its configurable encoding: gitlib reads everything in UTF-8. (#252)
  • Require git 1.8.4 or later, the oldest version the test suite passes with: it simplifies the log of a range filtered by path like the current versions, and Log::count() needs git 1.7.2. (#253)
  • Diff::parse() throws for a diff without its raw information, deprecated since 1.6.0 (#229): parse the output of git diff --raw --patch. (#253)
  • The constructors of Commit, Tree, Blob, Revision, the references and ReferenceBag are internal: get these objects from Repository, which returns the same commit, tree or blob while the application uses it, and reads the references again after its writes. Extending Revision or Reference isn't supported anymore. (#254)
  • ProcessException has a message of one line, with the error of git, the first line of its error output starting with fatal: or error:, after the warnings: The git command "clone" failed (exit 128): fatal: .... The command line, the rest of the error output and the output are no longer in the message: getErrorOutput() and getOutput() return the outputs of git. (#254)
  • Tree::resolvePath() throws an InvalidArgumentException for a path through a submodule, instead of an Exception\UnexpectedValueException, which gitlib no longer throws. (#254)
  • When git can't start, a missing binary for instance, CliDriver throws a DriverException instead of a ProcessException, with a message of one line, without the command line: The git command "clone" could not start: .... (#254)
  • WorkingCopy::checkout() throws a ReferenceNotFoundException for a name that no revision has, with both drivers: the name of a remote branch alone, like feature for origin/feature, created the local branch. Use checkoutNewBranch(). (#254)
  • Remove the API that 1.7 deprecates (#271); see UPGRADE-2.0.md:
    • Admin, replaced by the static methods of Repository, and Repository::cloneTo(), replaced by cloneFrom() and cloneBareFrom().
    • The array of options of Repository (working_dir, logger, command, environment_variables, inherit_environment_variables, process_timeout, debug): pass the working directory and a CliDriver instead; inherit_environment_variables has no counterpart, pass the variables git needs instead. Repository::setLogger() and getLogger().
    • The $reload argument of Repository::getReferences(), and the arguments of Commit::getIncludingBranches(). ReferenceBag::update() and Branch::isMergedTo(), replaced by Branch::moveTo() and isMergedInto().
    • Repository::getDiff() with one argument, Log::getDiff(), Diff::setRepository(), File::setRepository(), addChange(), isChangeMode(), isDelete() and getAnchor(), FileChange::getCount(), getLines(), replaced by getDiffLines(), and the LINE_* constants, replaced by DiffLineType, and the lines passed to the constructor of FileChange as arrays.
    • Log::setOffset() and setLimit().
    • A range of lines as a string in Repository::getBlame(), Blame::getGroupedLines() and Blame\Line::getLine().
    • CommitReference, Tree::getCommitReferenceEntries(), getEntries(), getBlobEntries() and getTreeEntries(): iterate the tree, or use getBlobs(), getTrees() and getSubmodules().
    • The branch to create of WorkingCopy::checkout().
    • Commit::getShortMessage() and getFixedShortHash(), Repository::shell(), PushReference::getReference(), getRevision(), isCreate() and isDelete().
    • Repository::getSize(), in kilobytes: use getSizeInBytes().
  • Make Parser\DiffParser and Parser\ParserBase internal, like the other parsers: parse a diff with Diff::parse(). (#274)
  • Log::getIterator() returns a \Traversable instead of an \ArrayIterator: iterate the log, or use getCommits(). (#274)
  • Run git in English with CliDriver (LANGUAGE=C), unless its environmentVariables set LANGUAGE: gitlib reads messages of git, see the bug fixes. (#274)

Features

  • Add an experimental Driver\Ffi\LibGit2Driver, running libgit2 1.9 in-process through PHP's FFI extension, as an alternative to the default Driver\Cli\CliDriver: pass it as the driver of Repository. It avoids spawning a git process for every operation; see "Choosing a driver" for its requirements, its differences with CliDriver, and when it is faster. benchmark.php, from a clone of gitlib, compares both drivers on a repository. With php-fpm, LibGit2Driver::preload() keeps libgit2 loaded from opcache.preload. (#253)
  • Repository takes the working directory and the driver as arguments: a Driver\Cli\CliDriver by default, configured through its constructor (git binary, environment, timeout and logger, which gets every command, clones included), or any Driver\DriverInterface, to replace it in tests; see "Using your own driver". The driver finds the repository: linked worktrees, submodules, clones with --separate-git-dir and reftable repositories (with CliDriver) open, and a directory that isn't a repository throws right away. (#253, #261, fixes #200)
  • Add static methods to Repository creating repositories, init(), initBare(), cloneFrom(), cloneBareFrom() and mirrorFrom(), and checking a repository URL, isValidRepository() and isValidRepositoryAndBranch(); see "Create and access git repositories". (#253)
  • Add Repository::getDiff($from, $to), Repository::getMergeBase(), Repository::getSizeInBytes() and WorkingCopy::getDiff(), WorkingCopy::checkoutNewBranch(), Branch::moveTo() and Branch::isMergedInto(), Log::withOffset() and withLimit(), Blame::getHunks() and the line numbers of Blame\Line, FileChange::getDiffLines(), which returns Diff\DiffLine objects typed by Diff\DiffLineType, iterating a Tree, which gives TreeEntry objects, Tree::getBlobs(), getTrees() and getSubmodules(), Submodule, File::isModeChange(), FileChange::getAdditions() and getDeletions(), PushReference::getFullname(), getRange(), isCreation() and isDeletion(), and the SSH and X.509 signatures of tags. (#253, #254, #263)
  • Add WorkingCopy::merge() to support git merge, fast-forwarding or not, with a FastForward enum. (#248, fixes #118)
  • Add Repository::runProcess() to expose stderr from successful commands: run() only ever returned stdout, even on success, but some git commands (e.g. push) write meaningful output to stderr even when they succeed. run() still returns the standard output. (#247, fixes #205)
  • Support git's mnemonic diff prefixes (diff.mnemonicPrefix) in the diff parser: enabling this option replaces the default a//b/ prefixes with context-specific ones (c//i//o//w/), which used to raise a RuntimeException in tools like GrumPHP that enable it. (#245, fixes #114)
  • Support "copy from"/"copy to" in the diff parser: diffs prod...
Read more

v1.7.2

Choose a tag to compare

@lyrixx lyrixx released this 10 Nov 08:04

Changes since v1.7.1.

Security

  • Fix Repository::isValidRepository() and isValidRepositoryAndBranch() reading the
    configuration of a repository of the temporary directory, where they run git ls-remote:
    another user of the machine may create a .git there, whose rewrites of URLs
    (url.<base>.insteadOf) make git run a command, or check another repository.
  • Refuse a git:// URL whose port starts with a dash, even encoded, like
    git://host:-oProxyCommand=.../repository: old versions of git, 1.8.4 for instance, pass it
    to the command of core.gitProxy, which reads it as an option.

Bug fixes

  • Fix a TypeError when hiding the credentials of a long text, the megabytes of a blob in the
    logs for instance: with a logger, reading a file with a long password in a URL failed. It
    no longer takes seconds either, without the JIT of PCRE.
  • Fix WorkingCopy::getUntrackedFiles() returning the former name of a staged rename, when
    it starts with ?? .
  • Fix a hash ending with a new line read as a hash: Repository::getCommit() returned a
    commit holding it, instead of throwing a ReferenceNotFoundException, and getTree() and
    getBlob() did not trigger the deprecation of a name that isn't a hash.
  • Read the annotated tags of other tools like git does: with a header after the tagger, or
    without the empty line before the message, Tag::getMessage() and the methods reading the
    tagger threw a RuntimeException.

Deprecations

  • Parser\DiffParser and Parser\ParserBase, internal in 2.0: parse a diff with
    Diff::parse().

v1.7.1

Choose a tag to compare

@lyrixx lyrixx released this 07 Nov 20:55

Changes since v1.7.0.

1.7.1 has the security fixes of 2.0 that break nothing of 1.6. Where 2.0 refuses every option,
1.7.1 only refuses what reads or writes a file: the other options of git log as revisions stay
deprecated, and work. The checks of a URL keep returning false, and clones keep throwing a
RuntimeException, where 2.0 throws an InvalidArgumentException.

Security

  • Refuse --output as a revision, which made git write a file: getRevision('--output=/path')
    and everything reading a revision through it, getLog(), getDiff(), getMergeBase() or
    Branch::moveTo() for instance.
  • Refuse the options of git blame reading or writing a file as a revision:
    getBlame('--contents=/path', 'README.md') returned the lines of any file, and the error of
    --ignore-revs-file or -S printed its first line.
  • Refuse a URL starting with a dash, which git read as an option:
    Admin::isValidRepository('--upload-pack=...') ran the command in a repository with a remote,
    Admin::isValidRepositoryAndBranch() and the clones when the second argument was a
    repository. A path may start with a dash: init() and the clones end the options of git with
    --, as cloneFrom($url, '--upload-pack=...') ran the command too.
  • Refuse a hash starting with a dash in ReferenceBag::createBranch() and createTag():
    createBranch('foo', '-d') deleted the branch. So do the branch and the start point of
    WorkingCopy::checkoutNewBranch().
  • Refuse an fd:: URL, which makes git talk through a file descriptor it inherits from PHP, like
    the socket of a database, and wait on it.
  • Refuse an ssh URL whose host or user starts with a dash, even encoded (%2D), like
    ssh://-oProxyCommand=.../repository: git before 2.14.1 passes it to ssh, which reads it as an
    option and runs the command (CVE-2017-1000117). A git:// URL whose host starts with a dash
    is refused too: git passes it to the command of core.gitProxy.
  • Hide the credentials of URLs (https://user:token@host), a password holding a # or a ?
    included, in the messages of ProcessException and of failed clones, in the logs, and in the
    messages of the exceptions of Symfony Process, a timeout for instance, which keep their class.
    From PHP 8.2, the traces hide them too (#[\SensitiveParameter]).
  • Refuse a hook name leading out of the hooks directory: Hooks::set('../../file', ...),
    remove('../config') and get('../config') wrote, deleted and read files of the repository.
    The names staying in the directory, like post-receive.d/notify, still work.
  • Fix Hooks writing through a symbolic link to a missing file, out of the hooks directory:
    has() returned false for it, and set() followed it.
  • Ignore core.fsmonitor: git ran the command the configuration of a repository names there to
    read the working tree, and even to diff a commit.
  • Fix deleting a symbolic reference, which deleted the branch it points to instead:
    ReferenceBag::delete('refs/remotes/origin/HEAD') deleted origin/main.
  • Fix ReferenceBag::delete('HEAD') deleting a detached HEAD, which left no repository: it
    throws an InvalidArgumentException.
  • Require symfony/process 5.4.51, 6.4.33, 7.3.11, 7.4.5 or 8.0.5 and later: the older versions
    escape the arguments wrongly on Windows (CVE-2024-51736, CVE-2026-24739).

Not fixed

These fixes of 2.0 would break code written for 1.6. An application giving gitlib values it can't
trust has to check them itself:

  • ext:: URLs stay accepted, as an application may use this transport on purpose. git refuses
    them by default since 2.12: before that, ext::sh -c ... runs the command.
  • The replacements of objects (git replace, refs/replace/) stay read, as git replace --graft
    relies on them: whoever can push such a reference changes the message of a commit, or the
    content of a blob, gitlib reads for a hash. Set GIT_NO_REPLACE_OBJECTS to 1 in the
    environmentVariables of CliDriver to ignore them.
  • WorkingCopy::checkout() still takes a path or an option: checkout('README.md') discards the
    changes of the file, and checkout('--force') all of them.
  • Moving a symbolic reference, with Branch::moveTo() or ReferenceBag::update(), still moves
    the branch it points to.

v1.7.0

Choose a tag to compare

@lyrixx lyrixx released this 15 Oct 13:42

Changes since v1.6.0.

1.7 prepares the upgrade to 2.0: it has the API of 2.0 that can be added without breaking 1.x, and deprecates what 2.0 replaces or breaks. Code without deprecations with 1.7 runs with 2.0 too, so a library can require ^1.7 || ^2.0 with a single code path. The exceptions, the changes of 2.0 1.7 can't bring, are listed in the UPGRADE-2.0.md of 2.0.

1.7 breaks nothing of 1.6: the parameters keep their names, the arguments added to the methods of classes that aren't final are read with func_get_arg(), commented out in their signature (@psalm-variadic for Psalm), and gitlib keeps calling the deprecated methods that a subclass overrides. Deprecations are triggered through symfony/deprecation-contracts, a new dependency.

1.7 requires PHP 8.1, for the DiffLineType enum: on PHP 8.0, Composer keeps 1.6.

Features

  • Gitonomy\Git\Driver\Cli\CliDriver configures git: the binary, the environment variables, the timeout and the logger. It takes the arguments of the CliDriver of 2.0.
  • new Repository($dir, $workingDir, $driver): the second argument may be the working directory, the third one is a CliDriver.
  • Repository::init(), initBare(), cloneFrom(), cloneBareFrom(), mirrorFrom(), isValidRepository() and isValidRepositoryAndBranch() take the URL before the path and a CliDriver as last argument. Like in 2.0, isValidRepositoryAndBranch() checks the exact name of the branch, and both read a relative path as a path, never as the name of a remote of the working directory of PHP.
  • Repository::getDiff($from, $to), with two arguments, compares two revisions, Repository::getMergeBase() returns their best common ancestor, WorkingCopy::getDiff() compares the working tree with a revision. Like in 2.0, they throw a ReferenceNotFoundException for an unknown revision, as WorkingCopy::checkoutNewBranch().
  • Diff::parse(), Diff::fromArray() and File::fromArray() take the repository to read the blobs from, the constructor of Diff\File the changes and the repository. File::isModeChange(), File::isCopy(), FileChange::getAdditions() and FileChange::getDeletions().
  • FileChange::getDiffLines() returns the lines of a hunk as Diff\DiffLine objects, with getType(), a Diff\DiffLineType, and getContent(). The constructor of FileChange takes DiffLine objects.
  • Repository::getBlame() and Blame take the first and the last lines to blame, as integers. Blame::getHunks() returns Blame\Hunk objects, numbered like the file; Blame\Line::getNumber() and getOriginalNumber().
  • Log::withOffset() and withLimit() return another log.
  • Branch::isMergedInto() and Branch::moveTo(). ReferenceBag::createBranch() and createTag() take a Revision too.
  • PushReference::getFullname(), getRange(), isCreation() and isDeletion().
  • Iterating a Tree gives its entries, TreeEntry objects with getName(), getMode() and getObject(), by name; Tree::getBlobs(), getTrees() and getSubmodules() return those of one type.
  • Submodule, with getHash(). The submodules of trees are still CommitReference objects, which extend Submodule.
  • WorkingCopy::checkoutNewBranch(). WorkingCopy::checkout() takes any Revision.
  • Repository::getSizeInBytes(), which doesn't follow links.

Deprecations

  • An array of options as second argument of Repository, the debug option set to false, Repository::setLogger() and getLogger(): use the workingDir and driver arguments.
  • Admin and Repository::cloneTo(): use the static methods of Repository.
  • Repository::getDiff() with one argument and Log::getDiff(): use Repository::getDiff($from, $to) or WorkingCopy::getDiff().
  • Diff::setRepository(), File::setRepository(), File::addChange(), File::isChangeMode(), File::isDelete(), File::getAnchor() and FileChange::getCount().
  • FileChange::getLines(), which returns the lines as arrays, the FileChange::LINE_* constants, and passing the lines to the constructor of FileChange as arrays: use getDiffLines(), DiffLineType and DiffLine objects.
  • A range of lines as a string in Repository::getBlame() and Blame, Blame::getGroupedLines() and Blame\Line::getLine().
  • Log::setOffset(), setLimit(), a negative offset or limit, an option of git log but --all as revision, and count() of a log whose offset or limit leaves commits out: it counts them all, where 2.0 counts the commits the log iterates. Use countCommits().
  • ReferenceBag::update(), Branch::isMergedTo(), arguments of Commit::getIncludingBranches(), creating a branch or a tag that exists already, deleting a reference by another name than its full name under refs/.
  • Passing an argument to Repository::getReferences(), to read the references again: open a new Repository.
  • PushReference::getReference(), getRevision(), isCreate() and isDelete().
  • CommitReference. Tree::getEntries(), getBlobEntries(), getTreeEntries() and getCommitReferenceEntries(), which return the entries as arrays: iterate the tree, or use getBlobs(), getTrees() and getSubmodules().
  • The second argument of WorkingCopy::checkout(): use checkoutNewBranch(). A local Branch object, which checkout() detaches HEAD on, where 2.0 attaches HEAD to the branch: pass its name, or its commit.
  • Passing a revision name to Repository::getTree() or getBlob() instead of a hash, and passing data to the constructor of Commit, internal in 2.0.
  • Repository::getSize(), Repository::shell(), Commit::getShortMessage(), Commit::getFixedShortHash() and Util\StringHelper.
  • The parsers that 2.0 moves to its CliDriver, all but DiffParser and ParserBase.
  • The classes final in 2.0 are @final since gitonomy/gitlib 1.7. The constructors internal in 2.0 (Commit, Tree, Blob, Revision, Reference, ReferenceBag) say so.

Full Changelog: v1.6.0...v1.7.0

v1.5.0

Choose a tag to compare

@GrahamCampbell GrahamCampbell released this 03 Nov 16:03
ac17834

What's Changed

  • Support only PHP 8.0-8.4
  • Detect binary file by NULL byte
  • Set default range counts
  • Add optional entry type option for tree entries
  • Fixed a few minor bugs

New Contributors

Full Changelog: v1.4.0...v1.5.0

v1.4.0

Choose a tag to compare

@alexandresalome alexandresalome released this 20 Dec 15:38
2c7fbbd

What's Changed

  • Support only Symfony 5-7
  • Support only PHP 8.0-8.2

Full Changelog: v1.3.8...v1.4.0

v1.3.8

Choose a tag to compare

@lyrixx lyrixx released this 11 May 08:30
9fea656

What's Changed

New Contributors

Full Changelog: v1.3.7...v1.3.8

v1.3.7

Choose a tag to compare

@lyrixx lyrixx released this 04 Oct 14:21
00b57b7

What's Changed

Full Changelog: v1.3.6...v1.3.7

v1.3.6

Choose a tag to compare

@lyrixx lyrixx released this 05 Aug 09:18
33ae0a2

What's Changed

  • Added more type hinting & Fixed bug when parsing renamed files with spaces and/or non english-symbols by @tolik518 in #194

New Contributors

Full Changelog: v1.3.5...v1.3.6

v1.3.5

Choose a tag to compare

@lyrixx lyrixx released this 10 May 12:28
793ffe5
Release v1.3.5