Repository navigation
Releases
v2.0.0
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 aDriver\RepositoryDriverInterface, typed (hashes, enums, value objects ofDriver\Data), instead of building processes and parsing their output. A failing operation always throws, a missing revision or object aReferenceNotFoundException, a timeout aProcessTimedOutException; 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 logshows them, instead of in UTC: the instant doesn't change, butformat()returns their local time. (#254) - Require PHP 8.4 or later, and
symfony/process^6.4.33,^7.4.5or^8.1: most classes arefinal(somereadonly), and every method has native types. (#238) - Remove
Gitonomy\Git\Util\StringHelper, replaced bysymfony/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 ofgit diff --raw --patch. (#253)- The constructors of
Commit,Tree,Blob,Revision, the references andReferenceBagare internal: get these objects fromRepository, which returns the same commit, tree or blob while the application uses it, and reads the references again after its writes. ExtendingRevisionorReferenceisn't supported anymore. (#254) ProcessExceptionhas a message of one line, with the error of git, the first line of its error output starting withfatal:orerror:, 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()andgetOutput()return the outputs of git. (#254)Tree::resolvePath()throws anInvalidArgumentExceptionfor a path through a submodule, instead of anException\UnexpectedValueException, which gitlib no longer throws. (#254)- When git can't start, a missing binary for instance,
CliDriverthrows aDriverExceptioninstead of aProcessException, with a message of one line, without the command line:The git command "clone" could not start: .... (#254) WorkingCopy::checkout()throws aReferenceNotFoundExceptionfor a name that no revision has, with both drivers: the name of a remote branch alone, likefeaturefororigin/feature, created the local branch. UsecheckoutNewBranch(). (#254)- Remove the API that 1.7 deprecates (#271); see UPGRADE-2.0.md:
Admin, replaced by the static methods ofRepository, andRepository::cloneTo(), replaced bycloneFrom()andcloneBareFrom().- The array of options of
Repository(working_dir,logger,command,environment_variables,inherit_environment_variables,process_timeout,debug): pass the working directory and aCliDriverinstead;inherit_environment_variableshas no counterpart, pass the variables git needs instead.Repository::setLogger()andgetLogger(). - The
$reloadargument ofRepository::getReferences(), and the arguments ofCommit::getIncludingBranches().ReferenceBag::update()andBranch::isMergedTo(), replaced byBranch::moveTo()andisMergedInto(). Repository::getDiff()with one argument,Log::getDiff(),Diff::setRepository(),File::setRepository(),addChange(),isChangeMode(),isDelete()andgetAnchor(),FileChange::getCount(),getLines(), replaced bygetDiffLines(), and theLINE_*constants, replaced byDiffLineType, and the lines passed to the constructor ofFileChangeas arrays.Log::setOffset()andsetLimit().- A range of lines as a string in
Repository::getBlame(),Blame::getGroupedLines()andBlame\Line::getLine(). CommitReference,Tree::getCommitReferenceEntries(),getEntries(),getBlobEntries()andgetTreeEntries(): iterate the tree, or usegetBlobs(),getTrees()andgetSubmodules().- The branch to create of
WorkingCopy::checkout(). Commit::getShortMessage()andgetFixedShortHash(),Repository::shell(),PushReference::getReference(),getRevision(),isCreate()andisDelete().Repository::getSize(), in kilobytes: usegetSizeInBytes().
- Make
Parser\DiffParserandParser\ParserBaseinternal, like the other parsers: parse a diff withDiff::parse(). (#274) Log::getIterator()returns a\Traversableinstead of an\ArrayIterator: iterate the log, or usegetCommits(). (#274)- Run git in English with
CliDriver(LANGUAGE=C), unless itsenvironmentVariablessetLANGUAGE: 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 defaultDriver\Cli\CliDriver: pass it as the driver ofRepository. It avoids spawning agitprocess for every operation; see "Choosing a driver" for its requirements, its differences withCliDriver, 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 fromopcache.preload. (#253) Repositorytakes the working directory and the driver as arguments: aDriver\Cli\CliDriverby default, configured through its constructor (git binary, environment, timeout and logger, which gets every command, clones included), or anyDriver\DriverInterface, to replace it in tests; see "Using your own driver". The driver finds the repository: linked worktrees, submodules, clones with--separate-git-dirand reftable repositories (withCliDriver) open, and a directory that isn't a repository throws right away. (#253, #261, fixes #200)- Add static methods to
Repositorycreating repositories,init(),initBare(),cloneFrom(),cloneBareFrom()andmirrorFrom(), and checking a repository URL,isValidRepository()andisValidRepositoryAndBranch(); see "Create and access git repositories". (#253) - Add
Repository::getDiff($from, $to),Repository::getMergeBase(),Repository::getSizeInBytes()andWorkingCopy::getDiff(),WorkingCopy::checkoutNewBranch(),Branch::moveTo()andBranch::isMergedInto(),Log::withOffset()andwithLimit(),Blame::getHunks()and the line numbers ofBlame\Line,FileChange::getDiffLines(), which returnsDiff\DiffLineobjects typed byDiff\DiffLineType, iterating aTree, which givesTreeEntryobjects,Tree::getBlobs(),getTrees()andgetSubmodules(),Submodule,File::isModeChange(),FileChange::getAdditions()andgetDeletions(),PushReference::getFullname(),getRange(),isCreation()andisDeletion(), and the SSH and X.509 signatures of tags. (#253, #254, #263) - Add
WorkingCopy::merge()to supportgit merge, fast-forwarding or not, with aFastForwardenum. (#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 defaulta//b/prefixes with context-specific ones (c//i//o//w/), which used to raise aRuntimeExceptionin tools like GrumPHP that enable it. (#245, fixes #114) - Support
"copy from"/"copy to"in the diff parser: diffs prod...
v1.7.2
Changes since v1.7.1.
Security
- Fix
Repository::isValidRepository()andisValidRepositoryAndBranch()reading the
configuration of a repository of the temporary directory, where they rungit ls-remote:
another user of the machine may create a.gitthere, 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 ofcore.gitProxy, which reads it as an option.
Bug fixes
- Fix a
TypeErrorwhen 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 aReferenceNotFoundException, andgetTree()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 aRuntimeException.
Deprecations
Parser\DiffParserandParser\ParserBase, internal in 2.0: parse a diff with
Diff::parse().
v1.7.1
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
--outputas 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 blamereading or writing a file as a revision:
getBlame('--contents=/path', 'README.md')returned the lines of any file, and the error of
--ignore-revs-fileor-Sprinted 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
--, ascloneFrom($url, '--upload-pack=...')ran the command too. - Refuse a hash starting with a dash in
ReferenceBag::createBranch()andcreateTag():
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). Agit://URL whose host starts with a dash
is refused too: git passes it to the command ofcore.gitProxy. - Hide the credentials of URLs (
https://user:token@host), a password holding a#or a?
included, in the messages ofProcessExceptionand 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')andget('../config')wrote, deleted and read files of the repository.
The names staying in the directory, likepost-receive.d/notify, still work. - Fix
Hookswriting through a symbolic link to a missing file, out of the hooks directory:
has()returnedfalsefor it, andset()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')deletedorigin/main. - Fix
ReferenceBag::delete('HEAD')deleting a detachedHEAD, which left no repository: it
throws anInvalidArgumentException. - Require
symfony/process5.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, asgit 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. SetGIT_NO_REPLACE_OBJECTSto1in the
environmentVariablesofCliDriverto ignore them. WorkingCopy::checkout()still takes a path or an option:checkout('README.md')discards the
changes of the file, andcheckout('--force')all of them.- Moving a symbolic reference, with
Branch::moveTo()orReferenceBag::update(), still moves
the branch it points to.
v1.7.0
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\CliDriverconfigures git: the binary, the environment variables, the timeout and the logger. It takes the arguments of theCliDriverof 2.0.new Repository($dir, $workingDir, $driver): the second argument may be the working directory, the third one is aCliDriver.Repository::init(),initBare(),cloneFrom(),cloneBareFrom(),mirrorFrom(),isValidRepository()andisValidRepositoryAndBranch()take the URL before the path and aCliDriveras 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 aReferenceNotFoundExceptionfor an unknown revision, asWorkingCopy::checkoutNewBranch().Diff::parse(),Diff::fromArray()andFile::fromArray()take the repository to read the blobs from, the constructor ofDiff\Filethe changes and the repository.File::isModeChange(),File::isCopy(),FileChange::getAdditions()andFileChange::getDeletions().FileChange::getDiffLines()returns the lines of a hunk asDiff\DiffLineobjects, withgetType(), aDiff\DiffLineType, andgetContent(). The constructor ofFileChangetakesDiffLineobjects.Repository::getBlame()andBlametake the first and the last lines to blame, as integers.Blame::getHunks()returnsBlame\Hunkobjects, numbered like the file;Blame\Line::getNumber()andgetOriginalNumber().Log::withOffset()andwithLimit()return another log.Branch::isMergedInto()andBranch::moveTo().ReferenceBag::createBranch()andcreateTag()take aRevisiontoo.PushReference::getFullname(),getRange(),isCreation()andisDeletion().- Iterating a
Treegives its entries,TreeEntryobjects withgetName(),getMode()andgetObject(), by name;Tree::getBlobs(),getTrees()andgetSubmodules()return those of one type. Submodule, withgetHash(). The submodules of trees are stillCommitReferenceobjects, which extendSubmodule.WorkingCopy::checkoutNewBranch().WorkingCopy::checkout()takes anyRevision.Repository::getSizeInBytes(), which doesn't follow links.
Deprecations
- An array of options as second argument of
Repository, thedebugoption set tofalse,Repository::setLogger()andgetLogger(): use theworkingDiranddriverarguments. AdminandRepository::cloneTo(): use the static methods ofRepository.Repository::getDiff()with one argument andLog::getDiff(): useRepository::getDiff($from, $to)orWorkingCopy::getDiff().Diff::setRepository(),File::setRepository(),File::addChange(),File::isChangeMode(),File::isDelete(),File::getAnchor()andFileChange::getCount().FileChange::getLines(), which returns the lines as arrays, theFileChange::LINE_*constants, and passing the lines to the constructor ofFileChangeas arrays: usegetDiffLines(),DiffLineTypeandDiffLineobjects.- A range of lines as a string in
Repository::getBlame()andBlame,Blame::getGroupedLines()andBlame\Line::getLine(). Log::setOffset(),setLimit(), a negative offset or limit, an option ofgit logbut--allas revision, andcount()of a log whose offset or limit leaves commits out: it counts them all, where 2.0 counts the commits the log iterates. UsecountCommits().ReferenceBag::update(),Branch::isMergedTo(), arguments ofCommit::getIncludingBranches(), creating a branch or a tag that exists already, deleting a reference by another name than its full name underrefs/.- Passing an argument to
Repository::getReferences(), to read the references again: open a newRepository. PushReference::getReference(),getRevision(),isCreate()andisDelete().CommitReference.Tree::getEntries(),getBlobEntries(),getTreeEntries()andgetCommitReferenceEntries(), which return the entries as arrays: iterate the tree, or usegetBlobs(),getTrees()andgetSubmodules().- The second argument of
WorkingCopy::checkout(): usecheckoutNewBranch(). A localBranchobject, whichcheckout()detaches HEAD on, where 2.0 attaches HEAD to the branch: pass its name, or its commit. - Passing a revision name to
Repository::getTree()orgetBlob()instead of a hash, and passing data to the constructor ofCommit, internal in 2.0. Repository::getSize(),Repository::shell(),Commit::getShortMessage(),Commit::getFixedShortHash()andUtil\StringHelper.- The parsers that 2.0 moves to its
CliDriver, all butDiffParserandParserBase. - The classes
finalin 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
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
- @thecaliskan made their first contribution in #215
- @Patrick-Beuks made their first contribution in #219
- @simonhamp made their first contribution in #211
- @claudiu-cristea made their first contribution in #217
- @codebymikey made their first contribution in #208
Full Changelog: v1.4.0...v1.5.0
v1.4.0
v1.3.8
What's Changed
- Method to check if a branch is merged (added code from PR #151) by @tolik518 in #197
- Fixed github test badge: badges/shields#8671 by @tolik518 in #199
- Adds feature to check if a branch name exists in a repository without… by @hostep in #202
New Contributors
Full Changelog: v1.3.7...v1.3.8