diff options
148 files changed, 3057 insertions, 762 deletions
diff --git a/.github/workflows/check-whitespace.yml b/.github/workflows/check-whitespace.yml new file mode 100644 index 0000000000..9d070b9cdf --- /dev/null +++ b/.github/workflows/check-whitespace.yml @@ -0,0 +1,69 @@ +name: check-whitespace + +# Get the repo with the commits(+1) in the series. +# Process `git log --check` output to extract just the check errors. +# Add a comment to the pull request with the check errors. + +on: + pull_request: + types: [opened, synchronize] + +jobs: + check-whitespace: + runs-on: ubuntu-latest + steps: + - name: Set commit count + shell: bash + run: echo "::set-env name=COMMIT_DEPTH::$((1+$COMMITS))" + env: + COMMITS: ${{ github.event.pull_request.commits }} + + - uses: actions/checkout@v2 + with: + fetch-depth: ${{ env.COMMIT_DEPTH }} + + - name: git log --check + id: check_out + run: | + log= + commit= + while read dash etc + do + case "${dash}" in + "---") + commit="${etc}" + ;; + "") + ;; + *) + if test -n "${commit}" + then + log="${log}\n${commit}" + echo "" + echo "--- ${commit}" + fi + commit= + log="${log}\n${dash} ${etc}" + echo "${dash} ${etc}" + ;; + esac + done <<< $(git log --check --pretty=format:"---% h% s" -${{github.event.pull_request.commits}}) + + if test -n "${log}" + then + echo "::set-output name=checkout::"${log}"" + exit 2 + fi + + - name: Add Check Output as Comment + uses: actions/github-script@v3 + id: add-comment + with: + script: | + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Whitespace errors found in workflow ${{ github.workflow }}:\n\n${{ steps.check_out.outputs.checkout }}" + }) + if: ${{ failure() }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a940997f1b..6c3453a10b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,35 +41,39 @@ jobs: with: github-token: ${{secrets.GITHUB_TOKEN}} script: | - // Figure out workflow ID, commit and tree - const { data: run } = await github.actions.getWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.runId, - }); - const workflow_id = run.workflow_id; - const head_sha = run.head_sha; - const tree_id = run.head_commit.tree_id; + try { + // Figure out workflow ID, commit and tree + const { data: run } = await github.actions.getWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId, + }); + const workflow_id = run.workflow_id; + const head_sha = run.head_sha; + const tree_id = run.head_commit.tree_id; - // See whether there is a successful run for that commit or tree - const { data: runs } = await github.actions.listWorkflowRuns({ - owner: context.repo.owner, - repo: context.repo.repo, - per_page: 500, - status: 'success', - workflow_id, - }); - for (const run of runs.workflow_runs) { - if (head_sha === run.head_sha) { - core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`); - core.setOutput('enabled', ' but skip'); - break; - } - if (tree_id === run.head_commit.tree_id) { - core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`); - core.setOutput('enabled', ' but skip'); - break; + // See whether there is a successful run for that commit or tree + const { data: runs } = await github.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + per_page: 500, + status: 'success', + workflow_id, + }); + for (const run of runs.workflow_runs) { + if (head_sha === run.head_sha) { + core.warning(`Successful run for the commit ${head_sha}: ${run.html_url}`); + core.setOutput('enabled', ' but skip'); + break; + } + if (run.head_commit && tree_id === run.head_commit.tree_id) { + core.warning(`Successful run for the tree ${tree_id}: ${run.html_url}`); + core.setOutput('enabled', ' but skip'); + break; + } } + } catch (e) { + core.warning(e); } windows-build: diff --git a/Documentation/MyFirstContribution.txt b/Documentation/MyFirstContribution.txt index 4f85a089ef..492f3998f7 100644 --- a/Documentation/MyFirstContribution.txt +++ b/Documentation/MyFirstContribution.txt @@ -249,7 +249,7 @@ component you're working on, followed by a blank line (always required) and then the body of your commit message, which should provide the bulk of the context. Remember to be explicit and provide the "Why" of your change, especially if it couldn't easily be understood from your diff. When editing your commit message, -don't remove the Signed-off-by line which was added by `-s` above. +don't remove the `Signed-off-by` trailer which was added by `-s` above. ---- psuh: add a built-in by popular demand diff --git a/Documentation/RelNotes/2.29.1.txt b/Documentation/RelNotes/2.29.1.txt new file mode 100644 index 0000000000..295ee2135f --- /dev/null +++ b/Documentation/RelNotes/2.29.1.txt @@ -0,0 +1,11 @@ +Git v2.29.1 Release Notes +========================= + +This is to fix the build procedure change in 2.28 where we failed to +install a few programs that should be installed in /usr/bin (namely, +receive-pack, upload-archive and upload-pack) when the non-default +SKIP_DASHED_BUILT_INS installation option is in effect. + +A minor glitch in a non-default installation may usually not deserve +a hotfix, but I know Git for Windows ship binaries built with this +option, so let's make an exception. diff --git a/Documentation/RelNotes/2.29.2.txt b/Documentation/RelNotes/2.29.2.txt new file mode 100644 index 0000000000..632b5b580a --- /dev/null +++ b/Documentation/RelNotes/2.29.2.txt @@ -0,0 +1,12 @@ +Git v2.29.2 Release Notes +========================= + +This release is primarily to fix brown-paper-bag breakages in the +2.29.0 release. + +Fixes since v2.29.1 +------------------- + + * In 2.29, "--committer-date-is-author-date" option of "rebase" and + "am" subcommands lost the e-mail address by mistake, which has been + corrected. diff --git a/Documentation/RelNotes/2.30.0.txt b/Documentation/RelNotes/2.30.0.txt new file mode 100644 index 0000000000..e17f5de200 --- /dev/null +++ b/Documentation/RelNotes/2.30.0.txt @@ -0,0 +1,65 @@ +Git 2.30 Release Notes +====================== + +Updates since v2.29 +------------------- + +UI, Workflows & Features + + * Userdiff for PHP update. + + * Userdiff for Rust update. + + * Userdiff for CSS update. + + * The command line completion script (in contrib/) learned that "git + stash show" takes the options "git diff" takes. + + * "git worktree list" now shows if each worktree is locked. This + possibly may open us to show other kinds of states in the future. + + * "git maintenance", an extended big brother of "git gc", continues + to evolve. + + * "git push --force-with-lease[=<ref>]" can easily be misused to lose + commits unless the user takes good care of their own "git fetch". + A new option "--force-if-includes" attempts to ensure that what is + being force-pushed was created after examining the commit at the + tip of the remote ref that is about to be force-replaced. + + * "git clone" learned clone.defaultremotename configuration variable + to customize what nickname to use to call the remote the repository + was cloned from. + + * "git checkout" learned to use checkout.guess configuration variable + and enable/disable its "--[no-]guess" option accordingly. + + * "git resurrect" script (in contrib/) learned that the object names + may be longer than 40-hex depending on the hash function in use. + + +Performance, Internal Implementation, Development Support etc. + + * Use "git archive" more to produce the release tarball. + + * GitHub Actions automated test improvement to skip tests on a tree + identical to what has already been tested. + + +Fixes since v2.29 +----------------- + + * In 2.29, "--committer-date-is-author-date" option of "rebase" and + "am" subcommands lost the e-mail address by mistake, which has been + corrected. + (merge 5f35edd9d7 jk/committer-date-is-author-date-fix later to maint). + + * "git checkout -p A...B [-- <path>]" did not work, even though the + same command without "-p" correctly used the merge-base between + commits A and B. + (merge 35166b1fb5 dl/checkout-p-merge-base later to maint). + + * Other code cleanup, docfix, build fix, etc. + (merge 3e0a5dc9af cc/doc-filter-branch-typofix later to maint). + (merge 32c83afc2c cw/ci-ghwf-check-ws-errors later to maint). + (merge 5eb2ed691b rs/tighten-callers-of-deref-tag later to maint). diff --git a/Documentation/SubmittingPatches b/Documentation/SubmittingPatches index 291b61e262..3bf2147787 100644 --- a/Documentation/SubmittingPatches +++ b/Documentation/SubmittingPatches @@ -209,7 +209,7 @@ send them as replies to either an additional "cover letter" message (see below), the first patch, or the respective preceding patch. If your log message (including your name on the -Signed-off-by line) is not writable in ASCII, make sure that +`Signed-off-by` trailer) is not writable in ASCII, make sure that you send off a message in the correct encoding. WARNING: Be wary of your MUAs word-wrap @@ -229,7 +229,7 @@ previously sent. The `git format-patch` command follows the best current practice to format the body of an e-mail message. At the beginning of the patch should come your commit message, ending with the -Signed-off-by: lines, and a line that consists of three dashes, +`Signed-off-by` trailers, and a line that consists of three dashes, followed by the diffstat information and the patch itself. If you are forwarding a patch from somebody else, optionally, at the beginning of the e-mail message just before the commit @@ -298,17 +298,14 @@ Do not forget to add trailers such as `Acked-by:`, `Reviewed-by:` and patch. [[sign-off]] -=== Certify your work by adding your "Signed-off-by: " line +=== Certify your work by adding your `Signed-off-by` trailer -To improve tracking of who did what, we've borrowed the -"sign-off" procedure from the Linux kernel project on patches -that are being emailed around. Although core Git is a lot -smaller project it is a good discipline to follow it. +To improve tracking of who did what, we ask you to certify that you +wrote the patch or have the right to pass it on under the same license +as ours, by "signing off" your patch. Without sign-off, we cannot +accept your patches. -The sign-off is a simple line at the end of the explanation for -the patch, which certifies that you wrote it or otherwise have -the right to pass it on as an open-source patch. The rules are -pretty simple: if you can certify the below D-C-O: +If you can certify the below D-C-O: [[dco]] .Developer's Certificate of Origin 1.1 @@ -338,23 +335,29 @@ d. I understand and agree that this project and the contribution this project or the open source license(s) involved. ____ -then you just add a line saying +you add a "Signed-off-by" trailer to your commit, that looks like +this: .... Signed-off-by: Random J Developer <random@developer.example.org> .... -This line can be automatically added by Git if you run the git-commit -command with the -s option. +This line can be added by Git if you run the git-commit command with +the -s option. -Notice that you can place your own Signed-off-by: line when +Notice that you can place your own `Signed-off-by` trailer when forwarding somebody else's patch with the above rules for D-C-O. Indeed you are encouraged to do so. Do not forget to place an in-body "From: " line at the beginning to properly attribute the change to its true author (see (2) above). +This procedure originally came from the Linux kernel project, so our +rule is quite similar to theirs, but what exactly it means to sign-off +your patch differs from project to project, so it may be different +from that of the project you are accustomed to. + [[real-name]] -Also notice that a real name is used in the Signed-off-by: line. Please +Also notice that a real name is used in the `Signed-off-by` trailer. Please don't hide your real name. [[commit-trailers]] diff --git a/Documentation/config.txt b/Documentation/config.txt index bf706b950e..025ca4df11 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -334,6 +334,8 @@ include::config/checkout.txt[] include::config/clean.txt[] +include::config/clone.txt[] + include::config/color.txt[] include::config/column.txt[] diff --git a/Documentation/config/advice.txt b/Documentation/config/advice.txt index bdd37c3eaa..acbd0c09aa 100644 --- a/Documentation/config/advice.txt +++ b/Documentation/config/advice.txt @@ -10,9 +10,8 @@ advice.*:: that the check is disabled. pushUpdateRejected:: Set this variable to 'false' if you want to disable - 'pushNonFFCurrent', - 'pushNonFFMatching', 'pushAlreadyExists', - 'pushFetchFirst', and 'pushNeedsForce' + 'pushNonFFCurrent', 'pushNonFFMatching', 'pushAlreadyExists', + 'pushFetchFirst', 'pushNeedsForce', and 'pushRefNeedsUpdate' simultaneously. pushNonFFCurrent:: Advice shown when linkgit:git-push[1] fails due to a @@ -41,6 +40,10 @@ advice.*:: we can still suggest that the user push to either refs/heads/* or refs/tags/* based on the type of the source object. + pushRefNeedsUpdate:: + Shown when linkgit:git-push[1] rejects a forced update of + a branch when its remote-tracking ref has updates that we + do not have locally. statusAheadBehind:: Shown when linkgit:git-status[1] computes the ahead/behind counts for a local ref compared to its remote tracking ref, diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt index 6b646813ab..2cddf7b4b4 100644 --- a/Documentation/config/checkout.txt +++ b/Documentation/config/checkout.txt @@ -1,18 +1,23 @@ checkout.defaultRemote:: - When you run 'git checkout <something>' - or 'git switch <something>' and only have one + When you run `git checkout <something>` + or `git switch <something>` and only have one remote, it may implicitly fall back on checking out and - tracking e.g. 'origin/<something>'. This stops working as soon - as you have more than one remote with a '<something>' + tracking e.g. `origin/<something>`. This stops working as soon + as you have more than one remote with a `<something>` reference. This setting allows for setting the name of a preferred remote that should always win when it comes to disambiguation. The typical use-case is to set this to `origin`. + Currently this is used by linkgit:git-switch[1] and -linkgit:git-checkout[1] when 'git checkout <something>' -or 'git switch <something>' -will checkout the '<something>' branch on another remote, -and by linkgit:git-worktree[1] when 'git worktree add' refers to a +linkgit:git-checkout[1] when `git checkout <something>` +or `git switch <something>` +will checkout the `<something>` branch on another remote, +and by linkgit:git-worktree[1] when `git worktree add` refers to a remote branch. This setting might be used for other checkout-like commands or functionality in the future. + +checkout.guess:: + Provides the default value for the `--guess` or `--no-guess` + option in `git checkout` and `git switch`. See + linkgit:git-switch[1] and linkgit:git-checkout[1]. diff --git a/Documentation/config/clone.txt b/Documentation/config/clone.txt new file mode 100644 index 0000000000..47de36a5fe --- /dev/null +++ b/Documentation/config/clone.txt @@ -0,0 +1,4 @@ +clone.defaultRemoteName:: + The name of the remote to create when cloning a repository. Defaults to + `origin`, and can be overridden by passing the `--origin` command-line + option to linkgit:git-clone[1]. diff --git a/Documentation/config/core.txt b/Documentation/config/core.txt index 02002cf109..160aacad84 100644 --- a/Documentation/config/core.txt +++ b/Documentation/config/core.txt @@ -606,8 +606,8 @@ core.useReplaceRefs:: core.multiPackIndex:: Use the multi-pack-index file to track multiple packfiles using a - single index. See link:technical/multi-pack-index.html[the - multi-pack-index design document]. + single index. See linkgit:git-multi-pack-index[1] for more + information. Defaults to true. core.sparseCheckout:: Enable "sparse checkout" feature. See linkgit:git-sparse-checkout[1] diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index c2efd8758a..851bf410a3 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -79,7 +79,7 @@ format.thread:: format.signOff:: A boolean value which lets you enable the `-s/--signoff` option of - format-patch by default. *Note:* Adding the Signed-off-by: line to a + format-patch by default. *Note:* Adding the `Signed-off-by` trailer to a patch should be a conscious act and means that you certify you have the rights to submit this work under the same open source license. Please see the 'SubmittingPatches' document for further discussion. diff --git a/Documentation/config/maintenance.txt b/Documentation/config/maintenance.txt index 7cc6700d57..a0706d8f09 100644 --- a/Documentation/config/maintenance.txt +++ b/Documentation/config/maintenance.txt @@ -14,3 +14,21 @@ maintenance.commit-graph.auto:: reachable commits that are not in the commit-graph file is at least the value of `maintenance.commit-graph.auto`. The default value is 100. + +maintenance.loose-objects.auto:: + This integer config option controls how often the `loose-objects` task + should be run as part of `git maintenance run --auto`. If zero, then + the `loose-objects` task will not run with the `--auto` option. A + negative value will force the task to run every time. Otherwise, a + positive value implies the command should run when the number of + loose objects is at least the value of `maintenance.loose-objects.auto`. + The default value is 100. + +maintenance.incremental-repack.auto:: + This integer config option controls how often the `incremental-repack` + task should be run as part of `git maintenance run --auto`. If zero, + then the `incremental-repack` task will not run with the `--auto` + option. A negative value will force the task to run every time. + Otherwise, a positive value implies the command should run when the + number of pack-files not in the multi-pack-index is at least the value + of `maintenance.incremental-repack.auto`. The default value is 10. diff --git a/Documentation/config/push.txt b/Documentation/config/push.txt index f5e5b38c68..21b256e0a4 100644 --- a/Documentation/config/push.txt +++ b/Documentation/config/push.txt @@ -114,3 +114,9 @@ push.recurseSubmodules:: specifying '--recurse-submodules=check|on-demand|no'. If not set, 'no' is used by default, unless 'submodule.recurse' is set (in which case a 'true' value means 'on-demand'). + +push.useForceIfIncludes:: + If set to "true", it is equivalent to specifying + `--force-if-includes` as an option to linkgit:git-push[1] + in the command line. Adding `--no-force-if-includes` at the + time of push overrides this configuration setting. diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 573fb9bb71..ee52b65e46 100644 --- a/Documentation/diff-options.txt +++ b/Documentation/diff-options.txt @@ -687,6 +687,11 @@ endif::git-format-patch[] --ignore-blank-lines:: Ignore changes whose lines are all blank. +-I<regex>:: +--ignore-matching-lines=<regex>:: + Ignore changes whose all lines match <regex>. This option may + be specified more than once. + --inter-hunk-context=<lines>:: Show the context between diff hunks, up to the specified number of lines, thereby fusing hunks that are close to each other. diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index 38c0852139..06bc063542 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -33,7 +33,7 @@ OPTIONS -s:: --signoff:: - Add a `Signed-off-by:` line to the commit message, using + Add a `Signed-off-by` trailer to the commit message, using the committer identity of yourself. See the signoff option in linkgit:git-commit[1] for more information. diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index afa5c11fd3..b1a6fe4499 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -192,7 +192,10 @@ branches from there if `<branch>` is ambiguous but exists on the 'origin' remote. See also `checkout.defaultRemote` in linkgit:git-config[1]. + -Use `--no-guess` to disable this. +`--guess` is the default behavior. Use `--no-guess` to disable it. ++ +The default behavior can be set via the `checkout.guess` configuration +variable. -l:: Create the new branch's reflog; see linkgit:git-branch[1] for @@ -351,6 +354,10 @@ leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. <tree-ish>:: Tree to checkout from (when paths are given). If not specified, the index will be used. ++ +As a special case, you may use `"A...B"` as a shortcut for the +merge base of `A` and `B` if there is exactly one merge base. You can +leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. \--:: Do not interpret any more arguments as options. diff --git a/Documentation/git-cherry-pick.txt b/Documentation/git-cherry-pick.txt index 75feeef08a..5d750314b2 100644 --- a/Documentation/git-cherry-pick.txt +++ b/Documentation/git-cherry-pick.txt @@ -104,7 +104,7 @@ effect to your index in a row. -s:: --signoff:: - Add Signed-off-by line at the end of the commit message. + Add a `Signed-off-by` trailer at the end of the commit message. See the signoff option in linkgit:git-commit[1] for more information. -S[<keyid>]:: diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 097e6a86c5..876aedcd47 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -183,8 +183,9 @@ objects from the source repository into a pack in the cloned repository. -o <name>:: --origin <name>:: - Instead of using the remote name `origin` to keep track - of the upstream repository, use `<name>`. + Instead of using the remote name `origin` to keep track of the upstream + repository, use `<name>`. Overrides `clone.defaultRemoteName` from the + config. -b <name>:: --branch <name>:: diff --git a/Documentation/git-commit-graph.txt b/Documentation/git-commit-graph.txt index de6b6de230..e1f48c95b3 100644 --- a/Documentation/git-commit-graph.txt +++ b/Documentation/git-commit-graph.txt @@ -39,7 +39,9 @@ COMMANDS -------- 'write':: -Write a commit-graph file based on the commits found in packfiles. +Write a commit-graph file based on the commits found in packfiles. If +the config option `core.commitGraph` is disabled, then this command will +output a warning, then return success without writing a commit-graph file. + With the `--stdin-packs` option, generate the new commit graph by walking objects only in the specified pack-indexes. (Cannot be combined diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt index a3baea32ae..17150fa7ea 100644 --- a/Documentation/git-commit.txt +++ b/Documentation/git-commit.txt @@ -59,6 +59,7 @@ commit by giving the same set of parameters (options and paths). If you make a commit and then find a mistake immediately after that, you can recover from it with 'git reset'. +:git-commit: 1 OPTIONS ------- @@ -163,14 +164,7 @@ The `-m` option is mutually exclusive with `-c`, `-C`, and `-F`. message, the commit is aborted. This has no effect when a message is given by other means, e.g. with the `-m` or `-F` options. --s:: ---signoff:: - Add Signed-off-by line by the committer at the end of the commit - log message. The meaning of a signoff depends on the project, - but it typically certifies that committer has - the rights to submit this work under the same license and - agrees to a Developer Certificate of Origin - (see http://developercertificate.org/ for more information). +include::signoff-option.txt[] -n:: --no-verify:: diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt index f4bd8155c0..27acb31cbf 100644 --- a/Documentation/git-diff-index.txt +++ b/Documentation/git-diff-index.txt @@ -9,7 +9,7 @@ git-diff-index - Compare a tree to the working tree or index SYNOPSIS -------- [verse] -'git diff-index' [-m] [--cached] [<common diff options>] <tree-ish> [<path>...] +'git diff-index' [-m] [--cached] [--merge-base] [<common diff options>] <tree-ish> [<path>...] DESCRIPTION ----------- @@ -27,7 +27,12 @@ include::diff-options.txt[] The id of a tree object to diff against. --cached:: - do not consider the on-disk file at all + Do not consider the on-disk file at all. + +--merge-base:: + Instead of comparing <tree-ish> directly, use the merge base + between <tree-ish> and HEAD instead. <tree-ish> must be a + commit. -m:: By default, files recorded in the index but not checked diff --git a/Documentation/git-diff-tree.txt b/Documentation/git-diff-tree.txt index 5c8a2a5e97..2fc24c542f 100644 --- a/Documentation/git-diff-tree.txt +++ b/Documentation/git-diff-tree.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git diff-tree' [--stdin] [-m] [-s] [-v] [--no-commit-id] [--pretty] - [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] + [-t] [-r] [-c | --cc] [--combined-all-paths] [--root] [--merge-base] [<common diff options>] <tree-ish> [<tree-ish>] [<path>...] DESCRIPTION @@ -43,6 +43,11 @@ include::diff-options.txt[] When `--root` is specified the initial commit will be shown as a big creation event. This is equivalent to a diff against the NULL tree. +--merge-base:: + Instead of comparing the <tree-ish>s directly, use the merge + base between the two <tree-ish>s as the "before" side. There + must be two <tree-ish>s given and they must both be commits. + --stdin:: When `--stdin` is specified, the command does not take <tree-ish> arguments from the command line. Instead, it diff --git a/Documentation/git-diff.txt b/Documentation/git-diff.txt index 727f24d16e..7f4c8a8ce7 100644 --- a/Documentation/git-diff.txt +++ b/Documentation/git-diff.txt @@ -10,8 +10,8 @@ SYNOPSIS -------- [verse] 'git diff' [<options>] [<commit>] [--] [<path>...] -'git diff' [<options>] --cached [<commit>] [--] [<path>...] -'git diff' [<options>] <commit> [<commit>...] <commit> [--] [<path>...] +'git diff' [<options>] --cached [--merge-base] [<commit>] [--] [<path>...] +'git diff' [<options>] [--merge-base] <commit> [<commit>...] <commit> [--] [<path>...] 'git diff' [<options>] <commit>...<commit> [--] [<path>...] 'git diff' [<options>] <blob> <blob> 'git diff' [<options>] --no-index [--] <path> <path> @@ -40,7 +40,7 @@ files on disk. or when running the command outside a working tree controlled by Git. This form implies `--exit-code`. -'git diff' [<options>] --cached [<commit>] [--] [<path>...]:: +'git diff' [<options>] --cached [--merge-base] [<commit>] [--] [<path>...]:: This form is to view the changes you staged for the next commit relative to the named <commit>. Typically you @@ -49,6 +49,10 @@ files on disk. If HEAD does not exist (e.g. unborn branches) and <commit> is not given, it shows all staged changes. --staged is a synonym of --cached. ++ +If --merge-base is given, instead of using <commit>, use the merge base +of <commit> and HEAD. `git diff --merge-base A` is equivalent to +`git diff $(git merge-base A HEAD)`. 'git diff' [<options>] <commit> [--] [<path>...]:: @@ -58,23 +62,27 @@ files on disk. branch name to compare with the tip of a different branch. -'git diff' [<options>] <commit> <commit> [--] [<path>...]:: +'git diff' [<options>] [--merge-base] <commit> <commit> [--] [<path>...]:: This is to view the changes between two arbitrary <commit>. ++ +If --merge-base is given, use the merge base of the two commits for the +"before" side. `git diff --merge-base A B` is equivalent to +`git diff $(git merge-base A B) B`. 'git diff' [<options>] <commit> <commit>... <commit> [--] [<path>...]:: This form is to view the results of a merge commit. The first listed <commit> must be the merge itself; the remaining two or more commits should be its parents. A convenient way to produce - the desired set of revisions is to use the {caret}@ suffix. + the desired set of revisions is to use the `^@` suffix. For instance, if `master` names a merge commit, `git diff master master^@` gives the same combined diff as `git show master`. 'git diff' [<options>] <commit>..<commit> [--] [<path>...]:: - This is synonymous to the earlier form (without the "..") for + This is synonymous to the earlier form (without the `..`) for viewing the changes between two arbitrary <commit>. If <commit> on one side is omitted, it will have the same effect as using HEAD instead. @@ -83,20 +91,20 @@ files on disk. This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor - of both <commit>. "git diff A\...B" is equivalent to - "git diff $(git merge-base A B) B". You can omit any one + of both <commit>. `git diff A...B` is equivalent to + `git diff $(git merge-base A B) B`. You can omit any one of <commit>, which has the same effect as using HEAD instead. Just in case you are doing something exotic, it should be noted that all of the <commit> in the above description, except -in the last two forms that use ".." notations, can be any -<tree>. +in the `--merge-base` case and in the last two forms that use `..` +notations, can be any <tree>. For a more complete list of ways to spell <commit>, see "SPECIFYING REVISIONS" section in linkgit:gitrevisions[7]. However, "diff" is about comparing two _endpoints_, not ranges, -and the range notations ("<commit>..<commit>" and -"<commit>\...<commit>") do not mean a range as defined in the +and the range notations (`<commit>..<commit>` and +`<commit>...<commit>`) do not mean a range as defined in the "SPECIFYING RANGES" section in linkgit:gitrevisions[7]. 'git diff' [<options>] <blob> <blob>:: @@ -144,9 +152,9 @@ $ git diff HEAD <3> + <1> Changes in the working tree not yet staged for the next commit. <2> Changes between the index and your last commit; what you - would be committing if you run "git commit" without "-a" option. + would be committing if you run `git commit` without `-a` option. <3> Changes in the working tree since your last commit; what you - would be committing if you run "git commit -a" + would be committing if you run `git commit -a` Comparing with arbitrary commits:: + diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt index 40ba4aa3e6..62e482a95e 100644 --- a/Documentation/git-filter-branch.txt +++ b/Documentation/git-filter-branch.txt @@ -532,7 +532,7 @@ The https://github.com/newren/git-filter-repo/[git filter-repo] tool is an alternative to git-filter-branch which does not suffer from these performance problems or the safety problems (mentioned below). For those with existing tooling which relies upon git-filter-branch, 'git -repo-filter' also provides +filter-repo' also provides https://github.com/newren/git-filter-repo/blob/master/contrib/filter-repo-demos/filter-lamely[filter-lamely], a drop-in git-filter-branch replacement (with a few caveats). While filter-lamely suffers from all the same safety issues as diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 0f81d0437b..bf1bb40f63 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -119,7 +119,7 @@ include::diff-options.txt[] -s:: --signoff:: - Add `Signed-off-by:` line to the commit message, using + Add a `Signed-off-by` trailer to the commit message, using the committer identity of yourself. See the signoff option in linkgit:git-commit[1] for more information. diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 6abcb8255a..3f5d8946b4 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -47,6 +47,21 @@ commit-graph:: `commit-graph-chain` file. They will be deleted by a later run based on the expiration delay. +prefetch:: + The `prefetch` task updates the object directory with the latest + objects from all registered remotes. For each remote, a `git fetch` + command is run. The refmap is custom to avoid updating local or remote + branches (those in `refs/heads` or `refs/remotes`). Instead, the + remote refs are stored in `refs/prefetch/<remote>/`. Also, tags are + not updated. ++ +This is done to avoid disrupting the remote-tracking branches. The end users +expect these refs to stay unmoved unless they initiate a fetch. With prefetch +task, however, the objects necessary to complete a later real fetch would +already be obtained, so the real fetch would go faster. In the ideal case, +it will just become an update to bunch of remote-tracking branches without +any object transfer. + gc:: Clean up unnecessary files and optimize the local repository. "GC" stands for "garbage collection," but this task performs many @@ -55,6 +70,39 @@ gc:: be disruptive in some situations, as it deletes stale data. See linkgit:git-gc[1] for more details on garbage collection in Git. +loose-objects:: + The `loose-objects` job cleans up loose objects and places them into + pack-files. In order to prevent race conditions with concurrent Git + commands, it follows a two-step process. First, it deletes any loose + objects that already exist in a pack-file; concurrent Git processes + will examine the pack-file for the object data instead of the loose + object. Second, it creates a new pack-file (starting with "loose-") + containing a batch of loose objects. The batch size is limited to 50 + thousand objects to prevent the job from taking too long on a + repository with many loose objects. The `gc` task writes unreachable + objects as loose objects to be cleaned up by a later step only if + they are not re-added to a pack-file; for this reason it is not + advisable to enable both the `loose-objects` and `gc` tasks at the + same time. + +incremental-repack:: + The `incremental-repack` job repacks the object directory + using the `multi-pack-index` feature. In order to prevent race + conditions with concurrent Git commands, it follows a two-step + process. First, it calls `git multi-pack-index expire` to delete + pack-files unreferenced by the `multi-pack-index` file. Second, it + calls `git multi-pack-index repack` to select several small + pack-files and repack them into a bigger one, and then update the + `multi-pack-index` entries that refer to the small pack-files to + refer to the new pack-file. This prepares those small pack-files + for deletion upon the next run of `git multi-pack-index expire`. + The selection of the small pack-files is such that the expected + size of the big pack-file is at least the batch size; see the + `--batch-size` option for the `repack` subcommand in + linkgit:git-multi-pack-index[1]. The default batch-size is zero, + which is a special case that attempts to repack all pack-files + into a single pack-file. + OPTIONS ------- --auto:: diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 3b8053447e..ab103c82cf 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -13,7 +13,7 @@ SYNOPSIS [--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-v | --verbose] [-u | --set-upstream] [-o <string> | --push-option=<string>] [--[no-]signed|--signed=(true|false|if-asked)] - [--force-with-lease[=<refname>[:<expect>]]] + [--force-with-lease[=<refname>[:<expect>]] [--force-if-includes]] [--no-verify] [<repository> [<refspec>...]] DESCRIPTION @@ -320,6 +320,14 @@ seen and are willing to overwrite, then rewrite history, and finally force push changes to `master` if the remote version is still at `base`, regardless of what your local `remotes/origin/master` has been updated to in the background. ++ +Alternatively, specifying `--force-if-includes` as an ancillary option +along with `--force-with-lease[=<refname>]` (i.e., without saying what +exact commit the ref on the remote side must be pointing at, or which +refs on the remote side are being protected) at the time of "push" will +verify if updates from the remote-tracking refs that may have been +implicitly updated in the background are integrated locally before +allowing a forced update. -f:: --force:: @@ -341,6 +349,22 @@ one branch, use a `+` in front of the refspec to push (e.g `git push origin +master` to force a push to the `master` branch). See the `<refspec>...` section above for details. +--[no-]force-if-includes:: + Force an update only if the tip of the remote-tracking ref + has been integrated locally. ++ +This option enables a check that verifies if the tip of the +remote-tracking ref is reachable from one of the "reflog" entries of +the local branch based in it for a rewrite. The check ensures that any +updates from the remote have been incorporated locally by rejecting the +forced update if that is not the case. ++ +If the option is passed without specifying `--force-with-lease`, or +specified along with `--force-with-lease=<refname>:<expect>`, it is +a "no-op". ++ +Specifying `--no-force-if-includes` disables this behavior. + --repo=<repository>:: This option is equivalent to the <repository> argument. If both are specified, the command-line argument takes precedence. diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 38e15488f6..a0487b5cc5 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -496,7 +496,7 @@ See also INCOMPATIBLE OPTIONS below. See also INCOMPATIBLE OPTIONS below. --signoff:: - Add a Signed-off-by: trailer to all the rebased commits. Note + Add a `Signed-off-by` trailer to all the rebased commits. Note that if `--interactive` is given then only commits marked to be picked, edited or reworded will have the trailer added. + diff --git a/Documentation/git-restore.txt b/Documentation/git-restore.txt index 84c6c40010..55bde91ef9 100644 --- a/Documentation/git-restore.txt +++ b/Documentation/git-restore.txt @@ -40,6 +40,10 @@ OPTIONS + If not specified, the contents are restored from `HEAD` if `--staged` is given, otherwise from the index. ++ +As a special case, you may use `"A...B"` as a shortcut for the +merge base of `A` and `B` if there is exactly one merge base. You can +leave out at most one of `A` and `B`, in which case it defaults to `HEAD`. -p:: --patch:: diff --git a/Documentation/git-revert.txt b/Documentation/git-revert.txt index 044276e9da..bb92a4a451 100644 --- a/Documentation/git-revert.txt +++ b/Documentation/git-revert.txt @@ -99,7 +99,7 @@ effect to your index in a row. -s:: --signoff:: - Add Signed-off-by line at the end of the commit message. + Add a `Signed-off-by` trailer at the end of the commit message. See the signoff option in linkgit:git-commit[1] for more information. --strategy=<strategy>:: diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index 0a69810147..b7bbbeadef 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -313,7 +313,7 @@ Automating the value of `sendemail.identity`. --[no-]signed-off-by-cc:: - If this is set, add emails found in Signed-off-by: or Cc: lines to the + If this is set, add emails found in the `Signed-off-by` trailer or Cc: lines to the cc list. Default is the value of `sendemail.signedoffbycc` configuration value; if that is unspecified, default to --signed-off-by-cc. @@ -340,7 +340,7 @@ Automating except for self (use 'self' for that). - 'bodycc' will avoid including anyone mentioned in Cc lines in the patch body (commit message) except for self (use 'self' for that). -- 'sob' will avoid including anyone mentioned in Signed-off-by lines except +- 'sob' will avoid including anyone mentioned in the Signed-off-by trailers except for self (use 'self' for that). - 'misc-by' will avoid including anyone mentioned in Acked-by, Reviewed-by, Tested-by and other "-by" lines in the patch body, diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 6624a14fbd..67b143cc81 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -701,7 +701,7 @@ creating the branch or tag. --use-log-author:: When retrieving svn commits into Git (as part of 'fetch', 'rebase', or - 'dcommit' operations), look for the first `From:` or `Signed-off-by:` line + 'dcommit' operations), look for the first `From:` line or `Signed-off-by` trailer in the log message and use that as the author string. + [verse] @@ -710,7 +710,7 @@ config key: svn.useLogAuthor --add-author-from:: When committing to svn from Git (as part of 'set-tree' or 'dcommit' operations), if the existing log message doesn't already have a - `From:` or `Signed-off-by:` line, append a `From:` line based on the + `From:` or `Signed-off-by` trailer, append a `From:` line based on the Git commit's author string. If you use this, then `--use-log-author` will retrieve a valid author string for all commits. + diff --git a/Documentation/git-switch.txt b/Documentation/git-switch.txt index 3759c3a265..5c438cd505 100644 --- a/Documentation/git-switch.txt +++ b/Documentation/git-switch.txt @@ -103,6 +103,9 @@ ambiguous but exists on the 'origin' remote. See also `checkout.defaultRemote` in linkgit:git-config[1]. + `--guess` is the default behavior. Use `--no-guess` to disable it. ++ +The default behavior can be set via the `checkout.guess` configuration +variable. -f:: --force:: diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt index 32e8440cde..af06128cc9 100644 --- a/Documentation/git-worktree.txt +++ b/Documentation/git-worktree.txt @@ -96,8 +96,9 @@ list:: List details of each working tree. The main working tree is listed first, followed by each of the linked working trees. The output details include -whether the working tree is bare, the revision currently checked out, and the -branch currently checked out (or "detached HEAD" if none). +whether the working tree is bare, the revision currently checked out, the +branch currently checked out (or "detached HEAD" if none), and "locked" if +the worktree is locked. lock:: diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 6e461ace6e..4e097dc4e9 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -164,7 +164,7 @@ can also be used to refuse the commit after inspecting the message file. The default 'commit-msg' hook, when enabled, detects duplicate -"Signed-off-by" lines, and aborts the commit if one is found. +`Signed-off-by` trailers, and aborts the commit if one is found. post-commit ~~~~~~~~~~~ diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt index 80d4831662..eb0aabd396 100644 --- a/Documentation/merge-options.txt +++ b/Documentation/merge-options.txt @@ -77,16 +77,7 @@ When not possible, refuse to merge and exit with a non-zero status. With --no-log do not list one-line descriptions from the actual commits being merged. ---signoff:: ---no-signoff:: - Add Signed-off-by line by the committer at the end of the commit - log message. The meaning of a signoff depends on the project, - but it typically certifies that committer has - the rights to submit this work under the same license and - agrees to a Developer Certificate of Origin - (see http://developercertificate.org/ for more information). -+ -With --no-signoff do not add a Signed-off-by line. +include::signoff-option.txt[] --stat:: -n:: diff --git a/Documentation/signoff-option.txt b/Documentation/signoff-option.txt new file mode 100644 index 0000000000..12aa2333e4 --- /dev/null +++ b/Documentation/signoff-option.txt @@ -0,0 +1,18 @@ +ifdef::git-commit[] +-s:: +endif::git-commit[] +--signoff:: +--no-signoff:: + Add a `Signed-off-by` trailer by the committer at the end of the commit + log message. The meaning of a signoff depends on the project + to which you're committing. For example, it may certify that + the committer has the rights to submit the work under the + project's license or agrees to some contributor representation, + such as a Developer Certificate of Origin. + (See http://developercertificate.org for the one used by the + Linux kernel and Git projects.) Consult the documentation or + leadership of the project to which you're contributing to + understand how the signoffs are used in that project. ++ +The --no-signoff option can be used to countermand an earlier --signoff +option on the command line. diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index b6b9c119f2..82bcd13f4c 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v2.29.0 +DEF_VER=v2.29.GIT LF=' ' @@ -2981,15 +2981,12 @@ endif } && \ for p in $(filter $(install_bindir_programs),$(BUILT_INS)); do \ $(RM) "$$bindir/$$p" && \ - if test -z "$(SKIP_DASHED_BUILT_INS)"; \ - then \ - test -n "$(INSTALL_SYMLINKS)" && \ - ln -s "git$X" "$$bindir/$$p" || \ - { test -z "$(NO_INSTALL_HARDLINKS)" && \ - ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \ - ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \ - cp "$$bindir/git$X" "$$bindir/$$p" || exit; }; \ - fi \ + test -n "$(INSTALL_SYMLINKS)" && \ + ln -s "git$X" "$$bindir/$$p" || \ + { test -z "$(NO_INSTALL_HARDLINKS)" && \ + ln "$$bindir/git$X" "$$bindir/$$p" 2>/dev/null || \ + ln -s "git$X" "$$bindir/$$p" 2>/dev/null || \ + cp "$$bindir/git$X" "$$bindir/$$p" || exit; }; \ done && \ for p in $(BUILT_INS); do \ $(RM) "$$execdir/$$p" && \ @@ -3053,9 +3050,6 @@ quick-install-html: ### Maintainer's dist rules -# Allow tweaking to hide local environment effects, like perm bits. -# With GNU tar, "--mode=u+rwX,og+rX,og-w" would be a good idea, for example. -TAR_DIST_EXTRA_OPTS = GIT_TARNAME = git-$(GIT_VERSION) GIT_ARCHIVE_EXTRA_FILES = \ --prefix=$(GIT_TARNAME)/ \ @@ -3105,11 +3099,15 @@ artifacts-tar:: $(ALL_COMMANDS_TO_INSTALL) $(SCRIPT_LIB) $(OTHER_PROGRAMS) \ htmldocs = git-htmldocs-$(GIT_VERSION) manpages = git-manpages-$(GIT_VERSION) .PHONY: dist-doc distclean -dist-doc: +dist-doc: git$X $(RM) -r .doc-tmp-dir mkdir .doc-tmp-dir $(MAKE) -C Documentation WEBDOC_DEST=../.doc-tmp-dir install-webdoc - cd .doc-tmp-dir && $(TAR) cf ../$(htmldocs).tar $(TAR_DIST_EXTRA_OPTS) . + ./git -C .doc-tmp-dir init + ./git -C .doc-tmp-dir add . + ./git -C .doc-tmp-dir commit -m htmldocs + ./git -C .doc-tmp-dir archive --format=tar --prefix=./ HEAD^{tree} \ + > $(htmldocs).tar gzip -n -9 -f $(htmldocs).tar : $(RM) -r .doc-tmp-dir @@ -3119,7 +3117,11 @@ dist-doc: man5dir=../.doc-tmp-dir/man5 \ man7dir=../.doc-tmp-dir/man7 \ install - cd .doc-tmp-dir && $(TAR) cf ../$(manpages).tar $(TAR_DIST_EXTRA_OPTS) . + ./git -C .doc-tmp-dir init + ./git -C .doc-tmp-dir add . + ./git -C .doc-tmp-dir commit -m manpages + ./git -C .doc-tmp-dir archive --format=tar --prefix=./ HEAD^{tree} \ + > $(manpages).tar gzip -n -9 -f $(manpages).tar $(RM) -r .doc-tmp-dir @@ -1 +1 @@ -Documentation/RelNotes/2.29.0.txt
\ No newline at end of file +Documentation/RelNotes/2.30.0.txt
\ No newline at end of file diff --git a/add-patch.c b/add-patch.c index bd94bd3a7c..be4cf6e9e5 100644 --- a/add-patch.c +++ b/add-patch.c @@ -1695,6 +1695,14 @@ int run_add_p(struct repository *r, enum add_p_mode mode, if (mode == ADD_P_STASH) s.mode = &patch_mode_stash; else if (mode == ADD_P_RESET) { + /* + * NEEDSWORK: Instead of comparing to the literal "HEAD", + * compare the commit objects instead so that other ways of + * saying the same thing (such as "@") are also handled + * appropriately. + * + * This applies to the cases below too. + */ if (!revision || !strcmp(revision, "HEAD")) s.mode = &patch_mode_reset_head; else @@ -11,6 +11,7 @@ int advice_push_already_exists = 1; int advice_push_fetch_first = 1; int advice_push_needs_force = 1; int advice_push_unqualified_ref_name = 1; +int advice_push_ref_needs_update = 1; int advice_status_hints = 1; int advice_status_u_option = 1; int advice_status_ahead_behind_warning = 1; @@ -72,6 +73,7 @@ static struct { { "pushFetchFirst", &advice_push_fetch_first }, { "pushNeedsForce", &advice_push_needs_force }, { "pushUnqualifiedRefName", &advice_push_unqualified_ref_name }, + { "pushRefNeedsUpdate", &advice_push_ref_needs_update }, { "statusHints", &advice_status_hints }, { "statusUoption", &advice_status_u_option }, { "statusAheadBehindWarning", &advice_status_ahead_behind_warning }, @@ -116,6 +118,7 @@ static struct { [ADVICE_PUSH_ALREADY_EXISTS] = { "pushAlreadyExists", 1 }, [ADVICE_PUSH_FETCH_FIRST] = { "pushFetchFirst", 1 }, [ADVICE_PUSH_NEEDS_FORCE] = { "pushNeedsForce", 1 }, + [ADVICE_PUSH_REF_NEEDS_UPDATE] = { "pushRefNeedsUpdate", 1 }, /* make this an alias for backward compatibility */ [ADVICE_PUSH_UPDATE_REJECTED_ALIAS] = { "pushNonFastForward", 1 }, @@ -11,6 +11,7 @@ extern int advice_push_already_exists; extern int advice_push_fetch_first; extern int advice_push_needs_force; extern int advice_push_unqualified_ref_name; +extern int advice_push_ref_needs_update; extern int advice_status_hints; extern int advice_status_u_option; extern int advice_status_ahead_behind_warning; @@ -60,6 +61,7 @@ extern int advice_add_empty_pathspec; ADVICE_PUSH_UNQUALIFIED_REF_NAME, ADVICE_PUSH_UPDATE_REJECTED_ALIAS, ADVICE_PUSH_UPDATE_REJECTED, + ADVICE_PUSH_REF_NEEDS_UPDATE, ADVICE_RESET_QUIET_WARNING, ADVICE_RESOLVE_CONFLICT, ADVICE_RM_HINTS, @@ -4699,8 +4699,13 @@ static int apply_patch(struct apply_state *state, reverse_patches(patch); if (use_patch(state, patch)) { patch_stats(state, patch); - *listp = patch; - listp = &patch->next; + if (!list || !state->apply_in_reverse) { + *listp = patch; + listp = &patch->next; + } else { + patch->next = list; + list = patch; + } if ((patch->new_name && ends_with_path_components(patch->new_name, @@ -2670,7 +2670,7 @@ static struct commit *find_single_final(struct rev_info *revs, if (obj->flags & UNINTERESTING) continue; obj = deref_tag(revs->repo, obj, NULL, 0); - if (obj->type != OBJ_COMMIT) + if (!obj || obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (found) die("More than one commit to dig from %s and %s?", @@ -2701,7 +2701,7 @@ static struct commit *dwim_reverse_initial(struct rev_info *revs, /* Is that sole rev a committish? */ obj = revs->pending.objects[0].item; obj = deref_tag(revs->repo, obj, NULL, 0); - if (obj->type != OBJ_COMMIT) + if (!obj || obj->type != OBJ_COMMIT) return NULL; /* Do we have HEAD? */ @@ -2737,7 +2737,7 @@ static struct commit *find_single_initial(struct rev_info *revs, if (!(obj->flags & UNINTERESTING)) continue; obj = deref_tag(revs->repo, obj, NULL, 0); - if (obj->type != OBJ_COMMIT) + if (!obj || obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (found) die("More than one commit to dig up from, %s and %s?", diff --git a/builtin/am.c b/builtin/am.c index 2c7673f74e..b727449aed 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -161,7 +161,7 @@ static void am_state_init(struct am_state *state) state->committer_name = xmemdupz(id.name_begin, id.name_end - id.name_begin); state->committer_email = - xmemdupz(id.mail_begin, id.mail_end - id.mail_end); + xmemdupz(id.mail_begin, id.mail_end - id.mail_begin); } /** @@ -1595,7 +1595,7 @@ static void do_commit(const struct am_state *state) if (state->committer_date_is_author_date) committer = fmt_ident(state->committer_name, - state->author_email, WANT_COMMITTER_IDENT, + state->committer_email, WANT_COMMITTER_IDENT, state->ignore_date ? NULL : state->author_date, IDENT_STRICT); @@ -2237,7 +2237,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) N_("allow fall back on 3way merging if needed")), OPT__QUIET(&state.quiet, N_("be quiet")), OPT_SET_INT('s', "signoff", &state.signoff, - N_("add a Signed-off-by line to the commit message"), + N_("add a Signed-off-by trailer to the commit message"), SIGNOFF_EXPLICIT), OPT_BOOL('u', "utf8", &state.utf8, N_("recode into utf8 (default)")), diff --git a/builtin/blame.c b/builtin/blame.c index bb0f29300e..b5036ab327 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -820,6 +820,8 @@ static int peel_to_commit_oid(struct object_id *oid_ret, void *cbdata) if (kind != OBJ_TAG) return -1; obj = deref_tag(r, parse_object(r, &oid), NULL, 0); + if (!obj) + return -1; oidcpy(&oid, &obj->oid); } } diff --git a/builtin/checkout.c b/builtin/checkout.c index 0951f8fee5..7c311cecb3 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -471,6 +471,19 @@ static int checkout_paths(const struct checkout_opts *opts, if (opts->patch_mode) { const char *patch_mode; + const char *rev = new_branch_info->name; + char rev_oid[GIT_MAX_HEXSZ + 1]; + + /* + * Since rev can be in the form of `<a>...<b>` (which is not + * recognized by diff-index), we will always replace the name + * with the hex of the commit (whether it's in `...` form or + * not) for the run_add_interactive() machinery to work + * properly. However, there is special logic for the HEAD case + * so we mustn't replace that. + */ + if (rev && strcmp(rev, "HEAD")) + rev = oid_to_hex_r(rev_oid, &new_branch_info->commit->object.oid); if (opts->checkout_index && opts->checkout_worktree) patch_mode = "--patch=checkout"; @@ -481,7 +494,7 @@ static int checkout_paths(const struct checkout_opts *opts, else BUG("either flag must have been set, worktree=%d, index=%d", opts->checkout_worktree, opts->checkout_index); - return run_add_interactive(new_branch_info->name, patch_mode, &opts->pathspec); + return run_add_interactive(rev, patch_mode, &opts->pathspec); } repo_hold_locked_index(the_repository, &lock_file, LOCK_DIE_ON_ERROR); @@ -1093,11 +1106,16 @@ static int switch_branches(const struct checkout_opts *opts, static int git_checkout_config(const char *var, const char *value, void *cb) { + struct checkout_opts *opts = cb; + if (!strcmp(var, "diff.ignoresubmodules")) { - struct checkout_opts *opts = cb; handle_ignore_submodules_arg(&opts->diff_options, value); return 0; } + if (!strcmp(var, "checkout.guess")) { + opts->dwim_new_local_branch = git_config_bool(var, value); + return 0; + } if (starts_with(var, "submodule.")) return git_default_submodule_config(var, value, NULL); diff --git a/builtin/clone.c b/builtin/clone.c index 391aa41075..a0841923cf 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -53,6 +53,7 @@ static int option_shallow_submodules; static int deepen; static char *option_template, *option_depth, *option_since; static char *option_origin = NULL; +static char *remote_name = NULL; static char *option_branch = NULL; static struct string_list option_not = STRING_LIST_INIT_NODUP; static const char *real_git_dir; @@ -721,7 +722,7 @@ static void update_head(const struct ref *our, const struct ref *remote, if (!option_bare) { update_ref(msg, "HEAD", &our->old_oid, NULL, 0, UPDATE_REFS_DIE_ON_ERR); - install_branch_config(0, head, option_origin, our->name); + install_branch_config(0, head, remote_name, our->name); } } else if (our) { struct commit *c = lookup_commit_reference(the_repository, @@ -851,8 +852,26 @@ static int checkout(int submodule_progress) return err; } +static int git_clone_config(const char *k, const char *v, void *cb) +{ + if (!strcmp(k, "clone.defaultremotename")) { + free(remote_name); + remote_name = xstrdup(v); + } + return git_default_config(k, v, cb); +} + static int write_one_config(const char *key, const char *value, void *data) { + /* + * give git_clone_config a chance to write config values back to the + * environment, since git_config_set_multivar_gently only deals with + * config-file writes + */ + int apply_failed = git_clone_config(key, value, data); + if (apply_failed) + return apply_failed; + return git_config_set_multivar_gently(key, value ? value : "true", CONFIG_REGEX_NONE, 0); @@ -905,12 +924,12 @@ static void write_refspec_config(const char *src_ref_prefix, } /* Configure the remote */ if (value.len) { - strbuf_addf(&key, "remote.%s.fetch", option_origin); + strbuf_addf(&key, "remote.%s.fetch", remote_name); git_config_set_multivar(key.buf, value.buf, "^$", 0); strbuf_reset(&key); if (option_mirror) { - strbuf_addf(&key, "remote.%s.mirror", option_origin); + strbuf_addf(&key, "remote.%s.mirror", remote_name); git_config_set(key.buf, "true"); strbuf_reset(&key); } @@ -963,6 +982,9 @@ int cmd_clone(int argc, const char **argv, const char *prefix) struct strvec ref_prefixes = STRVEC_INIT; packet_trace_identity("clone"); + + git_config(git_clone_config, NULL); + argc = parse_options(argc, argv, prefix, builtin_clone_options, builtin_clone_usage, 0); @@ -991,9 +1013,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) option_no_checkout = 1; } - if (!option_origin) - option_origin = "origin"; - repo_name = argv[0]; path = get_repo_path(repo_name, &is_bundle); @@ -1124,9 +1143,30 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (real_git_dir) git_dir = real_git_dir; + /* + * additional config can be injected with -c, make sure it's included + * after init_db, which clears the entire config environment. + */ write_config(&option_config); - git_config(git_default_config, NULL); + /* + * re-read config after init_db and write_config to pick up any config + * injected by --template and --config, respectively. + */ + git_config(git_clone_config, NULL); + + /* + * apply the remote name provided by --origin only after this second + * call to git_config, to ensure it overrides all config-based values. + */ + if (option_origin != NULL) + remote_name = xstrdup(option_origin); + + if (remote_name == NULL) + remote_name = xstrdup("origin"); + + if (!valid_remote_name(remote_name)) + die(_("'%s' is not a valid remote name"), remote_name); if (option_bare) { if (option_mirror) @@ -1135,15 +1175,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix) git_config_set("core.bare", "true"); } else { - strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin); + strbuf_addf(&branch_top, "refs/remotes/%s/", remote_name); } - strbuf_addf(&key, "remote.%s.url", option_origin); + strbuf_addf(&key, "remote.%s.url", remote_name); git_config_set(key.buf, repo); strbuf_reset(&key); if (option_no_tags) { - strbuf_addf(&key, "remote.%s.tagOpt", option_origin); + strbuf_addf(&key, "remote.%s.tagOpt", remote_name); git_config_set(key.buf, "--no-tags"); strbuf_reset(&key); } @@ -1154,7 +1194,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_sparse_checkout && git_sparse_checkout_init(dir)) return 1; - remote = remote_get(option_origin); + remote = remote_get(remote_name); refspec_appendf(&remote->fetch, "+%s*:%s*", src_ref_prefix, branch_top.buf); @@ -1266,7 +1306,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (!our_head_points_at) die(_("Remote branch %s not found in upstream %s"), - option_branch, option_origin); + option_branch, remote_name); } else our_head_points_at = remote_head_points_at; @@ -1274,7 +1314,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) else { if (option_branch) die(_("Remote branch %s not found in upstream %s"), - option_branch, option_origin); + option_branch, remote_name); warning(_("You appear to have cloned an empty repository.")); mapped_refs = NULL; @@ -1286,7 +1326,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) const char *branch = git_default_branch_name(); char *ref = xstrfmt("refs/heads/%s", branch); - install_branch_config(0, branch, option_origin, ref); + install_branch_config(0, branch, remote_name, ref); free(ref); } } @@ -1295,7 +1335,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) remote_head_points_at, &branch_top); if (filter_options.choice) - partial_clone_register(option_origin, &filter_options); + partial_clone_register(remote_name, &filter_options); if (is_local) clone_local(path, git_dir); @@ -1327,6 +1367,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) junk_mode = JUNK_LEAVE_REPO; err = checkout(submodule_progress); + free(remote_name); strbuf_release(&reflog_msg); strbuf_release(&branch_top); strbuf_release(&key); diff --git a/builtin/commit.c b/builtin/commit.c index 1dfd799ec5..505fe60956 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1507,7 +1507,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix) OPT_STRING(0, "fixup", &fixup_message, N_("commit"), N_("use autosquash formatted message to fixup specified commit")), OPT_STRING(0, "squash", &squash_message, N_("commit"), N_("use autosquash formatted message to squash specified commit")), OPT_BOOL(0, "reset-author", &renew_authorship, N_("the commit is authored by me now (used with -C/-c/--amend)")), - OPT_BOOL('s', "signoff", &signoff, N_("add Signed-off-by:")), + OPT_BOOL('s', "signoff", &signoff, N_("add a Signed-off-by trailer")), OPT_FILENAME('t', "template", &template_file, N_("use specified template file")), OPT_BOOL('e', "edit", &edit_flag, N_("force edit of commit")), OPT_CLEANUP(&cleanup_arg), diff --git a/builtin/credential.c b/builtin/credential.c index 879acfbcda..d75dcdc64a 100644 --- a/builtin/credential.c +++ b/builtin/credential.c @@ -1,6 +1,7 @@ #include "git-compat-util.h" #include "credential.h" #include "builtin.h" +#include "config.h" static const char usage_msg[] = "git credential [fill|approve|reject]"; @@ -10,6 +11,8 @@ int cmd_credential(int argc, const char **argv, const char *prefix) const char *op; struct credential c = CREDENTIAL_INIT; + git_config(git_default_config, NULL); + if (argc != 2 || !strcmp(argv[1], "-h")) usage(usage_msg); op = argv[1]; diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 93ec642423..7f5281c461 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -15,7 +15,7 @@ COMMON_DIFF_OPTIONS_HELP; int cmd_diff_index(int argc, const char **argv, const char *prefix) { struct rev_info rev; - int cached = 0; + unsigned int option = 0; int i; int result; @@ -32,7 +32,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) const char *arg = argv[i]; if (!strcmp(arg, "--cached")) - cached = 1; + option |= DIFF_INDEX_CACHED; + else if (!strcmp(arg, "--merge-base")) + option |= DIFF_INDEX_MERGE_BASE; else usage(diff_cache_usage); } @@ -46,7 +48,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) if (rev.pending.nr != 1 || rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) usage(diff_cache_usage); - if (!cached) { + if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); if (read_cache_preload(&rev.diffopt.pathspec) < 0) { perror("read_cache_preload"); @@ -56,7 +58,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) perror("read_cache"); return -1; } - result = run_diff_index(&rev, cached); + result = run_diff_index(&rev, option); UNLEAK(rev); return diff_result_code(&rev.diffopt, result); } diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c index 802363d0a2..9fc95e959f 100644 --- a/builtin/diff-tree.c +++ b/builtin/diff-tree.c @@ -111,6 +111,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) struct setup_revision_opt s_r_opt; struct userformat_want w; int read_stdin = 0; + int merge_base = 0; if (argc == 2 && !strcmp(argv[1], "-h")) usage(diff_tree_usage); @@ -143,9 +144,18 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) read_stdin = 1; continue; } + if (!strcmp(arg, "--merge-base")) { + merge_base = 1; + continue; + } usage(diff_tree_usage); } + if (read_stdin && merge_base) + die(_("--stdin and --merge-base are mutually exclusive")); + if (merge_base && opt->pending.nr != 2) + die(_("--merge-base only works with two commits")); + /* * NOTE! We expect "a..b" to expand to "^a b" but it is * perfectly valid for revision range parser to yield "b ^a", @@ -165,7 +175,12 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix) case 2: tree1 = opt->pending.objects[0].item; tree2 = opt->pending.objects[1].item; - if (tree2->flags & UNINTERESTING) { + if (merge_base) { + struct object_id oid; + + diff_get_merge_base(opt, &oid); + tree1 = lookup_object(the_repository, &oid); + } else if (tree2->flags & UNINTERESTING) { SWAP(tree2, tree1); } diff_tree_oid(&tree1->oid, &tree2->oid, "", &opt->diffopt); diff --git a/builtin/diff.c b/builtin/diff.c index cd4083fed9..780c33877f 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -26,7 +26,7 @@ static const char builtin_diff_usage[] = "git diff [<options>] [<commit>] [--] [<path>...]\n" " or: git diff [<options>] --cached [<commit>] [--] [<path>...]\n" -" or: git diff [<options>] <commit> [<commit>...] <commit> [--] [<path>...]\n" +" or: git diff [<options>] <commit> [--merge-base] [<commit>...] <commit> [--] [<path>...]\n" " or: git diff [<options>] <commit>...<commit>] [--] [<path>...]\n" " or: git diff [<options>] <blob> <blob>]\n" " or: git diff [<options>] --no-index [--] <path> <path>]\n" @@ -134,11 +134,13 @@ static int builtin_diff_blobs(struct rev_info *revs, static int builtin_diff_index(struct rev_info *revs, int argc, const char **argv) { - int cached = 0; + unsigned int option = 0; while (1 < argc) { const char *arg = argv[1]; if (!strcmp(arg, "--cached") || !strcmp(arg, "--staged")) - cached = 1; + option |= DIFF_INDEX_CACHED; + else if (!strcmp(arg, "--merge-base")) + option |= DIFF_INDEX_MERGE_BASE; else usage(builtin_diff_usage); argv++; argc--; @@ -151,7 +153,7 @@ static int builtin_diff_index(struct rev_info *revs, revs->max_count != -1 || revs->min_age != -1 || revs->max_age != -1) usage(builtin_diff_usage); - if (!cached) { + if (!(option & DIFF_INDEX_CACHED)) { setup_work_tree(); if (read_cache_preload(&revs->diffopt.pathspec) < 0) { perror("read_cache_preload"); @@ -161,7 +163,7 @@ static int builtin_diff_index(struct rev_info *revs, perror("read_cache"); return -1; } - return run_diff_index(revs, cached); + return run_diff_index(revs, option); } static int builtin_diff_tree(struct rev_info *revs, @@ -170,19 +172,34 @@ static int builtin_diff_tree(struct rev_info *revs, struct object_array_entry *ent1) { const struct object_id *(oid[2]); - int swap = 0; + struct object_id mb_oid; + int merge_base = 0; - if (argc > 1) - usage(builtin_diff_usage); + while (1 < argc) { + const char *arg = argv[1]; + if (!strcmp(arg, "--merge-base")) + merge_base = 1; + else + usage(builtin_diff_usage); + argv++; argc--; + } - /* - * We saw two trees, ent0 and ent1. If ent1 is uninteresting, - * swap them. - */ - if (ent1->item->flags & UNINTERESTING) - swap = 1; - oid[swap] = &ent0->item->oid; - oid[1 - swap] = &ent1->item->oid; + if (merge_base) { + diff_get_merge_base(revs, &mb_oid); + oid[0] = &mb_oid; + oid[1] = &revs->pending.objects[1].item->oid; + } else { + int swap = 0; + + /* + * We saw two trees, ent0 and ent1. If ent1 is uninteresting, + * swap them. + */ + if (ent1->item->flags & UNINTERESTING) + swap = 1; + oid[swap] = &ent0->item->oid; + oid[1 - swap] = &ent1->item->oid; + } diff_tree_oid(oid[0], oid[1], "", &revs->diffopt); log_tree_diff_flush(revs); return 0; diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 1bf50a73dc..dd4d09cece 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -150,7 +150,7 @@ struct recent_command { char *buf; }; -typedef void (*mark_set_inserter_t)(struct mark_set *s, struct object_id *oid, uintmax_t mark); +typedef void (*mark_set_inserter_t)(struct mark_set **s, struct object_id *oid, uintmax_t mark); typedef void (*each_mark_fn_t)(uintmax_t mark, void *obj, void *cbp); /* Configured limits on output */ @@ -526,13 +526,15 @@ static unsigned int hc_str(const char *s, size_t len) return r; } -static void insert_mark(struct mark_set *s, uintmax_t idnum, struct object_entry *oe) +static void insert_mark(struct mark_set **top, uintmax_t idnum, struct object_entry *oe) { + struct mark_set *s = *top; + while ((idnum >> s->shift) >= 1024) { s = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct mark_set)); - s->shift = marks->shift + 10; - s->data.sets[0] = marks; - marks = s; + s->shift = (*top)->shift + 10; + s->data.sets[0] = *top; + *top = s; } while (s->shift) { uintmax_t i = idnum >> s->shift; @@ -944,7 +946,7 @@ static int store_object( e = insert_object(&oid); if (mark) - insert_mark(marks, mark, e); + insert_mark(&marks, mark, e); if (e->idx.offset) { duplicate_count_by_type[type]++; return 1; @@ -1142,7 +1144,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark) e = insert_object(&oid); if (mark) - insert_mark(marks, mark, e); + insert_mark(&marks, mark, e); if (e->idx.offset) { duplicate_count_by_type[OBJ_BLOB]++; @@ -1717,7 +1719,7 @@ static void dump_marks(void) } } -static void insert_object_entry(struct mark_set *s, struct object_id *oid, uintmax_t mark) +static void insert_object_entry(struct mark_set **s, struct object_id *oid, uintmax_t mark) { struct object_entry *e; e = find_object(oid); @@ -1734,12 +1736,12 @@ static void insert_object_entry(struct mark_set *s, struct object_id *oid, uintm insert_mark(s, mark, e); } -static void insert_oid_entry(struct mark_set *s, struct object_id *oid, uintmax_t mark) +static void insert_oid_entry(struct mark_set **s, struct object_id *oid, uintmax_t mark) { insert_mark(s, mark, xmemdupz(oid, sizeof(*oid))); } -static void read_mark_file(struct mark_set *s, FILE *f, mark_set_inserter_t inserter) +static void read_mark_file(struct mark_set **s, FILE *f, mark_set_inserter_t inserter) { char line[512]; while (fgets(line, sizeof(line), f)) { @@ -1772,7 +1774,7 @@ static void read_marks(void) goto done; /* Marks file does not exist */ else die_errno("cannot read '%s'", import_marks_file); - read_mark_file(marks, f, insert_object_entry); + read_mark_file(&marks, f, insert_object_entry); fclose(f); done: import_marks_file_done = 1; @@ -3228,7 +3230,7 @@ static void parse_alias(void) die(_("Expected 'to' command, got %s"), command_buf.buf); e = find_object(&b.oid); assert(e); - insert_mark(marks, next_mark, e); + insert_mark(&marks, next_mark, e); } static char* make_fast_import_path(const char *path) @@ -3321,13 +3323,14 @@ static void option_rewrite_submodules(const char *arg, struct string_list *list) *f = '\0'; f++; ms = xcalloc(1, sizeof(*ms)); - string_list_insert(list, s)->util = ms; fp = fopen(f, "r"); if (!fp) die_errno("cannot read '%s'", f); - read_mark_file(ms, fp, insert_oid_entry); + read_mark_file(&ms, fp, insert_oid_entry); fclose(fp); + + string_list_insert(list, s)->util = ms; } static int parse_one_option(const char *option) @@ -3396,7 +3399,6 @@ static int parse_one_feature(const char *feature, int from_stream) option_rewrite_submodules(arg, &sub_marks_to); } else if (skip_prefix(feature, "rewrite-submodules-from=", &arg)) { option_rewrite_submodules(arg, &sub_marks_from); - } else if (skip_prefix(feature, "rewrite-submodules-from=", &arg)) { } else if (!strcmp(feature, "get-mark")) { ; /* Don't die - this feature is supported */ } else if (!strcmp(feature, "cat-blob")) { diff --git a/builtin/gc.c b/builtin/gc.c index 090959350e..3629a82299 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -29,6 +29,8 @@ #include "tree.h" #include "promisor-remote.h" #include "refs.h" +#include "remote.h" +#include "object-store.h" #define FAILED_RUN "failed to run %s" @@ -737,9 +739,15 @@ static int dfs_on_ref(const char *refname, commit = lookup_commit(the_repository, oid); if (!commit) return 0; - if (parse_commit(commit)) + if (parse_commit(commit) || + commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH) return 0; + data->num_not_in_graph++; + + if (data->num_not_in_graph >= data->limit) + return 1; + commit_list_append(commit, &stack); while (!result && stack) { @@ -807,6 +815,10 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts) static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) { + prepare_repo_settings(the_repository); + if (!the_repository->settings.core_commit_graph) + return 0; + close_object_store(the_repository->objects); if (run_write_commit_graph(opts)) { error(_("failed to write commit-graph")); @@ -816,6 +828,51 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts) return 0; } +static int fetch_remote(const char *remote, struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "fetch", remote, "--prune", "--no-tags", + "--no-write-fetch-head", "--recurse-submodules=no", + "--refmap=", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--quiet"); + + strvec_pushf(&child.args, "+refs/heads/*:refs/prefetch/%s/*", remote); + + return !!run_command(&child); +} + +static int append_remote(struct remote *remote, void *cbdata) +{ + struct string_list *remotes = (struct string_list *)cbdata; + + string_list_append(remotes, remote->name); + return 0; +} + +static int maintenance_task_prefetch(struct maintenance_run_opts *opts) +{ + int result = 0; + struct string_list_item *item; + struct string_list remotes = STRING_LIST_INIT_DUP; + + if (for_each_remote(append_remote, &remotes)) { + error(_("failed to fill remotes")); + result = 1; + goto cleanup; + } + + for_each_string_list_item(item, &remotes) + result |= fetch_remote(item->string, opts); + +cleanup: + string_list_clear(&remotes, 0); + return result; +} + static int maintenance_task_gc(struct maintenance_run_opts *opts) { struct child_process child = CHILD_PROCESS_INIT; @@ -834,6 +891,268 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts) return run_command(&child); } +static int prune_packed(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_push(&child.args, "prune-packed"); + + if (opts->quiet) + strvec_push(&child.args, "--quiet"); + + return !!run_command(&child); +} + +struct write_loose_object_data { + FILE *in; + int count; + int batch_size; +}; + +static int loose_object_auto_limit = 100; + +static int loose_object_count(const struct object_id *oid, + const char *path, + void *data) +{ + int *count = (int*)data; + if (++(*count) >= loose_object_auto_limit) + return 1; + return 0; +} + +static int loose_object_auto_condition(void) +{ + int count = 0; + + git_config_get_int("maintenance.loose-objects.auto", + &loose_object_auto_limit); + + if (!loose_object_auto_limit) + return 0; + if (loose_object_auto_limit < 0) + return 1; + + return for_each_loose_file_in_objdir(the_repository->objects->odb->path, + loose_object_count, + NULL, NULL, &count); +} + +static int bail_on_loose(const struct object_id *oid, + const char *path, + void *data) +{ + return 1; +} + +static int write_loose_object_to_stdin(const struct object_id *oid, + const char *path, + void *data) +{ + struct write_loose_object_data *d = (struct write_loose_object_data *)data; + + fprintf(d->in, "%s\n", oid_to_hex(oid)); + + return ++(d->count) > d->batch_size; +} + +static int pack_loose(struct maintenance_run_opts *opts) +{ + struct repository *r = the_repository; + int result = 0; + struct write_loose_object_data data; + struct child_process pack_proc = CHILD_PROCESS_INIT; + + /* + * Do not start pack-objects process + * if there are no loose objects. + */ + if (!for_each_loose_file_in_objdir(r->objects->odb->path, + bail_on_loose, + NULL, NULL, NULL)) + return 0; + + pack_proc.git_cmd = 1; + + strvec_push(&pack_proc.args, "pack-objects"); + if (opts->quiet) + strvec_push(&pack_proc.args, "--quiet"); + strvec_pushf(&pack_proc.args, "%s/pack/loose", r->objects->odb->path); + + pack_proc.in = -1; + + if (start_command(&pack_proc)) { + error(_("failed to start 'git pack-objects' process")); + return 1; + } + + data.in = xfdopen(pack_proc.in, "w"); + data.count = 0; + data.batch_size = 50000; + + for_each_loose_file_in_objdir(r->objects->odb->path, + write_loose_object_to_stdin, + NULL, + NULL, + &data); + + fclose(data.in); + + if (finish_command(&pack_proc)) { + error(_("failed to finish 'git pack-objects' process")); + result = 1; + } + + return result; +} + +static int maintenance_task_loose_objects(struct maintenance_run_opts *opts) +{ + return prune_packed(opts) || pack_loose(opts); +} + +static int incremental_repack_auto_condition(void) +{ + struct packed_git *p; + int enabled; + int incremental_repack_auto_limit = 10; + int count = 0; + + if (git_config_get_bool("core.multiPackIndex", &enabled) || + !enabled) + return 0; + + git_config_get_int("maintenance.incremental-repack.auto", + &incremental_repack_auto_limit); + + if (!incremental_repack_auto_limit) + return 0; + if (incremental_repack_auto_limit < 0) + return 1; + + for (p = get_packed_git(the_repository); + count < incremental_repack_auto_limit && p; + p = p->next) { + if (!p->multi_pack_index) + count++; + } + + return count >= incremental_repack_auto_limit; +} + +static int multi_pack_index_write(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "write", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + if (run_command(&child)) + return error(_("failed to write multi-pack-index")); + + return 0; +} + +static int multi_pack_index_expire(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "expire", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + close_object_store(the_repository->objects); + + if (run_command(&child)) + return error(_("'git multi-pack-index expire' failed")); + + return 0; +} + +#define TWO_GIGABYTES (INT32_MAX) + +static off_t get_auto_pack_size(void) +{ + /* + * The "auto" value is special: we optimize for + * one large pack-file (i.e. from a clone) and + * expect the rest to be small and they can be + * repacked quickly. + * + * The strategy we select here is to select a + * size that is one more than the second largest + * pack-file. This ensures that we will repack + * at least two packs if there are three or more + * packs. + */ + off_t max_size = 0; + off_t second_largest_size = 0; + off_t result_size; + struct packed_git *p; + struct repository *r = the_repository; + + reprepare_packed_git(r); + for (p = get_all_packs(r); p; p = p->next) { + if (p->pack_size > max_size) { + second_largest_size = max_size; + max_size = p->pack_size; + } else if (p->pack_size > second_largest_size) + second_largest_size = p->pack_size; + } + + result_size = second_largest_size + 1; + + /* But limit ourselves to a batch size of 2g */ + if (result_size > TWO_GIGABYTES) + result_size = TWO_GIGABYTES; + + return result_size; +} + +static int multi_pack_index_repack(struct maintenance_run_opts *opts) +{ + struct child_process child = CHILD_PROCESS_INIT; + + child.git_cmd = 1; + strvec_pushl(&child.args, "multi-pack-index", "repack", NULL); + + if (opts->quiet) + strvec_push(&child.args, "--no-progress"); + + strvec_pushf(&child.args, "--batch-size=%"PRIuMAX, + (uintmax_t)get_auto_pack_size()); + + close_object_store(the_repository->objects); + + if (run_command(&child)) + return error(_("'git multi-pack-index repack' failed")); + + return 0; +} + +static int maintenance_task_incremental_repack(struct maintenance_run_opts *opts) +{ + prepare_repo_settings(the_repository); + if (!the_repository->settings.core_multi_pack_index) { + warning(_("skipping incremental-repack task because core.multiPackIndex is disabled")); + return 0; + } + + if (multi_pack_index_write(opts)) + return 1; + if (multi_pack_index_expire(opts)) + return 1; + if (multi_pack_index_repack(opts)) + return 1; + return 0; +} + typedef int maintenance_task_fn(struct maintenance_run_opts *opts); /* @@ -854,6 +1173,9 @@ struct maintenance_task { }; enum maintenance_task_label { + TASK_PREFETCH, + TASK_LOOSE_OBJECTS, + TASK_INCREMENTAL_REPACK, TASK_GC, TASK_COMMIT_GRAPH, @@ -862,6 +1184,20 @@ enum maintenance_task_label { }; static struct maintenance_task tasks[] = { + [TASK_PREFETCH] = { + "prefetch", + maintenance_task_prefetch, + }, + [TASK_LOOSE_OBJECTS] = { + "loose-objects", + maintenance_task_loose_objects, + loose_object_auto_condition, + }, + [TASK_INCREMENTAL_REPACK] = { + "incremental-repack", + maintenance_task_incremental_repack, + incremental_repack_auto_condition, + }, [TASK_GC] = { "gc", maintenance_task_gc, diff --git a/builtin/grep.c b/builtin/grep.c index c8037388c6..e58e57504c 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -670,6 +670,17 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, NULL, 0); obj_read_unlock(); + if (!real_obj) { + char hex[GIT_MAX_HEXSZ + 1]; + const char *name = list->objects[i].name; + + if (!name) { + oid_to_hex_r(hex, &list->objects[i].item->oid); + name = hex; + } + die(_("invalid object '%s' given."), name); + } + /* load the gitmodules file for this rev */ if (recurse_submodules) { submodule_free(opt->repo); diff --git a/builtin/log.c b/builtin/log.c index 0a7ed4bef9..9f939e6cdf 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1738,7 +1738,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F('N', "no-numbered", &numbered, NULL, N_("use [PATCH] even with multiple patches"), PARSE_OPT_NOARG | PARSE_OPT_NONEG, no_numbered_callback), - OPT_BOOL('s', "signoff", &do_signoff, N_("add Signed-off-by:")), + OPT_BOOL('s', "signoff", &do_signoff, N_("add a Signed-off-by trailer")), OPT_BOOL(0, "stdout", &use_stdout, N_("print patches to standard out")), OPT_BOOL(0, "cover-letter", &cover_letter, diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index e72714a5a8..de8520778d 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -109,6 +109,7 @@ static void show_diff(struct merge_list *entry) xdemitconf_t xecfg; xdemitcb_t ecb; + memset(&xpp, 0, sizeof(xpp)); xpp.flags = 0; memset(&xecfg, 0, sizeof(xecfg)); xecfg.ctxlen = 3; diff --git a/builtin/merge.c b/builtin/merge.c index 9d5359edc2..4c133402a6 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -289,7 +289,7 @@ static struct option builtin_merge_options[] = { N_("GPG sign commit"), PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, OPT_AUTOSTASH(&autostash), OPT_BOOL(0, "overwrite-ignore", &overwrite_ignore, N_("update ignored files (default)")), - OPT_BOOL(0, "signoff", &signoff, N_("add Signed-off-by:")), + OPT_BOOL(0, "signoff", &signoff, N_("add a Signed-off-by trailer")), OPT_BOOL(0, "no-verify", &no_verify, N_("bypass pre-merge-commit and commit-msg hooks")), OPT_END() }; diff --git a/builtin/pull.c b/builtin/pull.c index 425950f469..17aa63cd35 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -142,7 +142,7 @@ static struct option pull_options[] = { N_("add (at most <n>) entries from shortlog to merge commit message"), PARSE_OPT_OPTARG), OPT_PASSTHRU(0, "signoff", &opt_signoff, NULL, - N_("add Signed-off-by:"), + N_("add a Signed-off-by trailer"), PARSE_OPT_OPTARG), OPT_PASSTHRU(0, "squash", &opt_squash, NULL, N_("create a single commit instead of doing a merge"), diff --git a/builtin/push.c b/builtin/push.c index 6da3a8e5d3..03adb58602 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -290,6 +290,12 @@ static const char message_advice_ref_needs_force[] = "or update a remote ref to make it point at a non-commit object,\n" "without using the '--force' option.\n"); +static const char message_advice_ref_needs_update[] = + N_("Updates were rejected because the tip of the remote-tracking\n" + "branch has been updated since the last checkout. You may want\n" + "to integrate those changes locally (e.g., 'git pull ...')\n" + "before forcing an update.\n"); + static void advise_pull_before_push(void) { if (!advice_push_non_ff_current || !advice_push_update_rejected) @@ -325,6 +331,13 @@ static void advise_ref_needs_force(void) advise(_(message_advice_ref_needs_force)); } +static void advise_ref_needs_update(void) +{ + if (!advice_push_ref_needs_update || !advice_push_update_rejected) + return; + advise(_(message_advice_ref_needs_update)); +} + static int push_with_options(struct transport *transport, struct refspec *rs, int flags) { @@ -374,6 +387,8 @@ static int push_with_options(struct transport *transport, struct refspec *rs, advise_ref_fetch_first(); } else if (reject_reasons & REJECT_NEEDS_FORCE) { advise_ref_needs_force(); + } else if (reject_reasons & REJECT_REF_NEEDS_UPDATE) { + advise_ref_needs_update(); } return 1; @@ -510,6 +525,12 @@ static int git_push_config(const char *k, const char *v, void *cb) if (!v) return config_error_nonbool(k); return color_parse(v, push_colors[slot]); + } else if (!strcmp(k, "push.useforceifincludes")) { + if (git_config_bool(k, v)) + *flags |= TRANSPORT_PUSH_FORCE_IF_INCLUDES; + else + *flags &= ~TRANSPORT_PUSH_FORCE_IF_INCLUDES; + return 0; } return git_default_config(k, v, NULL); @@ -541,6 +562,9 @@ int cmd_push(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"), N_("require old value of ref to be at this value"), PARSE_OPT_OPTARG | PARSE_OPT_LITERAL_ARGHELP, parseopt_push_cas_option), + OPT_BIT(0, TRANS_OPT_FORCE_IF_INCLUDES, &flags, + N_("require remote updates to be integrated locally"), + TRANSPORT_PUSH_FORCE_IF_INCLUDES), OPT_CALLBACK(0, "recurse-submodules", &recurse_submodules, "(check|on-demand|no)", N_("control recursive pushing of submodules"), option_parse_recurse_submodules), OPT_BOOL_F( 0 , "thin", &thin, N_("use thin pack"), PARSE_OPT_NOCOMPLETE), @@ -625,6 +649,9 @@ int cmd_push(int argc, const char **argv, const char *prefix) if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR)) die(_("--all and --mirror are incompatible")); + if (!is_empty_cas(&cas) && (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES)) + cas.use_force_if_includes = 1; + for_each_string_list_item(item, push_options) if (strchr(item->string, '\n')) die(_("push options must not have new line characters")); diff --git a/builtin/rebase.c b/builtin/rebase.c index eeca53382f..7b65525301 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1324,7 +1324,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) N_("do not show diffstat of what changed upstream"), PARSE_OPT_NOARG, NULL, REBASE_DIFFSTAT }, OPT_BOOL(0, "signoff", &options.signoff, - N_("add a Signed-off-by: line to each commit")), + N_("add a Signed-off-by trailer to each commit")), OPT_BOOL(0, "committer-date-is-author-date", &options.committer_date_is_author_date, N_("make committer date match author date")), diff --git a/builtin/remote.c b/builtin/remote.c index 64b4b551eb..63f2b46c3d 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -194,8 +194,7 @@ static int add(int argc, const char **argv) if (remote_is_configured(remote, 1)) die(_("remote %s already exists."), name); - strbuf_addf(&buf2, "refs/heads/test:refs/remotes/%s/test", name); - if (!valid_fetch_refspec(buf2.buf)) + if (!valid_remote_name(name)) die(_("'%s' is not a valid remote name"), name); strbuf_addf(&buf, "remote.%s.url", name); @@ -696,11 +695,9 @@ static int mv(int argc, const char **argv) if (remote_is_configured(newremote, 1)) die(_("remote %s already exists."), rename.new_name); - strbuf_addf(&buf, "refs/heads/test:refs/remotes/%s/test", rename.new_name); - if (!valid_fetch_refspec(buf.buf)) + if (!valid_remote_name(rename.new_name)) die(_("'%s' is not a valid remote name"), rename.new_name); - strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s", rename.old_name); strbuf_addf(&buf2, "remote.%s", rename.new_name); if (git_config_rename_section(buf.buf, buf2.buf) < 1) diff --git a/builtin/revert.c b/builtin/revert.c index f61cc5d82c..da8997dc86 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -107,7 +107,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts) OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")), OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")), OPT_NOOP_NOARG('r', NULL), - OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")), + OPT_BOOL('s', "signoff", &opts->signoff, N_("add a Signed-off-by trailer")), OPT_CALLBACK('m', "mainline", opts, N_("parent-number"), N_("select mainline parent"), option_parse_m), OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto), diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 7af148d733..a7e01667b0 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -71,6 +71,11 @@ static void print_helper_status(struct ref *ref) msg = "stale info"; break; + case REF_STATUS_REJECT_REMOTE_UPDATED: + res = "error"; + msg = "remote ref updated since checkout"; + break; + case REF_STATUS_REJECT_ALREADY_EXISTS: res = "error"; msg = "already exists"; @@ -173,6 +178,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) int progress = -1; int from_stdin = 0; struct push_cas_option cas = {0}; + int force_if_includes = 0; struct packet_reader reader; struct option options[] = { @@ -198,6 +204,8 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) OPT_CALLBACK_F(0, CAS_OPT_NAME, &cas, N_("<refname>:<expect>"), N_("require old value of ref to be at this value"), PARSE_OPT_OPTARG, parseopt_push_cas_option), + OPT_BOOL(0, TRANS_OPT_FORCE_IF_INCLUDES, &force_if_includes, + N_("require remote updates to be integrated locally")), OPT_END() }; @@ -299,6 +307,9 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) if (!is_empty_cas(&cas)) apply_push_cas(&cas, remote, remote_refs); + if (!is_empty_cas(&cas) && force_if_includes) + cas.use_force_if_includes = 1; + set_ref_status_for_push(remote_refs, args.send_mirror, args.force_update); diff --git a/builtin/worktree.c b/builtin/worktree.c index 99abaeec6c..ce56fdaaa9 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -676,8 +676,11 @@ static void show_worktree(struct worktree *wt, int path_maxlen, int abbrev_len) } else strbuf_addstr(&sb, "(error)"); } - printf("%s\n", sb.buf); + if (!is_main_worktree(wt) && worktree_lock_reason(wt)) + strbuf_addstr(&sb, " locked"); + + printf("%s\n", sb.buf); strbuf_release(&sb); } diff --git a/commit-graph.c b/commit-graph.c index cb042bdba8..6f62a07313 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2008,7 +2008,7 @@ static int commit_compare(const void *_a, const void *_b) static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx) { - uint32_t i; + uint32_t i, dedup_i = 0; if (ctx->report_progress) ctx->progress = start_delayed_progress( @@ -2023,17 +2023,27 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx) if (i && oideq(&ctx->commits.list[i - 1]->object.oid, &ctx->commits.list[i]->object.oid)) { - die(_("unexpected duplicate commit id %s"), - oid_to_hex(&ctx->commits.list[i]->object.oid)); + /* + * Silently ignore duplicates. These were likely + * created due to a commit appearing in multiple + * layers of the chain, which is unexpected but + * not invalid. We should make sure there is a + * unique copy in the new layer. + */ } else { unsigned int num_parents; + ctx->commits.list[dedup_i] = ctx->commits.list[i]; + dedup_i++; + num_parents = commit_list_count(ctx->commits.list[i]->parents); if (num_parents > 2) ctx->num_extra_edges += num_parents - 1; } } + ctx->commits.nr = dedup_i; + stop_progress(&ctx->progress); } @@ -2150,6 +2160,11 @@ int write_commit_graph(struct object_directory *odb, int replace = 0; struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS; + prepare_repo_settings(the_repository); + if (!the_repository->settings.core_commit_graph) { + warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled")); + return 0; + } if (!commit_graph_compatible(the_repository)) return 0; @@ -1586,7 +1586,7 @@ const char *find_commit_header(const char *msg, const char *key, size_t *out_len /* * Inspect the given string and determine the true "end" of the log message, in - * order to find where to put a new Signed-off-by: line. Ignored are + * order to find where to put a new Signed-off-by trailer. Ignored are * trailing comment lines and blank lines. To support "git commit -s * --amend" on an existing commit, we also ignore "Conflicts:". To * support "git commit -v", we truncate at cut lines. diff --git a/config.mak.dev b/config.mak.dev index 89b218d11a..89fefacd94 100644 --- a/config.mak.dev +++ b/config.mak.dev @@ -15,6 +15,7 @@ DEVELOPER_CFLAGS += -Wpointer-arith DEVELOPER_CFLAGS += -Wstrict-prototypes DEVELOPER_CFLAGS += -Wunused DEVELOPER_CFLAGS += -Wvla +DEVELOPER_CFLAGS += -fno-common ifndef COMPILER_FEATURES COMPILER_FEATURES := $(shell ./detect-compiler $(CC)) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 0a96ad87e7..36f5a91c7a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1467,14 +1467,15 @@ _git_bundle () # Helper function to decide whether or not we should enable DWIM logic for # git-switch and git-checkout. # -# To decide between the following rules in priority order -# 1) the last provided of "--guess" or "--no-guess" explicitly enable or -# disable completion of DWIM logic respectively. -# 2) If the --no-track option is provided, take this as a hint to disable the -# DWIM completion logic -# 3) If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion -# logic, as requested by the user. -# 4) Enable DWIM logic otherwise. +# To decide between the following rules in decreasing priority order: +# - the last provided of "--guess" or "--no-guess" explicitly enable or +# disable completion of DWIM logic respectively. +# - If checkout.guess is false, disable completion of DWIM logic. +# - If the --no-track option is provided, take this as a hint to disable the +# DWIM completion logic +# - If GIT_COMPLETION_CHECKOUT_NO_GUESS is set, disable the DWIM completion +# logic, as requested by the user. +# - Enable DWIM logic otherwise. # __git_checkout_default_dwim_mode () { @@ -1485,11 +1486,17 @@ __git_checkout_default_dwim_mode () fi # --no-track disables DWIM, but with lower priority than - # --guess/--no-guess + # --guess/--no-guess/checkout.guess if [ -n "$(__git_find_on_cmdline "--no-track")" ]; then dwim_opt="" fi + # checkout.guess = false disables DWIM, but with lower priority than + # --guess/--no-guess + if [ "$(__git config --type=bool checkout.guess)" = "false" ]; then + dwim_opt="" + fi + # Find the last provided --guess or --no-guess last_option="$(__git_find_last_on_cmdline "--guess --no-guess")" case "$last_option" in @@ -1688,8 +1695,13 @@ __git_diff_common_options="--stat --numstat --shortstat --summary --submodule --submodule= --ignore-submodules --indent-heuristic --no-indent-heuristic --textconv --no-textconv + --patch --no-patch " +__git_diff_difftool_options="--cached --staged --pickaxe-all --pickaxe-regex + --base --ours --theirs --no-index --relative --merge-base + $__git_diff_common_options" + _git_diff () { __git_has_doubledash && return @@ -1712,10 +1724,7 @@ _git_diff () return ;; --*) - __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex - --base --ours --theirs --no-index - $__git_diff_common_options - " + __gitcomp "$__git_diff_difftool_options" return ;; esac @@ -1737,11 +1746,7 @@ _git_difftool () return ;; --*) - __gitcomp_builtin difftool "$__git_diff_common_options - --base --cached --ours --theirs - --pickaxe-all --pickaxe-regex - --relative --staged - " + __gitcomp_builtin difftool "$__git_diff_difftool_options" return ;; esac @@ -2031,11 +2036,9 @@ _git_log () --no-walk --no-walk= --do-walk --parents --children --expand-tabs --expand-tabs= --no-expand-tabs - --patch $merge $__git_diff_common_options --pickaxe-all --pickaxe-regex - --patch --no-patch " return ;; @@ -2938,7 +2941,7 @@ _git_show () ;; --*) __gitcomp "--pretty= --format= --abbrev-commit --no-abbrev-commit - --oneline --show-signature --patch + --oneline --show-signature --expand-tabs --expand-tabs= --no-expand-tabs $__git_diff_common_options " @@ -3021,7 +3024,10 @@ _git_stash () list,--*) __gitcomp "--name-status --oneline --patch-with-stat" ;; - show,--*|branch,--*) + show,--*) + __gitcomp "$__git_diff_common_options" + ;; + branch,--*) ;; branch,*) if [ $cword -eq 3 ]; then diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index ce47e86b60..107869036d 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -9,13 +9,14 @@ # # If your script is somewhere else, you can configure it on your ~/.zshrc: # -# zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh +# zstyle ':completion:*:*:git:*' script ~/.git-completion.bash # # The recommended way to install this script is to make a copy of it in # ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following # to your ~/.zshrc file: # # fpath=(~/.zsh $fpath) +# autoload -Uz compinit && compinit complete () { diff --git a/contrib/git-resurrect.sh b/contrib/git-resurrect.sh index 8c171dd959..d843df3afd 100755 --- a/contrib/git-resurrect.sh +++ b/contrib/git-resurrect.sh @@ -27,7 +27,7 @@ n,dry-run don't recreate the branch" search_reflog () { sed -ne 's~^\([^ ]*\) .* checkout: moving from '"$1"' .*~\1~p' \ - < "$GIT_DIR"/logs/HEAD + < "$GIT_DIR"/logs/HEAD } search_reflog_merges () { @@ -37,19 +37,18 @@ search_reflog_merges () { ) } -_x40="[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]" -_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40" +oid_pattern=$(git hash-object --stdin </dev/null | sed -e 's/./[0-9a-f]/g') search_merges () { - git rev-list --all --grep="Merge branch '$1'" \ - --pretty=tformat:"%P %s" | - sed -ne "/^$_x40 \($_x40\) Merge .*/ {s//\1/p;$early_exit}" + git rev-list --all --grep="Merge branch '$1'" \ + --pretty=tformat:"%P %s" | + sed -ne "/^$oid_pattern \($oid_pattern\) Merge .*/ {s//\1/p;$early_exit}" } search_merge_targets () { git rev-list --all --grep="Merge branch '[^']*' into $branch\$" \ --pretty=tformat:"%H %s" --all | - sed -ne "/^\($_x40\) Merge .*/ {s//\1/p;$early_exit} " + sed -ne "/^\($oid_pattern\) Merge .*/ {s//\1/p;$early_exit} " } dry_run= diff --git a/diff-lib.c b/diff-lib.c index f95c6de75f..d18a118249 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -13,6 +13,7 @@ #include "submodule.h" #include "dir.h" #include "fsmonitor.h" +#include "commit-reach.h" /* * diff-files @@ -510,16 +511,74 @@ static int diff_cache(struct rev_info *revs, return unpack_trees(1, &t, &opts); } -int run_diff_index(struct rev_info *revs, int cached) +void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb) +{ + int i; + struct commit *mb_child[2] = {0}; + struct commit_list *merge_bases; + + for (i = 0; i < revs->pending.nr; i++) { + struct object *obj = revs->pending.objects[i].item; + if (obj->flags) + die(_("--merge-base does not work with ranges")); + if (obj->type != OBJ_COMMIT) + die(_("--merge-base only works with commits")); + } + + /* + * This check must go after the for loop above because A...B + * ranges produce three pending commits, resulting in a + * misleading error message. + */ + if (revs->pending.nr < 1 || revs->pending.nr > 2) + BUG("unexpected revs->pending.nr: %d", revs->pending.nr); + + for (i = 0; i < revs->pending.nr; i++) + mb_child[i] = lookup_commit_reference(the_repository, &revs->pending.objects[i].item->oid); + if (revs->pending.nr == 1) { + struct object_id oid; + + if (get_oid("HEAD", &oid)) + die(_("unable to get HEAD")); + + mb_child[1] = lookup_commit_reference(the_repository, &oid); + } + + merge_bases = repo_get_merge_bases(the_repository, mb_child[0], mb_child[1]); + if (!merge_bases) + die(_("no merge base found")); + if (merge_bases->next) + die(_("multiple merge bases found")); + + oidcpy(mb, &merge_bases->item->object.oid); + + free_commit_list(merge_bases); +} + +int run_diff_index(struct rev_info *revs, unsigned int option) { struct object_array_entry *ent; + int cached = !!(option & DIFF_INDEX_CACHED); + int merge_base = !!(option & DIFF_INDEX_MERGE_BASE); + struct object_id oid; + const char *name; + char merge_base_hex[GIT_MAX_HEXSZ + 1]; if (revs->pending.nr != 1) BUG("run_diff_index must be passed exactly one tree"); trace_performance_enter(); ent = revs->pending.objects; - if (diff_cache(revs, &ent->item->oid, ent->name, cached)) + + if (merge_base) { + diff_get_merge_base(revs, &oid); + name = oid_to_hex_r(merge_base_hex, &oid); + } else { + oidcpy(&oid, &ent->item->oid); + name = ent->name; + } + + if (diff_cache(revs, &oid, name, cached)) exit(128); diff_set_mnemonic_prefix(&revs->diffopt, "c/", cached ? "i/" : "w/"); @@ -3587,6 +3587,8 @@ static void builtin_diff(const char *name_a, if (header.len && !o->flags.suppress_diff_headers) ecbdata.header = &header; xpp.flags = o->xdl_opts; + xpp.ignore_regex = o->ignore_regex; + xpp.ignore_regex_nr = o->ignore_regex_nr; xpp.anchors = o->anchors; xpp.anchors_nr = o->anchors_nr; xecfg.ctxlen = o->context; @@ -3716,6 +3718,8 @@ static void builtin_diffstat(const char *name_a, const char *name_b, memset(&xpp, 0, sizeof(xpp)); memset(&xecfg, 0, sizeof(xecfg)); xpp.flags = o->xdl_opts; + xpp.ignore_regex = o->ignore_regex; + xpp.ignore_regex_nr = o->ignore_regex_nr; xpp.anchors = o->anchors; xpp.anchors_nr = o->anchors_nr; xecfg.ctxlen = o->context; @@ -5203,6 +5207,22 @@ static int diff_opt_patience(const struct option *opt, return 0; } +static int diff_opt_ignore_regex(const struct option *opt, + const char *arg, int unset) +{ + struct diff_options *options = opt->value; + regex_t *regex; + + BUG_ON_OPT_NEG(unset); + regex = xmalloc(sizeof(*regex)); + if (regcomp(regex, arg, REG_EXTENDED | REG_NEWLINE)) + return error(_("invalid regex given to -I: '%s'"), arg); + ALLOC_GROW(options->ignore_regex, options->ignore_regex_nr + 1, + options->ignore_regex_alloc); + options->ignore_regex[options->ignore_regex_nr++] = regex; + return 0; +} + static int diff_opt_pickaxe_regex(const struct option *opt, const char *arg, int unset) { @@ -5491,6 +5511,9 @@ static void prep_parse_options(struct diff_options *options) OPT_BIT_F(0, "ignore-blank-lines", &options->xdl_opts, N_("ignore changes whose lines are all blank"), XDF_IGNORE_BLANK_LINES, PARSE_OPT_NONEG), + OPT_CALLBACK_F('I', "ignore-matching-lines", options, N_("<regex>"), + N_("ignore changes whose all lines match <regex>"), + 0, diff_opt_ignore_regex), OPT_BIT(0, "indent-heuristic", &options->xdl_opts, N_("heuristic to shift diff hunk boundaries for easy reading"), XDF_INDENT_HEURISTIC), @@ -234,6 +234,10 @@ struct diff_options { */ const char *pickaxe; + /* -I<regex> */ + regex_t **ignore_regex; + size_t ignore_regex_nr, ignore_regex_alloc; + const char *single_follow; const char *a_prefix, *b_prefix; const char *line_prefix; @@ -578,12 +582,17 @@ void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc); */ const char *diff_aligned_abbrev(const struct object_id *sha1, int); +void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb); + /* do not report anything on removed paths */ #define DIFF_SILENT_ON_REMOVED 01 /* report racily-clean paths as modified */ #define DIFF_RACY_IS_MODIFIED 02 int run_diff_files(struct rev_info *revs, unsigned int option); -int run_diff_index(struct rev_info *revs, int cached); + +#define DIFF_INDEX_CACHED 01 +#define DIFF_INDEX_MERGE_BASE 02 +int run_diff_index(struct rev_info *revs, unsigned int option); int do_diff_cache(const struct object_id *, struct diff_options *); int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int); @@ -1040,9 +1040,9 @@ static int add_patterns_from_buffer(char *buf, size_t size, * an index if 'istate' is non-null), parse it and store the * exclude rules in "pl". * - * If "ss" is not NULL, compute SHA-1 of the exclude file and fill + * If "oid_stat" is not NULL, compute oid of the exclude file and fill * stat data from disk (only valid if add_patterns returns zero). If - * ss_valid is non-zero, "ss" must contain good value as input. + * oid_stat.valid is non-zero, "oid_stat" must contain good value as input. */ static int add_patterns(const char *fname, const char *base, int baselen, struct pattern_list *pl, struct index_state *istate, @@ -1090,7 +1090,7 @@ static int add_patterns(const char *fname, const char *base, int baselen, int pos; if (oid_stat->valid && !match_stat_data_racy(istate, &oid_stat->stat, &st)) - ; /* no content change, ss->sha1 still good */ + ; /* no content change, oid_stat->oid still good */ else if (istate && (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && !ce_stage(istate->cache[pos]) && diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 8a72018712..e713fe3d02 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -1830,6 +1830,13 @@ sub process_args { $arg = shift @ARGV or die __("missing --"); if ($arg ne '--') { $patch_mode_revision = $arg; + + # NEEDSWORK: Instead of comparing to the literal "HEAD", + # compare the commit objects instead so that other ways of + # saying the same thing (such as "@") are also handled + # appropriately. + # + # This applies to the cases below too. $patch_mode = ($arg eq 'HEAD' ? 'reset_head' : 'reset_nothead'); $arg = shift @ARGV or die __("missing --"); diff --git a/git-compat-util.h b/git-compat-util.h index 7a0fb7a045..adfea06897 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -489,11 +489,13 @@ static inline int const_error(void) #define error_errno(...) (error_errno(__VA_ARGS__), const_error()) #endif -void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)); -void set_error_routine(void (*routine)(const char *err, va_list params)); -extern void (*get_error_routine(void))(const char *err, va_list params); -void set_warn_routine(void (*routine)(const char *warn, va_list params)); -extern void (*get_warn_routine(void))(const char *warn, va_list params); +typedef void (*report_fn)(const char *, va_list params); + +void set_die_routine(NORETURN_PTR report_fn routine); +void set_error_routine(report_fn routine); +report_fn get_error_routine(void); +void set_warn_routine(report_fn routine); +report_fn get_warn_routine(void); void set_die_is_recursing_routine(int (*routine)(void)); int starts_with(const char *str, const char *prefix); diff --git a/line-log.c b/line-log.c index 68eeb425f8..75c8b1acff 100644 --- a/line-log.c +++ b/line-log.c @@ -481,7 +481,7 @@ static struct commit *check_single_commit(struct rev_info *revs) if (obj->flags & UNINTERESTING) continue; obj = deref_tag(revs->repo, obj, NULL, 0); - if (obj->type != OBJ_COMMIT) + if (!obj || obj->type != OBJ_COMMIT) die("Non commit %s?", revs->pending.objects[i].name); if (commit) die("More than one commit to dig from: %s and %s?", @@ -10,6 +10,7 @@ #include "progress.h" #include "trace2.h" #include "run-command.h" +#include "repository.h" #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */ #define MIDX_VERSION 1 @@ -398,15 +399,9 @@ int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, i { struct multi_pack_index *m; struct multi_pack_index *m_search; - int config_value; - static int env_value = -1; - if (env_value < 0) - env_value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0); - - if (!env_value && - (repo_config_get_bool(r, "core.multipackindex", &config_value) || - !config_value)) + prepare_repo_settings(r); + if (!r->settings.core_multi_pack_index) return 0; for (m_search = r->objects->multi_pack_index; m_search; m_search = m_search->next) @@ -850,7 +845,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * packs.pack_paths_checked = 0; if (flags & MIDX_PROGRESS) - packs.progress = start_progress(_("Adding packfiles to multi-pack-index"), 0); + packs.progress = start_delayed_progress(_("Adding packfiles to multi-pack-index"), 0); else packs.progress = NULL; @@ -987,7 +982,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * } if (flags & MIDX_PROGRESS) - progress = start_progress(_("Writing chunks to multi-pack-index"), + progress = start_delayed_progress(_("Writing chunks to multi-pack-index"), num_chunks); for (i = 0; i < num_chunks; i++) { if (written != chunk_offsets[i]) @@ -1129,7 +1124,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag } if (flags & MIDX_PROGRESS) - progress = start_progress(_("Looking for referenced packfiles"), + progress = start_delayed_progress(_("Looking for referenced packfiles"), m->num_packs); for (i = 0; i < m->num_packs; i++) { if (prepare_midx_pack(r, m, i)) @@ -1250,7 +1245,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla count = xcalloc(m->num_packs, sizeof(uint32_t)); if (flags & MIDX_PROGRESS) - progress = start_progress(_("Counting referenced objects"), + progress = start_delayed_progress(_("Counting referenced objects"), m->num_objects); for (i = 0; i < m->num_objects; i++) { int pack_int_id = nth_midxed_pack_int_id(m, i); @@ -1260,7 +1255,7 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla stop_progress(&progress); if (flags & MIDX_PROGRESS) - progress = start_progress(_("Finding and deleting unreferenced packfiles"), + progress = start_delayed_progress(_("Finding and deleting unreferenced packfiles"), m->num_packs); for (i = 0; i < m->num_packs; i++) { char *pack_name; diff --git a/perl/Git/SVN/Log.pm b/perl/Git/SVN/Log.pm index 3858fcf27d..9c819188ea 100644 --- a/perl/Git/SVN/Log.pm +++ b/perl/Git/SVN/Log.pm @@ -298,7 +298,7 @@ sub cmd_show_log { get_author_info($c, $1, $2, $3); } elsif (/^${esc_color}(?:tree|parent|committer) /o) { # ignore - } elsif (/^${esc_color}:\d{6} \d{6} $::sha1_short/o) { + } elsif (/^${esc_color}:\d{6} \d{6} $::oid_short/o) { push @{$c->{raw}}, $_; } elsif (/^${esc_color}[ACRMDT]\t/) { # we could add $SVN->{svn_path} here, but that requires diff --git a/pkt-line.c b/pkt-line.c index 844c253ccd..657a702927 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -471,6 +471,9 @@ int recv_sideband(const char *me, int in_stream, int out) write_or_die(out, buf + 1, len - 1); break; default: /* errors: message already written */ + if (scratch.len > 0) + BUG("unhandled incomplete sideband: '%s'", + scratch.buf); return sideband_type; } } @@ -245,6 +245,16 @@ int valid_fetch_refspec(const char *fetch_refspec_str) return ret; } +int valid_remote_name(const char *name) +{ + int result; + struct strbuf refspec = STRBUF_INIT; + strbuf_addf(&refspec, "refs/heads/test:refs/remotes/%s/test", name); + result = valid_fetch_refspec(refspec.buf); + strbuf_release(&refspec); + return result; +} + void refspec_ref_prefixes(const struct refspec *rs, struct strvec *ref_prefixes) { @@ -64,6 +64,7 @@ void refspec_appendn(struct refspec *rs, const char **refspecs, int nr); void refspec_clear(struct refspec *rs); int valid_fetch_refspec(const char *refspec); +int valid_remote_name(const char *name); struct strvec; /* diff --git a/remote-curl.c b/remote-curl.c index 32cc4a0c55..0290b04891 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -44,7 +44,8 @@ struct options { from_promisor : 1, atomic : 1, - object_format : 1; + object_format : 1, + force_if_includes : 1; const struct git_hash_algo *hash_algo; }; static struct options options; @@ -131,6 +132,14 @@ static int set_option(const char *name, const char *value) string_list_append(&cas_options, val.buf); strbuf_release(&val); return 0; + } else if (!strcmp(name, TRANS_OPT_FORCE_IF_INCLUDES)) { + if (!strcmp(value, "true")) + options.force_if_includes = 1; + else if (!strcmp(value, "false")) + options.force_if_includes = 0; + else + return -1; + return 0; } else if (!strcmp(name, "cloning")) { if (!strcmp(value, "true")) options.cloning = 1; @@ -1318,6 +1327,9 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) strvec_push(&args, cas_option->string); strvec_push(&args, url.buf); + if (options.force_if_includes) + strvec_push(&args, "--force-if-includes"); + strvec_push(&args, "--stdin"); for (i = 0; i < nr_spec; i++) packet_buf_write(&preamble, "%s\n", specs[i]); @@ -1568,12 +1568,23 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, * with the remote-tracking branch to find the value * to expect, but we did not have such a tracking * branch. + * + * If the tip of the remote-tracking ref is unreachable + * from any reflog entry of its local ref indicating a + * possible update since checkout; reject the push. */ if (ref->expect_old_sha1) { if (!oideq(&ref->old_oid, &ref->old_oid_expect)) reject_reason = REF_STATUS_REJECT_STALE; + else if (ref->check_reachable && ref->unreachable) + reject_reason = + REF_STATUS_REJECT_REMOTE_UPDATED; else - /* If the ref isn't stale then force the update. */ + /* + * If the ref isn't stale, and is reachable + * from from one of the reflog entries of + * the local branch, force the update. + */ force_ref_update = 1; } @@ -2351,12 +2362,13 @@ int is_empty_cas(const struct push_cas_option *cas) /* * Look at remote.fetch refspec and see if we have a remote - * tracking branch for the refname there. Fill its current - * value in sha1[]. + * tracking branch for the refname there. Fill the name of + * the remote-tracking branch in *dst_refname, and the name + * of the commit object at its tip in oid[]. * If we cannot do so, return negative to signal an error. */ static int remote_tracking(struct remote *remote, const char *refname, - struct object_id *oid) + struct object_id *oid, char **dst_refname) { char *dst; @@ -2365,9 +2377,150 @@ static int remote_tracking(struct remote *remote, const char *refname, return -1; /* no tracking ref for refname at remote */ if (read_ref(dst, oid)) return -1; /* we know what the tracking ref is but we cannot read it */ + + *dst_refname = dst; return 0; } +/* + * The struct "reflog_commit_array" and related helper functions + * are used for collecting commits into an array during reflog + * traversals in "check_and_collect_until()". + */ +struct reflog_commit_array { + struct commit **item; + size_t nr, alloc; +}; + +#define REFLOG_COMMIT_ARRAY_INIT { NULL, 0, 0 } + +/* Append a commit to the array. */ +static void append_commit(struct reflog_commit_array *arr, + struct commit *commit) +{ + ALLOC_GROW(arr->item, arr->nr + 1, arr->alloc); + arr->item[arr->nr++] = commit; +} + +/* Free and reset the array. */ +static void free_commit_array(struct reflog_commit_array *arr) +{ + FREE_AND_NULL(arr->item); + arr->nr = arr->alloc = 0; +} + +struct check_and_collect_until_cb_data { + struct commit *remote_commit; + struct reflog_commit_array *local_commits; + timestamp_t remote_reflog_timestamp; +}; + +/* Get the timestamp of the latest entry. */ +static int peek_reflog(struct object_id *o_oid, struct object_id *n_oid, + const char *ident, timestamp_t timestamp, + int tz, const char *message, void *cb_data) +{ + timestamp_t *ts = cb_data; + *ts = timestamp; + return 1; +} + +static int check_and_collect_until(struct object_id *o_oid, + struct object_id *n_oid, + const char *ident, timestamp_t timestamp, + int tz, const char *message, void *cb_data) +{ + struct commit *commit; + struct check_and_collect_until_cb_data *cb = cb_data; + + /* An entry was found. */ + if (oideq(n_oid, &cb->remote_commit->object.oid)) + return 1; + + if ((commit = lookup_commit_reference(the_repository, n_oid))) + append_commit(cb->local_commits, commit); + + /* + * If the reflog entry timestamp is older than the remote ref's + * latest reflog entry, there is no need to check or collect + * entries older than this one. + */ + if (timestamp < cb->remote_reflog_timestamp) + return -1; + + return 0; +} + +#define MERGE_BASES_BATCH_SIZE 8 + +/* + * Iterate through the reflog of the local ref to check if there is an entry + * for the given remote-tracking ref; runs until the timestamp of an entry is + * older than latest timestamp of remote-tracking ref's reflog. Any commits + * are that seen along the way are collected into an array to check if the + * remote-tracking ref is reachable from any of them. + */ +static int is_reachable_in_reflog(const char *local, const struct ref *remote) +{ + timestamp_t date; + struct commit *commit; + struct commit **chunk; + struct check_and_collect_until_cb_data cb; + struct reflog_commit_array arr = REFLOG_COMMIT_ARRAY_INIT; + size_t size = 0; + int ret = 0; + + commit = lookup_commit_reference(the_repository, &remote->old_oid); + if (!commit) + goto cleanup_return; + + /* + * Get the timestamp from the latest entry + * of the remote-tracking ref's reflog. + */ + for_each_reflog_ent_reverse(remote->tracking_ref, peek_reflog, &date); + + cb.remote_commit = commit; + cb.local_commits = &arr; + cb.remote_reflog_timestamp = date; + ret = for_each_reflog_ent_reverse(local, check_and_collect_until, &cb); + + /* We found an entry in the reflog. */ + if (ret > 0) + goto cleanup_return; + + /* + * Check if the remote commit is reachable from any + * of the commits in the collected array, in batches. + */ + for (chunk = arr.item; chunk < arr.item + arr.nr; chunk += size) { + size = arr.item + arr.nr - chunk; + if (MERGE_BASES_BATCH_SIZE < size) + size = MERGE_BASES_BATCH_SIZE; + + if ((ret = in_merge_bases_many(commit, size, chunk))) + break; + } + +cleanup_return: + free_commit_array(&arr); + return ret; +} + +/* + * Check for reachability of a remote-tracking + * ref in the reflog entries of its local ref. + */ +static void check_if_includes_upstream(struct ref *remote) +{ + struct ref *local = get_local_ref(remote->name); + if (!local) + return; + + if (is_reachable_in_reflog(local->name, remote) <= 0) + remote->unreachable = 1; +} + static void apply_cas(struct push_cas_option *cas, struct remote *remote, struct ref *ref) @@ -2382,8 +2535,12 @@ static void apply_cas(struct push_cas_option *cas, ref->expect_old_sha1 = 1; if (!entry->use_tracking) oidcpy(&ref->old_oid_expect, &entry->expect); - else if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) + else if (remote_tracking(remote, ref->name, + &ref->old_oid_expect, + &ref->tracking_ref)) oidclr(&ref->old_oid_expect); + else + ref->check_reachable = cas->use_force_if_includes; return; } @@ -2392,8 +2549,12 @@ static void apply_cas(struct push_cas_option *cas, return; ref->expect_old_sha1 = 1; - if (remote_tracking(remote, ref->name, &ref->old_oid_expect)) + if (remote_tracking(remote, ref->name, + &ref->old_oid_expect, + &ref->tracking_ref)) oidclr(&ref->old_oid_expect); + else + ref->check_reachable = cas->use_force_if_includes; } void apply_push_cas(struct push_cas_option *cas, @@ -2401,6 +2562,15 @@ void apply_push_cas(struct push_cas_option *cas, struct ref *remote_refs) { struct ref *ref; - for (ref = remote_refs; ref; ref = ref->next) + for (ref = remote_refs; ref; ref = ref->next) { apply_cas(cas, remote, ref); + + /* + * If "compare-and-swap" is in "use_tracking[_for_rest]" + * mode, and if "--force-if-includes" was specified, run + * the check. + */ + if (ref->check_reachable) + check_if_includes_upstream(ref); + } } @@ -107,12 +107,20 @@ struct ref { struct object_id new_oid; struct object_id old_oid_expect; /* used by expect-old */ char *symref; + char *tracking_ref; unsigned int force:1, forced_update:1, expect_old_sha1:1, exact_oid:1, - deletion:1; + deletion:1, + /* Need to check if local reflog reaches the remote tip. */ + check_reachable:1, + /* + * Store the result of the check enabled by "check_reachable"; + * implies the local reflog does not reach the remote tip. + */ + unreachable:1; enum { REF_NOT_MATCHED = 0, /* initial value */ @@ -142,6 +150,7 @@ struct ref { REF_STATUS_REJECT_NEEDS_FORCE, REF_STATUS_REJECT_STALE, REF_STATUS_REJECT_SHALLOW, + REF_STATUS_REJECT_REMOTE_UPDATED, REF_STATUS_UPTODATE, REF_STATUS_REMOTE_REJECT, REF_STATUS_EXPECTING_REPORT, @@ -348,6 +357,7 @@ struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map); struct push_cas_option { unsigned use_tracking_for_rest:1; + unsigned use_force_if_includes:1; struct push_cas { struct object_id expect; unsigned use_tracking:1; diff --git a/repo-settings.c b/repo-settings.c index 88ccce2036..f7fff0f5ab 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "repository.h" +#include "midx.h" #define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0) @@ -52,6 +53,11 @@ void prepare_repo_settings(struct repository *r) r->settings.pack_use_sparse = value; UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1); + value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0); + if (value || !repo_config_get_bool(r, "core.multipackindex", &value)) + r->settings.core_multi_pack_index = value; + UPDATE_DEFAULT_BOOL(r->settings.core_multi_pack_index, 1); + if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) { UPDATE_DEFAULT_BOOL(r->settings.index_version, 4); UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE); diff --git a/repository.h b/repository.h index bacf843d46..b385ca3c94 100644 --- a/repository.h +++ b/repository.h @@ -39,6 +39,8 @@ struct repo_settings { int pack_use_sparse; enum fetch_negotiation_setting fetch_negotiation_algorithm; + + int core_multi_pack_index; }; struct repository { diff --git a/send-pack.c b/send-pack.c index c9698070fc..eb4a44270b 100644 --- a/send-pack.c +++ b/send-pack.c @@ -299,6 +299,7 @@ static int check_to_send_update(const struct ref *ref, const struct send_pack_ar case REF_STATUS_REJECT_FETCH_FIRST: case REF_STATUS_REJECT_NEEDS_FORCE: case REF_STATUS_REJECT_STALE: + case REF_STATUS_REJECT_REMOTE_UPDATED: case REF_STATUS_REJECT_NODELETE: return CHECK_REF_STATUS_REJECTED; case REF_STATUS_UPTODATE: diff --git a/sequencer.c b/sequencer.c index 00acb12496..a65d7a6b7c 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3677,7 +3677,9 @@ static int do_merge(struct repository *r, strvec_push(&cmd.args, "-F"); strvec_push(&cmd.args, git_path_merge_msg(r)); if (opts->gpg_sign) - strvec_push(&cmd.args, opts->gpg_sign); + strvec_pushf(&cmd.args, "-S%s", opts->gpg_sign); + else + strvec_push(&cmd.args, "--no-gpg-sign"); /* Add the tips to be merged */ for (j = to_merge; j; j = j->next) @@ -3689,7 +3691,6 @@ static int do_merge(struct repository *r, NULL, 0); rollback_lock_file(&lock); - rollback_lock_file(&lock); ret = run_command(&cmd); /* force re-reading of the cache */ @@ -4478,7 +4479,7 @@ static int init_committer(struct replay_opts *opts) opts->committer_name = xmemdupz(id.name_begin, id.name_end - id.name_begin); opts->committer_email = - xmemdupz(id.mail_begin, id.mail_end - id.mail_end); + xmemdupz(id.mail_begin, id.mail_end - id.mail_begin); return 0; } diff --git a/sideband.c b/sideband.c index 0a60662fa6..a5405b9aaa 100644 --- a/sideband.c +++ b/sideband.c @@ -190,7 +190,7 @@ int demultiplex_sideband(const char *me, char *buf, int len, return 0; case 1: *sideband_type = SIDEBAND_PRIMARY; - break; + return 1; default: strbuf_addf(scratch, "%s%s: protocol error: bad band #%d", scratch->len ? "\n" : "", me, band); @@ -258,16 +258,21 @@ For an individual test suite --run could be used to specify that only some tests should be run or that some tests should be excluded from a run. -The argument for --run is a list of individual test numbers or -ranges with an optional negation prefix that define what tests in -a test suite to include in the run. A range is two numbers -separated with a dash and matches a range of tests with both ends -been included. You may omit the first or the second number to -mean "from the first test" or "up to the very last test" -respectively. - -Optional prefix of '!' means that the test or a range of tests -should be excluded from the run. +The argument for --run, <test-selector>, is a list of description +substrings or globs or individual test numbers or ranges with an +optional negation prefix (of '!') that define what tests in a test +suite to include (or exclude, if negated) in the run. A range is two +numbers separated with a dash and matches a range of tests with both +ends been included. You may omit the first or the second number to +mean "from the first test" or "up to the very last test" respectively. + +The argument to --run is split on commas into separate strings, +numbers, and ranges, and picks all tests that match any of the +individual selection criteria. If the substring of the description +text that you want to match includes a comma, use the glob character +'?' instead. For example --run='rebase,merge?cherry-pick' would match +on all tests that match either the glob *rebase* or the glob +*merge?cherry-pick*. If --run starts with an unprefixed number or range the initial set of tests to run is empty. If the first item starts with '!' @@ -275,9 +280,6 @@ all the tests are added to the initial set. After initial set is determined every test number or range is added or excluded from the set one by one, from left to right. -Individual numbers or ranges could be separated either by a space -or a comma. - For example, to run only tests up to a specific test (21), one could do this: @@ -290,7 +292,7 @@ or this: Common case is to run several setup tests (1, 2, 3) and then a specific test (21) that relies on that setup: - $ sh ./t9200-git-cvsexport-commit.sh --run='1 2 3 21' + $ sh ./t9200-git-cvsexport-commit.sh --run='1,2,3,21' or: @@ -298,17 +300,17 @@ or: or: - $ sh ./t9200-git-cvsexport-commit.sh --run='-3 21' + $ sh ./t9200-git-cvsexport-commit.sh --run='-3,21' As noted above, the test set is built by going through the items from left to right, so this: - $ sh ./t9200-git-cvsexport-commit.sh --run='1-4 !3' + $ sh ./t9200-git-cvsexport-commit.sh --run='1-4,!3' will run tests 1, 2, and 4. Items that come later have higher precedence. It means that this: - $ sh ./t9200-git-cvsexport-commit.sh --run='!3 1-4' + $ sh ./t9200-git-cvsexport-commit.sh --run='!3,1-4' would just run tests from 1 to 4, including 3. @@ -317,6 +319,18 @@ test in the test suite except from 7 up to 11: $ sh ./t9200-git-cvsexport-commit.sh --run='!7-11' +Sometimes there may be multiple tests with e.g. "setup" in their name +that are needed and rather than figuring out the number for all of them +we can just use "setup" as a substring/glob to match against the test +description: + + $ sh ./t0050-filesystem.sh --run=setup,9-11 + +or one could select both the setup tests and the rename ones (assuming all +relevant tests had those words in their descriptions): + + $ sh ./t0050-filesystem.sh --run=setup,rename + Some tests in a test suite rely on the previous tests performing certain actions, specifically some tests are designated as "setup" test, so you cannot _arbitrarily_ disable one test and diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index 69152958e5..5e638f0b97 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -84,6 +84,25 @@ static void unpack_sideband(void) } } +static int send_split_sideband(void) +{ + const char *part1 = "Hello,"; + const char *primary = "\001primary: regular output\n"; + const char *part2 = " world!\n"; + + send_sideband(1, 2, part1, strlen(part1), LARGE_PACKET_MAX); + packet_write(1, primary, strlen(primary)); + send_sideband(1, 2, part2, strlen(part2), LARGE_PACKET_MAX); + packet_response_end(1); + + return 0; +} + +static int receive_sideband(void) +{ + return recv_sideband("sideband", 0, 1); +} + int cmd__pkt_line(int argc, const char **argv) { if (argc < 2) @@ -95,6 +114,10 @@ int cmd__pkt_line(int argc, const char **argv) unpack(); else if (!strcmp(argv[1], "unpack-sideband")) unpack_sideband(); + else if (!strcmp(argv[1], "send-split-sideband")) + send_split_sideband(); + else if (!strcmp(argv[1], "receive-sideband")) + receive_sideband(); else die("invalid argument '%s'", argv[1]); diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 923281af93..22489c24dc 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -430,7 +430,7 @@ test_expect_success 'GIT_SKIP_TESTS does not skip unmatched suite' " test_expect_success '--run basic' " run_sub_test_lib_test run-basic \ - '--run basic' --run='1 3 5' <<-\\EOF && + '--run basic' --run='1,3,5' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -472,7 +472,7 @@ test_expect_success '--run with a range' " test_expect_success '--run with two ranges' " run_sub_test_lib_test run-two-ranges \ - '--run with two ranges' --run='1-2 5-6' <<-\\EOF && + '--run with two ranges' --run='1-2,5-6' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -556,7 +556,7 @@ test_expect_success '--run with basic negation' " test_expect_success '--run with two negations' " run_sub_test_lib_test run-two-neg \ - '--run with two negations' --run='"'!3 !6'"' <<-\\EOF && + '--run with two negations' --run='"'!3,!6'"' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -577,7 +577,7 @@ test_expect_success '--run with two negations' " test_expect_success '--run a range and negation' " run_sub_test_lib_test run-range-and-neg \ - '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF && + '--run a range and negation' --run='"'-4,!2'"' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -620,7 +620,7 @@ test_expect_success '--run range negation' " test_expect_success '--run include, exclude and include' " run_sub_test_lib_test run-inc-neg-inc \ '--run include, exclude and include' \ - --run='"'1-5 !1-3 2'"' <<-\\EOF && + --run='"'1-5,!1-3,2'"' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -664,7 +664,7 @@ test_expect_success '--run include, exclude and include, comma separated' " test_expect_success '--run exclude and include' " run_sub_test_lib_test run-neg-inc \ '--run exclude and include' \ - --run='"'!3- 5'"' <<-\\EOF && + --run='"'!3-,5'"' <<-\\EOF && for i in 1 2 3 4 5 6 do test_expect_success \"passing test #\$i\" 'true' @@ -705,7 +705,31 @@ test_expect_success '--run empty selectors' " EOF " -test_expect_success '--run invalid range start' " +test_expect_success '--run substring selector' " + run_sub_test_lib_test run-substring-selector \ + '--run empty selectors' \ + --run='relevant' <<-\\EOF && + test_expect_success \"relevant test\" 'true' + for i in 1 2 3 4 5 6 + do + test_expect_success \"other test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-substring-selector <<-\\EOF + > ok 1 - relevant test + > ok 2 # skip other test #1 (--run) + > ok 3 # skip other test #2 (--run) + > ok 4 # skip other test #3 (--run) + > ok 5 # skip other test #4 (--run) + > ok 6 # skip other test #5 (--run) + > ok 7 # skip other test #6 (--run) + > # passed all 7 test(s) + > 1..7 + EOF +" + +test_expect_success '--run keyword selection' " run_sub_test_lib_test_err run-inv-range-start \ '--run invalid range start' \ --run='a-5' <<-\\EOF && @@ -735,21 +759,6 @@ test_expect_success '--run invalid range end' " EOF_ERR " -test_expect_success '--run invalid selector' " - run_sub_test_lib_test_err run-inv-selector \ - '--run invalid selector' \ - --run='1?' <<-\\EOF && - test_expect_success \"passing test #1\" 'true' - test_done - EOF - check_sub_test_lib_test_err run-inv-selector \ - <<-\\EOF_OUT 3<<-\\EOF_ERR - > FATAL: Unexpected exit with code 1 - EOF_OUT - > error: --run: invalid non-numeric in test selector: '1?' - EOF_ERR -" - test_set_prereq HAVEIT haveit=no @@ -1191,7 +1200,7 @@ test_expect_success 'writing this tree with --missing-ok' ' test_expect_success 'git read-tree followed by write-tree should be idempotent' ' rm -f .git/index && git read-tree $tree && - test -f .git/index && + test_path_is_file .git/index && newtree=$(git write-tree) && test "$newtree" = "$tree" ' diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh index 7b111a56fd..357201640a 100755 --- a/t/t0070-fundamental.sh +++ b/t/t0070-fundamental.sh @@ -34,4 +34,10 @@ test_expect_success 'check for a bug in the regex routines' ' test-tool regex --bug ' +test_expect_success 'incomplete sideband messages are reassembled' ' + test-tool pkt-line send-split-sideband >split-sideband && + test-tool pkt-line receive-sideband <split-sideband 2>err && + grep "Hello, world" err +' + test_done diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh index bc2d74098f..a18f8a473b 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -265,6 +265,32 @@ test_expect_success 'internal getpass does not ask for known username' ' EOF ' +test_expect_success 'git-credential respects core.askPass' ' + write_script alternate-askpass <<-\EOF && + echo >&2 "alternate askpass invoked" + echo alternate-value + EOF + test_config core.askpass "$PWD/alternate-askpass" && + ( + # unset GIT_ASKPASS set by lib-credential.sh which would + # override our config, but do so in a subshell so that we do + # not interfere with other tests + sane_unset GIT_ASKPASS && + check fill <<-\EOF + protocol=http + host=example.com + -- + protocol=http + host=example.com + username=alternate-value + password=alternate-value + -- + alternate askpass invoked + alternate askpass invoked + EOF + ) +' + HELPER="!f() { cat >/dev/null echo username=foo diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh index 47aeb0b167..d91a329eb3 100755 --- a/t/t2016-checkout-patch.sh +++ b/t/t2016-checkout-patch.sh @@ -18,6 +18,10 @@ test_expect_success PERL 'setup' ' # note: bar sorts before dir/foo, so the first 'n' is always to skip 'bar' +# NEEDSWORK: Since the builtin add-p is used when $GIT_TEST_ADD_I_USE_BUILTIN +# is given, we should replace the PERL prerequisite with an ADD_I prerequisite +# which first checks if $GIT_TEST_ADD_I_USE_BUILTIN is defined before checking +# PERL. test_expect_success PERL 'saying "n" does nothing' ' set_and_save_state dir/foo work head && test_write_lines n n | git checkout -p && @@ -59,6 +63,13 @@ test_expect_success PERL 'git checkout -p HEAD with change already staged' ' verify_state dir/foo head head ' +test_expect_success PERL 'git checkout -p HEAD^...' ' + # the third n is to get out in case it mistakenly does not apply + test_write_lines n y n | git checkout -p HEAD^... && + verify_saved_state bar && + verify_state dir/foo parent parent +' + test_expect_success PERL 'git checkout -p HEAD^' ' # the third n is to get out in case it mistakenly does not apply test_write_lines n y n | git checkout -p HEAD^ && diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh index accfa9aa4b..a4f8d3a67e 100755 --- a/t/t2024-checkout-dwim.sh +++ b/t/t2024-checkout-dwim.sh @@ -166,6 +166,17 @@ test_expect_success '--no-guess suppresses branch auto-vivification' ' test_branch master ' +test_expect_success 'checkout.guess = false suppresses branch auto-vivification' ' + git checkout -B master && + status_uno_is_clean && + test_might_fail git branch -D bar && + + test_config checkout.guess false && + test_must_fail git checkout bar && + test_must_fail git rev-parse --verify refs/heads/bar && + test_branch master +' + test_expect_success 'setup more remotes with unconventional refspecs' ' git checkout -B master && status_uno_is_clean && diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index 2c1b8c0d6d..68c9101b02 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -85,9 +85,12 @@ test_expect_success 'switching ignores file of same branch name' ' test_cmp expected actual ' -test_expect_success 'guess and create branch ' ' +test_expect_success 'guess and create branch' ' test_when_finished git switch master && test_must_fail git switch --no-guess foo && + test_config checkout.guess false && + test_must_fail git switch foo && + test_config checkout.guess true && git switch foo && echo refs/heads/foo >expected && git symbolic-ref HEAD >actual && diff --git a/t/t2071-restore-patch.sh b/t/t2071-restore-patch.sh index 98b2476e7c..b5c5c0ff7e 100755 --- a/t/t2071-restore-patch.sh +++ b/t/t2071-restore-patch.sh @@ -60,6 +60,14 @@ test_expect_success PERL 'git restore -p --source=HEAD^' ' verify_state dir/foo parent index ' +test_expect_success PERL 'git restore -p --source=HEAD^...' ' + set_state dir/foo work index && + # the third n is to get out in case it mistakenly does not apply + test_write_lines n y n | git restore -p --source=HEAD^... && + verify_saved_state bar && + verify_state dir/foo parent index +' + test_expect_success PERL 'git restore -p handles deletion' ' set_state dir/foo work index && rm dir/foo && diff --git a/t/t2402-worktree-list.sh b/t/t2402-worktree-list.sh index 52585ec2aa..b85bd2655d 100755 --- a/t/t2402-worktree-list.sh +++ b/t/t2402-worktree-list.sh @@ -61,6 +61,16 @@ test_expect_success '"list" all worktrees --porcelain' ' test_cmp expect actual ' +test_expect_success '"list" all worktress with locked annotation' ' + test_when_finished "rm -rf locked unlocked out && git worktree prune" && + git worktree add --detach locked master && + git worktree add --detach unlocked master && + git worktree lock locked && + git worktree list >out && + grep "/locked *[0-9a-f].* locked$" out && + ! grep "/unlocked *[0-9a-f].* locked$" out +' + test_expect_success 'bare repo setup' ' git init --bare bare1 && echo "data" >file1 && diff --git a/t/t3435-rebase-gpg-sign.sh b/t/t3435-rebase-gpg-sign.sh index b47c59c190..54120b09d6 100755 --- a/t/t3435-rebase-gpg-sign.sh +++ b/t/t3435-rebase-gpg-sign.sh @@ -68,4 +68,60 @@ test_expect_failure 'rebase -p --no-gpg-sign override commit.gpgsign' ' test_must_fail git verify-commit HEAD ' +test_expect_success 'rebase -r, merge strategy, --gpg-sign will sign commit' ' + git reset --hard merged && + test_unconfig commit.gpgsign && + git rebase -fr --gpg-sign -s resolve --root && + git verify-commit HEAD +' + +test_expect_success 'rebase -r, merge strategy, commit.gpgsign=true will sign commit' ' + git reset --hard merged && + git config commit.gpgsign true && + git rebase -fr -s resolve --root && + git verify-commit HEAD +' + +test_expect_success 'rebase -r, merge strategy, commit.gpgsign=false --gpg-sign will sign commit' ' + git reset --hard merged && + git config commit.gpgsign false && + git rebase -fr --gpg-sign -s resolve --root && + git verify-commit HEAD +' + +test_expect_success "rebase -r, merge strategy, commit.gpgsign=true --no-gpg-sign won't sign commit" ' + git reset --hard merged && + git config commit.gpgsign true && + git rebase -fr --no-gpg-sign -s resolve --root && + test_must_fail git verify-commit HEAD +' + +test_expect_success 'rebase -r --gpg-sign will sign commit' ' + git reset --hard merged && + test_unconfig commit.gpgsign && + git rebase -fr --gpg-sign --root && + git verify-commit HEAD +' + +test_expect_success 'rebase -r with commit.gpgsign=true will sign commit' ' + git reset --hard merged && + git config commit.gpgsign true && + git rebase -fr --root && + git verify-commit HEAD +' + +test_expect_success 'rebase -r --gpg-sign with commit.gpgsign=false will sign commit' ' + git reset --hard merged && + git config commit.gpgsign false && + git rebase -fr --gpg-sign --root && + git verify-commit HEAD +' + +test_expect_success "rebase -r --no-gpg-sign with commit.gpgsign=true won't sign commit" ' + git reset --hard merged && + git config commit.gpgsign true && + git rebase -fr --no-gpg-sign --root && + test_must_fail git verify-commit HEAD +' + test_done diff --git a/t/t3436-rebase-more-options.sh b/t/t3436-rebase-more-options.sh index 996e82787e..eaaf4c8d1d 100755 --- a/t/t3436-rebase-more-options.sh +++ b/t/t3436-rebase-more-options.sh @@ -65,8 +65,8 @@ test_expect_success '--ignore-whitespace is remembered when continuing' ' ' test_ctime_is_atime () { - git log $1 --format=%ai >authortime && - git log $1 --format=%ci >committertime && + git log $1 --format="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> %ai" >authortime && + git log $1 --format="%cn <%ce> %ci" >committertime && test_cmp authortime committertime } diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 5c7b0122b4..f72d456d3b 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -6,6 +6,7 @@ test_description='Various diff formatting options' . ./test-lib.sh +. "$TEST_DIRECTORY"/diff-lib.sh test_expect_success setup ' @@ -333,6 +334,7 @@ log -SF master --max-count=2 log -GF master log -GF -p master log -GF -p --pickaxe-all master +log -IA -IB -I1 -I2 -p master log --decorate --all log --decorate=full --all @@ -473,4 +475,43 @@ test_expect_success 'diff-tree --stdin with log formatting' ' test_cmp expect actual ' +test_expect_success 'diff -I<regex>: setup' ' + git checkout master && + test_seq 50 >file0 && + git commit -m "Set up -I<regex> test file" file0 && + test_seq 50 | sed -e "s/13/ten and three/" -e "/7\$/d" >file0 && + echo >>file0 +' +test_expect_success 'diff -I<regex>' ' + git diff --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual && + cat >expect <<-\EOF && + diff --git a/file0 b/file0 + --- a/file0 + +++ b/file0 + @@ -34,7 +31,6 @@ + 34 + 35 + 36 + -37 + 38 + 39 + 40 + EOF + compare_diff_patch expect actual +' + +test_expect_success 'diff -I<regex> --stat' ' + git diff --stat --ignore-blank-lines -I"ten.*e" -I"^[124-9]" >actual && + cat >expect <<-\EOF && + file0 | 1 - + 1 file changed, 1 deletion(-) + EOF + test_cmp expect actual +' + +test_expect_success 'diff -I<regex>: detect malformed regex' ' + test_expect_code 129 git diff --ignore-matching-lines="^[124-9" 2>error && + test_i18ngrep "invalid regex given to -I: " error +' + test_done diff --git a/t/t4013/diff.log_-IA_-IB_-I1_-I2_-p_master b/t/t4013/diff.log_-IA_-IB_-I1_-I2_-p_master new file mode 100644 index 0000000000..929f35a05b --- /dev/null +++ b/t/t4013/diff.log_-IA_-IB_-I1_-I2_-p_master @@ -0,0 +1,99 @@ +$ git log -IA -IB -I1 -I2 -p master +commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 +Merge: 9a6d494 c7a2ab9 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:04:00 2006 +0000 + + Merge branch 'side' + +commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:03:00 2006 +0000 + + Side + +diff --git a/file0 b/file0 +index 01e79c3..f4615da 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++A ++B ++C +diff --git a/file3 b/file3 +new file mode 100644 +index 0000000..7289e35 + +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C + +commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:01:00 2006 +0000 + + Second + + This is the second commit. + +diff --git a/dir/sub b/dir/sub +index 35d242b..8422d40 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++C ++D +diff --git a/file0 b/file0 +index 01e79c3..b414108 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++4 ++5 ++6 +diff --git a/file2 b/file2 +deleted file mode 100644 +index 01e79c3..0000000 +--- a/file2 ++++ /dev/null +@@ -1,3 +0,0 @@ +-1 +-2 +-3 + +commit 444ac553ac7612cc88969031b02b3767fb8a353a +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:00:00 2006 +0000 + + Initial +$ diff --git a/t/t4018/css-attribute-value-selector b/t/t4018/css-attribute-value-selector new file mode 100644 index 0000000000..918256b20c --- /dev/null +++ b/t/t4018/css-attribute-value-selector @@ -0,0 +1,4 @@ +[class*="RIGHT"] { + background : #000; + border : 10px ChangeMe #C6C6C6; +} diff --git a/t/t4018/css-block-level-@-statements b/t/t4018/css-block-level-@-statements new file mode 100644 index 0000000000..d6755f2f3d --- /dev/null +++ b/t/t4018/css-block-level-@-statements @@ -0,0 +1,10 @@ +@keyframes RIGHT { + from { + background : #000; + border : 10px ChangeMe #C6C6C6; + } + to { + background : #fff; + border : 10px solid #C6C6C6; + } +} diff --git a/t/t4018/css-class-selector b/t/t4018/css-class-selector new file mode 100644 index 0000000000..f790a0062f --- /dev/null +++ b/t/t4018/css-class-selector @@ -0,0 +1,4 @@ +.RIGHT { + background : #000; + border : 10px ChangeMe #C6C6C6; +} diff --git a/t/t4018/css-id-selector b/t/t4018/css-id-selector new file mode 100644 index 0000000000..17c5111052 --- /dev/null +++ b/t/t4018/css-id-selector @@ -0,0 +1,4 @@ +#RIGHT { + background : #000; + border : 10px ChangeMe #C6C6C6; +} diff --git a/t/t4018/css-root-selector b/t/t4018/css-root-selector new file mode 100644 index 0000000000..22b958e369 --- /dev/null +++ b/t/t4018/css-root-selector @@ -0,0 +1,4 @@ +:RIGHT { + background : #000; + border : 10px ChangeMe #C6C6C6; +} diff --git a/t/t4018/php-abstract-method b/t/t4018/php-abstract-method new file mode 100644 index 0000000000..ce215df75a --- /dev/null +++ b/t/t4018/php-abstract-method @@ -0,0 +1,7 @@ +abstract class Klass +{ + abstract public function RIGHT(): ?string + { + return 'ChangeMe'; + } +} diff --git a/t/t4018/php-final-method b/t/t4018/php-final-method new file mode 100644 index 0000000000..537fb8ad9a --- /dev/null +++ b/t/t4018/php-final-method @@ -0,0 +1,7 @@ +class Klass +{ + final public function RIGHT(): string + { + return 'ChangeMe'; + } +} diff --git a/t/t4018/rust-macro-rules b/t/t4018/rust-macro-rules new file mode 100644 index 0000000000..ec610c5b62 --- /dev/null +++ b/t/t4018/rust-macro-rules @@ -0,0 +1,6 @@ +macro_rules! RIGHT { + () => { + // a comment + let x = ChangeMe; + }; +} diff --git a/t/t4068-diff-symmetric-merge-base.sh b/t/t4068-diff-symmetric-merge-base.sh new file mode 100755 index 0000000000..03487cc945 --- /dev/null +++ b/t/t4068-diff-symmetric-merge-base.sh @@ -0,0 +1,193 @@ +#!/bin/sh + +test_description='behavior of diff with symmetric-diff setups and --merge-base' + +. ./test-lib.sh + +# build these situations: +# - normal merge with one merge base (br1...b2r); +# - criss-cross merge ie 2 merge bases (br1...master); +# - disjoint subgraph (orphan branch, br3...master). +# +# B---E <-- master +# / \ / +# A X +# \ / \ +# C---D--G <-- br1 +# \ / +# ---F <-- br2 +# +# H <-- br3 +# +# We put files into a few commits so that we can verify the +# output as well. + +test_expect_success setup ' + git commit --allow-empty -m A && + echo b >b && + git add b && + git commit -m B && + git checkout -b br1 HEAD^ && + echo c >c && + git add c && + git commit -m C && + git tag commit-C && + git merge -m D master && + git tag commit-D && + git checkout master && + git merge -m E commit-C && + git checkout -b br2 commit-C && + echo f >f && + git add f && + git commit -m F && + git checkout br1 && + git merge -m G br2 && + git checkout --orphan br3 && + git commit -m H +' + +test_expect_success 'diff with one merge base' ' + git diff commit-D...br1 >tmp && + tail -n 1 tmp >actual && + echo +f >expect && + test_cmp expect actual +' + +# The output (in tmp) can have +b or +c depending +# on which merge base (commit B or C) is picked. +# It should have one of those two, which comes out +# to seven lines. +test_expect_success 'diff with two merge bases' ' + git diff br1...master >tmp 2>err && + test_line_count = 7 tmp && + test_line_count = 1 err +' + +test_expect_success 'diff with no merge bases' ' + test_must_fail git diff br2...br3 2>err && + test_i18ngrep "fatal: br2...br3: no merge base" err +' + +test_expect_success 'diff with too many symmetric differences' ' + test_must_fail git diff br1...master br2...br3 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with symmetric difference and extraneous arg' ' + test_must_fail git diff master br1...master 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with two ranges' ' + test_must_fail git diff master br1..master br2..br3 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with ranges and extra arg' ' + test_must_fail git diff master br1..master commit-D 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff --merge-base with no commits' ' + test_must_fail git diff --merge-base +' + +test_expect_success 'diff --merge-base with three commits' ' + test_must_fail git diff --merge-base br1 br2 master 2>err && + test_i18ngrep "usage" err +' + +for cmd in diff-index diff +do + test_expect_success "$cmd --merge-base with one commit" ' + git checkout master && + git $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base with one commit and unstaged changes" ' + git checkout master && + test_when_finished git reset --hard && + echo unstaged >>c && + git $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base with one commit and staged and unstaged changes" ' + git checkout master && + test_when_finished git reset --hard && + echo staged >>c && + git add c && + echo unstaged >>c && + git $cmd commit-C >expect && + git $cmd --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base --cached with one commit and staged and unstaged changes" ' + git checkout master && + test_when_finished git reset --hard && + echo staged >>c && + git add c && + echo unstaged >>c && + git $cmd --cached commit-C >expect && + git $cmd --cached --merge-base br2 >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base with non-commit" ' + git checkout master && + test_must_fail git $cmd --merge-base master^{tree} 2>err && + test_i18ngrep "fatal: --merge-base only works with commits" err + ' + + test_expect_success "$cmd --merge-base with no merge bases and one commit" ' + git checkout master && + test_must_fail git $cmd --merge-base br3 2>err && + test_i18ngrep "fatal: no merge base found" err + ' + + test_expect_success "$cmd --merge-base with multiple merge bases and one commit" ' + git checkout master && + test_must_fail git $cmd --merge-base br1 2>err && + test_i18ngrep "fatal: multiple merge bases found" err + ' +done + +for cmd in diff-tree diff +do + test_expect_success "$cmd --merge-base with two commits" ' + git $cmd commit-C master >expect && + git $cmd --merge-base br2 master >actual && + test_cmp expect actual + ' + + test_expect_success "$cmd --merge-base commit and non-commit" ' + test_must_fail git $cmd --merge-base br2 master^{tree} 2>err && + test_i18ngrep "fatal: --merge-base only works with commits" err + ' + + test_expect_success "$cmd --merge-base with no merge bases and two commits" ' + test_must_fail git $cmd --merge-base br2 br3 2>err && + test_i18ngrep "fatal: no merge base found" err + ' + + test_expect_success "$cmd --merge-base with multiple merge bases and two commits" ' + test_must_fail git $cmd --merge-base master br1 2>err && + test_i18ngrep "fatal: multiple merge bases found" err + ' +done + +test_expect_success 'diff-tree --merge-base with one commit' ' + test_must_fail git diff-tree --merge-base master 2>err && + test_i18ngrep "fatal: --merge-base only works with two commits" err +' + +test_expect_success 'diff --merge-base with range' ' + test_must_fail git diff --merge-base br2..br3 2>err && + test_i18ngrep "fatal: --merge-base does not work with ranges" err +' + +test_done diff --git a/t/t4068-diff-symmetric.sh b/t/t4068-diff-symmetric.sh deleted file mode 100755 index 31d17a5af0..0000000000 --- a/t/t4068-diff-symmetric.sh +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/sh - -test_description='behavior of diff with symmetric-diff setups' - -. ./test-lib.sh - -# build these situations: -# - normal merge with one merge base (br1...b2r); -# - criss-cross merge ie 2 merge bases (br1...master); -# - disjoint subgraph (orphan branch, br3...master). -# -# B---E <-- master -# / \ / -# A X -# \ / \ -# C---D--G <-- br1 -# \ / -# ---F <-- br2 -# -# H <-- br3 -# -# We put files into a few commits so that we can verify the -# output as well. - -test_expect_success setup ' - git commit --allow-empty -m A && - echo b >b && - git add b && - git commit -m B && - git checkout -b br1 HEAD^ && - echo c >c && - git add c && - git commit -m C && - git tag commit-C && - git merge -m D master && - git tag commit-D && - git checkout master && - git merge -m E commit-C && - git checkout -b br2 commit-C && - echo f >f && - git add f && - git commit -m F && - git checkout br1 && - git merge -m G br2 && - git checkout --orphan br3 && - git commit -m H -' - -test_expect_success 'diff with one merge base' ' - git diff commit-D...br1 >tmp && - tail -n 1 tmp >actual && - echo +f >expect && - test_cmp expect actual -' - -# The output (in tmp) can have +b or +c depending -# on which merge base (commit B or C) is picked. -# It should have one of those two, which comes out -# to seven lines. -test_expect_success 'diff with two merge bases' ' - git diff br1...master >tmp 2>err && - test_line_count = 7 tmp && - test_line_count = 1 err -' - -test_expect_success 'diff with no merge bases' ' - test_must_fail git diff br2...br3 >tmp 2>err && - test_i18ngrep "fatal: br2...br3: no merge base" err -' - -test_expect_success 'diff with too many symmetric differences' ' - test_must_fail git diff br1...master br2...br3 >tmp 2>err && - test_i18ngrep "usage" err -' - -test_expect_success 'diff with symmetric difference and extraneous arg' ' - test_must_fail git diff master br1...master >tmp 2>err && - test_i18ngrep "usage" err -' - -test_expect_success 'diff with two ranges' ' - test_must_fail git diff master br1..master br2..br3 >tmp 2>err && - test_i18ngrep "usage" err -' - -test_expect_success 'diff with ranges and extra arg' ' - test_must_fail git diff master br1..master commit-D >tmp 2>err && - test_i18ngrep "usage" err -' - -test_done diff --git a/t/t4114-apply-typechange.sh b/t/t4114-apply-typechange.sh index ebadbc347f..da3e64f811 100755 --- a/t/t4114-apply-typechange.sh +++ b/t/t4114-apply-typechange.sh @@ -88,6 +88,13 @@ test_expect_success 'symlink becomes file' ' ' test_debug 'cat patch' +test_expect_success 'symlink becomes file, in reverse' ' + git checkout -f foo-symlinked-to-bar && + git diff-tree -p HEAD foo-back-to-file > patch && + git checkout foo-back-to-file && + git apply -R --index < patch + ' + test_expect_success 'binary file becomes symlink' ' git checkout -f foo-becomes-binary && git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch && diff --git a/t/t4127-apply-same-fn.sh b/t/t4127-apply-same-fn.sh index 972946c174..305b7e649e 100755 --- a/t/t4127-apply-same-fn.sh +++ b/t/t4127-apply-same-fn.sh @@ -32,6 +32,10 @@ test_expect_success 'apply same filename with independent changes' ' test_expect_success 'apply same filename with overlapping changes' ' git reset --hard && + + # Store same_fn so that we can check apply -R in next test + cp same_fn same_fn1 && + modify "s/^d/z/" same_fn && git diff > patch0 && git add same_fn && @@ -43,6 +47,11 @@ test_expect_success 'apply same filename with overlapping changes' ' test_cmp same_fn same_fn2 ' +test_expect_success 'apply same filename with overlapping changes, in reverse' ' + git apply -R patch0 && + test_cmp same_fn same_fn1 +' + test_expect_success 'apply same new filename after rename' ' git reset --hard && git mv same_fn new_fn && diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index f340b376bc..ace469c95c 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -3,6 +3,7 @@ test_description='multi-pack-indexes' . ./test-lib.sh +GIT_TEST_MULTI_PACK_INDEX=0 objdir=.git/objects HASH_LEN=$(test_oid rawsz) @@ -173,12 +174,12 @@ test_expect_success 'write progress off for redirected stderr' ' ' test_expect_success 'write force progress on for stderr' ' - git multi-pack-index --object-dir=$objdir --progress write 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress write 2>err && test_file_not_empty err ' test_expect_success 'write with the --no-progress option' ' - git multi-pack-index --object-dir=$objdir --no-progress write 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress write 2>err && test_line_count = 0 err ' @@ -368,17 +369,17 @@ test_expect_success 'git-fsck incorrect offset' ' ' test_expect_success 'repack progress off for redirected stderr' ' - git multi-pack-index --object-dir=$objdir repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err && test_line_count = 0 err ' test_expect_success 'repack force progress on for stderr' ' - git multi-pack-index --object-dir=$objdir --progress repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --progress repack 2>err && test_file_not_empty err ' test_expect_success 'repack with the --no-progress option' ' - git multi-pack-index --object-dir=$objdir --no-progress repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir --no-progress repack 2>err && test_line_count = 0 err ' @@ -562,7 +563,7 @@ test_expect_success 'expire progress off for redirected stderr' ' test_expect_success 'expire force progress on for stderr' ' ( cd dup && - git multi-pack-index --progress expire 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --progress expire 2>err && test_file_not_empty err ) ' @@ -570,7 +571,7 @@ test_expect_success 'expire force progress on for stderr' ' test_expect_success 'expire with the --no-progress option' ' ( cd dup && - git multi-pack-index --no-progress expire 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index --no-progress expire 2>err && test_line_count = 0 err ) ' diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh index c334ee9155..4d3842b83b 100755 --- a/t/t5324-split-commit-graph.sh +++ b/t/t5324-split-commit-graph.sh @@ -440,4 +440,17 @@ test_expect_success '--split=replace with partial Bloom data' ' verify_chain_files_exist $graphdir ' +test_expect_success 'prevent regression for duplicate commits across layers' ' + git init dup && + git -C dup commit --allow-empty -m one && + git -C dup -c core.commitGraph=false commit-graph write --split=no-merge --reachable 2>err && + test_i18ngrep "attempting to write a commit-graph" err && + git -C dup commit-graph write --split=no-merge --reachable && + git -C dup commit --allow-empty -m two && + git -C dup commit-graph write --split=no-merge --reachable && + git -C dup commit --allow-empty -m three && + git -C dup commit-graph write --split --reachable && + git -C dup commit-graph verify +' + test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 8d62edd98b..1156f52069 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -179,6 +179,13 @@ test_expect_success 'rename errors out early when deleting non-existent branch' ) ' +test_expect_success 'rename errors out early when when new name is invalid' ' + test_config remote.foo.vcs bar && + echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && + test_must_fail git remote rename foo invalid...name 2>actual && + test_i18ncmp expect actual +' + test_expect_success 'add existing foreign_vcs remote' ' test_config remote.foo.vcs bar && echo "fatal: remote foo already exists." >expect && @@ -194,6 +201,12 @@ test_expect_success 'add existing foreign_vcs remote' ' test_i18ncmp expect actual ' +test_expect_success 'add invalid foreign_vcs remote' ' + echo "fatal: '\''invalid...name'\'' is not a valid remote name" >expect && + test_must_fail git remote add invalid...name bar 2>actual && + test_i18ncmp expect actual +' + cat >test/expect <<EOF * remote origin Fetch URL: $(pwd)/one diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index 0b0eb1d025..7813e8470e 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -13,6 +13,46 @@ setup_srcdst_basic () { ) } +# For tests with "--force-if-includes". +setup_src_dup_dst () { + rm -fr src dup dst && + git init --bare dst && + git clone --no-local dst src && + git clone --no-local dst dup + ( + cd src && + test_commit A && + test_commit B && + test_commit C && + git push origin + ) && + ( + cd dup && + git fetch && + git merge origin/master && + git switch -c branch master~2 && + test_commit D && + test_commit E && + git push origin --all + ) && + ( + cd src && + git switch master && + git fetch --all && + git branch branch --track origin/branch && + git rebase origin/master + ) && + ( + cd dup && + git switch master && + test_commit F && + test_commit G && + git switch branch && + test_commit H && + git push origin --all + ) +} + test_expect_success setup ' # create template repository test_commit A && @@ -256,4 +296,101 @@ test_expect_success 'background updates of REMOTE can be mitigated with a non-up ) ' +test_expect_success 'background updates to remote can be mitigated with "--force-if-includes"' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + git ls-remote dst refs/heads/master >expect.master && + git ls-remote dst refs/heads/branch >expect.branch && + ( + cd src && + git switch branch && + test_commit I && + git switch master && + test_commit J && + git fetch --all && + test_must_fail git push --force-with-lease --force-if-includes --all + ) && + git ls-remote dst refs/heads/master >actual.master && + git ls-remote dst refs/heads/branch >actual.branch && + test_cmp expect.master actual.master && + test_cmp expect.branch actual.branch +' + +test_expect_success 'background updates to remote can be mitigated with "push.useForceIfIncludes"' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + git ls-remote dst refs/heads/master >expect.master && + ( + cd src && + git switch branch && + test_commit I && + git switch master && + test_commit J && + git fetch --all && + git config --local push.useForceIfIncludes true && + test_must_fail git push --force-with-lease=master origin master + ) && + git ls-remote dst refs/heads/master >actual.master && + test_cmp expect.master actual.master +' + +test_expect_success '"--force-if-includes" should be disabled for --force-with-lease="<refname>:<expect>"' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + git ls-remote dst refs/heads/master >expect.master && + ( + cd src && + git switch branch && + test_commit I && + git switch master && + test_commit J && + remote_head="$(git rev-parse refs/remotes/origin/master)" && + git fetch --all && + test_must_fail git push --force-if-includes --force-with-lease="master:$remote_head" 2>err && + grep "stale info" err + ) && + git ls-remote dst refs/heads/master >actual.master && + test_cmp expect.master actual.master +' + +test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase")' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + ( + cd src && + git switch branch && + test_commit I && + git switch master && + test_commit J && + git pull --rebase origin master && + git push --force-if-includes --force-with-lease="master" + ) +' + +test_expect_success '"--force-if-includes" should allow forced update after a rebase ("pull --rebase", local rebase)' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + ( + cd src && + git switch branch && + test_commit I && + git switch master && + test_commit J && + git pull --rebase origin master && + git rebase --onto HEAD~4 HEAD~1 && + git push --force-if-includes --force-with-lease="master" + ) +' + +test_expect_success '"--force-if-includes" should allow deletes' ' + setup_src_dup_dst && + test_when_finished "rm -fr dst src dup" && + ( + cd src && + git switch branch && + git pull --rebase origin branch && + git push --force-if-includes --force-with-lease="branch" origin :branch + ) +' + test_done diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index e69427f881..5e201e7d85 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -15,7 +15,73 @@ test_expect_success 'setup' ' test_expect_success 'clone -o' ' git clone -o foo parent clone-o && - (cd clone-o && git rev-parse --verify refs/remotes/foo/master) + git -C clone-o rev-parse --verify refs/remotes/foo/master + +' + +test_expect_success 'rejects invalid -o/--origin' ' + + test_must_fail git clone -o "bad...name" parent clone-bad-name 2>err && + test_i18ngrep "'\''bad...name'\'' is not a valid remote name" err + +' + +test_expect_success 'disallows --bare with --origin' ' + + test_must_fail git clone -o foo --bare parent clone-bare-o 2>err && + test_debug "cat err" && + test_i18ngrep -e "--bare and --origin foo options are incompatible" err + +' + +test_expect_success 'disallows --bare with --separate-git-dir' ' + + test_must_fail git clone --bare --separate-git-dir dot-git-destiation parent clone-bare-sgd 2>err && + test_debug "cat err" && + test_i18ngrep -e "--bare and --separate-git-dir are incompatible" err + +' + +test_expect_success 'uses "origin" for default remote name' ' + + git clone parent clone-default-origin && + git -C clone-default-origin rev-parse --verify refs/remotes/origin/master + +' + +test_expect_success 'prefers --template config over normal config' ' + + template="$TRASH_DIRECTORY/template-with-config" && + mkdir "$template" && + git config --file "$template/config" foo.bar from_template && + test_config_global foo.bar from_global && + git clone "--template=$template" parent clone-template-config && + test "$(git -C clone-template-config config --local foo.bar)" = "from_template" + +' + +test_expect_success 'prefers -c config over --template config' ' + + template="$TRASH_DIRECTORY/template-with-ignored-config" && + mkdir "$template" && + git config --file "$template/config" foo.bar from_template && + git clone "--template=$template" -c foo.bar=inline parent clone-template-inline-config && + test "$(git -C clone-template-inline-config config --local foo.bar)" = "inline" + +' + +test_expect_success 'prefers config "clone.defaultRemoteName" over default' ' + + test_config_global clone.defaultRemoteName from_config && + git clone parent clone-config-origin && + git -C clone-config-origin rev-parse --verify refs/remotes/from_config/master + +' + +test_expect_success 'prefers --origin over -c config' ' + + git clone -c clone.defaultRemoteName=inline --origin from_option parent clone-o-and-inline-config && + git -C clone-o-and-inline-config rev-parse --verify refs/remotes/from_option/master ' diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index bc95da8a5f..99a1eaf332 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -339,7 +339,7 @@ commit $head1 .. (hinzugef${added_utf8_part_iso88591}gt) foo EOF -test_expect_success 'prepare expected messages (for test %b)' ' +test_expect_success 'setup expected messages (for test %b)' ' cat <<-EOF >expected.utf-8 && commit $head3 This commit message is much longer than the others, diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh index 7fc10f8593..fd202fcb94 100755 --- a/t/t6012-rev-list-simplify.sh +++ b/t/t6012-rev-list-simplify.sh @@ -168,7 +168,7 @@ test_expect_success '--full-diff is not affected by --parents' ' # # This example is explained in Documentation/rev-list-options.txt -test_expect_success 'rebuild repo' ' +test_expect_success 'setup rebuild repo' ' rm -rf .git * && git init && git switch -c topic && diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index 00e09a375c..fdb450e446 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -19,7 +19,7 @@ test_expect_success 'setup' ' test_expect_success TTY 'some commands use a pager' ' rm -f paginated.out && test_terminal git log && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_failure TTY 'pager runs from subdir' ' @@ -65,49 +65,49 @@ test_expect_success !MINGW,TTY 'LESS and LV envvars set by git-sh-setup' ' test_expect_success TTY 'some commands do not use a pager' ' rm -f paginated.out && test_terminal git rev-list HEAD && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success 'no pager when stdout is a pipe' ' rm -f paginated.out && git log | cat && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success 'no pager when stdout is a regular file' ' rm -f paginated.out && git log >file && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git --paginate rev-list uses a pager' ' rm -f paginated.out && test_terminal git --paginate rev-list HEAD && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success 'no pager even with --paginate when stdout is a pipe' ' rm -f file paginated.out && git --paginate log | cat && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'no pager with --no-pager' ' rm -f paginated.out && test_terminal git --no-pager log && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'configuration can disable pager' ' rm -f paginated.out && test_unconfig pager.grep && test_terminal git grep initial && - test -e paginated.out && + test_path_is_file paginated.out && rm -f paginated.out && test_config pager.grep false && test_terminal git grep initial && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'configuration can enable pager (from subdir)' ' @@ -122,107 +122,107 @@ test_expect_success TTY 'configuration can enable pager (from subdir)' ' test_terminal git bundle unbundle ../test.bundle ) && { - test -e paginated.out || - test -e subdir/paginated.out + test_path_is_file paginated.out || + test_path_is_file subdir/paginated.out } ' test_expect_success TTY 'git tag -l defaults to paging' ' rm -f paginated.out && test_terminal git tag -l && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git tag -l respects pager.tag' ' rm -f paginated.out && test_terminal git -c pager.tag=false tag -l && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag -l respects --no-pager' ' rm -f paginated.out && test_terminal git -c pager.tag --no-pager tag -l && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag with no args defaults to paging' ' # no args implies -l so this should page like -l rm -f paginated.out && test_terminal git tag && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git tag with no args respects pager.tag' ' # no args implies -l so this should page like -l rm -f paginated.out && test_terminal git -c pager.tag=false tag && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag --contains defaults to paging' ' # --contains implies -l so this should page like -l rm -f paginated.out && test_terminal git tag --contains && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git tag --contains respects pager.tag' ' # --contains implies -l so this should page like -l rm -f paginated.out && test_terminal git -c pager.tag=false tag --contains && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag -a defaults to not paging' ' test_when_finished "git tag -d newtag" && rm -f paginated.out && test_terminal git tag -am message newtag && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag -a ignores pager.tag' ' test_when_finished "git tag -d newtag" && rm -f paginated.out && test_terminal git -c pager.tag tag -am message newtag && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag -a respects --paginate' ' test_when_finished "git tag -d newtag" && rm -f paginated.out && test_terminal git --paginate tag -am message newtag && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git tag as alias ignores pager.tag with -a' ' test_when_finished "git tag -d newtag" && rm -f paginated.out && test_terminal git -c pager.tag -c alias.t=tag t -am message newtag && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git tag as alias respects pager.tag with -l' ' rm -f paginated.out && test_terminal git -c pager.tag=false -c alias.t=tag t -l && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git branch defaults to paging' ' rm -f paginated.out && test_terminal git branch && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git branch respects pager.branch' ' rm -f paginated.out && test_terminal git -c pager.branch=false branch && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git branch respects --no-pager' ' rm -f paginated.out && test_terminal git --no-pager branch && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git branch --edit-description ignores pager.branch' ' @@ -232,8 +232,8 @@ test_expect_success TTY 'git branch --edit-description ignores pager.branch' ' touch editor.used EOF EDITOR=./editor test_terminal git -c pager.branch branch --edit-description && - ! test -e paginated.out && - test -e editor.used + test_path_is_missing paginated.out && + test_path_is_file editor.used ' test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' ' @@ -242,13 +242,13 @@ test_expect_success TTY 'git branch --set-upstream-to ignores pager.branch' ' test_when_finished "git branch -D other" && test_terminal git -c pager.branch branch --set-upstream-to=other && test_when_finished "git branch --unset-upstream" && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git config ignores pager.config when setting' ' rm -f paginated.out && test_terminal git -c pager.config config foo.bar bar && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git config --edit ignores pager.config' ' @@ -257,33 +257,33 @@ test_expect_success TTY 'git config --edit ignores pager.config' ' touch editor.used EOF EDITOR=./editor test_terminal git -c pager.config config --edit && - ! test -e paginated.out && - test -e editor.used + test_path_is_missing paginated.out && + test_path_is_file editor.used ' test_expect_success TTY 'git config --get ignores pager.config' ' rm -f paginated.out && test_terminal git -c pager.config config --get foo.bar && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git config --get-urlmatch defaults to paging' ' rm -f paginated.out && test_terminal git -c http."https://foo.com/".bar=foo \ config --get-urlmatch http https://foo.com && - test -e paginated.out + test_path_is_file paginated.out ' test_expect_success TTY 'git config --get-all respects pager.config' ' rm -f paginated.out && test_terminal git -c pager.config=false config --get-all foo.bar && - ! test -e paginated.out + test_path_is_missing paginated.out ' test_expect_success TTY 'git config --list defaults to paging' ' rm -f paginated.out && test_terminal git config --list && - test -e paginated.out + test_path_is_file paginated.out ' @@ -392,7 +392,7 @@ test_default_pager() { export PATH && $full_command ) && - test -e default_pager_used + test_path_is_file default_pager_used " } @@ -406,7 +406,7 @@ test_PAGER_overrides() { PAGER='wc >PAGER_used' && export PAGER && $full_command && - test -e PAGER_used + test_path_is_file PAGER_used " } @@ -432,7 +432,7 @@ test_core_pager() { export PAGER && test_config core.pager 'wc >core.pager_used' && $full_command && - ${if_local_config}test -e core.pager_used + ${if_local_config}test_path_is_file core.pager_used " } @@ -464,7 +464,7 @@ test_pager_subdir_helper() { cd sub && $full_command ) && - ${if_local_config}test -e core.pager_used + ${if_local_config}test_path_is_file core.pager_used " } @@ -477,7 +477,7 @@ test_GIT_PAGER_overrides() { GIT_PAGER='wc >GIT_PAGER_used' && export GIT_PAGER && $full_command && - test -e GIT_PAGER_used + test_path_is_file GIT_PAGER_used " } @@ -489,7 +489,7 @@ test_doesnt_paginate() { GIT_PAGER='wc >GIT_PAGER_used' && export GIT_PAGER && $full_command && - ! test -e GIT_PAGER_used + test_path_is_missing GIT_PAGER_used " } diff --git a/t/t7101-reset-empty-subdirs.sh b/t/t7101-reset-empty-subdirs.sh index 96e163f084..bfce05ac5d 100755 --- a/t/t7101-reset-empty-subdirs.sh +++ b/t/t7101-reset-empty-subdirs.sh @@ -6,16 +6,15 @@ test_description='git reset should cull empty subdirs' . ./test-lib.sh -test_expect_success \ - 'creating initial files' \ - 'mkdir path0 && +test_expect_success 'creating initial files' ' + mkdir path0 && cp "$TEST_DIRECTORY"/../COPYING path0/COPYING && git add path0/COPYING && - git commit -m add -a' + git commit -m add -a +' -test_expect_success \ - 'creating second files' \ - 'mkdir path1 && +test_expect_success 'creating second files' ' + mkdir path1 && mkdir path1/path2 && cp "$TEST_DIRECTORY"/../COPYING path1/path2/COPYING && cp "$TEST_DIRECTORY"/../COPYING path1/COPYING && @@ -25,39 +24,40 @@ test_expect_success \ git add path1/COPYING && git add COPYING && git add path0/COPYING-TOO && - git commit -m change -a' + git commit -m change -a +' -test_expect_success \ - 'resetting tree HEAD^' \ - 'git reset --hard HEAD^' +test_expect_success 'resetting tree HEAD^' ' + git reset --hard HEAD^ +' -test_expect_success \ - 'checking initial files exist after rewind' \ - 'test -d path0 && - test -f path0/COPYING' +test_expect_success 'checking initial files exist after rewind' ' + test -d path0 && + test -f path0/COPYING +' -test_expect_success \ - 'checking lack of path1/path2/COPYING' \ - '! test -f path1/path2/COPYING' +test_expect_success 'checking lack of path1/path2/COPYING' ' + ! test -f path1/path2/COPYING +' -test_expect_success \ - 'checking lack of path1/COPYING' \ - '! test -f path1/COPYING' +test_expect_success 'checking lack of path1/COPYING' ' + ! test -f path1/COPYING +' -test_expect_success \ - 'checking lack of COPYING' \ - '! test -f COPYING' +test_expect_success 'checking lack of COPYING' ' + ! test -f COPYING +' -test_expect_success \ - 'checking checking lack of path1/COPYING-TOO' \ - '! test -f path0/COPYING-TOO' +test_expect_success 'checking checking lack of path1/COPYING-TOO' ' + ! test -f path0/COPYING-TOO +' -test_expect_success \ - 'checking lack of path1/path2' \ - '! test -d path1/path2' +test_expect_success 'checking lack of path1/path2' ' + ! test -d path1/path2 +' -test_expect_success \ - 'checking lack of path1' \ - '! test -d path1' +test_expect_success 'checking lack of path1' ' + ! test -d path1 +' test_done diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 22161b3b2d..b1affb001f 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -70,27 +70,27 @@ check_changes () { test_expect_success 'reset --hard message' ' hex=$(git log -1 --format="%h") && - git reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg) > .expected && + git reset --hard >.actual && + echo HEAD is now at $hex $(commit_msg) >.expected && test_i18ncmp .expected .actual ' test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && + git -c "i18n.logOutputEncoding=$test_encoding" reset --hard >.actual && + echo HEAD is now at $hex $(commit_msg $test_encoding) >.expected && test_i18ncmp .expected .actual ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF - test_expect_success 'giving a non existing revision should fail' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF + test_must_fail git reset aaaaaa && test_must_fail git reset --mixed aaaaaa && test_must_fail git reset --soft aaaaaa && @@ -107,8 +107,7 @@ test_expect_success 'reset --soft with unmerged index should fail' ' git rm --cached -- un ' -test_expect_success \ - 'giving paths with options different than --mixed should fail' ' +test_expect_success 'giving paths with options different than --mixed should fail' ' test_must_fail git reset --soft -- first && test_must_fail git reset --hard -- first && test_must_fail git reset --soft HEAD^ -- first && @@ -128,8 +127,7 @@ test_expect_success 'giving unrecognized options should fail' ' check_changes $head5 ' -test_expect_success \ - 'trying to do reset --soft with pending merge should fail' ' +test_expect_success 'trying to do reset --soft with pending merge should fail' ' git branch branch1 && git branch branch2 && @@ -152,8 +150,7 @@ test_expect_success \ check_changes $head5 ' -test_expect_success \ - 'trying to do reset --soft with pending checkout merge should fail' ' +test_expect_success 'trying to do reset --soft with pending checkout merge should fail' ' git branch branch3 && git branch branch4 && @@ -175,8 +172,7 @@ test_expect_success \ check_changes $head5 ' -test_expect_success \ - 'resetting to HEAD with no changes should succeed and do nothing' ' +test_expect_success 'resetting to HEAD with no changes should succeed and do nothing' ' git reset --hard && check_changes $head5 && git reset --hard HEAD && @@ -195,39 +191,38 @@ test_expect_success \ check_changes $head5 ' ->.diff_expect -cat >.cached_expect <<EOF -diff --git a/secondfile b/secondfile -index $head5p1s..$head5s 100644 ---- a/secondfile -+++ b/secondfile -@@ -1 +1,2 @@ --2nd file -+1st line 2nd file -+2nd line 2nd file -EOF -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF test_expect_success '--soft reset only should show changes in diff --cached' ' + >.diff_expect && + cat >.cached_expect <<-EOF && + diff --git a/secondfile b/secondfile + index $head5p1s..$head5s 100644 + --- a/secondfile + +++ b/secondfile + @@ -1 +1,2 @@ + -2nd file + +1st line 2nd file + +2nd line 2nd file + EOF + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git reset --soft HEAD^ && check_changes $head5p1 && test "$(git rev-parse ORIG_HEAD)" = \ $head5 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -3rd line 2nd file -EOF -test_expect_success \ - 'changing files and redo the last commit should succeed' ' +test_expect_success 'changing files and redo the last commit should succeed' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + 3rd line 2nd file + EOF echo "3rd line 2nd file" >>secondfile && git commit -a -C ORIG_HEAD && head4=$(git rev-parse --verify HEAD) && @@ -236,56 +231,54 @@ test_expect_success \ $head5 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -first: -1st file -2nd line 1st file -second: -2nd file -EOF -test_expect_success \ - '--hard reset should change the files and undo commits permanently' ' +test_expect_success '--hard reset should change the files and undo commits permanently' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + first: + 1st file + 2nd line 1st file + second: + 2nd file + EOF git reset --hard HEAD~2 && check_changes $head5p2 && test "$(git rev-parse ORIG_HEAD)" = \ $head4 ' ->.diff_expect -cat >.cached_expect <<EOF -diff --git a/first b/first -deleted file mode 100644 -index $head5p2f..0000000 ---- a/first -+++ /dev/null -@@ -1,2 +0,0 @@ --1st file --2nd line 1st file -diff --git a/second b/second -deleted file mode 100644 -index $head5p1s..0000000 ---- a/second -+++ /dev/null -@@ -1 +0,0 @@ --2nd file -diff --git a/secondfile b/secondfile -new file mode 100644 -index 0000000..$head5s ---- /dev/null -+++ b/secondfile -@@ -0,0 +1,2 @@ -+1st line 2nd file -+2nd line 2nd file -EOF -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF -test_expect_success \ - 'redoing changes adding them without commit them should succeed' ' +test_expect_success 'redoing changes adding them without commit them should succeed' ' + >.diff_expect && + cat >.cached_expect <<-EOF && + diff --git a/first b/first + deleted file mode 100644 + index $head5p2f..0000000 + --- a/first + +++ /dev/null + @@ -1,2 +0,0 @@ + -1st file + -2nd line 1st file + diff --git a/second b/second + deleted file mode 100644 + index $head5p1s..0000000 + --- a/second + +++ /dev/null + @@ -1 +0,0 @@ + -2nd file + diff --git a/secondfile b/secondfile + new file mode 100644 + index 0000000..$head5s + --- /dev/null + +++ b/secondfile + @@ -0,0 +1,2 @@ + +1st line 2nd file + +2nd line 2nd file + EOF + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git rm first && git mv second secondfile && @@ -295,46 +288,45 @@ test_expect_success \ check_changes $head5p2 ' -cat >.diff_expect <<EOF -diff --git a/first b/first -deleted file mode 100644 -index $head5p2f..0000000 ---- a/first -+++ /dev/null -@@ -1,2 +0,0 @@ --1st file --2nd line 1st file -diff --git a/second b/second -deleted file mode 100644 -index $head5p1s..0000000 ---- a/second -+++ /dev/null -@@ -1 +0,0 @@ --2nd file -EOF ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF test_expect_success '--mixed reset to HEAD should unadd the files' ' + cat >.diff_expect <<-EOF && + diff --git a/first b/first + deleted file mode 100644 + index $head5p2f..0000000 + --- a/first + +++ /dev/null + @@ -1,2 +0,0 @@ + -1st file + -2nd line 1st file + diff --git a/second b/second + deleted file mode 100644 + index $head5p1s..0000000 + --- a/second + +++ /dev/null + @@ -1 +0,0 @@ + -2nd file + EOF + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git reset && check_changes $head5p2 && test "$(git rev-parse ORIG_HEAD)" = $head5p2 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF test_expect_success 'redoing the last two commits should succeed' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git add secondfile && git reset --hard $head5p2 && - git rm first && git mv second secondfile && git commit -a -m "remove 1st and rename 2nd" && @@ -347,15 +339,15 @@ test_expect_success 'redoing the last two commits should succeed' ' check_changes $head5 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -3rd line in branch2 -EOF test_expect_success '--hard reset to HEAD should clear a failed merge' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + 3rd line in branch2 + EOF git branch branch1 && git branch branch2 && @@ -373,15 +365,14 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' ' check_changes $head3 ' ->.diff_expect ->.cached_expect -cat >.cat_expect <<EOF -secondfile: -1st line 2nd file -2nd line 2nd file -EOF -test_expect_success \ - '--hard reset to ORIG_HEAD should clear a fast-forward merge' ' +test_expect_success '--hard reset to ORIG_HEAD should clear a fast-forward merge' ' + >.diff_expect && + >.cached_expect && + cat >.cat_expect <<-\EOF && + secondfile: + 1st line 2nd file + 2nd line 2nd file + EOF git reset --hard HEAD^ && check_changes $head5 && @@ -395,25 +386,25 @@ test_expect_success \ ' test_expect_success 'test --mixed <paths>' ' - echo 1 > file1 && - echo 2 > file2 && + echo 1 >file1 && + echo 2 >file2 && git add file1 file2 && test_tick && git commit -m files && before1=$(git rev-parse --short HEAD:file1) && before2=$(git rev-parse --short HEAD:file2) && git rm file2 && - echo 3 > file3 && - echo 4 > file4 && - echo 5 > file1 && + echo 3 >file3 && + echo 4 >file4 && + echo 5 >file1 && after1=$(git rev-parse --short $(git hash-object file1)) && after4=$(git rev-parse --short $(git hash-object file4)) && git add file1 file3 file4 && git reset HEAD -- file1 file2 file3 && test_must_fail git diff --quiet && - git diff > output && + git diff >output && - cat > expect <<-EOF && + cat >expect <<-EOF && diff --git a/file1 b/file1 index $before1..$after1 100644 --- a/file1 @@ -431,9 +422,9 @@ test_expect_success 'test --mixed <paths>' ' EOF test_cmp expect output && - git diff --cached > output && + git diff --cached >output && - cat > cached_expect <<-EOF && + cat >cached_expect <<-EOF && diff --git a/file4 b/file4 new file mode 100644 index 0000000..$after4 @@ -447,7 +438,6 @@ test_expect_success 'test --mixed <paths>' ' ' test_expect_success 'test resetting the index at give paths' ' - mkdir sub && >sub/file1 && >sub/file2 && @@ -460,7 +450,6 @@ test_expect_success 'test resetting the index at give paths' ' echo "$U" && test_must_fail git diff-index --cached --exit-code "$T" && test "$T" != "$U" - ' test_expect_success 'resetting an unmodified path is a no-op' ' @@ -470,14 +459,13 @@ test_expect_success 'resetting an unmodified path is a no-op' ' git diff-index --cached --exit-code HEAD ' -cat > expect << EOF -Unstaged changes after reset: -M file2 -EOF - test_expect_success '--mixed refreshes the index' ' - echo 123 >> file2 && - git reset --mixed HEAD > output && + cat >expect <<-\EOF && + Unstaged changes after reset: + M file2 + EOF + echo 123 >>file2 && + git reset --mixed HEAD >output && test_i18ncmp expect output ' @@ -498,7 +486,6 @@ test_expect_success 'resetting specific path that is unmerged' ' ' test_expect_success 'disambiguation (1)' ' - git reset --hard && >secondfile && git add secondfile && @@ -507,11 +494,9 @@ test_expect_success 'disambiguation (1)' ' test -z "$(git diff --cached --name-only)" && test -f secondfile && test_must_be_empty secondfile - ' test_expect_success 'disambiguation (2)' ' - git reset --hard && >secondfile && git add secondfile && @@ -519,11 +504,9 @@ test_expect_success 'disambiguation (2)' ' test_must_fail git reset secondfile && test -n "$(git diff --cached --name-only -- secondfile)" && test ! -f secondfile - ' test_expect_success 'disambiguation (3)' ' - git reset --hard && >secondfile && git add secondfile && @@ -532,11 +515,9 @@ test_expect_success 'disambiguation (3)' ' test_must_fail git diff --quiet && test -z "$(git diff --cached --name-only)" && test ! -f secondfile - ' test_expect_success 'disambiguation (4)' ' - git reset --hard && >secondfile && git add secondfile && diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 4d62b9b00f..b36a93056f 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -33,8 +33,7 @@ fill () { test_expect_success setup ' - - fill x y z > same && + fill x y z >same && fill 1 2 3 4 5 6 7 8 >one && fill a b c d e >two && git add same one two && @@ -56,14 +55,13 @@ test_expect_success setup ' git checkout -b simple master && rm -f one && - fill a c e > two && + fill a c e >two && git commit -a -m "Simple D one, M two" && git checkout master ' -test_expect_success "checkout from non-existing branch" ' - +test_expect_success 'checkout from non-existing branch' ' git checkout -b delete-me master && git update-ref -d --no-deref refs/heads/delete-me && test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && @@ -71,8 +69,7 @@ test_expect_success "checkout from non-existing branch" ' test refs/heads/master = "$(git symbolic-ref HEAD)" ' -test_expect_success "checkout with dirty tree without -m" ' - +test_expect_success 'checkout with dirty tree without -m' ' fill 0 1 2 3 4 5 6 7 8 >one && if git checkout side then @@ -81,11 +78,9 @@ test_expect_success "checkout with dirty tree without -m" ' else echo "happy - failed correctly" fi - ' -test_expect_success "checkout with unrelated dirty tree without -m" ' - +test_expect_success 'checkout with unrelated dirty tree without -m' ' git checkout -f master && fill 0 1 2 3 4 5 6 7 8 >same && cp same kept && @@ -95,13 +90,12 @@ test_expect_success "checkout with unrelated dirty tree without -m" ' test_cmp messages.expect messages ' -test_expect_success "checkout -m with dirty tree" ' - +test_expect_success 'checkout -m with dirty tree' ' git checkout -f master && git clean -f && fill 0 1 2 3 4 5 6 7 8 >one && - git checkout -m side > messages && + git checkout -m side >messages && test "$(git symbolic-ref HEAD)" = "refs/heads/side" && @@ -120,8 +114,7 @@ test_expect_success "checkout -m with dirty tree" ' test_must_be_empty current.index ' -test_expect_success "checkout -m with dirty tree, renamed" ' - +test_expect_success 'checkout -m with dirty tree, renamed' ' git checkout -f master && git clean -f && fill 1 2 3 4 5 7 8 >one && @@ -139,11 +132,9 @@ test_expect_success "checkout -m with dirty tree, renamed" ' ! test -f one && git diff --cached >current && test_must_be_empty current - ' test_expect_success 'checkout -m with merge conflict' ' - git checkout -f master && git clean -f && fill 1 T 3 4 5 6 S 8 >one && @@ -166,10 +157,10 @@ test_expect_success 'checkout -m with merge conflict' ' ' test_expect_success 'format of merge conflict from checkout -m' ' + git checkout -f master && + git clean -f && - git checkout -f master && git clean -f && - - fill b d > two && + fill b d >two && git checkout -m simple && git ls-files >current && @@ -190,10 +181,11 @@ test_expect_success 'format of merge conflict from checkout -m' ' ' test_expect_success 'checkout --merge --conflict=diff3 <branch>' ' + git checkout -f master && + git reset --hard && + git clean -f && - git checkout -f master && git reset --hard && git clean -f && - - fill b d > two && + fill b d >two && git checkout --merge --conflict=diff3 simple && cat <<-EOF >expect && @@ -216,8 +208,9 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' ' ' test_expect_success 'switch to another branch while carrying a deletion' ' - - git checkout -f master && git reset --hard && git clean -f && + git checkout -f master && + git reset --hard && + git clean -f && git rm two && test_must_fail git checkout simple 2>errs && @@ -228,10 +221,10 @@ test_expect_success 'switch to another branch while carrying a deletion' ' ' test_expect_success 'checkout to detach HEAD (with advice declined)' ' - git config advice.detachedHead false && rev=$(git rev-parse --short renamer^) && - git checkout -f renamer && git clean -f && + git checkout -f renamer && + git clean -f && git checkout renamer^ 2>messages && test_i18ngrep "HEAD is now at $rev" messages && test_line_count = 1 messages && @@ -250,7 +243,8 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' ' test_expect_success 'checkout to detach HEAD' ' git config advice.detachedHead true && rev=$(git rev-parse --short renamer^) && - git checkout -f renamer && git clean -f && + git checkout -f renamer && + git clean -f && GIT_TEST_GETTEXT_POISON=false git checkout renamer^ 2>messages && grep "HEAD is now at $rev" messages && test_line_count -gt 1 messages && @@ -267,8 +261,8 @@ test_expect_success 'checkout to detach HEAD' ' ' test_expect_success 'checkout to detach HEAD with branchname^' ' - - git checkout -f master && git clean -f && + git checkout -f master && + git clean -f && git checkout renamer^ && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -283,8 +277,8 @@ test_expect_success 'checkout to detach HEAD with branchname^' ' ' test_expect_success 'checkout to detach HEAD with :/message' ' - - git checkout -f master && git clean -f && + git checkout -f master && + git clean -f && git checkout ":/Initial" && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -299,8 +293,8 @@ test_expect_success 'checkout to detach HEAD with :/message' ' ' test_expect_success 'checkout to detach HEAD with HEAD^0' ' - - git checkout -f master && git clean -f && + git checkout -f master && + git clean -f && git checkout HEAD^0 && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -315,7 +309,6 @@ test_expect_success 'checkout to detach HEAD with HEAD^0' ' ' test_expect_success 'checkout with ambiguous tag/branch names' ' - git tag both side && git branch both master && git reset --hard && @@ -327,11 +320,9 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' test "z$H" = "z$M" && name=$(git symbolic-ref HEAD 2>/dev/null) && test "z$name" = zrefs/heads/both - ' test_expect_success 'checkout with ambiguous tag/branch names' ' - git reset --hard && git checkout master && @@ -351,26 +342,19 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' else : happy fi - ' test_expect_success 'switch branches while in subdirectory' ' - git reset --hard && git checkout master && mkdir subs && - ( - cd subs && - git checkout side - ) && + git -C subs checkout side && ! test -f subs/one && rm -fr subs - ' test_expect_success 'checkout specific path while in subdirectory' ' - git reset --hard && git checkout side && mkdir subs && @@ -380,30 +364,26 @@ test_expect_success 'checkout specific path while in subdirectory' ' git checkout master && mkdir -p subs && - ( - cd subs && - git checkout side -- bero - ) && + git -C subs checkout side -- bero && test -f subs/bero - ' -test_expect_success \ - 'checkout w/--track sets up tracking' ' +test_expect_success 'checkout w/--track sets up tracking' ' git config branch.autosetupmerge false && git checkout master && git checkout --track -b track1 && test "$(git config branch.track1.remote)" && - test "$(git config branch.track1.merge)"' + test "$(git config branch.track1.merge)" +' -test_expect_success \ - 'checkout w/autosetupmerge=always sets up tracking' ' +test_expect_success 'checkout w/autosetupmerge=always sets up tracking' ' test_when_finished git config branch.autosetupmerge false && git config branch.autosetupmerge always && git checkout master && git checkout -b track2 && test "$(git config branch.track2.remote)" && - test "$(git config branch.track2.merge)"' + test "$(git config branch.track2.merge)" +' test_expect_success 'checkout w/--track from non-branch HEAD fails' ' git checkout master^0 && @@ -435,8 +415,7 @@ test_expect_success 'detach a symbolic link HEAD' ' test "z$(git rev-parse --verify refs/heads/master)" = "z$here" ' -test_expect_success \ - 'checkout with --track fakes a sensible -b <name>' ' +test_expect_success 'checkout with --track fakes a sensible -b <name>' ' git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && git update-ref refs/remotes/origin/koala/bear renamer && @@ -457,9 +436,9 @@ test_expect_success \ test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" ' -test_expect_success \ - 'checkout with --track, but without -b, fails with too short tracked name' ' - test_must_fail git checkout --track renamer' +test_expect_success 'checkout with --track, but without -b, fails with too short tracked name' ' + test_must_fail git checkout --track renamer +' setup_conflicting_index () { rm -f .git/index && @@ -609,7 +588,6 @@ test_expect_success 'failing checkout -b should not break working tree' ' test $(git symbolic-ref HEAD) = refs/heads/master && git diff --exit-code && git diff --cached --exit-code - ' test_expect_success 'switch out of non-branch' ' diff --git a/t/t7518-ident-corner-cases.sh b/t/t7518-ident-corner-cases.sh index dc3e9c8c88..905957bd0a 100755 --- a/t/t7518-ident-corner-cases.sh +++ b/t/t7518-ident-corner-cases.sh @@ -13,7 +13,7 @@ test_expect_success 'empty name and missing email' ' sane_unset GIT_AUTHOR_EMAIL && GIT_AUTHOR_NAME= && test_must_fail git commit --allow-empty -m foo 2>err && - test_i18ngrep ! null err + test_i18ngrep ! "(null)" err ) ' diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 53c883531e..b2def8bb16 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -5,6 +5,7 @@ test_description='git maintenance builtin' . ./test-lib.sh GIT_TEST_COMMIT_GRAPH=0 +GIT_TEST_MULTI_PACK_INDEX=0 test_expect_success 'help text' ' test_expect_code 129 git maintenance -h 2>err && @@ -52,6 +53,43 @@ test_expect_success 'run --task=<task>' ' test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt ' +test_expect_success 'core.commitGraph=false prevents write process' ' + GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \ + git -c core.commitGraph=false maintenance run \ + --task=commit-graph 2>/dev/null && + test_subcommand ! git commit-graph write --split --reachable --no-progress \ + <no-commit-graph.txt +' + +test_expect_success 'commit-graph auto condition' ' + COMMAND="maintenance run --task=commit-graph --auto --quiet" && + + GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \ + git -c maintenance.commit-graph.auto=1 $COMMAND && + GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \ + git -c maintenance.commit-graph.auto="-1" $COMMAND && + + test_commit first && + + GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \ + git -c maintenance.commit-graph.auto=0 $COMMAND && + GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \ + git -c maintenance.commit-graph.auto=1 $COMMAND && + + git commit --allow-empty -m "second" && + git commit --allow-empty -m "third" && + + GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \ + git -c maintenance.commit-graph.auto=2 $COMMAND && + + COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" && + test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt && + test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt && + test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt && + test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt && + test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt +' + test_expect_success 'run --task=bogus' ' test_must_fail git maintenance run --task=bogus 2>err && test_i18ngrep "is not a valid task" err @@ -62,4 +100,188 @@ test_expect_success 'run --task duplicate' ' test_i18ngrep "cannot be selected multiple times" err ' +test_expect_success 'run --task=prefetch with no remotes' ' + git maintenance run --task=prefetch 2>err && + test_must_be_empty err +' + +test_expect_success 'prefetch multiple remotes' ' + git clone . clone1 && + git clone . clone2 && + git remote add remote1 "file://$(pwd)/clone1" && + git remote add remote2 "file://$(pwd)/clone2" && + git -C clone1 switch -c one && + git -C clone2 switch -c two && + test_commit -C clone1 one && + test_commit -C clone2 two && + GIT_TRACE2_EVENT="$(pwd)/run-prefetch.txt" git maintenance run --task=prefetch 2>/dev/null && + fetchargs="--prune --no-tags --no-write-fetch-head --recurse-submodules=no --refmap= --quiet" && + test_subcommand git fetch remote1 $fetchargs +refs/heads/\\*:refs/prefetch/remote1/\\* <run-prefetch.txt && + test_subcommand git fetch remote2 $fetchargs +refs/heads/\\*:refs/prefetch/remote2/\\* <run-prefetch.txt && + test_path_is_missing .git/refs/remotes && + git log prefetch/remote1/one && + git log prefetch/remote2/two && + git fetch --all && + test_cmp_rev refs/remotes/remote1/one refs/prefetch/remote1/one && + test_cmp_rev refs/remotes/remote2/two refs/prefetch/remote2/two +' + +test_expect_success 'loose-objects task' ' + # Repack everything so we know the state of the object dir + git repack -adk && + + # Hack to stop maintenance from running during "git commit" + echo in use >.git/objects/maintenance.lock && + + # Assuming that "git commit" creates at least one loose object + test_commit create-loose-object && + rm .git/objects/maintenance.lock && + + ls .git/objects >obj-dir-before && + test_file_not_empty obj-dir-before && + ls .git/objects/pack/*.pack >packs-before && + test_line_count = 1 packs-before && + + # The first run creates a pack-file + # but does not delete loose objects. + git maintenance run --task=loose-objects && + ls .git/objects >obj-dir-between && + test_cmp obj-dir-before obj-dir-between && + ls .git/objects/pack/*.pack >packs-between && + test_line_count = 2 packs-between && + ls .git/objects/pack/loose-*.pack >loose-packs && + test_line_count = 1 loose-packs && + + # The second run deletes loose objects + # but does not create a pack-file. + git maintenance run --task=loose-objects && + ls .git/objects >obj-dir-after && + cat >expect <<-\EOF && + info + pack + EOF + test_cmp expect obj-dir-after && + ls .git/objects/pack/*.pack >packs-after && + test_cmp packs-between packs-after +' + +test_expect_success 'maintenance.loose-objects.auto' ' + git repack -adk && + GIT_TRACE2_EVENT="$(pwd)/trace-lo1.txt" \ + git -c maintenance.loose-objects.auto=1 maintenance \ + run --auto --task=loose-objects 2>/dev/null && + test_subcommand ! git prune-packed --quiet <trace-lo1.txt && + printf data-A | git hash-object -t blob --stdin -w && + GIT_TRACE2_EVENT="$(pwd)/trace-loA" \ + git -c maintenance.loose-objects.auto=2 \ + maintenance run --auto --task=loose-objects 2>/dev/null && + test_subcommand ! git prune-packed --quiet <trace-loA && + printf data-B | git hash-object -t blob --stdin -w && + GIT_TRACE2_EVENT="$(pwd)/trace-loB" \ + git -c maintenance.loose-objects.auto=2 \ + maintenance run --auto --task=loose-objects 2>/dev/null && + test_subcommand git prune-packed --quiet <trace-loB && + GIT_TRACE2_EVENT="$(pwd)/trace-loC" \ + git -c maintenance.loose-objects.auto=2 \ + maintenance run --auto --task=loose-objects 2>/dev/null && + test_subcommand git prune-packed --quiet <trace-loC +' + +test_expect_success 'incremental-repack task' ' + packDir=.git/objects/pack && + for i in $(test_seq 1 5) + do + test_commit $i || return 1 + done && + + # Create three disjoint pack-files with size BIG, small, small. + echo HEAD~2 | git pack-objects --revs $packDir/test-1 && + test_tick && + git pack-objects --revs $packDir/test-2 <<-\EOF && + HEAD~1 + ^HEAD~2 + EOF + test_tick && + git pack-objects --revs $packDir/test-3 <<-\EOF && + HEAD + ^HEAD~1 + EOF + rm -f $packDir/pack-* && + rm -f $packDir/loose-* && + ls $packDir/*.pack >packs-before && + test_line_count = 3 packs-before && + + # the job repacks the two into a new pack, but does not + # delete the old ones. + git maintenance run --task=incremental-repack && + ls $packDir/*.pack >packs-between && + test_line_count = 4 packs-between && + + # the job deletes the two old packs, and does not write + # a new one because the batch size is not high enough to + # pack the largest pack-file. + git maintenance run --task=incremental-repack && + ls .git/objects/pack/*.pack >packs-after && + test_line_count = 2 packs-after +' + +test_expect_success EXPENSIVE 'incremental-repack 2g limit' ' + for i in $(test_seq 1 5) + do + test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || + return 1 + done && + git add big && + git commit -m "Add big file (1)" && + + # ensure any possible loose objects are in a pack-file + git maintenance run --task=loose-objects && + + rm big && + for i in $(test_seq 6 10) + do + test-tool genrandom foo$i $((512 * 1024 * 1024 + 1)) >>big || + return 1 + done && + git add big && + git commit -m "Add big file (2)" && + + # ensure any possible loose objects are in a pack-file + git maintenance run --task=loose-objects && + + # Now run the incremental-repack task and check the batch-size + GIT_TRACE2_EVENT="$(pwd)/run-2g.txt" git maintenance run \ + --task=incremental-repack 2>/dev/null && + test_subcommand git multi-pack-index repack \ + --no-progress --batch-size=2147483647 <run-2g.txt +' + +test_expect_success 'maintenance.incremental-repack.auto' ' + git repack -adk && + git config core.multiPackIndex true && + git multi-pack-index write && + GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \ + -c maintenance.incremental-repack.auto=1 \ + maintenance run --auto --task=incremental-repack 2>/dev/null && + test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt && + test_commit A && + git pack-objects --revs .git/objects/pack/pack <<-\EOF && + HEAD + ^HEAD~1 + EOF + GIT_TRACE2_EVENT=$(pwd)/trace-A git \ + -c maintenance.incremental-repack.auto=2 \ + maintenance run --auto --task=incremental-repack 2>/dev/null && + test_subcommand ! git multi-pack-index write --no-progress <trace-A && + test_commit B && + git pack-objects --revs .git/objects/pack/pack <<-\EOF && + HEAD + ^HEAD~1 + EOF + GIT_TRACE2_EVENT=$(pwd)/trace-B git \ + -c maintenance.incremental-repack.auto=2 \ + maintenance run --auto --task=incremental-repack 2>/dev/null && + test_subcommand git multi-pack-index write --no-progress <trace-B +' + test_done diff --git a/t/t9304-fast-import-marks.sh b/t/t9304-fast-import-marks.sh new file mode 100755 index 0000000000..d4359dba21 --- /dev/null +++ b/t/t9304-fast-import-marks.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +test_description='test exotic situations with marks' +. ./test-lib.sh + +test_expect_success 'setup dump of basic history' ' + test_commit one && + git fast-export --export-marks=marks HEAD >dump +' + +test_expect_success 'setup large marks file' ' + # normally a marks file would have a lot of useful, unique + # marks. But for our purposes, just having a lot of nonsense + # ones is fine. Start at 1024 to avoid clashing with marks + # legitimately used in our tiny dump. + blob=$(git rev-parse HEAD:one.t) && + for i in $(test_seq 1024 16384) + do + echo ":$i $blob" + done >>marks +' + +test_expect_success 'import with large marks file' ' + git fast-import --import-marks=marks <dump +' + +test_expect_success 'setup dump with submodule' ' + git submodule add "$PWD" sub && + git commit -m "add submodule" && + git fast-export HEAD >dump +' + +test_expect_success 'setup submodule mapping with large id' ' + old=$(git rev-parse HEAD:sub) && + new=$(echo $old | sed s/./a/g) && + echo ":12345 $old" >from && + echo ":12345 $new" >to +' + +test_expect_success 'import with submodule mapping' ' + git init dst && + git -C dst fast-import \ + --rewrite-submodules-from=sub:../from \ + --rewrite-submodules-to=sub:../to \ + <dump && + git -C dst rev-parse HEAD:sub >actual && + echo "$new" >expect && + test_cmp expect actual +' + +test_done diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 7b7bc6e4bd..eb9e56c39e 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1360,6 +1360,58 @@ test_expect_success 'git checkout - a later --no-guess overrides previous --gues EOF ' +test_expect_success 'git checkout - with checkout.guess = false, only completes refs' ' + test_config checkout.guess false && + test_completion "git checkout " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with checkout.guess = true, completes refs and unique remote branches for DWIM' ' + test_config checkout.guess true && + test_completion "git checkout " <<-\EOF + HEAD Z + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --guess overrides previous checkout.guess = false, complete refs and unique remote branches for DWIM' ' + test_config checkout.guess false && + test_completion "git checkout --guess " <<-\EOF + HEAD Z + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --no-guess overrides previous checkout.guess = true, complete only refs' ' + test_config checkout.guess true && + test_completion "git checkout --no-guess " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + test_expect_success 'git switch - with --detach, complete all references' ' test_completion "git switch --detach " <<-\EOF HEAD Z diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 8d59b90348..4a35bde145 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -952,13 +952,7 @@ test_expect_code () { # - not all diff versions understand "-u" test_cmp() { - test $# -eq 2 || BUG "test_cmp requires two arguments" - if ! eval "$GIT_TEST_CMP" '"$@"' - then - test "x$1" = x- || test -e "$1" || BUG "test_cmp '$1' missing" - test "x$2" = x- || test -e "$2" || BUG "test_cmp '$2' missing" - return 1 - fi + eval "$GIT_TEST_CMP" '"$@"' } # Check that the given config key has the expected value. @@ -987,13 +981,7 @@ test_cmp_config() { # test_cmp_bin - helper to compare binary files test_cmp_bin() { - test $# -eq 2 || BUG "test_cmp_bin requires two arguments" - if ! cmp "$@" - then - test "x$1" = x- || test -e "$1" || BUG "test_cmp_bin '$1' missing" - test "x$2" = x- || test -e "$2" || BUG "test_cmp_bin '$2' missing" - return 1 - fi + cmp "$@" } # Use this instead of test_cmp to compare files that contain expected and diff --git a/t/test-lib.sh b/t/test-lib.sh index ef31f40037..f68bca745a 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -769,15 +769,17 @@ match_pattern_list () { } match_test_selector_list () { + operation="$1" + shift title="$1" shift arg="$1" shift test -z "$1" && return 0 - # Both commas and whitespace are accepted as separators. + # Commas are accepted as separators. OLDIFS=$IFS - IFS=' ,' + IFS=',' set -- $1 IFS=$OLDIFS @@ -805,13 +807,13 @@ match_test_selector_list () { *-*) if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null then - echo "error: $title: invalid non-numeric in range" \ + echo "error: $operation: invalid non-numeric in range" \ "start: '$orig_selector'" >&2 exit 1 fi if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null then - echo "error: $title: invalid non-numeric in range" \ + echo "error: $operation: invalid non-numeric in range" \ "end: '$orig_selector'" >&2 exit 1 fi @@ -819,9 +821,11 @@ match_test_selector_list () { *) if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null then - echo "error: $title: invalid non-numeric in test" \ - "selector: '$orig_selector'" >&2 - exit 1 + case "$title" in *${selector}*) + include=$positive + ;; + esac + continue fi esac @@ -1031,7 +1035,7 @@ test_skip () { skipped_reason="GIT_SKIP_TESTS" fi if test -z "$to_skip" && test -n "$run_list" && - ! match_test_selector_list '--run' $test_count "$run_list" + ! match_test_selector_list '--run' "$1" $test_count "$run_list" then to_skip=t skipped_reason="--run" @@ -1058,7 +1062,6 @@ test_skip () { " <skipped message=\"$message\" />" fi - say_color skip >&3 "skipping test: $@" say_color skip "ok $test_count # skip $1 ($skipped_reason)" : true ;; diff --git a/templates/hooks--push-to-checkout.sample b/templates/hooks--push-to-checkout.sample new file mode 100755 index 0000000000..af5a0c0018 --- /dev/null +++ b/templates/hooks--push-to-checkout.sample @@ -0,0 +1,78 @@ +#!/bin/sh + +# An example hook script to update a checked-out tree on a git push. +# +# This hook is invoked by git-receive-pack(1) when it reacts to git +# push and updates reference(s) in its repository, and when the push +# tries to update the branch that is currently checked out and the +# receive.denyCurrentBranch configuration variable is set to +# updateInstead. +# +# By default, such a push is refused if the working tree and the index +# of the remote repository has any difference from the currently +# checked out commit; when both the working tree and the index match +# the current commit, they are updated to match the newly pushed tip +# of the branch. This hook is to be used to override the default +# behaviour; however the code below reimplements the default behaviour +# as a starting point for convenient modification. +# +# The hook receives the commit with which the tip of the current +# branch is going to be updated: +commit=$1 + +# It can exit with a non-zero status to refuse the push (when it does +# so, it must not modify the index or the working tree). +die () { + echo >&2 "$*" + exit 1 +} + +# Or it can make any necessary changes to the working tree and to the +# index to bring them to the desired state when the tip of the current +# branch is updated to the new commit, and exit with a zero status. +# +# For example, the hook can simply run git read-tree -u -m HEAD "$1" +# in order to emulate git fetch that is run in the reverse direction +# with git push, as the two-tree form of git read-tree -u -m is +# essentially the same as git switch or git checkout that switches +# branches while keeping the local changes in the working tree that do +# not interfere with the difference between the branches. + +# The below is a more-or-less exact translation to shell of the C code +# for the default behaviour for git's push-to-checkout hook defined in +# the push_to_deploy() function in builtin/receive-pack.c. +# +# Note that the hook will be executed from the repository directory, +# not from the working tree, so if you want to perform operations on +# the working tree, you will have to adapt your code accordingly, e.g. +# by adding "cd .." or using relative paths. + +if ! git update-index -q --ignore-submodules --refresh +then + die "Up-to-date check failed" +fi + +if ! git diff-files --quiet --ignore-submodules -- +then + die "Working directory has unstaged changes" +fi + +# This is a rough translation of: +# +# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX +if git cat-file -e HEAD 2>/dev/null +then + head=HEAD +else + head=$(git hash-object -t tree --stdin </dev/null) +fi + +if ! git diff-index --quiet --cached --ignore-submodules $head -- +then + die "Working directory has staged changes" +fi + +if ! git read-tree -u -m "$commit" +then + die "Could not update working tree to new HEAD" +fi diff --git a/transport-helper.c b/transport-helper.c index b573b6c730..5f6e0b3bd8 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -827,6 +827,10 @@ static int push_update_ref_status(struct strbuf *buf, status = REF_STATUS_REJECT_STALE; FREE_AND_NULL(msg); } + else if (!strcmp(msg, "remote ref updated since checkout")) { + status = REF_STATUS_REJECT_REMOTE_UPDATED; + FREE_AND_NULL(msg); + } else if (!strcmp(msg, "forced update")) { forced = 1; FREE_AND_NULL(msg); @@ -934,6 +938,11 @@ static void set_common_push_options(struct transport *transport, if (set_helper_option(transport, TRANS_OPT_ATOMIC, "true") != 0) die(_("helper %s does not support --atomic"), name); + if (flags & TRANSPORT_PUSH_FORCE_IF_INCLUDES) + if (set_helper_option(transport, TRANS_OPT_FORCE_IF_INCLUDES, "true") != 0) + die(_("helper %s does not support --%s"), + name, TRANS_OPT_FORCE_IF_INCLUDES); + if (flags & TRANSPORT_PUSH_OPTIONS) { struct string_list_item *item; for_each_string_list_item(item, transport->push_options) @@ -967,6 +976,7 @@ static int push_refs_with_push(struct transport *transport, case REF_STATUS_REJECT_NONFASTFORWARD: case REF_STATUS_REJECT_STALE: case REF_STATUS_REJECT_ALREADY_EXISTS: + case REF_STATUS_REJECT_REMOTE_UPDATED: if (atomic) { reject_atomic_push(remote_refs, mirror); string_list_clear(&cas_options, 0); diff --git a/transport.c b/transport.c index ffe2115845..47da955e4f 100644 --- a/transport.c +++ b/transport.c @@ -633,6 +633,11 @@ static int print_one_push_report(struct ref *ref, const char *dest, int count, "stale info", report, porcelain, summary_width); break; + case REF_STATUS_REJECT_REMOTE_UPDATED: + print_ref_status('!', "[rejected]", ref, ref->peer_ref, + "remote ref updated since checkout", + report, porcelain, summary_width); + break; case REF_STATUS_REJECT_SHALLOW: print_ref_status('!', "[rejected]", ref, ref->peer_ref, "new shallow roots not allowed", @@ -743,6 +748,8 @@ void transport_print_push_status(const char *dest, struct ref *refs, *reject_reasons |= REJECT_FETCH_FIRST; } else if (ref->status == REF_STATUS_REJECT_NEEDS_FORCE) { *reject_reasons |= REJECT_NEEDS_FORCE; + } else if (ref->status == REF_STATUS_REJECT_REMOTE_UPDATED) { + *reject_reasons |= REJECT_REF_NEEDS_UPDATE; } } free(head); @@ -1185,6 +1192,7 @@ static int run_pre_push_hook(struct transport *transport, if (!r->peer_ref) continue; if (r->status == REF_STATUS_REJECT_NONFASTFORWARD) continue; if (r->status == REF_STATUS_REJECT_STALE) continue; + if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue; if (r->status == REF_STATUS_UPTODATE) continue; strbuf_reset(&buf); diff --git a/transport.h b/transport.h index ca409ea1e4..24558c027d 100644 --- a/transport.h +++ b/transport.h @@ -136,6 +136,7 @@ struct transport { #define TRANSPORT_PUSH_ATOMIC (1<<13) #define TRANSPORT_PUSH_OPTIONS (1<<14) #define TRANSPORT_RECURSE_SUBMODULES_ONLY (1<<15) +#define TRANSPORT_PUSH_FORCE_IF_INCLUDES (1<<16) int transport_summary_width(const struct ref *refs); @@ -208,6 +209,9 @@ void transport_check_allowed(const char *type); /* Request atomic (all-or-nothing) updates when pushing */ #define TRANS_OPT_ATOMIC "atomic" +/* Require remote changes to be integrated locally. */ +#define TRANS_OPT_FORCE_IF_INCLUDES "force-if-includes" + /** * Returns 0 if the option was used, non-zero otherwise. Prints a * message to stderr if the option is not used. @@ -217,11 +221,12 @@ int transport_set_option(struct transport *transport, const char *name, void transport_set_verbosity(struct transport *transport, int verbosity, int force_progress); -#define REJECT_NON_FF_HEAD 0x01 -#define REJECT_NON_FF_OTHER 0x02 -#define REJECT_ALREADY_EXISTS 0x04 -#define REJECT_FETCH_FIRST 0x08 -#define REJECT_NEEDS_FORCE 0x10 +#define REJECT_NON_FF_HEAD 0x01 +#define REJECT_NON_FF_OTHER 0x02 +#define REJECT_ALREADY_EXISTS 0x04 +#define REJECT_FETCH_FIRST 0x08 +#define REJECT_NEEDS_FORCE 0x10 +#define REJECT_REF_NEEDS_UPDATE 0x20 int transport_push(struct repository *repo, struct transport *connection, @@ -108,33 +108,33 @@ static int die_is_recursing_builtin(void) /* If we are in a dlopen()ed .so write to a global variable would segfault * (ugh), so keep things static. */ -static NORETURN_PTR void (*usage_routine)(const char *err, va_list params) = usage_builtin; -static NORETURN_PTR void (*die_routine)(const char *err, va_list params) = die_builtin; -static void (*error_routine)(const char *err, va_list params) = error_builtin; -static void (*warn_routine)(const char *err, va_list params) = warn_builtin; +static NORETURN_PTR report_fn usage_routine = usage_builtin; +static NORETURN_PTR report_fn die_routine = die_builtin; +static report_fn error_routine = error_builtin; +static report_fn warn_routine = warn_builtin; static int (*die_is_recursing)(void) = die_is_recursing_builtin; -void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params)) +void set_die_routine(NORETURN_PTR report_fn routine) { die_routine = routine; } -void set_error_routine(void (*routine)(const char *err, va_list params)) +void set_error_routine(report_fn routine) { error_routine = routine; } -void (*get_error_routine(void))(const char *err, va_list params) +report_fn get_error_routine(void) { return error_routine; } -void set_warn_routine(void (*routine)(const char *warn, va_list params)) +void set_warn_routine(report_fn routine) { warn_routine = routine; } -void (*get_warn_routine(void))(const char *warn, va_list params) +report_fn get_warn_routine(void) { return warn_routine; } diff --git a/userdiff.c b/userdiff.c index eb698eaca7..3f81a2261c 100644 --- a/userdiff.c +++ b/userdiff.c @@ -168,7 +168,7 @@ PATTERNS("perl", "|=~|!~" "|<<|<>|<=>|>>"), PATTERNS("php", - "^[\t ]*(((public|protected|private|static)[\t ]+)*function.*)$\n" + "^[\t ]*(((public|protected|private|static|abstract|final)[\t ]+)*function.*)$\n" "^[\t ]*((((final|abstract)[\t ]+)?class|interface|trait).*)$", /* -- */ "[a-zA-Z_][a-zA-Z0-9_]*" @@ -186,7 +186,7 @@ PATTERNS("ruby", "^[ \t]*((class|module|def)[ \t].*)$", "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+|\\?(\\\\C-)?(\\\\M-)?." "|//=?|[-+*/<>%&^|=!]=|<<=?|>>=?|===|\\.{1,3}|::|[!=]~"), PATTERNS("rust", - "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl)[< \t]+[^;]*)$", + "^[\t ]*((pub(\\([^\\)]+\\))?[\t ]+)?((async|const|unsafe|extern([\t ]+\"[^\"]+\"))[\t ]+)?(struct|enum|union|mod|trait|fn|impl|macro_rules!)[< \t]+[^;]*)$", /* -- */ "[a-zA-Z_][a-zA-Z0-9_]*" "|[0-9][0-9_a-fA-Fiosuxz]*(\\.([0-9]*[eE][+-]?)?[0-9_fF]*)?" @@ -221,7 +221,7 @@ PATTERNS("csharp", "|[-+*/<>%&^|=!]=|--|\\+\\+|<<=?|>>=?|&&|\\|\\||::|->"), IPATTERN("css", "![:;][[:space:]]*$\n" - "^[_a-z0-9].*$", + "^[:[@.#]?[_a-z0-9].*$", /* -- */ /* * This regex comes from W3C CSS specs. Should theoretically also diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h index 032e3a9f41..7a04605146 100644 --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@ -79,6 +79,10 @@ typedef struct s_mmbuffer { typedef struct s_xpparam { unsigned long flags; + /* -I<regex> */ + regex_t **ignore_regex; + size_t ignore_regex_nr; + /* See Documentation/diff-options.txt. */ char **anchors; size_t anchors_nr; diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c index bd035139f9..380eb728ed 100644 --- a/xdiff/xdiffi.c +++ b/xdiff/xdiffi.c @@ -998,7 +998,7 @@ static int xdl_call_hunk_func(xdfenv_t *xe, xdchange_t *xscr, xdemitcb_t *ecb, return 0; } -static void xdl_mark_ignorable(xdchange_t *xscr, xdfenv_t *xe, long flags) +static void xdl_mark_ignorable_lines(xdchange_t *xscr, xdfenv_t *xe, long flags) { xdchange_t *xch; @@ -1019,6 +1019,46 @@ static void xdl_mark_ignorable(xdchange_t *xscr, xdfenv_t *xe, long flags) } } +static int record_matches_regex(xrecord_t *rec, xpparam_t const *xpp) { + regmatch_t regmatch; + int i; + + for (i = 0; i < xpp->ignore_regex_nr; i++) + if (!regexec_buf(xpp->ignore_regex[i], rec->ptr, rec->size, 1, + ®match, 0)) + return 1; + + return 0; +} + +static void xdl_mark_ignorable_regex(xdchange_t *xscr, const xdfenv_t *xe, + xpparam_t const *xpp) +{ + xdchange_t *xch; + + for (xch = xscr; xch; xch = xch->next) { + xrecord_t **rec; + int ignore = 1; + long i; + + /* + * Do not override --ignore-blank-lines. + */ + if (xch->ignore) + continue; + + rec = &xe->xdf1.recs[xch->i1]; + for (i = 0; i < xch->chg1 && ignore; i++) + ignore = record_matches_regex(rec[i], xpp); + + rec = &xe->xdf2.recs[xch->i2]; + for (i = 0; i < xch->chg2 && ignore; i++) + ignore = record_matches_regex(rec[i], xpp); + + xch->ignore = ignore; + } +} + int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb) { xdchange_t *xscr; @@ -1038,7 +1078,10 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, } if (xscr) { if (xpp->flags & XDF_IGNORE_BLANK_LINES) - xdl_mark_ignorable(xscr, &xe, xpp->flags); + xdl_mark_ignorable_lines(xscr, &xe, xpp->flags); + + if (xpp->ignore_regex) + xdl_mark_ignorable_regex(xscr, &xe, xpp); if (ef(&xe, xscr, ecb, xecfg) < 0) { diff --git a/xdiff/xhistogram.c b/xdiff/xhistogram.c index c7b35a9667..e694bfd9e3 100644 --- a/xdiff/xhistogram.c +++ b/xdiff/xhistogram.c @@ -235,6 +235,8 @@ static int fall_back_to_classic_diff(xpparam_t const *xpp, xdfenv_t *env, int line1, int count1, int line2, int count2) { xpparam_t xpparam; + + memset(&xpparam, 0, sizeof(xpparam)); xpparam.flags = xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(env, &xpparam, diff --git a/xdiff/xpatience.c b/xdiff/xpatience.c index 3c5601b602..20699a6f60 100644 --- a/xdiff/xpatience.c +++ b/xdiff/xpatience.c @@ -318,6 +318,8 @@ static int fall_back_to_classic_diff(struct hashmap *map, int line1, int count1, int line2, int count2) { xpparam_t xpp; + + memset(&xpp, 0, sizeof(xpp)); xpp.flags = map->xpp->flags & ~XDF_DIFF_ALGORITHM_MASK; return xdl_fall_back_diff(map->env, &xpp, |