diff options
40 files changed, 939 insertions, 336 deletions
diff --git a/Documentation/Makefile b/Documentation/Makefile index f2e7fc1daa..4f801f4e4c 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -94,6 +94,7 @@ TECH_DOCS += MyFirstContribution TECH_DOCS += MyFirstObjectWalk TECH_DOCS += SubmittingPatches TECH_DOCS += ToolsForGit +TECH_DOCS += technical/bitmap-format TECH_DOCS += technical/bundle-format TECH_DOCS += technical/cruft-packs TECH_DOCS += technical/hash-function-transition diff --git a/Documentation/RelNotes/2.30.5.txt b/Documentation/RelNotes/2.30.5.txt new file mode 100644 index 0000000000..5191cab3ae --- /dev/null +++ b/Documentation/RelNotes/2.30.5.txt @@ -0,0 +1,12 @@ +Git v2.30.5 Release Notes +========================= + +This release contains minor fix-ups for the changes that went into +Git 2.30.3 and 2.30.4, addressing CVE-2022-29187. + + * The safety check that verifies a safe ownership of the Git + worktree is now extended to also cover the ownership of the Git + directory (and the `.git` file, if there is any). + +Carlo Marcelo Arenas Belón (1): + setup: tighten ownership checks post CVE-2022-24765 diff --git a/Documentation/RelNotes/2.31.4.txt b/Documentation/RelNotes/2.31.4.txt new file mode 100644 index 0000000000..97a91fd07a --- /dev/null +++ b/Documentation/RelNotes/2.31.4.txt @@ -0,0 +1,6 @@ +Git v2.31.4 Release Notes +========================= + +This release merges up the fixes that appear in v2.30.5 to address +the security issue CVE-2022-29187; see the release notes for that +version for details. diff --git a/Documentation/RelNotes/2.32.3.txt b/Documentation/RelNotes/2.32.3.txt new file mode 100644 index 0000000000..583fabe684 --- /dev/null +++ b/Documentation/RelNotes/2.32.3.txt @@ -0,0 +1,6 @@ +Git v2.32.3 Release Notes +========================= + +This release merges up the fixes that appear in v2.30.5 and +v2.31.4 to address the security issue CVE-2022-29187; see the +release notes for these versions for details. diff --git a/Documentation/RelNotes/2.33.4.txt b/Documentation/RelNotes/2.33.4.txt new file mode 100644 index 0000000000..a145cc25de --- /dev/null +++ b/Documentation/RelNotes/2.33.4.txt @@ -0,0 +1,6 @@ +Git v2.33.4 Release Notes +========================= + +This release merges up the fixes that appear in v2.30.5, v2.31.4 +and v2.32.3 to address the security issue CVE-2022-29187; see +the release notes for these versions for details. diff --git a/Documentation/RelNotes/2.34.4.txt b/Documentation/RelNotes/2.34.4.txt new file mode 100644 index 0000000000..2a6b223403 --- /dev/null +++ b/Documentation/RelNotes/2.34.4.txt @@ -0,0 +1,6 @@ +Git v2.34.4 Release Notes +========================= + +This release merges up the fixes that appear in v2.30.5, v2.31.4, +v2.32.3 and v2.33.4 to address the security issue CVE-2022-29187; +see the release notes for these versions for details. diff --git a/Documentation/RelNotes/2.35.4.txt b/Documentation/RelNotes/2.35.4.txt new file mode 100644 index 0000000000..47abd5ad45 --- /dev/null +++ b/Documentation/RelNotes/2.35.4.txt @@ -0,0 +1,7 @@ +Git v2.35.4 Release Notes +========================= + +This release merges up the fixes that appear in v2.30.5, +v2.31.4, v2.32.3, v2.33.4 and v2.34.4 to address the security +issue CVE-2022-29187; see the release notes for these versions +for details. diff --git a/Documentation/RelNotes/2.36.2.txt b/Documentation/RelNotes/2.36.2.txt index ba5d5acd07..958f5b4102 100644 --- a/Documentation/RelNotes/2.36.2.txt +++ b/Documentation/RelNotes/2.36.2.txt @@ -1,10 +1,16 @@ Git v2.36.2 Release Notes ========================= -This maintenance release is primarily to merge down updates to the -build and CI procedures from the 'master' front, in order to ensure -that we can cut healthy maintenance releases in the future. It also -contains a handful of small and trivially-correct bugfixes. +This release merges up the fixes that appear in v2.30.5, v2.31.4, +v2.32.3, v2.33.4, v2.34.4 and v2.35.4 to address the security +issue CVE-2022-29187; see the release notes for these versions +for details. + +Apart from that, this maintenance release is primarily to merge down +updates to the build and CI procedures from the 'master' front, in +order to ensure that we can cut healthy maintenance releases in the +future. It also contains a handful of small and trivially-correct +bugfixes. Fixes since v2.36.1 ------------------- diff --git a/Documentation/RelNotes/2.37.1.txt b/Documentation/RelNotes/2.37.1.txt new file mode 100644 index 0000000000..84609327d1 --- /dev/null +++ b/Documentation/RelNotes/2.37.1.txt @@ -0,0 +1,17 @@ +Git 2.37.1 Release Notes +======================== + +This release merges up the fixes that appear in v2.30.5, v2.31.4, +v2.32.3, v2.33.4, v2.34.4, v2.35.4, and v2.36.2 to address the +security issue CVE-2022-29187; see the release notes for these +versions for details. + +Fixes since Git 2.37 +-------------------- + + * Rewrite of "git add -i" in C that appeared in Git 2.25 didn't + correctly record a removed file to the index, which is an old + regression but has become widely known because the C version has + become the default in the latest release. + + * Fix for CVS-2022-29187. diff --git a/Documentation/diff-format.txt b/Documentation/diff-format.txt index 7a9c3b6ff4..a3ae8747a2 100644 --- a/Documentation/diff-format.txt +++ b/Documentation/diff-format.txt @@ -43,7 +43,7 @@ That is, from the left to the right: . a space. . sha1 for "src"; 0\{40\} if creation or unmerged. . a space. -. sha1 for "dst"; 0\{40\} if creation, unmerged or "look at work tree". +. sha1 for "dst"; 0\{40\} if deletion, unmerged or "work tree out of sync with the index". . a space. . status, followed by optional "score" number. . a tab or a NUL when `-z` option is used. @@ -69,8 +69,8 @@ percentage of similarity between the source and target of the move or copy). Status letter M may be followed by a score (denoting the percentage of dissimilarity) for file rewrites. -<sha1> is shown as all 0's if a file is new on the filesystem -and it is out of sync with the index. +The sha1 for "dst" is shown as all 0's if a file on the filesystem +is out of sync with the index. Example: diff --git a/Documentation/git-diff-index.txt b/Documentation/git-diff-index.txt index 679cae27d9..c30d8f0da8 100644 --- a/Documentation/git-diff-index.txt +++ b/Documentation/git-diff-index.txt @@ -69,8 +69,8 @@ done an `update-index` to make that effective in the index file. matches my working directory. But doing a 'git diff-index' does: torvalds@ppc970:~/git> git diff-index --cached HEAD - -100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 commit.c - +100644 blob 4161aecc6700a2eb579e842af0b7f22b98443f74 git-commit.c + :100644 000000 4161aecc6700a2eb579e842af0b7f22b98443f74 0000000000000000000000000000000000000000 D commit.c + :000000 100644 0000000000000000000000000000000000000000 4161aecc6700a2eb579e842af0b7f22b98443f74 A git-commit.c You can see easily that the above is a rename. @@ -103,7 +103,7 @@ have not actually done a 'git update-index' on it yet - there is no "object" associated with the new state, and you get: torvalds@ppc970:~/v2.6/linux> git diff-index --abbrev HEAD - :100644 100664 7476bb... 000000... kernel/sched.c + :100644 100644 7476bb5ba 000000000 M kernel/sched.c i.e., it shows that the tree has changed, and that `kernel/sched.c` is not up to date and may contain new stuff. The all-zero sha1 means that to diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt index 262fb01aec..a872ab0fbd 100644 --- a/Documentation/git-rebase.txt +++ b/Documentation/git-rebase.txt @@ -16,40 +16,40 @@ SYNOPSIS DESCRIPTION ----------- -If <branch> is specified, 'git rebase' will perform an automatic +If `<branch>` is specified, `git rebase` will perform an automatic `git switch <branch>` before doing anything else. Otherwise it remains on the current branch. -If <upstream> is not specified, the upstream configured in -branch.<name>.remote and branch.<name>.merge options will be used (see +If `<upstream>` is not specified, the upstream configured in +`branch.<name>.remote` and `branch.<name>.merge` options will be used (see linkgit:git-config[1] for details) and the `--fork-point` option is assumed. If you are currently not on any branch or if the current branch does not have a configured upstream, the rebase will abort. All changes made by commits in the current branch but that are not -in <upstream> are saved to a temporary area. This is the same set +in `<upstream>` are saved to a temporary area. This is the same set of commits that would be shown by `git log <upstream>..HEAD`; or by `git log 'fork_point'..HEAD`, if `--fork-point` is active (see the description on `--fork-point` below); or by `git log HEAD`, if the `--root` option is specified. -The current branch is reset to <upstream>, or <newbase> if the ---onto option was supplied. This has the exact same effect as -`git reset --hard <upstream>` (or <newbase>). ORIG_HEAD is set +The current branch is reset to `<upstream>` or `<newbase>` if the +`--onto` option was supplied. This has the exact same effect as +`git reset --hard <upstream>` (or `<newbase>`). `ORIG_HEAD` is set to point at the tip of the branch before the reset. The commits that were previously saved into the temporary area are then reapplied to the current branch, one by one, in order. Note that -any commits in HEAD which introduce the same textual changes as a commit -in HEAD..<upstream> are omitted (i.e., a patch already accepted upstream +any commits in `HEAD` which introduce the same textual changes as a commit +in `HEAD..<upstream>` are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped). It is possible that a merge failure will prevent this process from being completely automatic. You will have to resolve any such merge failure and run `git rebase --continue`. Another option is to bypass the commit that caused the merge failure with `git rebase --skip`. To check out the -original <branch> and remove the .git/rebase-apply working files, use the -command `git rebase --abort` instead. +original `<branch>` and remove the `.git/rebase-apply` working files, use +the command `git rebase --abort` instead. Assume the following history exists and the current branch is "topic": @@ -79,7 +79,7 @@ remain the checked-out branch. If the upstream branch already contains a change you have made (e.g., because you mailed a patch which was applied upstream), then that commit -will be skipped and warnings will be issued (if the `merge` backend is +will be skipped and warnings will be issued (if the 'merge' backend is used). For example, running `git rebase master` on the following history (in which `A'` and `A` introduce the same set of changes, but have different committer information): @@ -176,11 +176,11 @@ would result in the removal of commits F and G: ------------ This is useful if F and G were flawed in some way, or should not be -part of topicA. Note that the argument to --onto and the <upstream> +part of topicA. Note that the argument to `--onto` and the `<upstream>` parameter can be any valid commit-ish. -In case of conflict, 'git rebase' will stop at the first problematic commit -and leave conflict markers in the tree. You can use 'git diff' to locate +In case of conflict, `git rebase` will stop at the first problematic commit +and leave conflict markers in the tree. You can use `git diff` to locate the markers (<<<<<<) and make edits to resolve the conflict. For each file you edit, you need to tell Git that the conflict has been resolved, typically this would be done with @@ -205,8 +205,8 @@ OPTIONS ------- --onto <newbase>:: Starting point at which to create the new commits. If the - --onto option is not specified, the starting point is - <upstream>. May be any valid commit, and not just an + `--onto` option is not specified, the starting point is + `<upstream>`. May be any valid commit, and not just an existing branch name. + As a special case, you may use "A\...B" as a shortcut for the @@ -215,19 +215,19 @@ leave out at most one of A and B, in which case it defaults to HEAD. --keep-base:: Set the starting point at which to create the new commits to the - merge base of <upstream> and <branch>. Running - 'git rebase --keep-base <upstream> <branch>' is equivalent to + merge base of `<upstream>` and `<branch>`. Running + `git rebase --keep-base <upstream> <branch>` is equivalent to running - 'git rebase --onto <upstream>...<branch> <upstream> <branch>'. + `git rebase --onto <upstream>...<branch> <upstream> <branch>`. + This option is useful in the case where one is developing a feature on top of an upstream branch. While the feature is being worked on, the upstream branch may advance and it may not be the best idea to keep rebasing on top of the upstream but to keep the base commit as-is. + -Although both this option and --fork-point find the merge base between -<upstream> and <branch>, this option uses the merge base as the _starting -point_ on which new commits will be created, whereas --fork-point uses +Although both this option and `--fork-point` find the merge base between +`<upstream>` and `<branch>`, this option uses the merge base as the _starting +point_ on which new commits will be created, whereas `--fork-point` uses the merge base to determine the _set of commits_ which will be rebased. + See also INCOMPATIBLE OPTIONS below. @@ -238,23 +238,23 @@ See also INCOMPATIBLE OPTIONS below. upstream for the current branch. <branch>:: - Working branch; defaults to HEAD. + Working branch; defaults to `HEAD`. --continue:: Restart the rebasing process after having resolved a merge conflict. --abort:: Abort the rebase operation and reset HEAD to the original - branch. If <branch> was provided when the rebase operation was - started, then HEAD will be reset to <branch>. Otherwise HEAD + branch. If `<branch>` was provided when the rebase operation was + started, then `HEAD` will be reset to `<branch>`. Otherwise `HEAD` will be reset to where it was when the rebase operation was started. --quit:: - Abort the rebase operation but HEAD is not reset back to the + Abort the rebase operation but `HEAD` is not reset back to the original branch. The index and working tree are also left unchanged as a result. If a temporary stash entry was created - using --autostash, it will be saved to the stash list. + using `--autostash`, it will be saved to the stash list. --apply:: Use applying strategies to rebase (calling `git-am` @@ -269,16 +269,16 @@ See also INCOMPATIBLE OPTIONS below. empty after rebasing (because they contain a subset of already upstream changes). With drop (the default), commits that become empty are dropped. With keep, such commits are kept. - With ask (implied by --interactive), the rebase will halt when + With ask (implied by `--interactive`), the rebase will halt when an empty commit is applied allowing you to choose whether to drop it, edit files more, or just commit the empty changes. - Other options, like --exec, will use the default of drop unless - -i/--interactive is explicitly specified. + Other options, like `--exec`, will use the default of drop unless + `-i`/`--interactive` is explicitly specified. + -Note that commits which start empty are kept (unless --no-keep-empty +Note that commits which start empty are kept (unless `--no-keep-empty` is specified), and commits which are clean cherry-picks (as determined by `git log --cherry-mark ...`) are detected and dropped as a -preliminary step (unless --reapply-cherry-picks is passed). +preliminary step (unless `--reapply-cherry-picks` is passed). + See also INCOMPATIBLE OPTIONS below. @@ -287,7 +287,7 @@ See also INCOMPATIBLE OPTIONS below. Do not keep commits that start empty before the rebase (i.e. that do not change anything from its parent) in the result. The default is to keep commits which start empty, - since creating such commits requires passing the --allow-empty + since creating such commits requires passing the `--allow-empty` override flag to `git commit`, signifying that a user is very intentionally creating such a commit and thus wants to keep it. @@ -299,7 +299,7 @@ flag exists as a convenient shortcut, such as for cases where external tools generate many empty commits and you want them all removed. + For commits which do not start empty but become empty after rebasing, -see the --empty flag. +see the `--empty` flag. + See also INCOMPATIBLE OPTIONS below. @@ -314,7 +314,7 @@ See also INCOMPATIBLE OPTIONS below. By default (or if `--no-reapply-cherry-picks` is given), these commits will be automatically dropped. Because this necessitates reading all upstream commits, this can be expensive in repos with a large number -of upstream commits that need to be read. When using the `merge` +of upstream commits that need to be read. When using the 'merge' backend, warnings will be issued for each dropped commit (unless `--quiet` is given). Advice will also be issued unless `advice.skippedCherryPicks` is set to false (see linkgit:git-config[1]). @@ -348,10 +348,10 @@ See also INCOMPATIBLE OPTIONS below. Using merging strategies to rebase (default). + Note that a rebase merge works by replaying each commit from the working -branch on top of the <upstream> branch. Because of this, when a merge +branch on top of the `<upstream>` branch. Because of this, when a merge conflict happens, the side reported as 'ours' is the so-far rebased -series, starting with <upstream>, and 'theirs' is the working branch. In -other words, the sides are swapped. +series, starting with `<upstream>`, and 'theirs' is the working branch. +In other words, the sides are swapped. + See also INCOMPATIBLE OPTIONS below. @@ -360,9 +360,9 @@ See also INCOMPATIBLE OPTIONS below. Use the given merge strategy, instead of the default `ort`. This implies `--merge`. + -Because 'git rebase' replays each commit from the working branch -on top of the <upstream> branch using the given strategy, using -the 'ours' strategy simply empties all patches from the <branch>, +Because `git rebase` replays each commit from the working branch +on top of the `<upstream>` branch using the given strategy, using +the `ours` strategy simply empties all patches from the `<branch>`, which makes little sense. + See also INCOMPATIBLE OPTIONS below. @@ -392,11 +392,11 @@ See also INCOMPATIBLE OPTIONS below. -q:: --quiet:: - Be quiet. Implies --no-stat. + Be quiet. Implies `--no-stat`. -v:: --verbose:: - Be verbose. Implies --stat. + Be verbose. Implies `--stat`. --stat:: Show a diffstat of what changed upstream since the last rebase. The @@ -411,13 +411,13 @@ See also INCOMPATIBLE OPTIONS below. --verify:: Allows the pre-rebase hook to run, which is the default. This option can - be used to override --no-verify. See also linkgit:githooks[5]. + be used to override `--no-verify`. See also linkgit:githooks[5]. -C<n>:: - Ensure at least <n> lines of surrounding context match before + Ensure at least `<n>` lines of surrounding context match before and after each change. When fewer lines of surrounding context exist they all must match. By default no context is - ever ignored. Implies --apply. + ever ignored. Implies `--apply`. + See also INCOMPATIBLE OPTIONS below. @@ -436,21 +436,21 @@ details). --fork-point:: --no-fork-point:: - Use reflog to find a better common ancestor between <upstream> - and <branch> when calculating which commits have been - introduced by <branch>. + Use reflog to find a better common ancestor between `<upstream>` + and `<branch>` when calculating which commits have been + introduced by `<branch>`. + -When --fork-point is active, 'fork_point' will be used instead of -<upstream> to calculate the set of commits to rebase, where +When `--fork-point` is active, 'fork_point' will be used instead of +`<upstream>` to calculate the set of commits to rebase, where 'fork_point' is the result of `git merge-base --fork-point <upstream> <branch>` command (see linkgit:git-merge-base[1]). If 'fork_point' -ends up being empty, the <upstream> will be used as a fallback. +ends up being empty, the `<upstream>` will be used as a fallback. + -If <upstream> is given on the command line, then the default is +If `<upstream>` is given on the command line, then the default is `--no-fork-point`, otherwise the default is `--fork-point`. See also `rebase.forkpoint` in linkgit:git-config[1]. + -If your branch was based on <upstream> but <upstream> was rewound and +If your branch was based on `<upstream>` but `<upstream>` was rewound and your branch contains commits which were dropped, this option can be used with `--keep-base` in order to drop those commits from your branch. + @@ -458,24 +458,26 @@ See also INCOMPATIBLE OPTIONS below. --ignore-whitespace:: Ignore whitespace differences when trying to reconcile -differences. Currently, each backend implements an approximation of -this behavior: + differences. Currently, each backend implements an approximation of + this behavior: + -apply backend: When applying a patch, ignore changes in whitespace in -context lines. Unfortunately, this means that if the "old" lines being -replaced by the patch differ only in whitespace from the existing -file, you will get a merge conflict instead of a successful patch -application. +apply backend;; + When applying a patch, ignore changes in whitespace in context + lines. Unfortunately, this means that if the "old" lines being + replaced by the patch differ only in whitespace from the existing + file, you will get a merge conflict instead of a successful patch + application. + -merge backend: Treat lines with only whitespace changes as unchanged -when merging. Unfortunately, this means that any patch hunks that were -intended to modify whitespace and nothing else will be dropped, even -if the other side had no changes that conflicted. +merge backend;; + Treat lines with only whitespace changes as unchanged when merging. + Unfortunately, this means that any patch hunks that were intended + to modify whitespace and nothing else will be dropped, even if the + other side had no changes that conflicted. --whitespace=<option>:: - This flag is passed to the 'git apply' program + This flag is passed to the `git apply` program (see linkgit:git-apply[1]) that applies the patch. - Implies --apply. + Implies `--apply`. + See also INCOMPATIBLE OPTIONS below. @@ -537,7 +539,7 @@ See also REBASING MERGES and INCOMPATIBLE OPTIONS below. -x <cmd>:: --exec <cmd>:: Append "exec <cmd>" after each line creating a commit in the - final history. <cmd> will be interpreted as one or more shell + final history. `<cmd>` will be interpreted as one or more shell commands. Any command that fails will interrupt the rebase, with exit code 1. + @@ -550,7 +552,7 @@ or by giving more than one `--exec`: + git rebase -i --exec "cmd1" --exec "cmd2" --exec ... + -If `--autosquash` is used, "exec" lines will not be appended for +If `--autosquash` is used, `exec` lines will not be appended for the intermediate commits, and will only appear at the end of each squash/fixup series. + @@ -560,11 +562,12 @@ without an explicit `--interactive`. See also INCOMPATIBLE OPTIONS below. --root:: - Rebase all commits reachable from <branch>, instead of - limiting them with an <upstream>. This allows you to rebase - the root commit(s) on a branch. When used with --onto, it - will skip changes already contained in <newbase> (instead of - <upstream>) whereas without --onto it will operate on every change. + Rebase all commits reachable from `<branch>`, instead of + limiting them with an `<upstream>`. This allows you to rebase + the root commit(s) on a branch. When used with `--onto`, it + will skip changes already contained in `<newbase>` (instead of + `<upstream>`) whereas without `--onto` it will operate on every + change. + See also INCOMPATIBLE OPTIONS below. @@ -643,9 +646,9 @@ In addition, the following pairs of options are incompatible: BEHAVIORAL DIFFERENCES ----------------------- -git rebase has two primary backends: apply and merge. (The apply +`git rebase` has two primary backends: 'apply' and 'merge'. (The 'apply' backend used to be known as the 'am' backend, but the name led to -confusion as it looks like a verb instead of a noun. Also, the merge +confusion as it looks like a verb instead of a noun. Also, the 'merge' backend used to be known as the interactive backend, but it is now used for non-interactive cases as well. Both were renamed based on lower-level functionality that underpinned each.) There are some @@ -654,19 +657,19 @@ subtle differences in how these two backends behave: Empty commits ~~~~~~~~~~~~~ -The apply backend unfortunately drops intentionally empty commits, i.e. +The 'apply' backend unfortunately drops intentionally empty commits, i.e. commits that started empty, though these are rare in practice. It also drops commits that become empty and has no option for controlling this behavior. -The merge backend keeps intentionally empty commits by default (though -with -i they are marked as empty in the todo list editor, or they can -be dropped automatically with --no-keep-empty). +The 'merge' backend keeps intentionally empty commits by default (though +with `-i` they are marked as empty in the todo list editor, or they can +be dropped automatically with `--no-keep-empty`). Similar to the apply backend, by default the merge backend drops -commits that become empty unless -i/--interactive is specified (in +commits that become empty unless `-i`/`--interactive` is specified (in which case it stops and asks the user what to do). The merge backend -also has an --empty={drop,keep,ask} option for changing the behavior +also has an `--empty={drop,keep,ask}` option for changing the behavior of handling commits that become empty. Directory rename detection @@ -674,20 +677,20 @@ Directory rename detection Due to the lack of accurate tree information (arising from constructing fake ancestors with the limited information available in -patches), directory rename detection is disabled in the apply backend. +patches), directory rename detection is disabled in the 'apply' backend. Disabled directory rename detection means that if one side of history renames a directory and the other adds new files to the old directory, then the new files will be left behind in the old directory without any warning at the time of rebasing that you may want to move these files into the new directory. -Directory rename detection works with the merge backend to provide you +Directory rename detection works with the 'merge' backend to provide you warnings in such cases. Context ~~~~~~~ -The apply backend works by creating a sequence of patches (by calling +The 'apply' backend works by creating a sequence of patches (by calling `format-patch` internally), and then applying the patches in sequence (calling `am` internally). Patches are composed of multiple hunks, each with line numbers, a context region, and the actual changes. The @@ -698,11 +701,11 @@ order to apply the changes to the right lines. However, if multiple areas of the code have the same surrounding lines of context, the wrong one can be picked. There are real-world cases where this has caused commits to be reapplied incorrectly with no conflicts reported. -Setting diff.context to a larger value may prevent such types of +Setting `diff.context` to a larger value may prevent such types of problems, but increases the chance of spurious conflicts (since it will require more lines of matching context to apply). -The merge backend works with a full copy of each relevant file, +The 'merge' backend works with a full copy of each relevant file, insulating it from these types of problems. Labelling of conflicts markers @@ -710,30 +713,30 @@ Labelling of conflicts markers When there are content conflicts, the merge machinery tries to annotate each side's conflict markers with the commits where the -content came from. Since the apply backend drops the original +content came from. Since the 'apply' backend drops the original information about the rebased commits and their parents (and instead generates new fake commits based off limited information in the generated patches), those commits cannot be identified; instead it has -to fall back to a commit summary. Also, when merge.conflictStyle is -set to diff3 or zdiff3, the apply backend will use "constructed merge +to fall back to a commit summary. Also, when `merge.conflictStyle` is +set to `diff3` or `zdiff3`, the 'apply' backend will use "constructed merge base" to label the content from the merge base, and thus provide no information about the merge base commit whatsoever. -The merge backend works with the full commits on both sides of history +The 'merge' backend works with the full commits on both sides of history and thus has no such limitations. Hooks ~~~~~ -The apply backend has not traditionally called the post-commit hook, -while the merge backend has. Both have called the post-checkout hook, -though the merge backend has squelched its output. Further, both +The 'apply' backend has not traditionally called the post-commit hook, +while the 'merge' backend has. Both have called the post-checkout hook, +though the 'merge' backend has squelched its output. Further, both backends only call the post-checkout hook with the starting point commit of the rebase, not the intermediate commits nor the final commit. In each case, the calling of these hooks was by accident of implementation rather than by design (both backends were originally implemented as shell scripts and happened to invoke other commands -like 'git checkout' or 'git commit' that would call the hooks). Both +like `git checkout` or `git commit` that would call the hooks). Both backends should have the same behavior, though it is not entirely clear which, if any, is correct. We will likely make rebase stop calling either of these hooks in the future. @@ -741,10 +744,10 @@ calling either of these hooks in the future. Interruptability ~~~~~~~~~~~~~~~~ -The apply backend has safety problems with an ill-timed interrupt; if +The 'apply' backend has safety problems with an ill-timed interrupt; if the user presses Ctrl-C at the wrong time to try to abort the rebase, the rebase can enter a state where it cannot be aborted with a -subsequent `git rebase --abort`. The merge backend does not appear to +subsequent `git rebase --abort`. The 'merge' backend does not appear to suffer from the same shortcoming. (See https://lore.kernel.org/git/20200207132152.GC2868@szeder.dev/ for details.) @@ -756,8 +759,8 @@ When a conflict occurs while rebasing, rebase stops and asks the user to resolve. Since the user may need to make notable changes while resolving conflicts, after conflicts are resolved and the user has run `git rebase --continue`, the rebase should open an editor and ask the -user to update the commit message. The merge backend does this, while -the apply backend blindly applies the original commit message. +user to update the commit message. The 'merge' backend does this, while +the 'apply' backend blindly applies the original commit message. Miscellaneous differences ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -777,23 +780,23 @@ completeness: them to stderr. * State directories: The two backends keep their state in different - directories under .git/ + directories under `.git/` include::merge-strategies.txt[] NOTES ----- -You should understand the implications of using 'git rebase' on a +You should understand the implications of using `git rebase` on a repository that you share. See also RECOVERING FROM UPSTREAM REBASE below. -When the git-rebase command is run, it will first execute a "pre-rebase" -hook if one exists. You can use this hook to do sanity checks and -reject the rebase if it isn't appropriate. Please see the template -pre-rebase hook script for an example. +When the rebase is run, it will first execute a `pre-rebase` hook if one +exists. You can use this hook to do sanity checks and reject the rebase +if it isn't appropriate. Please see the template `pre-rebase` hook script +for an example. -Upon completion, <branch> will be the current branch. +Upon completion, `<branch>` will be the current branch. INTERACTIVE MODE ---------------- @@ -848,7 +851,7 @@ not look at them but at the commit names ("deadbee" and "fa1afe1" in this example), so do not delete or edit the names. By replacing the command "pick" with the command "edit", you can tell -'git rebase' to stop after applying that commit, so that you can edit +`git rebase` to stop after applying that commit, so that you can edit the files and/or the commit message, amend the commit, and continue rebasing. @@ -876,14 +879,13 @@ commit, the message from the final one is used. You can also use "fixup -C" to get the same behavior as "fixup -c" except without opening an editor. - -'git rebase' will stop when "pick" has been replaced with "edit" or +`git rebase` will stop when "pick" has been replaced with "edit" or when a command fails due to merge errors. When you are done editing and/or resolving conflicts you can continue with `git rebase --continue`. For example, if you want to reorder the last 5 commits, such that what -was HEAD~4 becomes the new HEAD. To achieve that, you would call -'git rebase' like this: +was `HEAD~4` becomes the new `HEAD`. To achieve that, you would call +`git rebase` like this: ---------------------- $ git rebase -i HEAD~5 @@ -903,7 +905,7 @@ like this: ------------------ Suppose you want to rebase the side branch starting at "A" to "Q". Make -sure that the current HEAD is "B", and call +sure that the current `HEAD` is "B", and call ----------------------------- $ git rebase -i -r --onto Q O @@ -956,23 +958,23 @@ SPLITTING COMMITS ----------------- In interactive mode, you can mark commits with the action "edit". However, -this does not necessarily mean that 'git rebase' expects the result of this +this does not necessarily mean that `git rebase` expects the result of this edit to be exactly one commit. Indeed, you can undo the commit, or you can add other commits. This can be used to split a commit into two: - Start an interactive rebase with `git rebase -i <commit>^`, where - <commit> is the commit you want to split. In fact, any commit range + `<commit>` is the commit you want to split. In fact, any commit range will do, as long as it contains that commit. - Mark the commit you want to split with the action "edit". - When it comes to editing that commit, execute `git reset HEAD^`. The - effect is that the HEAD is rewound by one, and the index follows suit. + effect is that the `HEAD` is rewound by one, and the index follows suit. However, the working tree stays the same. - Now add the changes to the index that you want to have in the first commit. You can use `git add` (possibly interactively) or - 'git gui' (or both) to do that. + `git gui` (or both) to do that. - Commit the now-current index with whatever commit message is appropriate now. @@ -983,7 +985,7 @@ add other commits. This can be used to split a commit into two: If you are not absolutely sure that the intermediate revisions are consistent (they compile, pass the testsuite, etc.) you should use -'git stash' to stash away the not-yet-committed changes +`git stash` to stash away the not-yet-committed changes after each commit, test, and amend the commit if fixes are necessary. @@ -1087,12 +1089,12 @@ NOTE: While an "easy case recovery" sometimes appears to be successful example, a commit that was removed via `git rebase --interactive` will be **resurrected**! -The idea is to manually tell 'git rebase' "where the old 'subsystem' +The idea is to manually tell `git rebase` "where the old 'subsystem' ended and your 'topic' began", that is, what the old merge base between them was. You will have to find a way to name the last commit of the old 'subsystem', for example: -* With the 'subsystem' reflog: after 'git fetch', the old tip of +* With the 'subsystem' reflog: after `git fetch`, the old tip of 'subsystem' is at `subsystem@{1}`. Subsequent fetches will increase the number. (See linkgit:git-reflog[1].) diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index f5f17b65a1..cef8c3c66f 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -283,7 +283,7 @@ The '..' (two-dot) Range Notation:: for commits that are reachable from r2 excluding those that are reachable from r1 by '{caret}r1 r2' and it can be written as 'r1..r2'. -The '...' (three-dot) Symmetric Difference Notation:: +The '\...' (three-dot) Symmetric Difference Notation:: A similar notation 'r1\...r2' is called symmetric difference of 'r1' and 'r2' and is defined as 'r1 r2 --not $(git merge-base --all r1 r2)'. diff --git a/Documentation/technical/bitmap-format.txt b/Documentation/technical/bitmap-format.txt index 04b3ec2178..a85f58f515 100644 --- a/Documentation/technical/bitmap-format.txt +++ b/Documentation/technical/bitmap-format.txt @@ -25,9 +25,9 @@ An object is uniquely described by its bit position within a bitmap: is defined as follows: o1 <= o2 <==> pack(o1) <= pack(o2) /\ offset(o1) <= offset(o2) - - The ordering between packs is done according to the MIDX's .rev file. - Notably, the preferred pack sorts ahead of all other packs. ++ +The ordering between packs is done according to the MIDX's .rev file. +Notably, the preferred pack sorts ahead of all other packs. The on-disk representation (described below) of a bitmap is the same regardless of whether or not that bitmap belongs to a packfile or a MIDX. The only @@ -39,97 +39,108 @@ MIDXs, both the bit-cache and rev-cache extensions are required. == On-disk format - - A header appears at the beginning: - - 4-byte signature: {'B', 'I', 'T', 'M'} - - 2-byte version number (network byte order) - The current implementation only supports version 1 - of the bitmap index (the same one as JGit). - - 2-byte flags (network byte order) - - The following flags are supported: - - - BITMAP_OPT_FULL_DAG (0x1) REQUIRED - This flag must always be present. It implies that the - bitmap index has been generated for a packfile or - multi-pack index (MIDX) with full closure (i.e. where - every single object in the packfile/MIDX can find its - parent links inside the same packfile/MIDX). This is a - requirement for the bitmap index format, also present in - JGit, that greatly reduces the complexity of the - implementation. - - - BITMAP_OPT_HASH_CACHE (0x4) - If present, the end of the bitmap file contains - `N` 32-bit name-hash values, one per object in the - pack/MIDX. The format and meaning of the name-hash is - described below. - - 4-byte entry count (network byte order) - - The total count of entries (bitmapped commits) in this bitmap index. - - 20-byte checksum - - The SHA1 checksum of the pack/MIDX this bitmap index - belongs to. - - - 4 EWAH bitmaps that act as type indexes - - Type indexes are serialized after the hash cache in the shape - of four EWAH bitmaps stored consecutively (see Appendix A for - the serialization format of an EWAH bitmap). - - There is a bitmap for each Git object type, stored in the following - order: - - - Commits - - Trees - - Blobs - - Tags - - In each bitmap, the `n`th bit is set to true if the `n`th object - in the packfile or multi-pack index is of that type. - - The obvious consequence is that the OR of all 4 bitmaps will result - in a full set (all bits set), and the AND of all 4 bitmaps will - result in an empty bitmap (no bits set). - - - N entries with compressed bitmaps, one for each indexed commit - - Where `N` is the total amount of entries in this bitmap index. - Each entry contains the following: - - - 4-byte object position (network byte order) - The position **in the index for the packfile or - multi-pack index** where the bitmap for this commit is - found. - - - 1-byte XOR-offset - The xor offset used to compress this bitmap. For an entry - in position `x`, a XOR offset of `y` means that the actual - bitmap representing this commit is composed by XORing the - bitmap for this entry with the bitmap in entry `x-y` (i.e. - the bitmap `y` entries before this one). - - Note that this compression can be recursive. In order to - XOR this entry with a previous one, the previous entry needs - to be decompressed first, and so on. - - The hard-limit for this offset is 160 (an entry can only be - xor'ed against one of the 160 entries preceding it). This - number is always positive, and hence entries are always xor'ed - with **previous** bitmaps, not bitmaps that will come afterwards - in the index. - - - 1-byte flags for this bitmap - At the moment the only available flag is `0x1`, which hints - that this bitmap can be re-used when rebuilding bitmap indexes - for the repository. - - - The compressed bitmap itself, see Appendix A. + * A header appears at the beginning: + + 4-byte signature: :: {'B', 'I', 'T', 'M'} + + 2-byte version number (network byte order): :: + + The current implementation only supports version 1 + of the bitmap index (the same one as JGit). + + 2-byte flags (network byte order): :: + + The following flags are supported: + + ** {empty} + BITMAP_OPT_FULL_DAG (0x1) REQUIRED: ::: + + This flag must always be present. It implies that the + bitmap index has been generated for a packfile or + multi-pack index (MIDX) with full closure (i.e. where + every single object in the packfile/MIDX can find its + parent links inside the same packfile/MIDX). This is a + requirement for the bitmap index format, also present in + JGit, that greatly reduces the complexity of the + implementation. + + ** {empty} + BITMAP_OPT_HASH_CACHE (0x4): ::: + + If present, the end of the bitmap file contains + `N` 32-bit name-hash values, one per object in the + pack/MIDX. The format and meaning of the name-hash is + described below. + + 4-byte entry count (network byte order): :: + The total count of entries (bitmapped commits) in this bitmap index. + + 20-byte checksum: :: + The SHA1 checksum of the pack/MIDX this bitmap index + belongs to. + + * 4 EWAH bitmaps that act as type indexes ++ +Type indexes are serialized after the hash cache in the shape +of four EWAH bitmaps stored consecutively (see Appendix A for +the serialization format of an EWAH bitmap). ++ +There is a bitmap for each Git object type, stored in the following +order: ++ + - Commits + - Trees + - Blobs + - Tags + ++ +In each bitmap, the `n`th bit is set to true if the `n`th object +in the packfile or multi-pack index is of that type. ++ +The obvious consequence is that the OR of all 4 bitmaps will result +in a full set (all bits set), and the AND of all 4 bitmaps will +result in an empty bitmap (no bits set). + + * N entries with compressed bitmaps, one for each indexed commit ++ +Where `N` is the total amount of entries in this bitmap index. +Each entry contains the following: + + ** {empty} + 4-byte object position (network byte order): :: + The position **in the index for the packfile or + multi-pack index** where the bitmap for this commit is + found. + + ** {empty} + 1-byte XOR-offset: :: + The xor offset used to compress this bitmap. For an entry + in position `x`, a XOR offset of `y` means that the actual + bitmap representing this commit is composed by XORing the + bitmap for this entry with the bitmap in entry `x-y` (i.e. + the bitmap `y` entries before this one). ++ +NOTE: This compression can be recursive. In order to +XOR this entry with a previous one, the previous entry needs +to be decompressed first, and so on. ++ +The hard-limit for this offset is 160 (an entry can only be +xor'ed against one of the 160 entries preceding it). This +number is always positive, and hence entries are always xor'ed +with **previous** bitmaps, not bitmaps that will come afterwards +in the index. + + ** {empty} + 1-byte flags for this bitmap: :: + At the moment the only available flag is `0x1`, which hints + that this bitmap can be re-used when rebuilding bitmap indexes + for the repository. + + ** The compressed bitmap itself, see Appendix A. + + * {empty} + TRAILER: :: + Trailing checksum of the preceding contents. == Appendix A: Serialization format for an EWAH bitmap @@ -142,8 +153,8 @@ implementation: - 4-byte number of words of the COMPRESSED bitmap, when stored - N x 8-byte words, as specified by the previous field - - This is the actual content of the compressed bitmap. ++ +This is the actual content of the compressed bitmap. - 4-byte position of the current RLW for the compressed bitmap diff --git a/GIT-VERSION-GEN b/GIT-VERSION-GEN index b210b306b7..1b2c580ecc 100755 --- a/GIT-VERSION-GEN +++ b/GIT-VERSION-GEN @@ -1,7 +1,7 @@ #!/bin/sh GVF=GIT-VERSION-FILE -DEF_VER=v2.37.0 +DEF_VER=v2.37.1 LF=' ' @@ -1 +1 @@ -Documentation/RelNotes/2.37.0.txt
\ No newline at end of file +Documentation/RelNotes/2.37.1.txt
\ No newline at end of file diff --git a/add-interactive.c b/add-interactive.c index 6047e8f648..22fcd3412c 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -697,8 +697,16 @@ static int run_update(struct add_i_state *s, const struct pathspec *ps, for (i = 0; i < files->items.nr; i++) { const char *name = files->items.items[i].string; - if (files->selected[i] && - add_file_to_index(s->r->index, name, 0) < 0) { + struct stat st; + + if (!files->selected[i]) + continue; + if (lstat(name, &st) && is_missing_file_error(errno)) { + if (remove_file_from_index(s->r->index, name) < 0) { + res = error(_("could not stage '%s'"), name); + break; + } + } else if (add_file_to_index(s->r->index, name, 0) < 0) { res = error(_("could not stage '%s'"), name); break; } diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 2bfaf9ba7a..92cf6e1e92 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -80,9 +80,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix) result = -1; goto cleanup; } -cleanup: result = run_diff_files(&rev, options); result = diff_result_code(&rev.diffopt, result); +cleanup: release_revisions(&rev); return result; } diff --git a/builtin/mktree.c b/builtin/mktree.c index 902edba6d2..06d81400f5 100644 --- a/builtin/mktree.c +++ b/builtin/mktree.c @@ -74,6 +74,7 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing) unsigned mode; enum object_type mode_type; /* object type derived from mode */ enum object_type obj_type; /* object type derived from sha */ + struct object_info oi = OBJECT_INFO_INIT; char *path, *to_free = NULL; struct object_id oid; @@ -116,8 +117,14 @@ static void mktree_line(char *buf, int nul_term_line, int allow_missing) path, ptr, type_name(mode_type)); } - /* Check the type of object identified by sha1 */ - obj_type = oid_object_info(the_repository, &oid, NULL); + /* Check the type of object identified by oid without fetching objects */ + oi.typep = &obj_type; + if (oid_object_info_extended(the_repository, &oid, &oi, + OBJECT_INFO_LOOKUP_REPLACE | + OBJECT_INFO_QUICK | + OBJECT_INFO_SKIP_FETCH_OBJECT) < 0) + obj_type = -1; + if (obj_type < 0) { if (allow_missing) { ; /* no problem - missing objects are presumed to be of the right type */ diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 35825f075e..086dfee45a 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -443,7 +443,7 @@ void shortlog_output(struct shortlog *log) struct strbuf sb = STRBUF_INIT; if (log->sort_by_number) - QSORT(log->list.items, log->list.nr, + STABLE_QSORT(log->list.items, log->list.nr, log->summary ? compare_by_counter : compare_by_list); for (i = 0; i < log->list.nr; i++) { const struct string_list_item *item = &log->list.items[i]; diff --git a/combine-diff.c b/combine-diff.c index b724f02123..b0ece95480 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -1498,6 +1498,13 @@ void diff_tree_combined(const struct object_id *oid, int i, num_paths, needsep, show_log_first, num_parent = parents->nr; int need_generic_pathscan; + if (opt->ignore_regex_nr) + die("combined diff and '%s' cannot be used together", + "--ignore-matching-lines"); + if (opt->close_file) + die("combined diff and '%s' cannot be used together", + "--output"); + /* nothing to do, if no parents */ if (!num_parent) return; diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index f139fd8644..521d303722 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -25,8 +25,12 @@ cat >.vscode/settings.json.new <<\EOF || "editor.detectIndentation": false, "editor.insertSpaces": false, "editor.tabSize": 8, - "editor.wordWrap": "wordWrapColumn", - "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + }, + "[txt]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, "files.trimTrailingWhitespace": true }, "files.associations": { @@ -1861,7 +1861,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, */ enum path_treatment state; int matches_how = 0; - int nested_repo = 0, check_only, stop_early; + int check_only, stop_early; int old_ignored_nr, old_untracked_nr; /* The "len-1" is to strip the final '/' */ enum exist_status status = directory_exists_in_index(istate, dirname, len-1); @@ -1893,16 +1893,37 @@ static enum path_treatment treat_directory(struct dir_struct *dir, if ((dir->flags & DIR_SKIP_NESTED_GIT) || !(dir->flags & DIR_NO_GITLINKS)) { + /* + * Determine if `dirname` is a nested repo by confirming that: + * 1) we are in a nonbare repository, and + * 2) `dirname` is not an immediate parent of `the_repository->gitdir`, + * which could occur if the git_dir or worktree location was + * manually configured by the user; see t2205 testcases 1-3 for + * examples where this matters + */ + int nested_repo; struct strbuf sb = STRBUF_INIT; strbuf_addstr(&sb, dirname); nested_repo = is_nonbare_repository_dir(&sb); + + if (nested_repo) { + char *real_dirname, *real_gitdir; + strbuf_addstr(&sb, ".git"); + real_dirname = real_pathdup(sb.buf, 1); + real_gitdir = real_pathdup(the_repository->gitdir, 1); + + nested_repo = !!strcmp(real_dirname, real_gitdir); + free(real_gitdir); + free(real_dirname); + } strbuf_release(&sb); - } - if (nested_repo) { - if ((dir->flags & DIR_SKIP_NESTED_GIT) || - (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC)) - return path_none; - return excluded ? path_excluded : path_untracked; + + if (nested_repo) { + if ((dir->flags & DIR_SKIP_NESTED_GIT) || + (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC)) + return path_none; + return excluded ? path_excluded : path_untracked; + } } if (!(dir->flags & DIR_SHOW_OTHER_DIRECTORIES)) { diff --git a/merge-ort.c b/merge-ort.c index b5015b9afd..8c4927f0e1 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -2260,6 +2260,27 @@ static void compute_collisions(struct strmap *collisions, } } +static void free_collisions(struct strmap *collisions) +{ + struct hashmap_iter iter; + struct strmap_entry *entry; + + /* Free each value in the collisions map */ + strmap_for_each_entry(collisions, &iter, entry) { + struct collision_info *info = entry->value; + string_list_clear(&info->source_files, 0); + } + /* + * In compute_collisions(), we set collisions.strdup_strings to 0 + * so that we wouldn't have to make another copy of the new_path + * allocated by apply_dir_rename(). But now that we've used them + * and have no other references to these strings, it is time to + * deallocate them. + */ + free_strmap_strings(collisions); + strmap_clear(collisions, 1); +} + static char *check_for_directory_rename(struct merge_options *opt, const char *path, unsigned side_index, @@ -2268,18 +2289,23 @@ static char *check_for_directory_rename(struct merge_options *opt, struct strmap *collisions, int *clean_merge) { - char *new_path = NULL; + char *new_path; struct strmap_entry *rename_info; - struct strmap_entry *otherinfo = NULL; + struct strmap_entry *otherinfo; const char *new_dir; + int other_side = 3 - side_index; + /* + * Cases where we don't have or don't want a directory rename for + * this path. + */ if (strmap_empty(dir_renames)) - return new_path; + return NULL; + if (strmap_get(&collisions[other_side], path)) + return NULL; rename_info = check_dir_renamed(path, dir_renames); if (!rename_info) - return new_path; - /* old_dir = rename_info->key; */ - new_dir = rename_info->value; + return NULL; /* * This next part is a little weird. We do not want to do an @@ -2305,6 +2331,7 @@ static char *check_for_directory_rename(struct merge_options *opt, * As it turns out, this also prevents N-way transient rename * confusion; See testcases 9c and 9d of t6043. */ + new_dir = rename_info->value; /* old_dir = rename_info->key; */ otherinfo = strmap_get_entry(dir_rename_exclusions, new_dir); if (otherinfo) { path_msg(opt, rename_info->key, 1, @@ -2315,7 +2342,8 @@ static char *check_for_directory_rename(struct merge_options *opt, } new_path = handle_path_level_conflicts(opt, path, side_index, - rename_info, collisions); + rename_info, + &collisions[side_index]); *clean_merge &= (new_path != NULL); return new_path; @@ -3024,18 +3052,15 @@ static int detect_regular_renames(struct merge_options *opt, static int collect_renames(struct merge_options *opt, struct diff_queue_struct *result, unsigned side_index, + struct strmap *collisions, struct strmap *dir_renames_for_side, struct strmap *rename_exclusions) { int i, clean = 1; - struct strmap collisions; struct diff_queue_struct *side_pairs; - struct hashmap_iter iter; - struct strmap_entry *entry; struct rename_info *renames = &opt->priv->renames; side_pairs = &renames->pairs[side_index]; - compute_collisions(&collisions, dir_renames_for_side, side_pairs); for (i = 0; i < side_pairs->nr; ++i) { struct diff_filepair *p = side_pairs->queue[i]; @@ -3051,7 +3076,7 @@ static int collect_renames(struct merge_options *opt, side_index, dir_renames_for_side, rename_exclusions, - &collisions, + collisions, &clean); possibly_cache_new_pair(renames, p, side_index, new_path); @@ -3077,20 +3102,6 @@ static int collect_renames(struct merge_options *opt, result->queue[result->nr++] = p; } - /* Free each value in the collisions map */ - strmap_for_each_entry(&collisions, &iter, entry) { - struct collision_info *info = entry->value; - string_list_clear(&info->source_files, 0); - } - /* - * In compute_collisions(), we set collisions.strdup_strings to 0 - * so that we wouldn't have to make another copy of the new_path - * allocated by apply_dir_rename(). But now that we've used them - * and have no other references to these strings, it is time to - * deallocate them. - */ - free_strmap_strings(&collisions); - strmap_clear(&collisions, 1); return clean; } @@ -3101,6 +3112,7 @@ static int detect_and_process_renames(struct merge_options *opt, { struct diff_queue_struct combined = { 0 }; struct rename_info *renames = &opt->priv->renames; + struct strmap collisions[3]; int need_dir_renames, s, i, clean = 1; unsigned detection_run = 0; @@ -3150,12 +3162,22 @@ static int detect_and_process_renames(struct merge_options *opt, ALLOC_GROW(combined.queue, renames->pairs[1].nr + renames->pairs[2].nr, combined.alloc); + for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) { + int other_side = 3 - i; + compute_collisions(&collisions[i], + &renames->dir_renames[other_side], + &renames->pairs[i]); + } clean &= collect_renames(opt, &combined, MERGE_SIDE1, + collisions, &renames->dir_renames[2], &renames->dir_renames[1]); clean &= collect_renames(opt, &combined, MERGE_SIDE2, + collisions, &renames->dir_renames[1], &renames->dir_renames[2]); + for (i = MERGE_SIDE1; i <= MERGE_SIDE2; i++) + free_collisions(&collisions[i]); STABLE_QSORT(combined.queue, combined.nr, compare_pairs); trace2_region_leave("merge", "directory renames", opt->repo); diff --git a/mergetools/vimdiff b/mergetools/vimdiff index 461a89b6f9..f770b8fe24 100644 --- a/mergetools/vimdiff +++ b/mergetools/vimdiff @@ -228,14 +228,14 @@ gen_cmd_aux () { elif ! test -z "$index_horizontal_split" then - before="split" + before="leftabove split" after="wincmd j" index=$index_horizontal_split terminate="true" elif ! test -z "$index_vertical_split" then - before="vertical split" + before="leftabove vertical split" after="wincmd l" index=$index_vertical_split terminate="true" @@ -310,7 +310,7 @@ gen_cmd () { # # gen_cmd "@LOCAL , REMOTE" # | - # `-> FINAL_CMD == "-c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + # `-> FINAL_CMD == "-c \"echo | leftabove vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" # FINAL_TARGET == "LOCAL" LAYOUT=$1 @@ -414,8 +414,8 @@ merge_cmd () { if $base_present then - eval "$merge_tool_path" \ - -f "$FINAL_CMD" "$LOCAL" "$BASE" "$REMOTE" "$MERGED" + eval '"$merge_tool_path"' \ + -f "$FINAL_CMD" '"$LOCAL"' '"$BASE"' '"$REMOTE"' '"$MERGED"' else # If there is no BASE (example: a merge conflict in a new file # with the same name created in both braches which didn't exist @@ -424,8 +424,8 @@ merge_cmd () { FINAL_CMD=$(echo "$FINAL_CMD" | \ sed -e 's:2b:quit:g' -e 's:3b:2b:g' -e 's:4b:3b:g') - eval "$merge_tool_path" \ - -f "$FINAL_CMD" "$LOCAL" "$REMOTE" "$MERGED" + eval '"$merge_tool_path"' \ + -f "$FINAL_CMD" '"$LOCAL"' '"$REMOTE"' '"$MERGED"' fi ret="$?" @@ -555,22 +555,22 @@ run_unit_tests () { TEST_CASE_15=" (( (LOCAL , BASE , REMOTE) / MERGED)) +(BASE) , LOCAL+ BASE , REMOTE+ (((LOCAL / BASE / REMOTE)) , MERGED ) " TEST_CASE_16="LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL / BASE / REMOTE),MERGED" - EXPECTED_CMD_01="-c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_02="-c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_03="-c \"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_01="-c \"echo | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_02="-c \"echo | leftabove vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_03="-c \"echo | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" EXPECTED_CMD_04="-c \"echo | 4b | bufdo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_05="-c \"echo | split | 1b | wincmd j | split | 4b | wincmd j | 3b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_06="-c \"echo | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_07="-c \"echo | vertical split | 4b | wincmd l | split | 1b | wincmd j | 3b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_08="-c \"echo | split | vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_09="-c \"echo | split | 4b | wincmd j | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_10="-c \"echo | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_11="-c \"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_12="-c \"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_13="-c \"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_14="-c \"echo | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_15="-c \"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" - EXPECTED_CMD_16="-c \"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_05="-c \"echo | leftabove split | 1b | wincmd j | leftabove split | 4b | wincmd j | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_06="-c \"echo | leftabove vertical split | leftabove split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_07="-c \"echo | leftabove vertical split | 4b | wincmd l | leftabove split | 1b | wincmd j | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_08="-c \"echo | leftabove split | leftabove vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_09="-c \"echo | leftabove split | 4b | wincmd j | leftabove vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_10="-c \"echo | leftabove vertical split | leftabove split | 1b | wincmd j | leftabove split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_11="-c \"echo | -tabnew | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 3b | tabnext | leftabove vertical split | leftabove split | 1b | wincmd j | leftabove split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_12="-c \"echo | leftabove vertical split | leftabove split | leftabove vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_13="-c \"echo | leftabove vertical split | leftabove split | leftabove vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | leftabove vertical split | leftabove split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_14="-c \"echo | -tabnew | leftabove vertical split | 2b | wincmd l | 3b | tabnext | leftabove vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_15="-c \"echo | -tabnew | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 3b | tabnext | leftabove vertical split | leftabove split | 1b | wincmd j | leftabove split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" + EXPECTED_CMD_16="-c \"echo | -tabnew | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | leftabove vertical split | 2b | wincmd l | 3b | tabnext | leftabove vertical split | leftabove split | 1b | wincmd j | leftabove split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\" -c \"tabfirst\"" EXPECTED_TARGET_01="MERGED" EXPECTED_TARGET_02="LOCAL" @@ -614,6 +614,37 @@ run_unit_tests () { fi done + # verify that `merge_cmd` handles paths with spaces + record_parameters () { + >actual + for arg + do + echo "$arg" >>actual + done + } + + base_present=false + LOCAL='lo cal' + BASE='ba se' + REMOTE="' '" + MERGED='mer ged' + merge_tool_path=record_parameters + + merge_cmd vimdiff || at_least_one_ko=true + + cat >expect <<-\EOF + -f + -c + echo | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | quit | wincmd l | 2b | wincmd j | 3b | tabdo windo diffthis + -c + tabfirst + lo cal + ' ' + mer ged + EOF + + diff -u expect actual || at_least_one_ko=true + if test "$at_least_one_ko" = "true" then return 255 diff --git a/pack-objects.h b/pack-objects.h index 393b9db546..579476687c 100644 --- a/pack-objects.h +++ b/pack-objects.h @@ -116,16 +116,6 @@ struct object_entry { unsigned dfs_state:OE_DFS_STATE_BITS; unsigned depth:OE_DEPTH_BITS; unsigned ext_base:1; /* delta_idx points outside packlist */ - - /* - * pahole results on 64-bit linux (gcc and clang) - * - * size: 80, bit_padding: 9 bits - * - * and on 32-bit (gcc) - * - * size: 76, bit_padding: 9 bits - */ }; struct packing_data { @@ -1129,14 +1129,32 @@ static int safe_directory_cb(const char *key, const char *value, void *d) return 0; } -static int ensure_valid_ownership(const char *path) +/* + * Check if a repository is safe, by verifying the ownership of the + * worktree (if any), the git directory, and the gitfile (if any). + * + * Exemptions for known-safe repositories can be added via `safe.directory` + * config settings; for non-bare repositories, their worktree needs to be + * added, for bare ones their git directory. + */ +static int ensure_valid_ownership(const char *gitfile, + const char *worktree, const char *gitdir) { - struct safe_directory_data data = { .path = path }; + struct safe_directory_data data = { + .path = worktree ? worktree : gitdir + }; if (!git_env_bool("GIT_TEST_ASSUME_DIFFERENT_OWNER", 0) && - is_path_owned_by_current_user(path)) + (!gitfile || is_path_owned_by_current_user(gitfile)) && + (!worktree || is_path_owned_by_current_user(worktree)) && + (!gitdir || is_path_owned_by_current_user(gitdir))) return 1; + /* + * data.path is the "path" that identifies the repository and it is + * constant regardless of what failed above. data.is_safe should be + * initialized to false, and might be changed by the callback. + */ read_very_early_config(safe_directory_cb, &data); return data.is_safe; @@ -1224,6 +1242,8 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, current_device = get_device_or_die(dir->buf, NULL, 0); for (;;) { int offset = dir->len, error_code = 0; + char *gitdir_path = NULL; + char *gitfile = NULL; if (offset > min_offset) strbuf_addch(dir, '/'); @@ -1234,21 +1254,50 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir, if (die_on_error || error_code == READ_GITFILE_ERR_NOT_A_FILE) { /* NEEDSWORK: fail if .git is not file nor dir */ - if (is_git_directory(dir->buf)) + if (is_git_directory(dir->buf)) { gitdirenv = DEFAULT_GIT_DIR_ENVIRONMENT; + gitdir_path = xstrdup(dir->buf); + } } else if (error_code != READ_GITFILE_ERR_STAT_FAILED) return GIT_DIR_INVALID_GITFILE; - } + } else + gitfile = xstrdup(dir->buf); + /* + * Earlier, we tentatively added DEFAULT_GIT_DIR_ENVIRONMENT + * to check that directory for a repository. + * Now trim that tentative addition away, because we want to + * focus on the real directory we are in. + */ strbuf_setlen(dir, offset); if (gitdirenv) { - if (!ensure_valid_ownership(dir->buf)) - return GIT_DIR_INVALID_OWNERSHIP; - strbuf_addstr(gitdir, gitdirenv); - return GIT_DIR_DISCOVERED; + enum discovery_result ret; + + if (ensure_valid_ownership(gitfile, + dir->buf, + (gitdir_path ? gitdir_path : gitdirenv))) { + strbuf_addstr(gitdir, gitdirenv); + ret = GIT_DIR_DISCOVERED; + } else + ret = GIT_DIR_INVALID_OWNERSHIP; + + /* + * Earlier, during discovery, we might have allocated + * string copies for gitdir_path or gitfile so make + * sure we don't leak by freeing them now, before + * leaving the loop and function. + * + * Note: gitdirenv will be non-NULL whenever these are + * allocated, therefore we need not take care of releasing + * them outside of this conditional block. + */ + free(gitdir_path); + free(gitfile); + + return ret; } if (is_git_directory(dir->buf)) { - if (!ensure_valid_ownership(dir->buf)) + if (!ensure_valid_ownership(NULL, NULL, dir->buf)) return GIT_DIR_INVALID_OWNERSHIP; strbuf_addstr(gitdir, "."); return GIT_DIR_BARE; @@ -1386,7 +1435,7 @@ const char *setup_git_directory_gently(int *nongit_ok) struct strbuf quoted = STRBUF_INIT; sq_quote_buf_pretty("ed, dir.buf); - die(_("unsafe repository ('%s' is owned by someone else)\n" + die(_("detected dubious ownership in repository at '%s'\n" "To add an exception for this directory, call:\n" "\n" "\tgit config --global --add safe.directory %s"), @@ -1402,7 +1451,7 @@ const char *setup_git_directory_gently(int *nongit_ok) * find a repository. */ default: - BUG("unhandled setup_git_directory_1() result"); + BUG("unhandled setup_git_directory_gently_1() result"); } /* diff --git a/t/t0033-safe-directory.sh b/t/t0033-safe-directory.sh index 238b25f91a..3908597d42 100755 --- a/t/t0033-safe-directory.sh +++ b/t/t0033-safe-directory.sh @@ -9,7 +9,7 @@ export GIT_TEST_ASSUME_DIFFERENT_OWNER expect_rejected_dir () { test_must_fail git status 2>err && - grep "unsafe repository" err + grep "dubious ownership" err } test_expect_success 'safe.directory is not set' ' @@ -18,7 +18,7 @@ test_expect_success 'safe.directory is not set' ' test_expect_success 'ignoring safe.directory on the command line' ' test_must_fail git -c safe.directory="$(pwd)" status 2>err && - grep "unsafe repository" err + grep "dubious ownership" err ' test_expect_success 'ignoring safe.directory in the environment' ' @@ -26,14 +26,14 @@ test_expect_success 'ignoring safe.directory in the environment' ' GIT_CONFIG_KEY_0="safe.directory" \ GIT_CONFIG_VALUE_0="$(pwd)" \ git status 2>err && - grep "unsafe repository" err + grep "dubious ownership" err ' test_expect_success 'ignoring safe.directory in GIT_CONFIG_PARAMETERS' ' test_must_fail env \ GIT_CONFIG_PARAMETERS="${SQ}safe.directory${SQ}=${SQ}$(pwd)${SQ}" \ git status 2>err && - grep "unsafe repository" err + grep "dubious ownership" err ' test_expect_success 'ignoring safe.directory in repo config' ' diff --git a/t/t1300-config.sh b/t/t1300-config.sh index d3d9adbb3d..c6661e61af 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2083,12 +2083,13 @@ test_expect_success '--show-scope with --show-origin' ' ' test_expect_success 'override global and system config' ' - test_when_finished rm -f "$HOME"/.config/git && - + test_when_finished rm -f \"\$HOME\"/.gitconfig && cat >"$HOME"/.gitconfig <<-EOF && [home] config = true EOF + + test_when_finished rm -rf \"\$HOME\"/.config/git && mkdir -p "$HOME"/.config/git && cat >"$HOME"/.config/git/config <<-EOF && [xdg] diff --git a/t/t2205-add-worktree-config.sh b/t/t2205-add-worktree-config.sh new file mode 100755 index 0000000000..43d950de64 --- /dev/null +++ b/t/t2205-add-worktree-config.sh @@ -0,0 +1,265 @@ +#!/bin/sh + +test_description='directory traversal respects user config + +This test verifies the traversal of the directory tree when the traversal begins +outside the repository. Two instances for which this can occur are tested: + + 1) The user manually sets the worktree. For this instance, the test sets + the worktree two levels above the `.git` directory and checks whether we + are able to add to the index those files that are in either (1) the + manually configured worktree directory or (2) the standard worktree + location with respect to the `.git` directory (i.e. ensuring that the + encountered `.git` directory is not treated as belonging to a foreign + nested repository). + 2) The user manually sets the `git_dir` while the working directory is + outside the repository. The test checks that files inside the + repository can be added to the index. + ' + +. ./test-lib.sh + +test_expect_success '1a: setup--config worktree' ' + mkdir test1 && + ( + cd test1 && + test_create_repo repo && + git --git-dir="repo/.git" config core.worktree "$(pwd)" && + + mkdir -p outside-tracked outside-untracked && + mkdir -p repo/inside-tracked repo/inside-untracked && + >file-tracked && + >file-untracked && + >outside-tracked/file && + >outside-untracked/file && + >repo/file-tracked && + >repo/file-untracked && + >repo/inside-tracked/file && + >repo/inside-untracked/file && + + cat >expect-tracked-unsorted <<-EOF && + ../file-tracked + ../outside-tracked/file + file-tracked + inside-tracked/file + EOF + + cat >expect-untracked-unsorted <<-EOF && + ../file-untracked + ../outside-untracked/file + file-untracked + inside-untracked/file + EOF + + cat >expect-all-dir-unsorted <<-EOF && + ../file-untracked + ../file-tracked + ../outside-untracked/ + ../outside-tracked/ + ./ + EOF + + cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && + + cat >.gitignore <<-EOF + .gitignore + actual-* + expect-* + EOF + ) +' + +test_expect_success '1b: pre-add all' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-all-unsorted && + sort actual-all-unsorted >actual-all && + sort expect-all-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '1c: pre-add dir all' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --directory --exclude-standard "$parent_dir" >actual-all-dir-unsorted && + sort actual-all-dir-unsorted >actual-all && + sort expect-all-dir-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '1d: post-add tracked' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + ( + cd repo && + git add file-tracked && + git add inside-tracked && + git add ../outside-tracked && + git add "$parent_dir/file-tracked" && + git ls-files "$parent_dir" >../actual-tracked-unsorted + ) && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_expect_success '1e: post-add untracked' ' + ( + cd test1 && + local parent_dir="$(pwd)" && + git -C repo ls-files -o --exclude-standard "$parent_dir" >actual-untracked-unsorted && + sort actual-untracked-unsorted >actual-untracked && + sort expect-untracked-unsorted >expect-untracked && + test_cmp expect-untracked actual-untracked + ) +' + +test_expect_success '2a: setup--set git-dir' ' + mkdir test2 && + ( + cd test2 && + test_create_repo repo && + # create two foreign repositories that should remain untracked + test_create_repo repo-outside && + test_create_repo repo/repo-inside && + + mkdir -p repo/inside-tracked repo/inside-untracked && + >repo/file-tracked && + >repo/file-untracked && + >repo/inside-tracked/file && + >repo/inside-untracked/file && + >repo-outside/file && + >repo/repo-inside/file && + + cat >expect-tracked-unsorted <<-EOF && + repo/file-tracked + repo/inside-tracked/file + EOF + + cat >expect-untracked-unsorted <<-EOF && + repo/file-untracked + repo/inside-untracked/file + repo/repo-inside/ + repo-outside/ + EOF + + cat >expect-all-dir-unsorted <<-EOF && + repo/ + repo-outside/ + EOF + + cat expect-tracked-unsorted expect-untracked-unsorted >expect-all-unsorted && + + cat >.gitignore <<-EOF + .gitignore + actual-* + expect-* + EOF + ) +' + +test_expect_success '2b: pre-add all' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --exclude-standard >actual-all-unsorted && + sort actual-all-unsorted >actual-all && + sort expect-all-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '2c: pre-add dir all' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --directory --exclude-standard >actual-all-dir-unsorted && + sort actual-all-dir-unsorted >actual-all && + sort expect-all-dir-unsorted >expect-all && + test_cmp expect-all actual-all + ) +' + +test_expect_success '2d: post-add tracked' ' + ( + cd test2 && + git --git-dir=repo/.git add repo/file-tracked && + git --git-dir=repo/.git add repo/inside-tracked && + git --git-dir=repo/.git ls-files >actual-tracked-unsorted && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_expect_success '2e: post-add untracked' ' + ( + cd test2 && + git --git-dir=repo/.git ls-files -o --exclude-standard >actual-untracked-unsorted && + sort actual-untracked-unsorted >actual-untracked && + sort expect-untracked-unsorted >expect-untracked && + test_cmp expect-untracked actual-untracked + ) +' + +test_expect_success '3a: setup--add repo dir' ' + mkdir test3 && + ( + cd test3 && + test_create_repo repo && + + mkdir -p repo/inside-tracked repo/inside-ignored && + >repo/file-tracked && + >repo/file-ignored && + >repo/inside-tracked/file && + >repo/inside-ignored/file && + + cat >.gitignore <<-EOF && + .gitignore + actual-* + expect-* + *ignored + EOF + + cat >expect-tracked-unsorted <<-EOF && + repo/file-tracked + repo/inside-tracked/file + EOF + + cat >expect-ignored-unsorted <<-EOF + repo/file-ignored + repo/inside-ignored/ + .gitignore + actual-ignored-unsorted + expect-ignored-unsorted + expect-tracked-unsorted + EOF + ) +' + +test_expect_success '3b: ignored' ' + ( + cd test3 && + git --git-dir=repo/.git ls-files -io --directory --exclude-standard >actual-ignored-unsorted && + sort actual-ignored-unsorted >actual-ignored && + sort expect-ignored-unsorted >expect-ignored && + test_cmp expect-ignored actual-ignored + ) +' + +test_expect_success '3c: add repo' ' + ( + cd test3 && + git --git-dir=repo/.git add repo && + git --git-dir=repo/.git ls-files >actual-tracked-unsorted && + sort actual-tracked-unsorted >actual-tracked && + sort expect-tracked-unsorted >expect-tracked && + test_cmp expect-tracked actual-tracked + ) +' + +test_done diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 8979c8a5f0..8689b48589 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -8,7 +8,7 @@ test_description='Test of git add, including the -- option.' TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh -. $TEST_DIRECTORY/lib-unique-files.sh +. "$TEST_DIRECTORY"/lib-unique-files.sh # Test the file mode "$1" of the file "$2" in the index. test_mode_in_index () { diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index fc26cb8bae..b354fb39de 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -103,6 +103,15 @@ test_expect_success 'status works (commit)' ' grep "+1/-0 *+2/-0 file" output ' +test_expect_success 'update can stage deletions' ' + >to-delete && + git add to-delete && + rm to-delete && + test_write_lines u t "" | git add -i && + git ls-files to-delete >output && + test_must_be_empty output +' + test_expect_success 'setup expected' ' cat >expected <<-\EOF index 180b47c..b6f2c08 100644 diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 20e9488196..2a4c3fd61c 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -9,7 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh -. $TEST_DIRECTORY/lib-unique-files.sh +. "$TEST_DIRECTORY"/lib-unique-files.sh test_expect_success 'usage on cmd and subcommand invalid option' ' test_expect_code 129 git stash --invalid-option 2>usage && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 4620f0ca7f..b45879a760 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -853,7 +853,11 @@ test_configured_prune_type () { then new_cmdline=$cmdline_setup else - new_cmdline=$(printf "%s" "$cmdline" | perl -pe 's[origin(?!/)]["'"$remote_url"'"]g') + new_cmdline=$(perl -e ' + my ($cmdline, $url) = @ARGV; + $cmdline =~ s[origin(?!/)][quotemeta($url)]ge; + print $cmdline; + ' -- "$cmdline" "$remote_url") fi if test "$fetch_prune_tags" = 'true' || diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh index 479db32cd6..99baf77cbf 100755 --- a/t/t6423-merge-rename-directories.sh +++ b/t/t6423-merge-rename-directories.sh @@ -5199,6 +5199,111 @@ test_expect_success '12k: Directory rename with sibling causes rename-to-self' ' ) ' +# Testcase 12l, Both sides rename a directory into the other side, both add +# a file which after directory renames are the same filename +# Commit O: sub1/file, sub2/other +# Commit A: sub3/file, sub2/{other, new_add_add_file_1} +# Commit B: sub1/{file, newfile}, sub1/sub2/{other, new_add_add_file_2} +# +# In words: +# A: sub1/ -> sub3/, add sub2/new_add_add_file_1 +# B: sub2/ -> sub1/sub2, add sub1/newfile, add sub1/sub2/new_add_add_file_2 +# +# Expected: sub3/{file, newfile, sub2/other} +# CONFLICT (add/add): sub1/sub2/new_add_add_file +# +# Note that sub1/newfile is not extraneous. Directory renames are only +# detected if they are needed, and they are only needed if the old directory +# had a new file added on the opposite side of history. So sub1/newfile +# is needed for there to be a sub1/ -> sub3/ rename. + +test_setup_12l () { + test_create_repo 12l_$1 && + ( + cd 12l_$1 && + + mkdir sub1 sub2 + echo file >sub1/file && + echo other >sub2/other && + git add sub1 sub2 && + git commit -m "O" && + + git branch O && + git branch A && + git branch B && + + git checkout A && + git mv sub1 sub3 && + echo conflicting >sub2/new_add_add_file && + git add sub2 && + test_tick && + git add -u && + git commit -m "A" && + + git checkout B && + echo dissimilar >sub2/new_add_add_file && + echo brand >sub1/newfile && + git add sub1 sub2 && + git mv sub2 sub1 && + test_tick && + git commit -m "B" + ) +} + +test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' ' + test_setup_12l BintoA && + ( + cd 12l_BintoA && + + git checkout -q A^0 && + + test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 && + + test_stdout_line_count = 5 git ls-files -s && + + git rev-parse >actual \ + :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \ + :2:sub1/sub2/new_add_add_file \ + :3:sub1/sub2/new_add_add_file && + git rev-parse >expect \ + O:sub1/file B:sub1/newfile O:sub2/other \ + A:sub2/new_add_add_file \ + B:sub1/sub2/new_add_add_file && + test_cmp expect actual && + + git ls-files -o >actual && + test_write_lines actual expect >expect && + test_cmp expect actual + ) +' + +test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' ' + test_setup_12l AintoB && + ( + cd 12l_AintoB && + + git checkout -q B^0 && + + test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 && + + test_stdout_line_count = 5 git ls-files -s && + + git rev-parse >actual \ + :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \ + :2:sub1/sub2/new_add_add_file \ + :3:sub1/sub2/new_add_add_file && + git rev-parse >expect \ + O:sub1/file B:sub1/newfile O:sub2/other \ + B:sub1/sub2/new_add_add_file \ + A:sub2/new_add_add_file && + test_cmp expect actual && + + git ls-files -o >actual && + test_write_lines actual expect >expect && + test_cmp expect actual + ) +' + ########################################################################### # SECTION 13: Checking informational and conflict messages # diff --git a/t/t6429-merge-sequence-rename-caching.sh b/t/t6429-merge-sequence-rename-caching.sh index f2bc8a7d2a..e1ce919916 100755 --- a/t/t6429-merge-sequence-rename-caching.sh +++ b/t/t6429-merge-sequence-rename-caching.sh @@ -760,7 +760,7 @@ test_expect_success 'avoid assuming we detected renames' ' test_must_fail git -c merge.renameLimit=1 rebase upstream && git ls-files -u >actual && - ! test_file_is_empty actual + test_line_count = 2 actual ) ' diff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh index d848fe6442..330d6d603d 100755 --- a/t/t7609-mergetool--lib.sh +++ b/t/t7609-mergetool--lib.sh @@ -7,7 +7,7 @@ Testing basic merge tools options' . ./test-lib.sh test_expect_success 'mergetool --tool=vimdiff creates the expected layout' ' - . $GIT_BUILD_DIR/mergetools/vimdiff && + . "$GIT_BUILD_DIR"/mergetools/vimdiff && run_unit_tests ' diff --git a/t/test-lib-junit.sh b/t/test-lib-junit.sh index c959183c7e..79c31c788b 100644 --- a/t/test-lib-junit.sh +++ b/t/test-lib-junit.sh @@ -46,7 +46,7 @@ finalize_test_case_output () { shift case "$test_case_result" in ok) - set "$*" + set -- "$*" ;; failure) junit_insert="<failure message=\"not ok $test_count -" @@ -65,17 +65,17 @@ finalize_test_case_output () { junit_insert="$junit_insert<system-err>$(xml_attr_encode \ "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>" fi - set "$1" " $junit_insert" + set -- "$1" " $junit_insert" ;; fixed) - set "$* (breakage fixed)" + set -- "$* (breakage fixed)" ;; broken) - set "$* (known breakage)" + set -- "$* (known breakage)" ;; skip) message="$(xml_attr_encode --no-lf "$skipped_reason")" - set "$1" " <skipped message=\"$message\" />" + set -- "$1" " <skipped message=\"$message\" />" ;; esac diff --git a/t/test-lib.sh b/t/test-lib.sh index 55857af601..8cabb4d10f 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -57,14 +57,14 @@ fi # # prepend_var VAR : VALUE prepend_var () { - eval "$1=$3\${$1:+${3:+$2}\$$1}" + eval "$1=\"$3\${$1:+${3:+$2}\$$1}\"" } # If [AL]SAN is in effect we want to abort so that we notice # problems. The GIT_SAN_OPTIONS variable can be used to set common # defaults shared between [AL]SAN_OPTIONS. prepend_var GIT_SAN_OPTIONS : abort_on_error=1 -prepend_var GIT_SAN_OPTIONS : strip_path_prefix=\"$GIT_BUILD_DIR/\" +prepend_var GIT_SAN_OPTIONS : strip_path_prefix="$GIT_BUILD_DIR/" # If we were built with ASAN, it may complain about leaks # of program-lifetime variables. Disable it by default to lower @@ -33,7 +33,7 @@ static void vreportf(const char *prefix, const char *err, va_list params) static NORETURN void usage_builtin(const char *err, va_list params) { - vreportf("usage: ", err, params); + vreportf(_("usage: "), err, params); /* * When we detect a usage error *before* the command dispatch in @@ -58,7 +58,7 @@ static NORETURN void usage_builtin(const char *err, va_list params) static void die_message_builtin(const char *err, va_list params) { trace2_cmd_error_va(err, params); - vreportf("fatal: ", err, params); + vreportf(_("fatal: "), err, params); } /* @@ -78,14 +78,14 @@ static void error_builtin(const char *err, va_list params) { trace2_cmd_error_va(err, params); - vreportf("error: ", err, params); + vreportf(_("error: "), err, params); } static void warn_builtin(const char *warn, va_list params) { trace2_cmd_error_va(warn, params); - vreportf("warning: ", warn, params); + vreportf(_("warning: "), warn, params); } static int die_is_recursing_builtin(void) |
