From 027fe7f44732e6e5de0a6d700179e22af71953f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 7 Nov 2026 23:36:46 +0100 Subject: [PATCH] Remove the API deprecated in 1.7 --- CHANGELOG.md | 73 +++--- UPGRADE-2.0.md | 118 ++++----- composer.json | 1 - doc/admin.md | 2 +- doc/blame.md | 8 - doc/branch.md | 6 +- doc/commit.md | 9 +- doc/diff.md | 19 -- doc/log.md | 9 - doc/references.md | 6 +- doc/repository.md | 23 +- doc/tree.md | 7 - doc/workingcopy.md | 6 - src/Gitonomy/Git/Admin.php | 195 -------------- src/Gitonomy/Git/Blame.php | 14 - src/Gitonomy/Git/Blame/Line.php | 10 - src/Gitonomy/Git/Commit.php | 54 +--- src/Gitonomy/Git/CommitReference.php | 28 -- src/Gitonomy/Git/Diff/Diff.php | 13 - src/Gitonomy/Git/Diff/DiffLineType.php | 4 +- src/Gitonomy/Git/Diff/File.php | 70 +---- src/Gitonomy/Git/Diff/FileChange.php | 57 +--- src/Gitonomy/Git/Driver/Cli/CliDriver.php | 20 +- src/Gitonomy/Git/Driver/Cli/LegacyOptions.php | 111 -------- src/Gitonomy/Git/Log.php | 35 --- src/Gitonomy/Git/PushReference.php | 40 --- src/Gitonomy/Git/Reference/Branch.php | 17 -- src/Gitonomy/Git/ReferenceBag.php | 19 -- src/Gitonomy/Git/Repository.php | 243 +----------------- src/Gitonomy/Git/Submodule.php | 5 - src/Gitonomy/Git/Tree.php | 63 ----- src/Gitonomy/Git/WorkingCopy.php | 10 +- tests/Gitonomy/Git/Tests/AdminTest.php | 219 ---------------- tests/Gitonomy/Git/Tests/BlameTest.php | 20 -- tests/Gitonomy/Git/Tests/CommitTest.php | 63 ----- tests/Gitonomy/Git/Tests/DiffTest.php | 125 --------- tests/Gitonomy/Git/Tests/LogTest.php | 42 --- .../Gitonomy/Git/Tests/PushReferenceTest.php | 38 --- tests/Gitonomy/Git/Tests/ReferenceTest.php | 44 ---- tests/Gitonomy/Git/Tests/RepositoryTest.php | 135 ---------- tests/Gitonomy/Git/Tests/TreeTest.php | 74 ------ tests/Gitonomy/Git/Tests/WorkingCopyTest.php | 14 - 42 files changed, 122 insertions(+), 1947 deletions(-) delete mode 100644 src/Gitonomy/Git/Admin.php delete mode 100644 src/Gitonomy/Git/CommitReference.php delete mode 100644 src/Gitonomy/Git/Driver/Cli/LegacyOptions.php delete mode 100644 tests/Gitonomy/Git/Tests/AdminTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d6459ea0..11570c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,8 @@ All notable changes to this project are documented in this file. ## [Unreleased] -Changes since [v1.6.0](https://github.com/gitonomy/gitlib/releases/tag/v1.6.0). To upgrade, see -[UPGRADE-2.0.md](UPGRADE-2.0.md): most of the API of 1.x that 2.0 replaces keeps working, -deprecated until 3.0. +Changes since [v1.6.0](https://github.com/gitonomy/gitlib/releases/tag/v1.6.0). To upgrade, fix +the deprecations of 1.7 first, then see [UPGRADE-2.0.md](UPGRADE-2.0.md). ### Breaking changes @@ -54,6 +53,32 @@ deprecated until 3.0. with both drivers: the name of a remote branch alone, like `feature` for `origin/feature`, created the local branch. Use `checkoutNewBranch()`. ([#254](https://github.com/gitonomy/gitlib/pull/254)) +- Remove the API that 1.7 deprecates; see [UPGRADE-2.0.md](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()`. ### Features @@ -105,38 +130,6 @@ deprecated until 3.0. still exists afterward. ([#244](https://github.com/gitonomy/gitlib/pull/244), fixes #14) -### Deprecations - -All are removed in 3.0; see [UPGRADE-2.0.md](UPGRADE-2.0.md). -([#253](https://github.com/gitonomy/gitlib/pull/253)) 1.7 deprecates them already: they are -all deprecated since 1.7. - -- `Admin`, replaced by the static methods of `Repository`, and `Repository::cloneTo()`, - replaced by `cloneFrom()` and `cloneBareFrom()`. -- The array of options of `Repository` and `Admin` (`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()`. -- Passing `$reload` to `Repository::getReferences()`, and arguments to - `Commit::getIncludingBranches()`. `ReferenceBag::update()` and `Branch::isMergedTo()`, - replaced by `Branch::moveTo()` and `isMergedInto()`. -- Calling `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`, 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()`. - ([#254](https://github.com/gitonomy/gitlib/pull/254)) - ### Security 1.7.1 has those that break nothing of 1.x: see @@ -246,8 +239,9 @@ all deprecated since 1.7. - Fix blame lines numbered from 1 for a range of lines. ([#253](https://github.com/gitonomy/gitlib/pull/253)) - Fix `Hooks` failing silently, in a repository without hooks directory, and writing the hooks of a linked worktree where git doesn't run them. ([#253](https://github.com/gitonomy/gitlib/pull/253)) -- Fix `Repository::getSize()` throwing for a link to a missing file in the git directory, like - a hook not deployed yet: it no longer follows links. A file or a directory git deletes +- Fix the size of a repository (`getSizeInBytes()`, which replaces `getSize()`) throwing for a + link to a missing file in the git directory, like a hook not deployed yet: it no longer follows + links. A file or a directory git deletes meanwhile, like a lock during a `gc` or the quarantine of a push, no longer makes it throw either, and one it can't read throws a `RuntimeException` of gitlib, instead of PHP's. ([#254](https://github.com/gitonomy/gitlib/pull/254), [#263](https://github.com/gitonomy/gitlib/pull/263)) @@ -256,7 +250,7 @@ all deprecated since 1.7. - Fix reading a commit whose `encoding` header isn't UTF-8, which threw: its message, author and committer are now re-encoded to UTF-8, like `git log` does. ([#253](https://github.com/gitonomy/gitlib/pull/253)) - Fix file names holding non-ASCII or special characters (tab, quote, backslash) in trees - (`Tree::getEntries()`), and special characters in diffs, which kept git's C-style quoting. + (iterating a `Tree`), and special characters in diffs, which kept git's C-style quoting. ([#253](https://github.com/gitonomy/gitlib/pull/253)) - Fix relative paths not resolving against the repository in `Repository::run()`: the git process spawned by `run()` never had its working directory set, so commands such as @@ -273,11 +267,8 @@ all deprecated since 1.7. branch existed. - `Tag::getBodyMessage()` dropped or truncated a line for annotated tags using the standard `subject\n\nbody` convention. - - `Repository::shell()` interpolated the repository path into the shell command without - escaping it; it is now passed through `escapeshellarg()`. - `Hooks::set()` created hook scripts world-writable (`0777`); they are now created `0700`. - - Fixed the `isSuccessFul()` casing typo in `Admin`. ### Minor diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index dbe90c3e..2f95c00e 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -6,15 +6,13 @@ default, runs the `git` binary like 1.x did, and the experimental `LibGit2Driver` runs libgit2 in-process (see ["Choosing a driver"](doc/repository.md#choosing-a-driver)). -Most of the API of 1.x that 2.0 replaces keeps working, deprecated: each -call triggers a deprecation (`E_USER_DEPRECATED`, through -`symfony/deprecation-contracts`) naming its replacement, and 3.0 removes -them. Log the deprecations of your application to find them. The other -changes, listed below too, break code that relies on them. - -Upgrade to 1.7.1 first, which requires PHP 8.1: it has most of the -replacements, and triggers the deprecations of the API they replace (see -[Supporting 1.x and 2.x](#supporting-1x-and-2x)). +2.0 removes the API of 1.x that it replaces. Upgrade to 1.7.1 first, which +requires PHP 8.1: it has the replacements, and each call to the API that +2.0 removes triggers a deprecation (`E_USER_DEPRECATED`) naming its +replacement. Log the deprecations of your application to find them, and fix +them before upgrading to 2.0 (see +[Supporting 1.x and 2.x](#supporting-1x-and-2x)). The other changes, listed +below too, break code that relies on them. Requirements ------------ @@ -26,9 +24,8 @@ Requirements * `symfony/process` must be `^6.4.33`, `^7.4.5` or `^8.1`: the older versions escape the arguments wrongly on Windows (CVE-2024-51736, CVE-2026-24739). -* `symfony/string` `^7.4.6` or `^8.0.6`, `symfony/deprecation-contracts` - `^2.5` or `^3`, and `psr/log` `^1.1`, `^2.0` or `^3.0` are new - dependencies. +* `symfony/string` `^7.4.6` or `^8.0.6`, and `psr/log` `^1.1`, `^2.0` or + `^3.0` are new dependencies. * Repositories using SHA-256 hashes are refused, with an `UnsupportedOperationException`, by both drivers. @@ -36,7 +33,7 @@ Supporting 1.x and 2.x ---------------------- gitlib 1.7 has the API of 2.0 that can be added without breaking 1.x, and -deprecates what 2.0 replaces or breaks: `new Repository($dir, $workingDir, +deprecates what 2.0 removes or breaks: `new Repository($dir, $workingDir, $driver)` with a `CliDriver` of the same arguments, the static methods of `Repository` creating repositories, `Diff::parse($rawDiff, $repository)`, `Repository::getDiff($from, $to)`, `FileChange::getDiffLines()`, iterating @@ -85,7 +82,7 @@ both versions: `Blame::getHunks()`, numbered like the file in 1.7 too. * 1.7 doesn't read the references again after a write: open a new `Repository` to read them, with both versions. `getReferences(true)` is - deprecated in 1.7 too. + deprecated in 1.7, and 2.0 removes its argument. * The classes `final` in 2.0 are only `@final` in 1.7: see [Testing code using gitlib](#testing-code-using-gitlib). * The other changes listed below: dates, the stricter parser of diffs, @@ -95,11 +92,12 @@ Opening a repository -------------------- * The second argument of `Repository` is the working directory, when the - git directory is kept apart from it. An array of options there is - deprecated: its `working_dir` option is this argument, and its `logger`, - `command`, `environment_variables` and `process_timeout` options configure - a `Gitonomy\Git\Driver\Cli\CliDriver`, which `Repository` takes as its last - argument. They can't be combined with this argument. + git directory is kept apart from it, instead of an array of options: its + `working_dir` option is this argument, its `logger`, `command`, + `environment_variables` and `process_timeout` options configure a + `Gitonomy\Git\Driver\Cli\CliDriver`, which `Repository` takes as its last + argument, and its `debug` option is removed: a failing git operation + always throws, see [Errors](#errors). * The `inherit_environment_variables` option has no counterpart in `CliDriver`: git inherits the environment variables of PHP anyway, and `$_SERVER` holds, under php-fpm, the headers and the credentials of the @@ -137,12 +135,8 @@ Opening a repository * The logger is an argument of `CliDriver`, which logs every git command it runs, cloning and initializing included: `Repository::setLogger()` and - `Repository::getLogger()` are deprecated. `LibGit2Driver` runs no command, + `Repository::getLogger()` are removed. `LibGit2Driver` runs no command, and logs nothing. -* An unknown option throws an `InvalidArgumentException`, instead of being - ignored. -* The `debug` option is deprecated, and setting it to `false` throws an - `InvalidArgumentException`: see [Errors](#errors). * `$path` may be a linked worktree, a submodule or a clone with `--separate-git-dir`, whose `.git` is a file. * A directory that isn't a repository throws an `InvalidArgumentException` @@ -151,7 +145,8 @@ Opening a repository Creating repositories --------------------- -* `Admin` is deprecated: use the static methods of `Repository`. They take +* `Admin` and `Repository::cloneTo()` are removed: use the static methods + of `Repository`. They take the URL before the path, have a method for each kind of repository instead of the `$bare` argument, whose default was a bare repository, and take the driver as last argument: @@ -170,9 +165,6 @@ Creating repositories | `$repository->cloneTo($path)` | `Repository::cloneBareFrom($repository->getGitDir(), $path)` | | `$repository->cloneTo($path, false)` | `Repository::cloneFrom($repository->getGitDir(), $path)` | - Until 3.0, `Admin` keeps working like in 1.x, with `CliDriver` and the - options of 1.x. - * `isValidRepositoryAndBranch()` checks the exact name of the branch: `release` no longer matches `feature/release`, nor `rel*` `release`. * `isValidRepository()` and `isValidRepositoryAndBranch()` read a relative @@ -197,9 +189,9 @@ Creating repositories * `Repository::cloneTo()` cloned with the driver of the repository: pass it to `cloneFrom()` or `cloneBareFrom()` as well. -* `Admin::cloneRepository()` is deprecated, with no replacement for the - arguments of `git clone` other than `--bare`, `--branch` and `--mirror`: - run `git clone` yourself, then open the repository with +* `Admin::cloneRepository()` has no replacement for the arguments of + `git clone` other than `--bare`, `--branch` and `--mirror`: run + `git clone` yourself, then open the repository with `new Repository($path)`. References @@ -207,9 +199,9 @@ References * `Repository::getReferences()` reads the references again after every write gitlib makes (creating or deleting a reference, a checkout, a merge, - `run()`...): passing `true` to read them again is deprecated. Open a new - `Repository` to see the writes of other processes. A `Reference` object - keeps the commit it pointed to when it was read. + `run()`...), and takes no argument: open a new `Repository` to see the + writes of other processes. A `Reference` object keeps the commit it + pointed to when it was read. * `Reference::getCommitHash()` returns the commit an annotated tag points to, instead of the hash of the tag object: `ReferenceBag::resolve()`, `resolveTags()` and `Commit::resolveReferences()` find annotated tags. @@ -217,7 +209,7 @@ References `InvalidArgumentException` when the reference exists, instead of moving it, and take a `Revision` or a revision name as second argument, instead of a commit hash only. -* `ReferenceBag::update()` is deprecated: use `Branch::moveTo()`. +* `ReferenceBag::update()` is removed: use `Branch::moveTo()`. Before: @@ -231,12 +223,11 @@ References $repository->getReferences()->getBranch('main')->moveTo($hash); ``` -* `Branch::isMergedTo()` is deprecated: use `isMergedInto()`, which takes +* `Branch::isMergedTo()` is removed: use `isMergedInto()`, which takes the destination as a `Revision` or a revision name, without a default (`'master'` before) nor `$compareOnlyWithRemote`. -* Passing arguments to `Commit::getIncludingBranches()` is deprecated: it - returns the local and remote branches, which `Branch::isLocal()` and - `isRemote()` filter. +* `Commit::getIncludingBranches()` takes no argument: it returns the local + and remote branches, which `Branch::isLocal()` and `isRemote()` filter. Before: @@ -275,7 +266,7 @@ References History ------- -* `Log::setOffset()` and `setLimit()` are deprecated: `withOffset()` and +* `Log::setOffset()` and `setLimit()` are removed: `withOffset()` and `withLimit()` return another `Log`. * `count($log)` returns the number of commits the log iterates, after its offset and up to its limit; `countCommits()` still counts them all. @@ -284,14 +275,14 @@ History exclude (`^a`) or `--all`: any other option of `git log` throws an `InvalidArgumentException`, instead of being passed to git. An unknown revision throws a `ReferenceNotFoundException` naming it. -* `Log::getDiff()` is deprecated: it ignored the paths of the log. Use +* `Log::getDiff()` is removed: it ignored the paths of the log. Use `Repository::getDiff()`. Diffs ----- -* `Repository::getDiff()` takes the commits to compare: `$from` and `$to`. - Calling it with one argument is deprecated. +* `Repository::getDiff()` takes the commits to compare: `$from` and `$to`, + both required. | 1.x | 2.0 | |------------------------------------|------------------------------------------------------------------| @@ -304,15 +295,15 @@ Diffs parent, like GitHub shows it, with both drivers. * `Diff`, `Diff\File` and `Diff\FileChange` get their repository and their changes when constructed: `Diff::setRepository()`, - `File::setRepository()` and `File::addChange()` are deprecated. + `File::setRepository()` and `File::addChange()` are removed. `Diff::parse()` and `fromArray()` take the repository to read blobs from. * `FileChange::getDiffLines()` returns the lines of a hunk as `Diff\DiffLine` objects, with `getType()`, a `Diff\DiffLineType`, and `getContent()`: `FileChange::getLines()`, which returns them as arrays, - is deprecated, as the `FileChange::LINE_*` constants and + is removed, as the `FileChange::LINE_*` constants and `FileChange::getCount()`, replaced by `getAdditions()` and `getDeletions()`. The constructor of `FileChange` takes `DiffLine` - objects: arrays are deprecated. + objects, instead of arrays. Before: @@ -336,7 +327,7 @@ Diffs } ``` -* `File::isChangeMode()`, `isDelete()` and `getAnchor()` are deprecated: +* `File::isChangeMode()`, `isDelete()` and `getAnchor()` are removed: use `isModeChange()`, `isDeletion()`, and `substr($file->getNewIndex(), 0, 12)`. * `File::getOldIndex()` and `getNewIndex()` return `null` for a missing @@ -363,15 +354,15 @@ Diffs Blame ----- -* `Repository::getBlame()` takes the first and the last lines to blame: - a range as a string (`'3,5'`, `'3,+3'`) is deprecated, and a regular - expression is no longer supported. +* `Repository::getBlame()` takes the first and the last lines to blame, + instead of a range as a string (`'3,5'`, `'3,+3'` or a regular + expression). * `Blame::getLines()` and `getLine()` number the lines like the file, from the first blamed line, instead of from 1. * `Blame\Line::getNumber()` and `getOriginalNumber()` return the number of the line in the file and in the commit that changed it, as integers: - `Line::getLine()` is deprecated. -* `Blame::getGroupedLines()` is deprecated: `getHunks()` returns + `Line::getLine()` is removed. +* `Blame::getGroupedLines()` is removed: `getHunks()` returns `Blame\Hunk` objects. Trees @@ -381,7 +372,7 @@ Trees `getName()`, `getMode()` and `getObject()`; `getBlobs()`, `getTrees()` and `getSubmodules()` return them by kind. `getEntries()`, `getBlobEntries()` and `getTreeEntries()`, which return them as arrays - (`[$mode, $object]`), are deprecated. + (`[$mode, $object]`), are removed. Before: @@ -399,7 +390,7 @@ Trees } ``` -* `CommitReference` is deprecated: it is `Submodule`. So is +* `CommitReference` is removed: it is `Submodule`. So is `Tree::getCommitReferenceEntries()`: use `getSubmodules()`. * `Tree::resolvePath()` throws an `InvalidArgumentException` explaining why a path doesn't resolve, a path through a submodule included, which @@ -410,7 +401,7 @@ Working copy * `WorkingCopy::checkout()` takes a `Revision` or a revision name: a local `Branch` object attaches `HEAD` to the branch, instead of detaching it. - Its second argument, a branch to create, is deprecated: use + Its second argument, a branch to create, is removed: use `checkoutNewBranch($branch, $startPoint)`. * `WorkingCopy::checkout()` throws a `ReferenceNotFoundException` for a name that no revision has, with both drivers: the name of a remote @@ -442,7 +433,7 @@ Commits, trees and blobs its body what follows, like `git log --format=%s` and `%b`: a message without an empty line after its first line has no body, where its second line was lost. -* `Commit::getShortMessage()` and `getFixedShortHash()` are deprecated: use +* `Commit::getShortMessage()` and `getFixedShortHash()` are removed: use `symfony/string` (`u($commit->getSubjectMessage())->truncate(50, '...')`) and `substr()`. * `Blob::getMimetype()` returns the mimetype alone (`text/plain`, instead @@ -530,9 +521,6 @@ Errors creates the hooks directory. `remove()` of a hook that doesn't exist throws an `InvalidArgumentException`, like `get()`, still a `LogicException`. -* The `Admin` methods throw a `ProcessException`, still a - `RuntimeException`, with the first line of git's error output in its - message, or a `DriverException` when git can't start. * An argument holding a NUL byte throws an `InvalidArgumentException`, where PHP threw a `ValueError`: git and libgit2 read their arguments as C strings, which end at the first NUL byte. @@ -605,14 +593,14 @@ Dates Extending gitlib ---------------- -* These classes are `final`: `Admin`, `Blame`, `Blob`, `Commit`, - `Diff\File`, `Log`, `Parser\DiffParser`, `PushReference`, +* These classes are `final`: `Blame`, `Blob`, `Commit`, `Log`, + `Parser\DiffParser`, `PushReference`, `Reference\Branch`, `Reference\Stash`, `Reference\Tag`, `ReferenceBag`, `Repository`, `Tree`, and the exceptions `LogicException`, `ProcessException`, `ReferenceNotFoundException` and `UnexpectedValueException`. * These classes are `final readonly`: `Blame\Line`, `Diff\Diff`, - `Diff\FileChange`, `Hooks`, `RevisionList`, `WorkingCopy`. + `Diff\File`, `Diff\FileChange`, `Hooks`, `RevisionList`, `WorkingCopy`. * Every method has native parameter and return types. A class extending `Parser\ParserBase`, which remains extendable, must declare the same types, and must not redeclare its properties. @@ -695,7 +683,7 @@ Data returned * `PushReference::isForce()` returns `true` for histories without a common ancestor, where the constructor threw. `PushReference` runs git when `isForce()` needs it, not when constructed. `getReference()`, - `getRevision()`, `isCreate()` and `isDelete()` are deprecated: use + `getRevision()`, `isCreate()` and `isDelete()` are removed: use `getFullname()`, `getRange()`, `isCreation()` and `isDeletion()`, named like the ones of `Diff\File`. The `$reference` argument of its constructor is named `$fullname`. @@ -728,13 +716,13 @@ Other changes Nothing changes when PHP runs out of the repository. * `Hooks::set()` makes hooks executable by their owner only (`0700`, instead of `0777`): change their permissions if another user runs them. -* `Repository::shell()` is deprecated: it ignored the driver. Run +* `Repository::shell()` is removed: it ignored the driver. Run `git shell` with Symfony Process instead. * `Hooks::has()` returns `true` for a symbolic link to a missing file: `get()` throws a `RuntimeException`, as it can't read it, `set()` and `setSymlink()` refuse it, as a hook that exists already, and `remove()` removes the link. -* `Repository::getSize()` is deprecated: `getSizeInBytes()` returns bytes, +* `Repository::getSize()` is removed: `getSizeInBytes()` returns bytes, instead of kilobytes. Neither follows links: a link in the git directory, to a hook not deployed yet for instance, counts for nothing, where `getSize()` counted the file it points to, and threw for a missing one. diff --git a/composer.json b/composer.json index 42bdc86b..4900ca6b 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,6 @@ "php": "^8.4", "ext-pcre": "*", "psr/log": "^1.1 || ^2.0 || ^3.0", - "symfony/deprecation-contracts": "^2.5 || ^3", "symfony/process": "^6.4.33 || ^7.4.5 || ^8.1", "symfony/string": "^7.4.6 || ^8.0.6" }, diff --git a/doc/admin.md b/doc/admin.md index 5ba076fe..9237bed0 100644 --- a/doc/admin.md +++ b/doc/admin.md @@ -2,7 +2,7 @@ Create and access git repositories ================================== The static methods of `Repository` create new repositories, and return them. -They replace `Admin`, deprecated since 1.7: see +They replace `Admin`, removed in 2.0: see [UPGRADE-2.0.md](../UPGRADE-2.0.md#creating-repositories). To open a repository that exists already, use `new Repository($path)`: see diff --git a/doc/blame.md b/doc/blame.md index 9b24da4e..b9299ebe 100644 --- a/doc/blame.md +++ b/doc/blame.md @@ -25,9 +25,6 @@ Like git, the blame stops at the end of the file, and a first line after it throws a `DriverException`. A last line before the first one blames the lines in order, like `git blame -L 5,3`. -Passing a range as a string (`'2,3'` or `'2,+2'`, like `git blame -L`) is -deprecated since 1.7: pass the first and the last lines instead. - Line-per-line iteration ----------------------- @@ -66,9 +63,6 @@ $line->getCommit(); // The commit that last changed it $author = $line->getCommit()->getAuthorName(); ``` -`Line::getLine()` is deprecated since 1.7: use `getOriginalNumber()`, which -returns an integer. - Group reading by commit ----------------------- @@ -86,5 +80,3 @@ foreach ($blame->getHunks() as $hunk) { } } ``` - -`getGroupedLines()` is deprecated since 1.7: use `getHunks()`. diff --git a/doc/branch.md b/doc/branch.md index 42879169..64afd16c 100644 --- a/doc/branch.md +++ b/doc/branch.md @@ -41,8 +41,7 @@ $branch = $branch->moveTo('master~2'); ``` Like `git update-ref`, it doesn't touch the working tree, even for the -branch checked out. `ReferenceBag::update()` is deprecated since 1.7: use -`moveTo()`. +branch checked out. Merged branches --------------- @@ -56,9 +55,6 @@ if ($branch->isMergedInto('master')) { } ``` -`isMergedTo()` is deprecated since 1.7: use `isMergedInto()`, which has no -default destination (`master`) nor flag to compare remote branches only. - Branches containing a commit ---------------------------- diff --git a/doc/commit.md b/doc/commit.md index aac1dfca..82f0c15c 100644 --- a/doc/commit.md +++ b/doc/commit.md @@ -30,9 +30,6 @@ $commit->getHash(); // "7e9ba14939b0ce67ab95d83e03bd64710db91ef4" $commit->getShortHash(); // "7e9ba14", abbreviated and unique in the repository ``` -`getFixedShortHash()` is deprecated since 1.7: use -`substr($commit->getHash(), 0, 6)`. - Browsing parents ---------------- @@ -125,8 +122,7 @@ the subject is `"Fix the parser of dates"`, and the body `"It failed on leap years.\n"`. A message without an empty line has no body. -`getShortMessage()` is deprecated since 1.7: truncate the subject with -`symfony/string`, a dependency of gitlib, instead: +To truncate the subject, use `symfony/string`, a dependency of gitlib: ```php use function Symfony\Component\String\u; @@ -195,6 +191,3 @@ $branches = $commit->getIncludingBranches(); $localBranches = array_filter($branches, static fn (Branch $branch): bool => $branch->isLocal()); $remoteBranches = array_filter($branches, static fn (Branch $branch): bool => $branch->isRemote()); ``` - -Passing arguments to `getIncludingBranches()`, to keep the local or the -remote branches only, is deprecated since 1.7. diff --git a/doc/diff.md b/doc/diff.md index e474f5f3..55b25113 100644 --- a/doc/diff.md +++ b/doc/diff.md @@ -23,11 +23,6 @@ start from their best common ancestor: $diff = $repository->getDiff($repository->getMergeBase('master', 'feature'), 'feature'); ``` -Calling `getDiff()` with one argument (a range like `a..b` or `a...b`, two -revisions in an array, or one revision to compare with the working tree) -is deprecated since 1.7: see [UPGRADE-2.0.md](../UPGRADE-2.0.md). -`Log::getDiff()` is deprecated too: it ignored the paths of the log. - Other diffs ----------- @@ -126,9 +121,6 @@ $file->getDeletions(); $file->getChanges(); // FileChange objects: see below ``` -`isChangeMode()`, `isDelete()` and `getAnchor()` are deprecated since 1.7: -use `isModeChange()`, `isDeletion()` and `substr($file->getNewIndex(), 0, 12)`. - The FileChange object --------------------- @@ -164,13 +156,6 @@ foreach ($file->getChanges() as $change) { `getAdditions()` and `getDeletions()` count the lines the hunk adds and deletes. -`getLines()`, which returns each line as an array (`[$type, $content]`), the -`FileChange::LINE_ADD`, `LINE_CONTEXT` and `LINE_REMOVE` constants, and -`FileChange::getCount()` are deprecated since 1.7: use `getDiffLines()`, -`DiffLineType`, and `getAdditions()` or `getDeletions()`. So is passing the -lines to the constructor of `FileChange` as arrays: pass `DiffLine` -objects. - Parsing a diff -------------- @@ -211,7 +196,3 @@ $diff = Diff::fromArray($array, $repository); ``` The arrays of 1.x are read too. - -`Diff::setRepository()`, `File::setRepository()` and `File::addChange()` are -deprecated since 1.7: pass the repository to `Diff::parse()` or -`Diff::fromArray()`, and the changes to the constructor of `File`. diff --git a/doc/log.md b/doc/log.md index 1cd66947..86b73329 100644 --- a/doc/log.md +++ b/doc/log.md @@ -131,12 +131,3 @@ $secondPage = $firstPage->withOffset(10); $secondPage->getOffset(); // 10 $secondPage->getLimit(); // 10 ``` - -`setOffset()` and `setLimit()`, which changed the log, are deprecated since -2.0: use `withOffset()` and `withLimit()`. - -Diff of a log -------------- - -`Log::getDiff()` is deprecated since 1.7: it ignored the paths of the log. -Use `Repository::getDiff($from, $to)`, see [diff.md](diff.md). diff --git a/doc/references.md b/doc/references.md index adab71f6..1d891383 100644 --- a/doc/references.md +++ b/doc/references.md @@ -13,8 +13,7 @@ $references = $repository->getReferences(); The bag reads the references again after every write gitlib makes: creating or deleting a reference, a checkout, a merge, `Repository::run()`... To see -the writes of other processes, open a new `Repository`. Passing an argument -to `getReferences()`, to read them again, is deprecated since 1.7. +the writes of other processes, open a new `Repository`. First, you can test the existence of tags and branches like this: @@ -109,8 +108,7 @@ like `refs/heads/foobar`, and does nothing when it doesn't exist, like `createBranch()` and `createTag()` throw an `InvalidArgumentException` when the reference exists: they never move it. To move a branch, use -`Branch::moveTo()`: see [branch.md](branch.md). `ReferenceBag::update()` is -deprecated since 1.7: use `Branch::moveTo()`. +`Branch::moveTo()`: see [branch.md](branch.md). Tags ---- diff --git a/doc/repository.md b/doc/repository.md index a81e85de..de78ef81 100644 --- a/doc/repository.md +++ b/doc/repository.md @@ -46,11 +46,6 @@ use Gitonomy\Git\Repository; $repository = new Repository('/srv/project.git', '/srv/project', new CliDriver(processTimeout: 60)); ``` -An array of options as second argument (`working_dir`, `logger`, `command`, -`process_timeout`...) is deprecated since 1.7: pass the working directory, -and configure a `CliDriver` instead. See -[UPGRADE-2.0.md](../UPGRADE-2.0.md#opening-a-repository). - A directory that doesn't exist, or that isn't a repository, throws an `InvalidArgumentException`. @@ -150,8 +145,7 @@ $references = $repository->getReferences(); gitlib reads them again after every write it makes: creating or deleting a reference, a checkout, a merge, `run()`... It doesn't see the writes of other processes (a push to the repository, another worker...): open a new -`Repository` to see them. The `$reload` argument of `getReferences()` is -deprecated since 1.7. +`Repository` to see them. Description ----------- @@ -176,9 +170,6 @@ $size = $repository->getSizeInBytes(); echo 'Your repository size is '.round($size / 1000).' KB'; ``` -`getSize()`, which returns kilobytes (1,000 bytes), is deprecated since 1.7: -use `getSizeInBytes()`. - Running git commands -------------------- @@ -208,9 +199,6 @@ your users starting with a dash is an option for git, unless `--` comes before it. gitlib reads the references again after the command, which may have written them. -`shell()` is deprecated since 1.7: run `git shell` with Symfony Process -instead. - Errors ------ @@ -480,12 +468,6 @@ $repository = new Repository('/tmp/foo', driver: new CliDriver( )); ``` -The `command`, `environment_variables` and `process_timeout` options of -`Repository` and `Admin`, from 1.x, are deprecated since 1.7 in favor of these -arguments. So is `inherit_environment_variables`, which passed the entries of -`$_SERVER` to git, the headers and credentials of an HTTP request included: -pass the variables git needs to `environmentVariables`. - Git configuration ----------------- @@ -560,9 +542,6 @@ A failing command also logs its error output, at the `debug` level: the exception it throws reports the failure. The logs hide the credentials of URLs, like exceptions. `LibGit2Driver` logs nothing. -`Repository::setLogger()` and `Repository::getLogger()` are deprecated since -2.0: give the logger to `CliDriver`. - Using your own driver --------------------- diff --git a/doc/tree.md b/doc/tree.md index 21451d12..9a671544 100644 --- a/doc/tree.md +++ b/doc/tree.md @@ -69,10 +69,6 @@ function displayTree(Tree $tree, int $depth = 0): void displayTree($commit->getTree()); ``` -`getEntries()`, `getBlobEntries()` and `getTreeEntries()`, which return -the mode and the object of each entry as an array (`[$mode, $object]`), are -deprecated since 1.7: iterate the tree, or use `getBlobs()` and `getTrees()`. - Submodules ---------- @@ -86,9 +82,6 @@ foreach ($tree->getSubmodules() as $name => $entry) { } ``` -`CommitReference` is deprecated since 1.7: it is `Submodule`. So is -`Tree::getCommitReferenceEntries()`: use `getSubmodules()`. - Resolve a path -------------- diff --git a/doc/workingcopy.md b/doc/workingcopy.md index 462c7a46..8e84c3df 100644 --- a/doc/workingcopy.md +++ b/doc/workingcopy.md @@ -71,9 +71,6 @@ Like `git checkout`, both methods keep the local changes, and refuse to overwrite the ones the checkout would change: they throw a `DriverException`. *checkoutNewBranch* then creates no branch. -Passing the branch to create as second argument of *checkout* is deprecated -since 1.7: use *checkoutNewBranch*. - Merge a revision ---------------- @@ -131,9 +128,6 @@ $diff = $wc->getDiff(); $diff = $wc->getDiff('master'); ``` -Calling `Repository::getDiff()` with one revision, to compare it with the -working copy, is deprecated since 1.7: use `WorkingCopy::getDiff()`. - Staged modifications -------------------- diff --git a/src/Gitonomy/Git/Admin.php b/src/Gitonomy/Git/Admin.php deleted file mode 100644 index d29f7b57..00000000 --- a/src/Gitonomy/Git/Admin.php +++ /dev/null @@ -1,195 +0,0 @@ - - * (c) Julien DIDIER - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Gitonomy\Git; - -use Gitonomy\Git\Driver\Cli\CliDriver; -use Gitonomy\Git\Driver\Cli\LegacyOptions; - -/** - * Administration class for Git repositories. - * - * Its methods behave like in 1.x: the git options of 1.x (command, - * environment_variables, inherit_environment_variables and process_timeout) - * configure the CliDriver they run, and the repositories they return; - * inherit_environment_variables only applies to these repositories. - * - * @author Alexandre Salomé - * - * @deprecated since gitonomy/gitlib 1.7, use the static methods of Repository instead - * - * @phpstan-import-type Options from LegacyOptions - */ -final class Admin -{ - /** - * Initializes a repository and returns the instance. - * - * @param string $path path to the repository - * @param bool $bare indicate to create a bare repository - * @param Options $options options for Repository creation - * - * @throws Exception\DriverException Directory exists or not writable - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::initBare() or Repository::init() instead - */ - public static function init(string $path, bool $bare = true, array $options = []): Repository - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::%s()" instead.', __METHOD__, Repository::class, $bare ? 'initBare' : 'init'); - - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? new CliDriver(); - if ($bare) { - $driver->initBare($path); - } else { - $driver->init($path); - } - - return new Repository($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } - - /** - * Checks the validity of a git repository url without cloning it. - * - * This will use the `ls-remote` command of git against the given url. - * Usually, this command returns 0 when successful, and 128 when the - * repository is not found. - * - * @param string $url url of repository to check - * @param Options $options options for Repository creation - * - * @return bool true if url is valid - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::isValidRepository() instead - */ - public static function isValidRepository(#[\SensitiveParameter] string $url, array $options = []): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::isValidRepository()" instead.', __METHOD__, Repository::class); - - return (new LegacyOptions($options)->adminDriver() ?? new CliDriver())->isValidRepository($url); - } - - /** - * Checks the validity of a git repository url without cloning it and - * check if a certain branch exists in that repository. - * - * This will use the `ls-remote` command of git against the given url. - * Usually, this command returns 0 when successful, and 128 when the - * repository is not found. - * - * @param string $url url of repository to check - * @param string $branchName name of branch to check - * @param Options $options options for Repository creation - * - * @return bool true if url is valid and branch exists - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::isValidRepositoryAndBranch() instead - */ - public static function isValidRepositoryAndBranch(#[\SensitiveParameter] string $url, string $branchName, array $options = []): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::isValidRepositoryAndBranch()" instead.', __METHOD__, Repository::class); - - return (new LegacyOptions($options)->adminDriver() ?? new CliDriver())->isValidRepositoryAndBranch($url, $branchName); - } - - /** - * Clone a repository to a local path. - * - * @param string $path indicates where to clone repository - * @param string $url url of repository to clone - * @param bool $bare indicates if repository should be bare or have a working copy - * @param Options $options options for Repository creation - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::cloneBareFrom() or Repository::cloneFrom() instead - */ - public static function cloneTo(string $path, #[\SensitiveParameter] string $url, bool $bare = true, array $options = []): Repository - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::%s()" instead, which takes the URL before the path.', __METHOD__, Repository::class, $bare ? 'cloneBareFrom' : 'cloneFrom'); - - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? new CliDriver(); - if ($bare) { - $driver->cloneBareFrom($url, $path, null); - } else { - $driver->cloneFrom($url, $path, null); - } - - return new Repository($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } - - /** - * Clone a repository branch to a local path. - * - * @param string $path indicates where to clone repository - * @param string $url url of repository to clone - * @param string $branch branch to clone - * @param bool $bare indicates if repository should be bare or have a working copy - * @param Options $options options for Repository creation - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::cloneBareFrom() or Repository::cloneFrom() with their "branch" argument instead - */ - public static function cloneBranchTo(string $path, #[\SensitiveParameter] string $url, string $branch, bool $bare = true, array $options = []): Repository - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::%s()" with its "branch" argument instead, which takes the URL before the path.', __METHOD__, Repository::class, $bare ? 'cloneBareFrom' : 'cloneFrom'); - - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? new CliDriver(); - if ($bare) { - $driver->cloneBareFrom($url, $path, $branch); - } else { - $driver->cloneFrom($url, $path, $branch); - } - - return new Repository($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } - - /** - * Mirrors a repository (fetch all revisions, not only branches). - * - * @param string $path indicates where to clone repository - * @param string $url url of repository to clone - * @param Options $options options for Repository creation - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::mirrorFrom() instead - */ - public static function mirrorTo(string $path, #[\SensitiveParameter] string $url, array $options = []): Repository - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::mirrorFrom()" instead, which takes the URL before the path.', __METHOD__, Repository::class); - - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? new CliDriver(); - $driver->mirrorFrom($url, $path); - - return new Repository($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } - - /** - * Internal method to launch effective ``git clone`` command. - * - * @param string $path indicates where to clone repository - * @param string $url url of repository to clone - * @param string[] $args arguments to be added to the command-line - * @param Options $options options for Repository creation - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::cloneFrom(), Repository::cloneBareFrom() or Repository::mirrorFrom() instead - */ - public static function cloneRepository(string $path, #[\SensitiveParameter] string $url, array $args = [], array $options = []): Repository - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%1$s()" method is deprecated, use "%2$s::cloneFrom()", "%2$s::cloneBareFrom()" or "%2$s::mirrorFrom()" instead, which take the URL before the path; they support no other argument of "git clone".', __METHOD__, Repository::class); - - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? new CliDriver(); - $driver->cloneRepository($path, $url, $args); - - return new Repository($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } -} diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index d9b31acd..b935ecfd 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -87,20 +87,6 @@ public function getHunks(): array return $hunks; } - /** - * Returns lines grouped by commit. - * - * @return list}> - * - * @deprecated since gitonomy/gitlib 1.7, use getHunks() instead - */ - public function getGroupedLines(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getHunks()" instead.', __METHOD__); - - return array_map(static fn (Hunk $hunk): array => [$hunk->getCommit(), $hunk->getLines()], $this->getHunks()); - } - /** * @return array The lines of the blame, by number */ diff --git a/src/Gitonomy/Git/Blame/Line.php b/src/Gitonomy/Git/Blame/Line.php index 6bc8b01b..87156771 100644 --- a/src/Gitonomy/Git/Blame/Line.php +++ b/src/Gitonomy/Git/Blame/Line.php @@ -52,16 +52,6 @@ public function getOriginalNumber(): int return $this->originalNumber; } - /** - * @deprecated since gitonomy/gitlib 1.7, use getOriginalNumber() instead - */ - public function getLine(): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getOriginalNumber()" instead.', __METHOD__); - - return (string) $this->originalNumber; - } - /** * @return Commit The commit that last changed the line */ diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 9b82f896..54c05fb7 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -14,11 +14,9 @@ use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Driver\Data\CommitData; -use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Util\Message; -use Symfony\Component\String\CodePointString; /** * Representation of a Git commit. @@ -86,18 +84,6 @@ public function getShortHash(): string return $this->shortHash ??= $this->repository->getRepositoryDriver()->getShortHash($this->revision); } - /** - * Returns a fixed-with short hash. - * - * @deprecated since gitonomy/gitlib 1.7, use substr($commit->getHash(), 0, $length) instead - */ - public function getFixedShortHash(int $length = 6): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "substr($commit->getHash(), 0, $length)" instead.', __METHOD__); - - return new CodePointString($this->revision)->slice(0, $length)->toString(); - } - /** * Returns parent hashes. * @@ -152,32 +138,6 @@ public function getLastModification(?string $path = null): self } } - /** - * Returns the first line of the commit, and the first 50 characters. - * - * Ported from https://github.com/fabpot/Twig-extensions/blob/d67bc7e69788795d7905b52d31188bbc1d390e01/lib/Twig/Extensions/Extension/Text.php#L52-L109 - * - * @deprecated since gitonomy/gitlib 1.7, use symfony/string instead: u($commit->getSubjectMessage())->truncate($length, $separator, !$preserve) - */ - public function getShortMessage(int $length = 50, bool $preserve = false, string $separator = '...'): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use symfony/string instead: "u($commit->getSubjectMessage())->truncate($length, $separator, !$preserve)".', __METHOD__); - - $message = $this->getSubjectMessage(); - - $codePointMessage = new CodePointString($message); - - if ($codePointMessage->length() > $length) { - if ($preserve && null !== ($breakpoint = $codePointMessage->indexOf(' ', $length))) { - $length = $breakpoint; - } - - return rtrim($codePointMessage->slice(0, $length)->toString()).$separator; - } - - return $message; - } - /** * Resolves all references associated to this commit. * @@ -191,20 +151,10 @@ public function resolveReferences(): array /** * Returns the local and remote branches whose history contains the commit. * - * Passing arguments, to keep local or remote branches only, is deprecated. - * * @return Branch[] */ - public function getIncludingBranches(bool $local = true, bool $remote = true): array + public function getIncludingBranches(): array { - if (\func_num_args() > 0) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing arguments to "%s()" is deprecated, filter the branches it returns with "%s::isLocal()" or "isRemote()" instead.', __METHOD__, Branch::class); - } - - if (!$local && !$remote) { - throw new InvalidArgumentException('Keep the local branches, the remote ones, or both: $local and $remote can\'t both be false.'); - } - $fullnames = $this->repository->getRepositoryDriver()->getIncludingBranches($this->revision); $references = $this->repository->getReferences(); // A branch another process created since gitlib read the references. @@ -221,7 +171,7 @@ public function getIncludingBranches(bool $local = true, bool $remote = true): a } $branch = $references->get($fullname); - if ($branch instanceof Branch && ($branch->isLocal() ? $local : $remote)) { + if ($branch instanceof Branch) { $branches[] = $branch; } } diff --git a/src/Gitonomy/Git/CommitReference.php b/src/Gitonomy/Git/CommitReference.php deleted file mode 100644 index 01a6d55f..00000000 --- a/src/Gitonomy/Git/CommitReference.php +++ /dev/null @@ -1,28 +0,0 @@ - - * (c) Julien DIDIER - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Gitonomy\Git; - -trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s" class is deprecated, use "%s" instead.', CommitReference::class, Submodule::class); - -// Declares the alias, unless Submodule already did. -class_exists(Submodule::class); - -// @phpstan-ignore if.alwaysFalse (Declares the class for IDEs only.) -if (false) { - /** - * @deprecated since gitonomy/gitlib 1.7, use Submodule instead - */ - final readonly class CommitReference - { - } -} diff --git a/src/Gitonomy/Git/Diff/Diff.php b/src/Gitonomy/Git/Diff/Diff.php index 4abd4347..ee3ff2e9 100644 --- a/src/Gitonomy/Git/Diff/Diff.php +++ b/src/Gitonomy/Git/Diff/Diff.php @@ -61,19 +61,6 @@ public static function fromData(DiffData $data, Repository $repository): self return new self(array_map(static fn (DiffFileData $file): File => File::fromData($file, $repository), $data->files), $data->rawDiff); } - /** - * @deprecated since gitonomy/gitlib 1.7, the diffs gitlib returns have their repository already - */ - public function setRepository(Repository $repository): void - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, the diffs gitlib returns have their repository already.', __METHOD__); - - foreach ($this->files as $file) { - // Without one more deprecation for each file. - \Closure::bind(static fn () => $file->repository = $repository, null, File::class)(); - } - } - /** * Get list of files modified in the diff's revision. * diff --git a/src/Gitonomy/Git/Diff/DiffLineType.php b/src/Gitonomy/Git/Diff/DiffLineType.php index b7a88a70..0ee2e6bf 100644 --- a/src/Gitonomy/Git/Diff/DiffLineType.php +++ b/src/Gitonomy/Git/Diff/DiffLineType.php @@ -13,8 +13,8 @@ namespace Gitonomy\Git\Diff; /** - * The kind of a line of a hunk, its values those of the deprecated - * FileChange::LINE_* constants. + * The kind of a line of a hunk, its values the types of the lines of + * FileChange::toArray(). * * @author Grégoire Pineau */ diff --git a/src/Gitonomy/Git/Diff/File.php b/src/Gitonomy/Git/Diff/File.php index c18e2cd3..ebe7e622 100644 --- a/src/Gitonomy/Git/Diff/File.php +++ b/src/Gitonomy/Git/Diff/File.php @@ -26,9 +26,9 @@ * * @phpstan-type FileArray array{old_name: string|null, new_name: string|null, old_mode: string|null, new_mode: string|null, old_index: string|null, new_index: string|null, is_binary: bool, is_copy: bool, changes: list} */ -final class File +final readonly class File { - private readonly string $name; + private string $name; /** * @param string|null $oldName Null for a creation @@ -41,30 +41,20 @@ final class File * @throws InvalidArgumentException Both names are null */ public function __construct( - private readonly ?string $oldName, - private readonly ?string $newName, - private readonly ?string $oldMode, - private readonly ?string $newMode, - private readonly ?string $oldIndex, - private readonly ?string $newIndex, - private readonly bool $isBinary, - private readonly bool $isCopy = false, + private ?string $oldName, + private ?string $newName, + private ?string $oldMode, + private ?string $newMode, + private ?string $oldIndex, + private ?string $newIndex, + private bool $isBinary, + private bool $isCopy = false, private array $changes = [], private ?Repository $repository = null, ) { $this->name = $newName ?? $oldName ?? throw new InvalidArgumentException('A file of a diff has an old name, a new name, or both.'); } - /** - * @deprecated since gitonomy/gitlib 1.7, give the changes to the constructor instead - */ - public function addChange(FileChange $change): void - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, give the changes to the constructor instead.', __METHOD__); - - $this->changes[] = $change; - } - /** * Indicates if this diff file is a creation. */ @@ -109,16 +99,6 @@ public function isModeChange(): bool return $this->isModification() && $this->oldMode !== $this->newMode; } - /** - * @deprecated since gitonomy/gitlib 1.7, use isModeChange() instead - */ - public function isChangeMode(): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "isModeChange()" instead.', __METHOD__); - - return $this->isModeChange(); - } - /** * Indicates if this diff file is a deletion. */ @@ -127,16 +107,6 @@ public function isDeletion(): bool return null === $this->newName; } - /** - * @deprecated since gitonomy/gitlib 1.7, use isDeletion() instead - */ - public function isDelete(): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "isDeletion()" instead.', __METHOD__); - - return $this->isDeletion(); - } - /** * @return int Number of added lines */ @@ -250,31 +220,11 @@ public static function fromArray(array $array, ?Repository $repository = null): ); } - /** - * @deprecated since gitonomy/gitlib 1.7, a presentation concern: use substr($file->getNewIndex(), 0, 12) instead - */ - public function getAnchor(): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "substr($file->getNewIndex(), 0, 12)" instead.', __METHOD__); - - return substr($this->newIndex ?? '', 0, 12); - } - public function getRepository(): ?Repository { return $this->repository; } - /** - * @deprecated since gitonomy/gitlib 1.7, the diffs gitlib returns have their repository already - */ - public function setRepository(Repository $repository): void - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, the diffs gitlib returns have their repository already.', __METHOD__); - - $this->repository = $repository; - } - /** * @throws LogicException The file has no repository, or is a creation * @throws RuntimeException The diff doesn't know the hash of the old blob diff --git a/src/Gitonomy/Git/Diff/FileChange.php b/src/Gitonomy/Git/Diff/FileChange.php index 20f02e7e..cab89c02 100644 --- a/src/Gitonomy/Git/Diff/FileChange.php +++ b/src/Gitonomy/Git/Diff/FileChange.php @@ -21,30 +21,13 @@ */ final readonly class FileChange { - /** - * @deprecated since gitonomy/gitlib 1.7, use DiffLineType::Context instead - */ - public const int LINE_CONTEXT = 0; - - /** - * @deprecated since gitonomy/gitlib 1.7, use DiffLineType::Deletion instead - */ - public const int LINE_REMOVE = -1; - - /** - * @deprecated since gitonomy/gitlib 1.7, use DiffLineType::Addition instead - */ - public const int LINE_ADD = 1; - /** * @var list */ private array $lines; /** - * @param array $lines Passing arrays is deprecated - * - * @throws InvalidArgumentException An array has none of the types of line + * @param DiffLine[] $lines */ public function __construct( private int $rangeOldStart, @@ -53,21 +36,7 @@ public function __construct( private int $rangeNewCount, array $lines, ) { - if ([] !== array_filter($lines, is_array(...))) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing the lines to "%s()" as arrays is deprecated, pass "%s" objects instead.', __METHOD__, DiffLine::class); - } - - $this->lines = array_map(static fn (DiffLine|array $line): DiffLine => \is_array($line) ? new DiffLine(self::lineType($line[0]), $line[1]) : $line, array_values($lines)); - } - - /** - * @deprecated since gitonomy/gitlib 1.7, use getAdditions() or getDeletions() instead - */ - public function getCount(int $type): int - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getAdditions()" or "getDeletions()" instead.', __METHOD__); - - return $this->count(self::lineType($type)); + $this->lines = array_values($lines); } public function getAdditions(): int @@ -108,18 +77,6 @@ public function getDiffLines(): array return $this->lines; } - /** - * @return list The type of each line, one of the LINE_* constants, and its content - * - * @deprecated since gitonomy/gitlib 1.7, use getDiffLines() instead - */ - public function getLines(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getDiffLines()" instead.', __METHOD__); - - return $this->linesToArray(); - } - /** * @return FileChangeArray */ @@ -130,7 +87,7 @@ public function toArray(): array 'range_old_count' => $this->rangeOldCount, 'range_new_start' => $this->rangeNewStart, 'range_new_count' => $this->rangeNewCount, - 'lines' => $this->linesToArray(), + 'lines' => array_map(static fn (DiffLine $line): array => [$line->getType()->value, $line->getContent()], $this->lines), ]; } @@ -160,12 +117,4 @@ private function count(DiffLineType $type): int { return \count(array_filter($this->lines, static fn (DiffLine $line): bool => $line->getType() === $type)); } - - /** - * @return list - */ - private function linesToArray(): array - { - return array_map(static fn (DiffLine $line): array => [$line->getType()->value, $line->getContent()], $this->lines); - } } diff --git a/src/Gitonomy/Git/Driver/Cli/CliDriver.php b/src/Gitonomy/Git/Driver/Cli/CliDriver.php index 005a2b04..3f1ec458 100644 --- a/src/Gitonomy/Git/Driver/Cli/CliDriver.php +++ b/src/Gitonomy/Git/Driver/Cli/CliDriver.php @@ -102,13 +102,11 @@ public function isValidRepositoryAndBranch(#[\SensitiveParameter] string $url, s } /** - * @internal For the deprecated Admin::cloneRepository(), to be removed in 3.0 - * * @param string[] $args Arguments of ``git clone`` * * @throws ProcessException */ - public function cloneRepository(string $path, #[\SensitiveParameter] string $url, array $args): void + private function cloneRepository(string $path, #[\SensitiveParameter] string $url, array $args): void { // Like isValidRepository(), whose ls-remote can't take "--". RemoteUrl::assertSafe($url); @@ -117,22 +115,6 @@ public function cloneRepository(string $path, #[\SensitiveParameter] string $url $this->mustRun('clone', ['-q', ...$args, '--', $url, $path]); } - /** - * @internal For the deprecated Repository::getLogger(), to be removed in 3.0 - */ - public function getLogger(): ?LoggerInterface - { - return $this->logger; - } - - /** - * @internal For the deprecated Repository::setLogger(), to be removed in 3.0 - */ - public function withLogger(LoggerInterface $logger): self - { - return new self($this->command, $this->environmentVariables, $this->processTimeout, $logger); - } - private function runner(): GitRunner { return new GitRunner($this->command, $this->environmentVariables, $this->processTimeout, $this->logger); diff --git a/src/Gitonomy/Git/Driver/Cli/LegacyOptions.php b/src/Gitonomy/Git/Driver/Cli/LegacyOptions.php deleted file mode 100644 index d4effff3..00000000 --- a/src/Gitonomy/Git/Driver/Cli/LegacyOptions.php +++ /dev/null @@ -1,111 +0,0 @@ - - * (c) Julien DIDIER - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Gitonomy\Git\Driver\Cli; - -use Gitonomy\Git\Exception\InvalidArgumentException; -use Psr\Log\LoggerInterface; - -/** - * The options of Repository and Admin in 1.x, deprecated in favor of the - * "workingDir" argument of Repository, and of the arguments of CliDriver. - * - * @author Grégoire Pineau - * - * @internal To be removed in 3.0, with these options - * - * @phpstan-type Options array{command?: string, debug?: bool, environment_variables?: array, inherit_environment_variables?: bool, logger?: LoggerInterface|null, process_timeout?: float|null, working_dir?: string|null} - */ -final readonly class LegacyOptions -{ - /** - * The options configuring CliDriver. - */ - private const array DRIVER_OPTIONS = ['command', 'environment_variables', 'inherit_environment_variables', 'logger', 'process_timeout']; - - public ?string $workingDir; - - /** - * @var Options - */ - private array $options; - - /** - * @param Options $options - * - * @throws InvalidArgumentException An unknown option, or the "debug" one set to false - */ - public function __construct(array $options) - { - if (\array_key_exists('debug', $options) && !$options['debug']) { - throw new InvalidArgumentException('The "debug" option set to false is not supported anymore: a failing git operation always throws, catch its exception instead.'); - } - - $unknownOptions = array_diff(array_keys($options), [...self::DRIVER_OPTIONS, 'debug', 'working_dir']); - if ([] !== $unknownOptions) { - throw new InvalidArgumentException(\sprintf(1 === \count($unknownOptions) ? 'Unknown option "%s".' : 'Unknown options "%s".', implode('", "', $unknownOptions))); - } - - // PHP doesn't check the types of the options, unlike PHPStan. - if (null !== ($options['logger'] ?? null) && !$options['logger'] instanceof LoggerInterface) { // @phpstan-ignore instanceof.alwaysTrue, booleanAnd.alwaysFalse - throw new InvalidArgumentException(\sprintf('The "logger" option must be a Psr\Log\LoggerInterface, "%s" given.', get_debug_type($options['logger']))); - } - - $this->workingDir = $options['working_dir'] ?? null; - $this->options = $options; - } - - /** - * The CliDriver running the git processes of a repository, null when no option configures one. - * - * Like in 1.x, "inherit_environment_variables" also gives them the entries of $_SERVER. - */ - public function repositoryDriver(): ?CliDriver - { - $environmentVariables = $this->options['environment_variables'] ?? []; - if ($this->options['inherit_environment_variables'] ?? false) { - // $_SERVER also holds entries that aren't environment variables (argv, REQUEST_TIME...). - $environmentVariables = array_replace(array_filter($_SERVER, \is_string(...)), $environmentVariables); - } - - return $this->driver($environmentVariables); - } - - /** - * The CliDriver running the commands of Admin (init, clone, ls-remote), null when no option configures one. - * - * Like in 1.x, it ignores "inherit_environment_variables": these commands - * reach remotes, and $_SERVER holds the credentials of an HTTP request. - */ - public function adminDriver(): ?CliDriver - { - return $this->driver($this->options['environment_variables'] ?? []); - } - - /** - * @param array $environmentVariables - */ - private function driver(array $environmentVariables): ?CliDriver - { - if ([] === array_intersect(array_keys($this->options), self::DRIVER_OPTIONS)) { - return null; - } - - return new CliDriver( - $this->options['command'] ?? 'git', - $environmentVariables, - // null disables the timeout. - \array_key_exists('process_timeout', $this->options) ? $this->options['process_timeout'] : 3600, - $this->options['logger'] ?? null, - ); - } -} diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 1f4eddb7..a39780fd 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -12,7 +12,6 @@ namespace Gitonomy\Git; -use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Exception\ReferenceNotFoundException; @@ -71,16 +70,6 @@ public function __construct( $this->limit = self::limit($limit); } - /** - * @deprecated since gitonomy/gitlib 1.7, use Repository::getDiff() instead: it ignored the paths of the log - */ - public function getDiff(): Diff - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::getDiff()" instead.', __METHOD__, Repository::class); - - return $this->repository->getLegacyDiff($this->revisions); - } - public function getRevisions(): ?RevisionList { return $this->revisions; @@ -112,18 +101,6 @@ public function withOffset(?int $offset): self return $log; } - /** - * @deprecated since gitonomy/gitlib 1.7, use withOffset() instead - */ - public function setOffset(?int $offset): static - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "withOffset()" instead.', __METHOD__); - - $this->offset = self::offset($offset); - - return $this; - } - public function getLimit(): ?int { return $this->limit; @@ -142,18 +119,6 @@ public function withLimit(?int $limit): self return $log; } - /** - * @deprecated since gitonomy/gitlib 1.7, use withLimit() instead - */ - public function setLimit(?int $limit): static - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "withLimit()" instead.', __METHOD__); - - $this->limit = self::limit($limit); - - return $this; - } - /** * @throws ReferenceNotFoundException The log is empty */ diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index 0efdde24..4ed8727b 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -52,16 +52,6 @@ public function getFullname(): string return $this->fullname; } - /** - * @deprecated since gitonomy/gitlib 1.7, use getFullname() instead - */ - public function getReference(): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getFullname()" instead.', __METHOD__); - - return $this->fullname; - } - public function getBefore(): string { return $this->before; @@ -80,16 +70,6 @@ public function getLog(array $excludes = []): Log return $this->repository->getLog([$this->getRange(), ...array_map(static fn (string $exclude): string => '^'.$exclude, $excludes)]); } - /** - * @deprecated since gitonomy/gitlib 1.7, use getRange() instead - */ - public function getRevision(): string - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getRange()" instead.', __METHOD__); - - return $this->getRange(); - } - /** * @return string The pushed commits: "before..after", or "after" for a creation * @@ -116,16 +96,6 @@ public function isCreation(): bool return $this->isZero($this->before); } - /** - * @deprecated since gitonomy/gitlib 1.7, use isCreation() instead - */ - public function isCreate(): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "isCreation()" instead.', __METHOD__); - - return $this->isCreation(); - } - /** * @return bool Whether the push deletes the reference, like File::isDeletion() for a file */ @@ -134,16 +104,6 @@ public function isDeletion(): bool return $this->isZero($this->after); } - /** - * @deprecated since gitonomy/gitlib 1.7, use isDeletion() instead - */ - public function isDelete(): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "isDeletion()" instead.', __METHOD__); - - return $this->isDeletion(); - } - public function isForce(): bool { return $this->isForce ??= $this->getForce(); diff --git a/src/Gitonomy/Git/Reference/Branch.php b/src/Gitonomy/Git/Reference/Branch.php index 5ee7ef42..039b97f1 100644 --- a/src/Gitonomy/Git/Reference/Branch.php +++ b/src/Gitonomy/Git/Reference/Branch.php @@ -58,23 +58,6 @@ public function isMergedInto(Revision|string $revision): bool return \in_array($this->commitHash, $this->repository->getRepositoryDriver()->getMergeBases($this->commitHash, $destination), true); } - /** - * Check if this branch is merged to a destination branch - * Optionally, check only with remote branches. - * - * @deprecated since gitonomy/gitlib 1.7, use isMergedInto() instead - */ - public function isMergedTo(string $destinationBranchName = 'master', bool $compareOnlyWithRemote = false): bool - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::isMergedInto()" instead.', __METHOD__, self::class); - - if ($compareOnlyWithRemote && $this->isLocal()) { - return false; - } - - return $this->isMergedInto($destinationBranchName); - } - /** * Points the branch to $revision. * diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index 8790f609..78970c06 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -58,25 +58,6 @@ public function has(string $fullname): bool return isset($this->references()[$fullname]); } - /** - * @template T of Reference - * - * @param T $reference - * - * @return T - * - * @deprecated since gitonomy/gitlib 1.7, use Branch::moveTo() instead - */ - public function update(Reference $reference): Reference - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::moveTo()" instead.', __METHOD__, Branch::class); - - $this->repository->getRepositoryDriver()->updateReference($reference->getFullname(), $reference->getCommitHash()); - $this->invalidate(); - - return $reference; - } - /** * @throws InvalidArgumentException The branch exists already */ diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index 22fd984c..b2505e41 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -15,7 +15,6 @@ use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Driver\Cli\CliDriver; use Gitonomy\Git\Driver\Cli\CliRepositoryDriver; -use Gitonomy\Git\Driver\Cli\LegacyOptions; use Gitonomy\Git\Driver\Data\ObjectType; use Gitonomy\Git\Driver\DriverInterface; use Gitonomy\Git\Driver\RepositoryDriverInterface; @@ -28,7 +27,6 @@ use Gitonomy\Git\Exception\UnsupportedOperationException; use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Util\WeakCache; -use Psr\Log\LoggerInterface; use Symfony\Component\Process\Process; /** @@ -37,8 +35,6 @@ * Main entry point for browsing a Git repository. * * @author Alexandre Salomé - * - * @phpstan-import-type Options from LegacyOptions */ final class Repository { @@ -80,55 +76,27 @@ final class Repository */ private ?ReferenceBag $referenceBag = null; - /** - * Backend used to run operations. - */ - private DriverInterface $driver; - /** * Operations on this repository, opened by the driver. */ - private RepositoryDriverInterface $repositoryDriver; + private readonly RepositoryDriverInterface $repositoryDriver; /** * Opens the repository in $dir: a bare repository, or a working tree with * its ".git" directory or file (a linked worktree, a submodule...). * - * An array of options as second argument is deprecated: its "working_dir" - * option is the $workingDir argument, and its "logger", "command", - * "environment_variables", "inherit_environment_variables" and - * "process_timeout" options configure a CliDriver. + * @param string|null $workingDir The working tree, when $dir is a git directory kept apart from it + * @param DriverInterface $driver Backend running the operations * - * @param Options|string|null $workingDir The working tree, when $dir is a git directory kept apart from it - * @param DriverInterface $driver Backend running the operations - * - * @throws InvalidArgumentException $dir doesn't exist or isn't a repository, or an option is unknown + * @throws InvalidArgumentException $dir doesn't exist or isn't a repository * @throws DriverException The driver can't open the repository * @throws UnsupportedOperationException The repository uses SHA-256 hashes, or with LibGit2Driver the reftable format */ - public function __construct(string $dir, array|string|null $workingDir = null, DriverInterface $driver = new CliDriver()) + public function __construct(string $dir, ?string $workingDir = null, DriverInterface $driver = new CliDriver()) { - if (\is_array($workingDir)) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing an array of options to "%s()" is deprecated, pass the working directory as "workingDir" argument, and configure the logger and git through the "driver" argument.', __METHOD__); - - $options = new LegacyOptions($workingDir); - $optionsDriver = $options->repositoryDriver(); - if (null !== $optionsDriver) { - // The driver is the third argument. - if (\func_num_args() > 2) { - throw new InvalidArgumentException('The driver argument can\'t be combined with the "logger" or git options: configure the driver instead.'); - } - - $driver = $optionsDriver; - } - - $workingDir = $options->workingDir; - } - $this->commits = new WeakCache(); $this->trees = new WeakCache(); $this->blobs = new WeakCache(); - $this->driver = $driver; $this->repositoryDriver = $driver->open($dir, $workingDir); $this->gitDir = $this->repositoryDriver->getGitDir(); $this->workingDir = $this->repositoryDriver->getWorkingDir(); @@ -330,22 +298,10 @@ public function getWorkingCopy(): WorkingCopy * Returns the references of the repository, read again after every write * gitlib makes. Open a new Repository to see the writes of other * processes. - * - * Passing true, to read them again, is deprecated. */ - public function getReferences(bool $reload = false): ReferenceBag + public function getReferences(): ReferenceBag { - $this->referenceBag ??= new ReferenceBag($this); - - if (\func_num_args() > 0) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing an argument to "%s()" is deprecated, gitlib reads the references again after its writes: open a new Repository to see the writes of other processes.', __METHOD__); - } - - if ($reload) { - $this->referenceBag->invalidate(); - } - - return $this->referenceBag; + return $this->referenceBag ??= new ReferenceBag($this); } /** @@ -419,29 +375,13 @@ public function getMergeBase(Revision|string $one, Revision|string $two): ?Commi /** * Returns the commits that last changed the lines of $file. * - * A string as third argument, "," or ",+" like - * "git blame -L", is deprecated. + * @param int|null $firstLine The first line to blame, from 1, the first one of the file when null + * @param int|null $lastLine The last line to blame, the last one of the file when null * - * @param int|string|null $firstLine The first line to blame, from 1, the first one of the file when null - * @param int|null $lastLine The last line to blame, the last one of the file when null + * @throws InvalidArgumentException An invalid range of lines */ - public function getBlame(Revision|string $revision, string $file, int|string|null $firstLine = null, ?int $lastLine = null): Blame + public function getBlame(Revision|string $revision, string $file, ?int $firstLine = null, ?int $lastLine = null): Blame { - if (\is_string($firstLine)) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing a range of lines as a string to "%s()" is deprecated, pass the first and the last lines instead.', __METHOD__); - - if (!preg_match('/^(\d+),(\+?)(\d*)$/', $firstLine, $vars)) { - throw new InvalidArgumentException(\sprintf('Unsupported range of lines "%s": pass the first and the last lines instead.', $firstLine)); - } - - $firstLine = (int) $vars[1]; - $lastLine = match (true) { - '' === $vars[3] => null, - '+' === $vars[2] => $firstLine + (int) $vars[3] - 1, - default => (int) $vars[3], - }; - } - return new Blame($this, \is_string($revision) ? $this->getRevision($revision) : $revision, $file, $firstLine, $lastLine); } @@ -466,71 +406,12 @@ public function getLog(RevisionList|Revision|string|array|null $revisions = null /** * Returns the changes from the commit $from to the commit $to. - * - * Passing one argument is deprecated: an "a..b" or "a...b" range, two - * revisions in an array or a RevisionList, or one revision to compare - * with the working tree, like WorkingCopy::getDiff() does. - * - * @param RevisionList|Revision|string|array|null $from */ - public function getDiff(RevisionList|Revision|string|array|null $from, Revision|string|null $to = null): Diff + public function getDiff(Revision|string $from, Revision|string $to): Diff { - if (null === $to) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Calling "%s()" with one argument is deprecated, pass the revisions to compare as "from" and "to" arguments, or use "%s::getDiff()" to compare a revision with the working tree.', __METHOD__, WorkingCopy::class); - - return $this->getLegacyDiff($from); - } - - if (\is_array($from) || $from instanceof RevisionList || null === $from) { - throw new InvalidArgumentException('The "from" argument of "Repository::getDiff()" must be a revision, when "to" is given.'); - } - return Diff::fromData($this->repositoryDriver->getDiff($this->commitHash($from), $this->commitHash($to)), $this); } - /** - * For the deprecated forms of getDiff() and Log::getDiff(), to be removed in 3.0. - * - * @param RevisionList|Revision|string|array|null $revisions - * - * @internal - */ - public function getLegacyDiff(RevisionList|Revision|string|array|null $revisions): Diff - { - if (null === $revisions) { - throw new InvalidArgumentException('Cannot compute a diff without revisions.'); - } - - if (!$revisions instanceof RevisionList) { - $revisions = new RevisionList($this, $revisions); - } - $revisions = $revisions->getAsTextArray(); - - if (2 === \count($revisions)) { - return $this->getDiff($revisions[0], $revisions[1]); - } - - if (1 === \count($revisions) && str_contains($revisions[0], '..')) { - $symmetric = str_contains($revisions[0], '...'); - [$from, $to] = explode($symmetric ? '...' : '..', $revisions[0], 2); - $from = '' === $from ? 'HEAD' : $from; - $to = '' === $to ? 'HEAD' : $to; - - if ($symmetric) { - // Like git diff: from the best common ancestor. - $from = $this->getMergeBase($from, $to) ?? throw new InvalidArgumentException(\sprintf('The revisions of "%s" have no common ancestor.', $revisions[0])); - } - - return $this->getDiff($from, $to); - } - - if (1 === \count($revisions)) { - return $this->getWorkingCopy()->getDiff($revisions[0]); - } - - throw new InvalidArgumentException(\sprintf('Cannot compute a diff of "%s".', implode('", "', $revisions))); - } - /** * @return int The size of the files of the git directory, working tree excluded, in bytes * @@ -541,42 +422,6 @@ public function getSizeInBytes(): int return self::directorySize($this->gitDir); } - /** - * Returns the size of repository, in kilobytes. - * - * @return int A sum, in kilobytes - * - * @deprecated since gitonomy/gitlib 1.7, use getSizeInBytes() instead - */ - public function getSize(): int - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getSizeInBytes()" instead.', __METHOD__); - - return (int) round($this->getSizeInBytes() / 1000); - } - - /** - * Executes a shell command on the repository, using PHP pipes. - * - * @param string $command The command to execute - * @param array $env Environment variables of the command - * - * @deprecated since gitonomy/gitlib 1.7, run "git shell" with Symfony Process instead - */ - public function shell(string $command, array $env = []): void - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, run "git shell" with Symfony Process instead: it ignores the driver.', __METHOD__); - - $argument = \sprintf('%s %s', $command, escapeshellarg($this->gitDir)); - - $prefix = ''; - foreach ($env as $name => $value) { - $prefix .= \sprintf('export %s=%s;', escapeshellarg($name), escapeshellarg($value)); - } - - proc_open($prefix.'git shell -c '.escapeshellarg($argument), [\STDIN, \STDOUT, \STDERR], $pipes); - } - /** * Returns the hooks object. */ @@ -682,70 +527,6 @@ public function runProcess(string $command, #[\SensitiveParameter] array $args = } } - /** - * Set repository logger. - * - * @return $this - * - * @throws UnsupportedOperationException The driver isn't a CliDriver - * - * @deprecated since gitonomy/gitlib 1.7, pass a CliDriver configured with the logger as driver argument instead - */ - public function setLogger(LoggerInterface $logger): static - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, pass a "%s" configured with the logger as driver argument instead.', __METHOD__, CliDriver::class); - - if (!$this->driver instanceof CliDriver) { - throw new UnsupportedOperationException('Only CliDriver logs the git commands it runs.'); - } - - $this->driver = $this->driver->withLogger($logger); - $this->repositoryDriver = $this->driver->open($this->gitDir, $this->workingDir); - - return $this; - } - - /** - * Returns the logger of the CliDriver. - * - * @deprecated since gitonomy/gitlib 1.7, the logger is an argument of CliDriver - */ - public function getLogger(): ?LoggerInterface - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, the logger is an argument of "%s".', __METHOD__, CliDriver::class); - - return $this->driver instanceof CliDriver ? $this->driver->getLogger() : null; - } - - /** - * Clones the current repository to a new directory and return instance of new repository. - * - * The clone uses the driver of the current repository. - * - * @param string $path path to the new repository in which current repository will be cloned - * @param bool $bare flag indicating if repository is bare or has a working-copy - * @param Options $options options of the new repository - * - * @return Repository the newly created repository - * - * @deprecated since gitonomy/gitlib 1.7, use Repository::cloneBareFrom() or Repository::cloneFrom() with getGitDir() as URL instead - */ - public function cloneTo(string $path, bool $bare = true, array $options = []): self - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "%s::%s()" with "getGitDir()" as URL instead.', __METHOD__, self::class, $bare ? 'cloneBareFrom' : 'cloneFrom'); - - // Like in 1.x, the options configuring git apply to the clone. - $options = new LegacyOptions($options); - $driver = $options->adminDriver() ?? $this->driver; - if ($bare) { - $driver->cloneBareFrom($this->gitDir, $path, null); - } else { - $driver->cloneFrom($this->gitDir, $path, null); - } - - return new self($path, $options->workingDir, $options->repositoryDriver() ?? $driver); - } - private function commitHash(Revision|string $revision): string { return ($revision instanceof Revision ? $revision : $this->getRevision($revision))->getCommit()->getHash(); diff --git a/src/Gitonomy/Git/Submodule.php b/src/Gitonomy/Git/Submodule.php index 92990d2a..754a4556 100644 --- a/src/Gitonomy/Git/Submodule.php +++ b/src/Gitonomy/Git/Submodule.php @@ -31,8 +31,3 @@ public function getHash(): string return $this->hash; } } - -// For the deprecated name, like Symfony renames classes. -if (!class_exists(CommitReference::class, false)) { - class_alias(Submodule::class, CommitReference::class); -} diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index b36ef119..b2a86943 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -75,57 +75,6 @@ public function getTrees(): array return array_filter($this->entries(), static fn (TreeEntry $entry): bool => $entry->getObject() instanceof self); } - /** - * @return array The mode and the object of each entry, by name - * - * @deprecated since gitonomy/gitlib 1.7, iterate the tree instead - */ - public function getEntries(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, iterate the tree instead.', __METHOD__); - - return self::toArrays($this->entries()); - } - - /** - * @return array The mode and the blob of each blob, by name - * - * @deprecated since gitonomy/gitlib 1.7, use getBlobs() instead - */ - public function getBlobEntries(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getBlobs()" instead.', __METHOD__); - - // @phpstan-ignore return.type (getBlobs() returns blobs only.) - return self::toArrays($this->getBlobs()); - } - - /** - * @return array The mode and the submodule of each submodule, by name - * - * @deprecated since gitonomy/gitlib 1.7, use getSubmodules() instead - */ - public function getCommitReferenceEntries(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getSubmodules()" instead.', __METHOD__); - - // @phpstan-ignore return.type (getSubmodules() returns submodules only.) - return self::toArrays($this->getSubmodules()); - } - - /** - * @return array The mode and the tree of each tree, by name - * - * @deprecated since gitonomy/gitlib 1.7, use getTrees() instead - */ - public function getTreeEntries(): array - { - trigger_deprecation('gitonomy/gitlib', '1.7', 'The "%s()" method is deprecated, use "getTrees()" instead.', __METHOD__); - - // @phpstan-ignore return.type (getTrees() returns trees only.) - return self::toArrays($this->getTrees()); - } - /** * @throws InvalidArgumentException The tree has no entry $name */ @@ -177,16 +126,4 @@ private function entries(): array return $this->entries; } - - /** - * The entries in the format of 1.x. - * - * @param array $entries - * - * @return array - */ - private static function toArrays(array $entries): array - { - return array_map(static fn (TreeEntry $entry): array => [$entry->getMode(), $entry->getObject()], $entries); - } } diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index fc959417..27a59f03 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -75,19 +75,11 @@ public function getDiffStaged(): Diff * a remote branch alone included, like "feature" for "origin/feature": * create its local branch with checkoutNewBranch(). * - * Passing a branch to create as second argument is deprecated. - * * @throws ReferenceNotFoundException $revision names no commit * @throws DriverException The checkout would overwrite local changes */ - public function checkout(Revision|string $revision, ?string $branch = null): static + public function checkout(Revision|string $revision): static { - if (null !== $branch) { - trigger_deprecation('gitonomy/gitlib', '1.7', 'Passing a branch to create to "%s()" is deprecated, use "checkoutNewBranch()" instead.', __METHOD__); - - return $this->checkoutNewBranch($branch, $revision); - } - // A name that no revision has throws, where "git checkout" would create // the branch of a remote one, or discard the changes of a file. ($revision instanceof Revision ? $revision : $this->repository->getRevision($revision))->getCommit(); diff --git a/tests/Gitonomy/Git/Tests/AdminTest.php b/tests/Gitonomy/Git/Tests/AdminTest.php deleted file mode 100644 index 80701707..00000000 --- a/tests/Gitonomy/Git/Tests/AdminTest.php +++ /dev/null @@ -1,219 +0,0 @@ - - * (c) Julien DIDIER - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace Gitonomy\Git\Tests; - -use Gitonomy\Git\Admin; -use Gitonomy\Git\Exception\DriverException; -use Gitonomy\Git\Exception\InvalidArgumentException; -use Gitonomy\Git\Reference\Branch; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; -use Psr\Log\LoggerInterface; - -/** - * Admin is deprecated: its methods must keep behaving like in 1.x, always - * with CliDriver, whatever the driver under test. - */ -#[Group('legacy')] -#[IgnoreDeprecations] -class AdminTest extends AbstractTestCase -{ - public function testInit(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::init()" method is deprecated, use "Gitonomy\Git\Repository::initBare()" instead.'); - - $repository = Admin::init(self::createTempDir(), options: self::getOptions()); - - $this->assertTrue($repository->isBare()); - } - - public function testInitNotBare(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::init()" method is deprecated, use "Gitonomy\Git\Repository::init()" instead.'); - - $repository = Admin::init(self::createTempDir(), false, self::getOptions()); - - $this->assertFalse($repository->isBare()); - } - - public function testIsValidRepository(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::isValidRepository()" method is deprecated, use "Gitonomy\Git\Repository::isValidRepository()" instead.'); - - $this->assertTrue(Admin::isValidRepository(self::repositoryUrl(), self::getOptions())); - } - - public function testIsValidRepositoryAndBranch(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::isValidRepositoryAndBranch()" method is deprecated, use "Gitonomy\Git\Repository::isValidRepositoryAndBranch()" instead.'); - - $this->assertTrue(Admin::isValidRepositoryAndBranch(self::repositoryUrl(), 'new-feature', self::getOptions())); - $this->assertFalse(Admin::isValidRepositoryAndBranch(self::repositoryUrl(), 'unknown', self::getOptions())); - } - - public function testCloneTo(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::cloneTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneBareFrom()" instead, which takes the URL before the path.'); - - $repository = Admin::cloneTo(self::createTempDir(), self::repositoryUrl(), options: self::getOptions()); - - $this->assertTrue($repository->isBare()); - $this->assertContains('refs/heads/new-feature', array_keys($repository->getReferences()->getAll())); - } - - public function testCloneToNotBare(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::cloneTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneFrom()" instead, which takes the URL before the path.'); - - $repository = Admin::cloneTo(self::createTempDir(), self::repositoryUrl(), false, self::getOptions()); - - $this->assertFalse($repository->isBare()); - } - - public function testCloneBranchTo(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::cloneBranchTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneBareFrom()" with its "branch" argument instead, which takes the URL before the path.'); - - $repository = Admin::cloneBranchTo(self::createTempDir(), self::repositoryUrl(), 'new-feature', options: self::getOptions()); - - $this->assertTrue($repository->isBare()); - $head = $repository->getHead(); - $this->assertInstanceOf(Branch::class, $head); - $this->assertSame('new-feature', $head->getName()); - } - - public function testCloneBranchToNotBare(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::cloneBranchTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneFrom()" with its "branch" argument instead, which takes the URL before the path.'); - - $repository = Admin::cloneBranchTo(self::createTempDir(), self::repositoryUrl(), 'new-feature', false, self::getOptions()); - - $this->assertFalse($repository->isBare()); - $head = $repository->getHead(); - $this->assertInstanceOf(Branch::class, $head); - $this->assertSame('new-feature', $head->getName()); - } - - public function testMirrorTo(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::mirrorTo()" method is deprecated, use "Gitonomy\Git\Repository::mirrorFrom()" instead, which takes the URL before the path.'); - - $repository = Admin::mirrorTo(self::createTempDir(), self::repositoryUrl(), self::getOptions()); - - $this->assertSame('true', trim($repository->run('config', ['remote.origin.mirror']))); - } - - public function testCloneRepositoryPassesItsArgumentsToGit(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Admin::cloneRepository()" method is deprecated, use "Gitonomy\Git\Repository::cloneFrom()", "Gitonomy\Git\Repository::cloneBareFrom()" or "Gitonomy\Git\Repository::mirrorFrom()" instead, which take the URL before the path; they support no other argument of "git clone".'); - - // --config is the only argument --bare accepts on every git version. - $repository = Admin::cloneRepository(self::createTempDir(), self::repositoryUrl(), ['--bare', '--config', 'gitlib.test=yes'], self::getOptions()); - - $this->assertTrue($repository->isBare()); - $this->assertSame('yes', trim($repository->run('config', ['gitlib.test']))); - } - - public function testOptionsConfigureGitAndTheRepository(): void - { - $logger = $this->createStub(LoggerInterface::class); - - $repository = Admin::init(self::createTempDir(), options: [...self::getOptions(), 'logger' => $logger, 'process_timeout' => 42]); - - $this->assertSame($logger, $repository->getLogger()); - $this->assertSame(42.0, $repository->runProcess('config', ['core.bare'])->getTimeout()); - } - - public function testCommandOptionRunsAnotherGitBinary(): void - { - $this->expectException(DriverException::class); - $this->expectExceptionMessage('The git command "init" could not start: '); - - Admin::init(self::createTempDir(), options: ['command' => 'not-git']); - } - - public function testInheritEnvironmentVariablesOnlyAppliesToTheRepository(): void - { - if (\defined('PHP_WINDOWS_VERSION_MAJOR')) { - $this->markTestSkipped('The fake git binary is a shell script.'); - } - - // A git binary logging whether it gets SECRET. - $dir = self::createTempDir(); - file_put_contents($dir.'/git', \sprintf("#!/bin/sh\necho \"\${GITLIB_TEST_SECRET:-none}\" >> %s\nexec %s \"\$@\"\n", escapeshellarg($dir.'/log'), escapeshellarg(self::gitCommand()))); - chmod($dir.'/git', 0o755); - // Like the credentials of an HTTP request, in $_SERVER only. - $_SERVER['GITLIB_TEST_SECRET'] = 'secret'; - - try { - $repository = Admin::init($dir.'/repository', options: [...self::getOptions(), 'command' => $dir.'/git', 'inherit_environment_variables' => true]); - $repository->run('config', ['core.bare']); - } finally { - unset($_SERVER['GITLIB_TEST_SECRET']); - } - - // Like in 1.x, git init doesn't get $_SERVER, the git processes of the repository do. - $this->assertSame("none\nsecret\n", file_get_contents($dir.'/log'), 'git init, then git config'); - } - - public function testRemovedOptionsAreRefused(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The "debug" option set to false is not supported anymore: a failing git operation always throws, catch its exception instead.'); - - Admin::init(self::createTempDir(), options: ['debug' => false]); - } - - public function testRepositoryCloneTo(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Repository::cloneTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneBareFrom()" with "getGitDir()" as URL instead.'); - - $repository = self::createFoobarRepository(); - $new = $repository->cloneTo(self::createTempDir()); - - $this->assertTrue($new->isBare()); - $this->assertSame($repository->getHeadCommit()->getHash(), $new->getHeadCommit()->getHash()); - } - - public function testRepositoryCloneToNotBare(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Repository::cloneTo()" method is deprecated, use "Gitonomy\Git\Repository::cloneFrom()" with "getGitDir()" as URL instead.'); - - $repository = self::createFoobarRepository(); - $new = $repository->cloneTo(self::createTempDir(), false); - - $this->assertFalse($new->isBare()); - $this->assertSame($repository->getHeadCommit()->getHash(), $new->getHeadCommit()->getHash()); - } - - public function testRepositoryCloneToWithGitOptions(): void - { - $repository = self::createFoobarRepository(); - $new = $repository->cloneTo(self::createTempDir(), options: [...self::getOptions(), 'process_timeout' => 42]); - - $this->assertSame(42.0, $new->runProcess('config', ['core.bare'])->getTimeout()); - } - - /** - * The options of 1.x running the git binary of the tests. - * - * @return array{command: string, environment_variables: array} - */ - private static function getOptions(): array - { - return [ - 'command' => self::gitCommand(), - 'environment_variables' => self::gitEnvs(), - ]; - } -} diff --git a/tests/Gitonomy/Git/Tests/BlameTest.php b/tests/Gitonomy/Git/Tests/BlameTest.php index 9d71544e..b6ddf22b 100644 --- a/tests/Gitonomy/Git/Tests/BlameTest.php +++ b/tests/Gitonomy/Git/Tests/BlameTest.php @@ -18,8 +18,6 @@ use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; class BlameTest extends AbstractTestCase { @@ -148,22 +146,4 @@ public function testBlameOfAPathNormalizesIt(): void $this->assertSame($lines('README.md'), $lines('./README.md')); $this->assertSame($lines('README.md'), $lines('dir/../README.md')); } - - #[DataProvider('provideBare')] - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyBlameLineRange(bool $bare): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing a range of lines as a string to "Gitonomy\Git\Repository::getBlame()" is deprecated, pass the first and the last lines instead.'); - - $repository = self::createFoobarRepository($bare); - - foreach (['3,+3', '3,5'] as $lineRange) { - $blame = $repository->getBlame(self::LONGFILE_COMMIT, 'README.md', $lineRange); - - $this->assertSame([3, 4, 5], array_keys($blame->getLines()), $lineRange); - $this->assertSame('3', $blame->getLine(3)->getLine(), $lineRange); - } - $this->assertSame(self::INITIAL_COMMIT, $repository->getBlame(self::LONGFILE_COMMIT, 'README.md')->getGroupedLines()[0][0]->getHash()); - } } diff --git a/tests/Gitonomy/Git/Tests/CommitTest.php b/tests/Gitonomy/Git/Tests/CommitTest.php index e0174d98..a37fcee3 100644 --- a/tests/Gitonomy/Git/Tests/CommitTest.php +++ b/tests/Gitonomy/Git/Tests/CommitTest.php @@ -15,14 +15,11 @@ use Gitonomy\Git\Blob; use Gitonomy\Git\Commit; use Gitonomy\Git\Diff\File; -use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Exception\RuntimeException; use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use Symfony\Component\Process\Process; class CommitTest extends AbstractTestCase @@ -321,38 +318,6 @@ public function testGetSignedMessage(bool $bare): void $this->assertSame('signed commit'."\n", $commit->getMessage()); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetFixedShortHash(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Commit::getFixedShortHash()" method is deprecated, use "substr($commit->getHash(), 0, $length)" instead.'); - - $this->assertSame(substr(self::LONGFILE_COMMIT, 0, 6), self::createFoobarRepository()->getCommit(self::LONGFILE_COMMIT)->getFixedShortHash()); - } - - #[DataProvider('provideBare')] - #[Group('legacy')] - #[IgnoreDeprecations] - public function testGetShortMessage(bool $bare): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Commit::getShortMessage()" method is deprecated, use symfony/string instead: "u($commit->getSubjectMessage())->truncate($length, $separator, !$preserve)".'); - - $repository = self::createFoobarRepository($bare); - // tests with a multi-line message - $commit = $repository->getCommit(self::LONGMESSAGE_COMMIT); - - $this->assertSame('Fixed perm...', $commit->getShortMessage(10)); - $this->assertSame('Fixed perm!!!', $commit->getShortMessage(10, false, '!!!')); - $this->assertSame('Fixed permissions!!!', $commit->getShortMessage(10, true, '!!!')); - - // tests with a single-line message - $commit = $repository->getCommit(self::INITIAL_COMMIT); - - $this->assertSame('Add README', $commit->getShortMessage(20)); - $this->assertSame('A', $commit->getShortMessage(1, false, '')); - $this->assertSame('Add!!!', $commit->getShortMessage(1, true, '!!!')); - } - public function testSubjectIsTheFirstParagraph(): void { $repository = self::createFoobarRepository(); @@ -378,20 +343,6 @@ public function testGetBodyMessage(bool $bare): void $this->assertSame('', $commit->getBodyMessage()); } - #[DataProvider('provideBare')] - #[Group('legacy')] - #[IgnoreDeprecations] - public function testGetIncludingBranchesException(bool $bare): void - { - $repository = self::createFoobarRepository($bare); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Keep the local branches, the remote ones, or both: $local and $remote can\'t both be false.'); - - $commit = $repository->getCommit(self::INITIAL_COMMIT); - - $commit->getIncludingBranches(false, false); - } - public function testTheLastModificationOfAPathNoCommitChanges(): void { $this->expectException(ReferenceNotFoundException::class); @@ -409,20 +360,6 @@ public function testGetIncludingBranches(bool $bare): void $this->assertSame($repository->getReferences()->getBranches(), $commit->getIncludingBranches()); } - #[DataProvider('provideBare')] - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetIncludingLocalOrRemoteBranches(bool $bare): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing arguments to "Gitonomy\Git\Commit::getIncludingBranches()" is deprecated, filter the branches it returns with "Gitonomy\Git\Reference\Branch::isLocal()" or "isRemote()" instead.'); - - $repository = self::createFoobarRepository($bare); - $commit = $repository->getCommit(self::INITIAL_COMMIT); - - $this->assertSame($repository->getReferences()->getLocalBranches(), $commit->getIncludingBranches(true, false)); - $this->assertSame($repository->getReferences()->getRemoteBranches(), $commit->getIncludingBranches(false, true)); - } - public function testGetIncludingBranchesNamedLikeRemoteOnes(): void { $repository = self::createFoobarRepository(); diff --git a/tests/Gitonomy/Git/Tests/DiffTest.php b/tests/Gitonomy/Git/Tests/DiffTest.php index 5cb585f6..fab81f49 100644 --- a/tests/Gitonomy/Git/Tests/DiffTest.php +++ b/tests/Gitonomy/Git/Tests/DiffTest.php @@ -24,8 +24,6 @@ use Gitonomy\Git\Exception\RuntimeException; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; class DiffTest extends AbstractTestCase { @@ -438,52 +436,6 @@ public function testParseQuotedNames(): void $this->assertSame("caf\u{e9}\t.txt", $files[0]->getName()); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetDiffOfARange(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Calling "Gitonomy\Git\Repository::getDiff()" with one argument is deprecated, pass the revisions to compare as "from" and "to" arguments, or use "Gitonomy\Git\WorkingCopy::getDiff()" to compare a revision with the working tree.'); - - $repository = self::createFoobarRepository(); - - $this->assertSame($repository->getDiff(self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT)->toArray(), $repository->getDiff(self::BEFORE_LONGFILE_COMMIT.'..'.self::LONGFILE_COMMIT)->toArray()); - $this->assertSame($repository->getDiff(self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT)->toArray(), $repository->getDiff([self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT])->toArray()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetLines(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\FileChange::getLines()" method is deprecated, use "getDiffLines()" instead.'); - - $change = new FileChange(1, 1, 1, 2, [new DiffLine(DiffLineType::Context, 'kept'), new DiffLine(DiffLineType::Addition, 'added')]); - - $this->assertSame([[FileChange::LINE_CONTEXT, 'kept'], [FileChange::LINE_ADD, 'added']], $change->getLines()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyConstructorWithLinesAsArrays(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing the lines to "Gitonomy\Git\Diff\FileChange::__construct()" as arrays is deprecated, pass "Gitonomy\Git\Diff\DiffLine" objects instead.'); - - $change = new FileChange(1, 1, 1, 2, [[FileChange::LINE_CONTEXT, 'kept'], new DiffLine(DiffLineType::Addition, 'added')]); - - $this->assertSame([[DiffLineType::Context, 'kept'], [DiffLineType::Addition, 'added']], array_map(static fn (DiffLine $line): array => [$line->getType(), $line->getContent()], $change->getDiffLines())); - $this->assertSame(1, $change->getAdditions()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyConstructorRefusesAnUnknownTypeOfLine(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing the lines to "Gitonomy\Git\Diff\FileChange::__construct()" as arrays is deprecated, pass "Gitonomy\Git\Diff\DiffLine" objects instead.'); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unknown type of line 2: the types are 1 (an addition), 0 (a context line) and -1 (a deletion).'); - - new FileChange(1, 1, 1, 1, [[2, 'line']]); - } - public function testFromArrayRefusesAnUnknownTypeOfLine(): void { $this->expectException(InvalidArgumentException::class); @@ -524,83 +476,6 @@ public function testGetBlobWithoutRepositoryThrows(): void $file->getOldBlob(); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacySetRepository(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\File::setRepository()" method is deprecated, the diffs gitlib returns have their repository already.'); - - $repository = self::createFoobarRepository(); - $file = new File('README.md', 'README.md', '100644', '100644', null, null, false); - $file->setRepository($repository); - - $this->assertSame($repository, $file->getRepository()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyDiffSetRepository(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\Diff::setRepository()" method is deprecated, the diffs gitlib returns have their repository already.'); - - $repository = self::createFoobarRepository(); - $diff = Diff::parse(":100644 100644 1111111111111111111111111111111111111111 2222222222222222222222222222222222222222 M\tREADME.md\n"); - $diff->setRepository($repository); - - $this->assertSame($repository, $diff->getFiles()[0]->getRepository()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyAddChange(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\File::addChange()" method is deprecated, give the changes to the constructor instead.'); - - $file = new File('README.md', 'README.md', '100644', '100644', null, null, false); - $change = new FileChange(1, 1, 1, 1, [new DiffLine(DiffLineType::Addition, 'added')]); - $file->addChange($change); - - $this->assertSame([$change], $file->getChanges()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyIsChangeMode(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\File::isChangeMode()" method is deprecated, use "isModeChange()" instead.'); - - $this->assertTrue(new File('run.sh', 'run.sh', '100644', '100755', null, null, false)->isChangeMode()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyFileIsDelete(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\File::isDelete()" method is deprecated, use "isDeletion()" instead.'); - - $this->assertTrue(new File('README.md', null, '100644', null, null, null, false)->isDelete()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetAnchor(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\File::getAnchor()" method is deprecated, use "substr($file->getNewIndex(), 0, 12)" instead.'); - - $this->assertSame('222222222222', new File('README.md', 'README.md', '100644', '100644', str_repeat('1', 40), str_repeat('2', 40), false)->getAnchor()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetCount(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Diff\FileChange::getCount()" method is deprecated, use "getAdditions()" or "getDeletions()" instead.'); - - $change = new FileChange(1, 1, 1, 2, [new DiffLine(DiffLineType::Context, 'kept'), new DiffLine(DiffLineType::Addition, 'added')]); - - $this->assertSame(1, $change->getCount(FileChange::LINE_ADD)); - } - public function testMnemonicPrefix(): void { // With `diff.mnemonicPrefix` enabled, git replaces the default "a/" and "b/" diff --git a/tests/Gitonomy/Git/Tests/LogTest.php b/tests/Gitonomy/Git/Tests/LogTest.php index 045bd33b..993b53db 100644 --- a/tests/Gitonomy/Git/Tests/LogTest.php +++ b/tests/Gitonomy/Git/Tests/LogTest.php @@ -23,8 +23,6 @@ use Gitonomy\Git\Log; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\Attributes\TestWith; class LogTest extends AbstractTestCase @@ -335,46 +333,6 @@ public function testWithersReturnAnotherLog(bool $bare): void $this->assertSame(\array_slice(self::hashes($log), 0, 2), self::hashes($limited)); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacySetOffset(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Log::setOffset()" method is deprecated, use "withOffset()" instead.'); - - $log = self::createFoobarRepository()->getLog(); - $log->setOffset(2); - - $this->assertSame(2, $log->getOffset()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacySetLimit(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Log::setLimit()" method is deprecated, use "withLimit()" instead.'); - - $log = self::createFoobarRepository()->getLog(self::LONGFILE_COMMIT); - - $this->assertSame($log, $log->setLimit(1)); - $this->assertCount(1, $log->getCommits()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetDiffIgnoresThePathsOfTheLog(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Log::getDiff()" method is deprecated, use "Gitonomy\Git\Repository::getDiff()" instead.'); - - $repository = self::createFoobarRepository(); - $diff = $repository->getDiff(self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT)->toArray(); - $legacyDiff = $repository->getLog(self::BEFORE_LONGFILE_COMMIT.'..'.self::LONGFILE_COMMIT, 'README.md')->getDiff(); - - // A log of README.md, but the diff of the range, which changes long.php only. - $this->assertSame(['long.php'], array_map(static fn (File $file): string => $file->getName(), $legacyDiff->getFiles())); - $this->assertSame($diff, $legacyDiff->toArray()); - $this->assertSame($diff, $repository->getLog([self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT])->getDiff()->toArray()); - } - public function testLogOfExcludedAndSymmetricRevisions(): void { $repository = self::createRepositoryToCommitTo(); diff --git a/tests/Gitonomy/Git/Tests/PushReferenceTest.php b/tests/Gitonomy/Git/Tests/PushReferenceTest.php index 6092b15c..583f533d 100644 --- a/tests/Gitonomy/Git/Tests/PushReferenceTest.php +++ b/tests/Gitonomy/Git/Tests/PushReferenceTest.php @@ -15,8 +15,6 @@ use Gitonomy\Git\Exception\DriverException; use Gitonomy\Git\PushReference; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; class PushReferenceTest extends AbstractTestCase { @@ -49,42 +47,6 @@ public static function provideIsers(): array ]; } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyIsCreate(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\PushReference::isCreate()" method is deprecated, use "isCreation()" instead.'); - - $this->assertTrue(new PushReference(self::createFoobarRepository(), 'foo', PushReference::ZERO, self::LONGFILE_COMMIT)->isCreate()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyIsDelete(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\PushReference::isDelete()" method is deprecated, use "isDeletion()" instead.'); - - $this->assertTrue(new PushReference(self::createFoobarRepository(), 'foo', self::LONGFILE_COMMIT, PushReference::ZERO)->isDelete()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetReference(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\PushReference::getReference()" method is deprecated, use "getFullname()" instead.'); - - $this->assertSame('refs/heads/foo', new PushReference(self::createFoobarRepository(), 'refs/heads/foo', self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT)->getReference()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetRevision(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\PushReference::getRevision()" method is deprecated, use "getRange()" instead.'); - - $this->assertSame(self::BEFORE_LONGFILE_COMMIT.'..'.self::LONGFILE_COMMIT, new PushReference(self::createFoobarRepository(), 'refs/heads/foo', self::BEFORE_LONGFILE_COMMIT, self::LONGFILE_COMMIT)->getRevision()); - } - public function testUnknownBeforeIsAnErrorNotAForcePush(): void { $reference = new PushReference(self::createFoobarRepository(), 'foo', str_repeat('1', 40), self::LONGFILE_COMMIT); diff --git a/tests/Gitonomy/Git/Tests/ReferenceTest.php b/tests/Gitonomy/Git/Tests/ReferenceTest.php index d17fc808..c9ab4785 100644 --- a/tests/Gitonomy/Git/Tests/ReferenceTest.php +++ b/tests/Gitonomy/Git/Tests/ReferenceTest.php @@ -19,9 +19,6 @@ use Gitonomy\Git\Reference\Tag; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; -use Symfony\Component\Process\Process; class ReferenceTest extends AbstractTestCase { @@ -280,20 +277,6 @@ public function testIsBranchMergedToMaster(): void $this->assertTrue($master->isMergedInto('foobar-new')); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyIsMergedTo(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Reference\Branch::isMergedTo()" method is deprecated, use "Gitonomy\Git\Reference\Branch::isMergedInto()" instead.'); - - $repository = self::createFoobarRepository(false); - $references = $repository->getReferences(); - $branch = $references->createBranch('foobar-new', 'master'); - - $this->assertTrue($branch->isMergedTo()); - $this->assertFalse($branch->isMergedTo('master', true), 'A local branch is not remote'); - } - #[DataProvider('provideBare')] public function testCreateRefusesAnExistingReference(bool $bare): void { @@ -341,33 +324,6 @@ public function testBranchMoveTo(): void $this->assertSame(self::INITIAL_COMMIT, $branch->getCommitHash(), 'A branch is read once'); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyUpdate(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\ReferenceBag::update()" method is deprecated, use "Gitonomy\Git\Reference\Branch::moveTo()" instead.'); - - $repository = self::createFoobarRepository(); - $references = $repository->getReferences(); - - $references->update(new Branch($repository, 'refs/heads/master', self::INITIAL_COMMIT)); - - $this->assertSame(self::INITIAL_COMMIT, $references->getBranch('master')->getCommitHash()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetReferencesReadsThemAgain(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing an argument to "Gitonomy\Git\Repository::getReferences()" is deprecated, gitlib reads the references again after its writes: open a new Repository to see the writes of other processes.'); - - $repository = self::createFoobarRepository(); - $this->assertFalse($repository->getReferences()->hasBranch('elsewhere')); - new Process([self::gitCommand(), 'branch', 'elsewhere', 'master'], $repository->getGitDir(), self::gitEnvs())->mustRun(); - - $this->assertTrue($repository->getReferences(true)->hasBranch('elsewhere')); - } - public function testBranchesEndingWithHead(): void { $repository = self::createFoobarRepository(); diff --git a/tests/Gitonomy/Git/Tests/RepositoryTest.php b/tests/Gitonomy/Git/Tests/RepositoryTest.php index 236c4b74..21202642 100644 --- a/tests/Gitonomy/Git/Tests/RepositoryTest.php +++ b/tests/Gitonomy/Git/Tests/RepositoryTest.php @@ -29,8 +29,6 @@ use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use Psr\Log\LoggerInterface; use Symfony\Component\Process\Process; @@ -821,17 +819,6 @@ public function testGetSizeInBytesOfAnUnreadableDirectoryThrows(): void } } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetSizeInKilobytes(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Repository::getSize()" method is deprecated, use "getSizeInBytes()" instead.'); - - $repository = self::createFoobarRepository(); - - $this->assertSame((int) round($repository->getSizeInBytes() / 1000), $repository->getSize()); - } - public function testIsBare(): void { $bare = self::createFoobarRepository(true); @@ -951,128 +938,6 @@ public function testDriverOpensTheRepository(): void $this->assertSame(self::INITIAL_COMMIT, $repository->getReferences()->getBranch('main')->getCommitHash()); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacySetLogger(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Repository::setLogger()" method is deprecated, pass a "Gitonomy\Git\Driver\Cli\CliDriver" configured with the logger as driver argument instead.'); - - $logger = $this->createMock(LoggerInterface::class); - $logger->expects($this->once()) - ->method('info') - ->with('run command: remote "" ') - ; - - $repository = new Repository(self::createFoobarRepository()->getPath(), driver: self::getCliDriver()); - $repository->setLogger($logger); - $repository->run('remote'); - - $this->assertSame($logger, $repository->getLogger()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacySetLoggerRequiresCliDriver(): void - { - $this->expectException(UnsupportedOperationException::class); - - new Repository(self::createTempDir(), driver: $this->createStub(DriverInterface::class))->setLogger($this->createStub(LoggerInterface::class)); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyShell(): void - { - if (\defined('PHP_WINDOWS_VERSION_BUILD')) { - $this->markTestSkipped('The command of git shell is a shell script.'); - } - - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Repository::shell()" method is deprecated, run "git shell" with Symfony Process instead: it ignores the driver.'); - - // git shell runs the commands of ~/git-shell-commands. - $home = self::createTempDir(); - mkdir($home.'/git-shell-commands'); - file_put_contents($home.'/git-shell-commands/record', "#!/bin/sh\n".'echo "$1" > "$HOME/recorded"'."\n"); - chmod($home.'/git-shell-commands/record', 0o700); - $repository = self::createFoobarRepository(); - - $repository->shell('record', ['HOME' => $home]); - - // shell() doesn't wait for git. - for ($i = 0; $i < 100 && !is_file($home.'/recorded'); ++$i) { - usleep(50_000); - } - $this->assertStringEqualsFile($home.'/recorded', $repository->getGitDir()."\n"); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testAnUnknownOptionIsRefused(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unknown option "foo".'); - - new Repository(self::createTempDir(), ['foo' => 1]); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testUnknownOptionsAreRefused(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('Unknown options "foo", "bar".'); - - new Repository(self::createTempDir(), ['foo' => 1, 'bar' => 2]); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyOptionsConfigureACliDriver(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing an array of options to "Gitonomy\Git\Repository::__construct()" is deprecated, pass the working directory as "workingDir" argument, and configure the logger and git through the "driver" argument.'); - - $logger = $this->createStub(LoggerInterface::class); - $repository = new Repository(self::createFoobarRepository()->getGitDir(), [ - 'command' => self::gitCommand(), - 'logger' => $logger, - 'process_timeout' => 42, - ]); - - $this->assertSame($logger, $repository->getLogger()); - $this->assertSame(42.0, $repository->runProcess('rev-parse', ['HEAD'])->getTimeout()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyOptionsCantBeCombinedWithADriver(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The driver argument can\'t be combined with the "logger" or git options: configure the driver instead.'); - - new Repository(self::createTempDir(), ['process_timeout' => 60], self::getDriver()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyDebugOption(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing an array of options to "Gitonomy\Git\Repository::__construct()" is deprecated, pass the working directory as "workingDir" argument, and configure the logger and git through the "driver" argument.'); - - $repository = new Repository(self::createFoobarRepository()->getGitDir(), ['debug' => true], self::getDriver()); - - $this->assertSame(self::LONGFILE_COMMIT, $repository->getCommit(self::LONGFILE_COMMIT)->getHash()); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testDebugOptionSetToFalseIsRefused(): void - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('The "debug" option set to false is not supported anymore: a failing git operation always throws, catch its exception instead.'); - - new Repository(self::createTempDir(), ['debug' => false]); - } - /** * @return array{string, string} The working tree of the clone, and its git directory */ diff --git a/tests/Gitonomy/Git/Tests/TreeTest.php b/tests/Gitonomy/Git/Tests/TreeTest.php index 2e64b54b..1dab3e00 100644 --- a/tests/Gitonomy/Git/Tests/TreeTest.php +++ b/tests/Gitonomy/Git/Tests/TreeTest.php @@ -13,14 +13,10 @@ namespace Gitonomy\Git\Tests; use Gitonomy\Git\Blob; -use Gitonomy\Git\CommitReference; use Gitonomy\Git\Exception\InvalidArgumentException; use Gitonomy\Git\Submodule; use Gitonomy\Git\Tree; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; -use PHPUnit\Framework\Attributes\RunInSeparateProcess; class TreeTest extends AbstractTestCase { @@ -76,36 +72,6 @@ public function testGetSubmodules(bool $bare): void $this->assertSame('160000', $submodules['barbaz']->getMode()); } - /** - * In a process of its own: once Submodule is loaded, it declares the alias, - * whose file isn't loaded anymore. - */ - #[Group('legacy')] - #[IgnoreDeprecations] - #[RunInSeparateProcess] - public function testLegacyCommitReference(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\CommitReference" class is deprecated, use "Gitonomy\Git\Submodule" instead.'); - - $this->assertTrue(class_exists(CommitReference::class)); - } - - #[DataProvider('provideBare')] - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetCommitReferenceEntries(bool $bare): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Tree::getCommitReferenceEntries()" method is deprecated, use "getSubmodules()" instead.'); - - $tree = self::createFoobarRepository($bare)->getCommit(self::NO_MESSAGE_COMMIT)->getTree(); - - [$mode, $object] = $tree->getCommitReferenceEntries()['barbaz']; - - $this->assertSame('160000', $mode); - // @phpstan-ignore method.impossibleType (PHPStan doesn't follow the alias of the deprecated class.) - $this->assertInstanceOf(CommitReference::class, $object); - } - public function testResolvePathThroughASubmoduleThrows(): void { $tree = self::createFoobarRepository()->getCommit(self::NO_MESSAGE_COMMIT)->getTree(); @@ -160,46 +126,6 @@ public function testGetBlobs(bool $bare): void $this->assertInstanceOf(Blob::class, $blobs['README.md']->getObject()); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetEntries(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Tree::getEntries()" method is deprecated, iterate the tree instead.'); - - $tree = self::createFoobarRepository()->getCommit(self::NO_MESSAGE_COMMIT)->getTree(); - - $entries = $tree->getEntries(); - - $this->assertSame(array_keys(iterator_to_array($tree)), array_keys($entries)); - $this->assertSame(['100644', $tree->getEntry('README.md')], $entries['README.md']); - $this->assertSame(['160000', $tree->getEntry('barbaz')], $entries['barbaz']); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetBlobEntries(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Tree::getBlobEntries()" method is deprecated, use "getBlobs()" instead.'); - - $tree = self::createFoobarRepository()->getCommit(self::NO_MESSAGE_COMMIT)->getTree(); - - $blobs = $tree->getBlobEntries(); - - $this->assertSame(array_keys($tree->getBlobs()), array_keys($blobs)); - $this->assertSame(['100644', $tree->getEntry('README.md')], $blobs['README.md']); - } - - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyGetTreeEntries(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: The "Gitonomy\Git\Tree::getTreeEntries()" method is deprecated, use "getTrees()" instead.'); - - $tree = self::createFoobarRepository()->getCommit(self::PATH_RESOLVING_COMMIT)->getTree(); - - $this->assertSame(['test' => ['040000', $tree->getEntry('test')]], $tree->getTreeEntries()); - } - #[DataProvider('provideBare')] public function testResolvePath(bool $bare): void { diff --git a/tests/Gitonomy/Git/Tests/WorkingCopyTest.php b/tests/Gitonomy/Git/Tests/WorkingCopyTest.php index f5d52c04..77971430 100644 --- a/tests/Gitonomy/Git/Tests/WorkingCopyTest.php +++ b/tests/Gitonomy/Git/Tests/WorkingCopyTest.php @@ -21,8 +21,6 @@ use Gitonomy\Git\Reference\Branch; use Gitonomy\Git\Repository; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\Attributes\Group; -use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\Attributes\TestWith; class WorkingCopyTest extends AbstractTestCase @@ -61,18 +59,6 @@ public function testCheckoutOfABranchObjectAttachesHead(): void $this->assertSame('refs/heads/twin', self::headBranch($repository)->getFullname()); } - #[Group('legacy')] - #[IgnoreDeprecations] - public function testLegacyCheckoutOfANewBranch(): void - { - $this->expectUserDeprecationMessage('Since gitonomy/gitlib 1.7: Passing a branch to create to "Gitonomy\Git\WorkingCopy::checkout()" is deprecated, use "checkoutNewBranch()" instead.'); - - $repository = self::createFoobarRepository(false); - $repository->getWorkingCopy()->checkout('origin/new-feature', 'new-feature'); - - $this->assertSame('new-feature', self::headBranch($repository)->getName()); - } - public function testDiffStaged(): void { $repository = self::createFoobarRepository(false);