diff options
124 files changed, 2030 insertions, 992 deletions
diff --git a/.gitignore b/.gitignore index 1c2f832138..5087ce1eb7 100644 --- a/.gitignore +++ b/.gitignore @@ -187,6 +187,7 @@ /test-dump-cache-tree /test-dump-split-index /test-dump-untracked-cache +/test-fake-ssh /test-scrap-cache-tree /test-genrandom /test-hashmap diff --git a/Documentation/RelNotes/2.7.1.txt b/Documentation/RelNotes/2.7.1.txt new file mode 100644 index 0000000000..6553d69e33 --- /dev/null +++ b/Documentation/RelNotes/2.7.1.txt @@ -0,0 +1,87 @@ +Git v2.7.1 Release Notes +======================== + +Fixes since v2.7 +---------------- + + * An earlier change in 2.5.x-era broke users' hooks and aliases by + exporting GIT_WORK_TREE to point at the root of the working tree, + interfering when they tried to use a different working tree without + setting GIT_WORK_TREE environment themselves. + + * The "exclude_list" structure has the usual "alloc, nr" pair of + fields to be used by ALLOC_GROW(), but clear_exclude_list() forgot + to reset 'alloc' to 0 when it cleared 'nr' to discard the managed + array. + + * "git send-email" was confused by escaped quotes stored in the alias + files saved by "mutt", which has been corrected. + + * A few unportable C construct have been spotted by clang compiler + and have been fixed. + + * The documentation has been updated to hint the connection between + the '--signoff' option and DCO. + + * "git reflog" incorrectly assumed that all objects that used to be + at the tip of a ref must be commits, which caused it to segfault. + + * The ignore mechanism saw a few regressions around untracked file + listing and sparse checkout selection areas in 2.7.0; the change + that is responsible for the regression has been reverted. + + * Some codepaths used fopen(3) when opening a fixed path in $GIT_DIR + (e.g. COMMIT_EDITMSG) that is meant to be left after the command is + done. This however did not work well if the repository is set to + be shared with core.sharedRepository and the umask of the previous + user is tighter. They have been made to work better by calling + unlink(2) and retrying after fopen(3) fails with EPERM. + + * Asking gitweb for a nonexistent commit left a warning in the server + log. + + * "git rebase", unlike all other callers of "gc --auto", did not + ignore the exit code from "gc --auto". + + * Many codepaths that run "gc --auto" before exiting kept packfiles + mapped and left the file descriptors to them open, which was not + friendly to systems that cannot remove files that are open. They + now close the packs before doing so. + + * A recent optimization to filter-branch in v2.7.0 introduced a + regression when --prune-empty filter is used, which has been + corrected. + + * The description for SANITY prerequisite the test suite uses has + been clarified both in the comment and in the implementation. + + * "git tag" started listing a tag "foo" as "tags/foo" when a branch + named "foo" exists in the same repository; remove this unnecessary + disambiguation, which is a regression introduced in v2.7.0. + + * The way "git svn" uses auth parameter was broken by Subversion + 1.9.0 and later. + + * The "split" subcommand of "git subtree" (in contrib/) incorrectly + skipped merges when it shouldn't, which was corrected. + + * A few options of "git diff" did not work well when the command was + run from a subdirectory. + + * dirname() emulation has been added, as Msys2 lacks it. + + * The underlying machinery used by "ls-files -o" and other commands + have been taught not to create empty submodule ref cache for a + directory that is not a submodule. This removes a ton of wasted + CPU cycles. + + * Drop a few old "todo" items by deciding that the change one of them + suggests is not such a good idea, and doing the change the other + one suggested to do. + + * Documentation for "git fetch --depth" has been updated for clarity. + + * The command line completion learned a handful of additional options + and command specific syntax. + +Also includes a handful of documentation and test updates. diff --git a/Documentation/RelNotes/2.7.2.txt b/Documentation/RelNotes/2.7.2.txt new file mode 100644 index 0000000000..4feef76704 --- /dev/null +++ b/Documentation/RelNotes/2.7.2.txt @@ -0,0 +1,41 @@ +Git v2.7.2 Release Notes +======================== + +Fixes since v2.7.1 +------------------ + + * The low-level merge machinery has been taught to use CRLF line + termination when inserting conflict markers to merged contents that + are themselves CRLF line-terminated. + + * "git worktree" had a broken code that attempted to auto-fix + possible inconsistency that results from end-users moving a + worktree to different places without telling Git (the original + repository needs to maintain backpointers to its worktrees, but + "mv" run by end-users who are not familiar with that fact will + obviously not adjust them), which actually made things worse + when triggered. + + * "git push --force-with-lease" has been taught to report if the push + needed to force (or fast-forwarded). + + * The emulated "yes" command used in our test scripts has been + tweaked not to spend too much time generating unnecessary output + that is not used, to help those who test on Windows where it would + not stop until it fills the pipe buffer due to lack of SIGPIPE. + + * The vimdiff backend for "git mergetool" has been tweaked to arrange + and number buffers in the order that would match the expectation of + majority of people who read left to right, then top down and assign + buffers 1 2 3 4 "mentally" to local base remote merge windows based + on that order. + + * The documentation for "git clean" has been corrected; it mentioned + that .git/modules/* are removed by giving two "-f", which has never + been the case. + + * Paths that have been told the index about with "add -N" are not + quite yet in the index, but a few commands behaved as if they + already are in a harmful way. + +Also includes tiny documentation and test updates. diff --git a/Documentation/RelNotes/2.8.0.txt b/Documentation/RelNotes/2.8.0.txt index 1a0fcb2027..3df3a98f70 100644 --- a/Documentation/RelNotes/2.8.0.txt +++ b/Documentation/RelNotes/2.8.0.txt @@ -1,13 +1,22 @@ Git 2.8 Release Notes ===================== +Backward compatibility note +--------------------------- + +The rsync:// transport has been removed. + + Updates since v2.7 ------------------ UI, Workflows & Features + * It turns out "git clone" over rsync transport has been broken when + the source repository has packed references for a long time, and + nobody noticed nor complained about it. + * "branch --delete" has "branch -d" but "push --delete" does not. - (merge 38a2559 ps/push-delete-option later to maint). * "git blame" learned to produce the progress eye-candy when it takes too much time before emitting the first line of the result. @@ -42,6 +51,65 @@ UI, Workflows & Features * "interpret-trailers" has been taught to optionally update a file in place, instead of always writing the result to the standard output. + * Many commands that read files that are expected to contain text + that is generated (or can be edited) by the end user to control + their behaviour (e.g. "git grep -f <filename>") have been updated + to be more tolerant to lines that are terminated with CRLF (they + used to treat such a line to contain payload that ends with CR, + which is usually not what the users expect). + + * "git notes merge" used to limit the source of the merged notes tree + to somewhere under refs/notes/ hierarchy, which was too limiting + when inventing a workflow to exchange notes with remote + repositories using remote-tracking notes trees (located in e.g. + refs/remote-notes/ or somesuch). + + * "git ls-files" learned a new "--eol" option to help diagnose + end-of-line problems. + + * "ls-remote" learned an option to show which branch the remote + repository advertises as its primary by pointing its HEAD at. + + * New http.proxyAuthMethod configuration variable can be used to + specify what authentication method to use, as a way to work around + proxies that do not give error response expected by libcurl when + CURLAUTH_ANY is used. Also, the codepath for proxy authentication + has been taught to use credential API to store the authentication + material in user's keyrings. + + * Update the untracked cache subsystem and change its primary UI from + "git update-index" to "git config". + + * There were a few "now I am doing this thing" progress messages in + the TCP connection code that can be triggered by setting a verbose + option internally in the code, but "git fetch -v" and friends never + passed the verbose option down to that codepath. + + * Clean/smudge filters defined in a configuration file of lower + precedence can now be overridden to be a pass-through no-op by + setting the variable to an empty string. + + * A new "<branch>^{/!-<pattern>}" notation can be used to name a + commit that is reachable from <branch> that does not match the + given <pattern>. + + * The "user.useConfigOnly" configuration variable can be used to + force the user to always set user.email & user.name configuration + variables, serving as a reminder for those who work on multiple + projects and do not want to put these in their $HOME/.gitconfig. + + * "git fetch" and friends that make network connections can now be + told to only use ipv4 (or ipv6). + + * Some authentication methods do not need username or password, but + libcurl needs some hint that it needs to perform authentication. + Supplying an empty username and password string is a valid way to + do so, but you can set the http.[<url>.]emptyAuth configuration + variable to achieve the same, if you find it cleaner. + + * You can now set http.[<url>.]pinnedpubkey to specify the pinned + public key when building with recent enough versions of libcURL. + Performance, Internal Implementation, Development Support etc. @@ -77,6 +145,39 @@ Performance, Internal Implementation, Development Support etc. (e.g. there is no need to collect the log messages when showing only the number of changes). + * "git checkout $branch" (and other operations that share the same + underlying machinery) has been optimized. + + * Automated tests in Travis CI environment has been optimized by + persisting runtime statistics of previous "prove" run, executing + tests that take longer before other ones; this reduces the total + wallclock time. + + * Test scripts have been updated to remove assumptions that are not + portable between Git for POSIX and Git for Windows, or to skip ones + with expectations that are not satisfiable on Git for Windows. + + * Some calls to strcpy(3) triggers a false warning from static + analysers that are less intelligent than humans, and reducing the + number of these false hits helps us notice real issues. A few + calls to strcpy(3) in test-path-utils that are already safe has + been rewritten to avoid false wanings. + + * Some calls to strcpy(3) triggers a false warning from static + analysers that are less intelligent than humans, and reducing the + number of these false hits helps us notice real issues. A few + calls to strcpy(3) in "git rerere" that are already safe has been + rewritten to avoid false wanings. + + * The "name_path" API was an attempt to reduce the need to construct + the full path out of a series of path components while walking a + tree hierarchy, but over time made less efficient because the path + needs to be flattened, e.g. to be compared with another path that + is already flat. The API has been removed and its users have been + rewritten to simplify the overall code complexity. + + * Help those who debug http(s) part of the system. + (merge 0054045 sp/remote-curl-ssl-strerror later to maint). Also contains various documentation updates and code clean-ups. @@ -92,39 +193,31 @@ notes for details). exporting GIT_WORK_TREE to point at the root of the working tree, interfering when they tried to use a different working tree without setting GIT_WORK_TREE environment themselves. - (merge df1e6ea nd/stop-setenv-work-tree later to maint). * The "exclude_list" structure has the usual "alloc, nr" pair of fields to be used by ALLOC_GROW(), but clear_exclude_list() forgot to reset 'alloc' to 0 when it cleared 'nr' to discard the managed array. - (merge 2653a8c nd/dir-exclude-cleanup later to maint). * Paths that have been told the index about with "add -N" are not quite yet in the index, but a few commands behaved as if they already are in a harmful way. - (merge 4d55200 nd/ita-cleanup later to maint). * "git send-email" was confused by escaped quotes stored in the alias files saved by "mutt", which has been corrected. - (merge 2c510f2 ew/send-email-mutt-alias-fix later to maint). * A few unportable C construct have been spotted by clang compiler and have been fixed. - (merge a0df2e5 jk/clang-pedantic later to maint). * The documentation has been updated to hint the connection between the '--signoff' option and DCO. - (merge b2c150d dw/signoff-doc later to maint). * "git reflog" incorrectly assumed that all objects that used to be at the tip of a ref must be commits, which caused it to segfault. - (merge aecad37 dk/reflog-walk-with-non-commit later to maint). * The ignore mechanism saw a few regressions around untracked file listing and sparse checkout selection areas in 2.7.0; the change that is responsible for the regression has been reverted. - (merge 8c72236 nd/exclusion-regression-fix later to maint). * Some codepaths used fopen(3) when opening a fixed path in $GIT_DIR (e.g. COMMIT_EDITMSG) that is meant to be left after the command is @@ -132,7 +225,6 @@ notes for details). be shared with core.sharedRepository and the umask of the previous user is tighter. They have been made to work better by calling unlink(2) and retrying after fopen(3) fails with EPERM. - (merge ea56518 js/fopen-harder later to maint). * Asking gitweb for a nonexistent commit left a warning in the server log. @@ -140,38 +232,92 @@ notes for details). Somebody may want to follow this up with an additional test, perhaps? IIRC, we do test that no Perl warnings are given to the server log, so this should have been caught if our test coverage were good. - (merge a9eb90a ho/gitweb-squelch-undef-warning later to maint). * "git rebase", unlike all other callers of "gc --auto", did not ignore the exit code from "gc --auto". - (merge 8c24f5b jk/ok-to-fail-gc-auto-in-rebase later to maint). * Many codepaths that run "gc --auto" before exiting kept packfiles mapped and left the file descriptors to them open, which was not friendly to systems that cannot remove files that are open. They now close the packs before doing so. - (merge d562102 js/close-packs-before-gc later to maint). * A recent optimization to filter-branch in v2.7.0 introduced a regression when --prune-empty filter is used, which has been corrected. - (merge 1dc413e jk/filter-branch-no-index later to maint). * The description for SANITY prerequisite the test suite uses has been clarified both in the comment and in the implementation. - (merge 719c3da jk/sanity later to maint). * "git tag" started listing a tag "foo" as "tags/foo" when a branch named "foo" exists in the same repository; remove this unnecessary disambiguation, which is a regression introduced in v2.7.0. - (merge 0571979 jk/list-tag-2.7-regression later to maint). * The way "git svn" uses auth parameter was broken by Subversion 1.9.0 and later. - (merge 0b66415 ew/svn-1.9.0-auth later to maint). + + * The "split" subcommand of "git subtree" (in contrib/) incorrectly + skipped merges when it shouldn't, which was corrected. + + * A few options of "git diff" did not work well when the command was + run from a subdirectory. + + * The command line completion learned a handful of additional options + and command specific syntax. + + * dirname() emulation has been added, as Msys2 lacks it. + + * The underlying machinery used by "ls-files -o" and other commands + have been taught not to create empty submodule ref cache for a + directory that is not a submodule. This removes a ton of wasted + CPU cycles. + + * "git worktree" had a broken code that attempted to auto-fix + possible inconsistency that results from end-users moving a + worktree to different places without telling Git (the original + repository needs to maintain backpointers to its worktrees, but + "mv" run by end-users who are not familiar with that fact will + obviously not adjust them), which actually made things worse + when triggered. + + * The low-level merge machinery has been taught to use CRLF line + termination when inserting conflict markers to merged contents that + are themselves CRLF line-terminated. + + * "git push --force-with-lease" has been taught to report if the push + needed to force (or fast-forwarded). + + * The emulated "yes" command used in our test scripts has been + tweaked not to spend too much time generating unnecessary output + that is not used, to help those who test on Windows where it would + not stop until it fills the pipe buffer due to lack of SIGPIPE. + + * The documentation for "git clean" has been corrected; it mentioned + that .git/modules/* are removed by giving two "-f", which has never + been the case. + + * The vimdiff backend for "git mergetool" has been tweaked to arrange + and number buffers in the order that would match the expectation of + majority of people who read left to right, then top down and assign + buffers 1 2 3 4 "mentally" to local base remote merge windows based + on that order. + + * "git show 'HEAD:Foo[BAR]Baz'" did not interpret the argument as a + rev, i.e. the object named by the the pathname with wildcard + characters in a tree object. + (merge aac4fac nd/dwim-wildcards-as-pathspecs later to maint). + + * "git rev-parse --git-common-dir" used in the worktree feature + misbehaved when run from a subdirectory. + (merge 17f1365 nd/git-common-dir-fix later to maint). + + * Another try to add support to the ignore mechanism that lets you + say "this is excluded" and then later say "oh, no, this part (that + is a subset of the previous part) is not excluded". + + * "git worktree add -B <branchname>" did not work. + + * The "v(iew)" subcommand of the interactive "git am -i" command was + broken in 2.6.0 timeframe when the command was rewritten in C. + (merge 708b8cc jc/am-i-v-fix later to maint). * Other minor clean-ups and documentation updates - (merge 99487cf ss/user-manual later to maint). - (merge e914ef0 ew/for-each-ref-doc later to maint). - (merge 36fc7d8 sg/t6050-failing-editor-test-fix later to maint). - (merge 60253a6 ss/clone-depth-single-doc later to maint). diff --git a/Documentation/config.txt b/Documentation/config.txt index 02bcde6bb5..2cd6bdd7d2 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -308,6 +308,15 @@ core.trustctime:: crawlers and some backup systems). See linkgit:git-update-index[1]. True by default. +core.untrackedCache:: + Determines what to do about the untracked cache feature of the + index. It will be kept, if this variable is unset or set to + `keep`. It will automatically be added if set to `true`. And + it will automatically be removed, if set to `false`. Before + setting it to `true`, you should check that mtime is working + properly on your system. + See linkgit:git-update-index[1]. `keep` by default. + core.checkStat:: Determines which stat fields to match between the index and work tree. The user can set this to 'default' or @@ -1639,6 +1648,12 @@ http.proxyAuthMethod:: * `ntlm` - NTLM authentication (compare the --ntlm option of `curl(1)`) -- +http.emptyAuth:: + Attempt authentication without seeking a username or password. This + can be used to attempt GSS-Negotiate authentication without specifying + a username in the URL, as libcurl normally requires a username for + authentication. + http.cookieFile:: File containing previously stored cookie lines which should be used in the Git http session, if they match the server. The file format @@ -1718,6 +1733,14 @@ http.sslCAPath:: with when fetching or pushing over HTTPS. Can be overridden by the 'GIT_SSL_CAPATH' environment variable. +http.pinnedpubkey:: + Public key of the https service. It may either be the filename of + a PEM or DER encoded public key file or a string starting with + 'sha256//' followed by the base64 encoded sha256 hash of the + public key. See also libcurl 'CURLOPT_PINNEDPUBLICKEY'. git will + exit with an error if this option is set but not supported by + cURL. + http.sslTry:: Attempt to use AUTH SSL/TLS and encrypted data transfers when connecting via regular FTP protocol. This might be needed @@ -2113,7 +2136,7 @@ pack.indexVersion:: larger than 2 GB. + If you have an old Git that does not understand the version 2 `*.idx` file, -cloning or fetching over a non native protocol (e.g. "http" and "rsync") +cloning or fetching over a non native protocol (e.g. "http") that will copy both `*.pack` file and corresponding `*.idx` file from the other side may give you a repository that cannot be accessed with your older version of Git. If the `*.pack` file is smaller than 2 GB, however, @@ -2821,6 +2844,16 @@ user.name:: Can be overridden by the 'GIT_AUTHOR_NAME' and 'GIT_COMMITTER_NAME' environment variables. See linkgit:git-commit-tree[1]. +user.useConfigOnly:: + Instruct Git to avoid trying to guess defaults for 'user.email' + and 'user.name', and instead retrieve the values only from the + configuration. For example, if you have multiple email addresses + and would like to use a different one for each repository, then + with this configuration option set to `true` in the global config + along with a name, Git will prompt you to set up an email before + making new commits in a newly cloned repository. + Defaults to `false`. + user.signingKey:: If linkgit:git-tag[1] or linkgit:git-commit[1] is not selecting the key you want it to automatically when creating a signed tag or diff --git a/Documentation/fetch-options.txt b/Documentation/fetch-options.txt index 952dfdfef0..036edfb099 100644 --- a/Documentation/fetch-options.txt +++ b/Documentation/fetch-options.txt @@ -158,3 +158,11 @@ endif::git-pull[] by default when it is attached to a terminal, unless -q is specified. This flag forces progress status even if the standard error stream is not directed to a terminal. + +-4:: +--ipv4:: + Use IPv4 addresses only, ignoring IPv6 addresses. + +-6:: +--ipv6:: + Use IPv6 addresses only, ignoring IPv4 addresses. diff --git a/Documentation/git-bundle.txt b/Documentation/git-bundle.txt index 0417562eb7..3a8120c3b3 100644 --- a/Documentation/git-bundle.txt +++ b/Documentation/git-bundle.txt @@ -20,7 +20,7 @@ DESCRIPTION Some workflows require that one or more branches of development on one machine be replicated on another machine, but the two machines cannot be directly connected, and therefore the interactive Git protocols (git, -ssh, rsync, http) cannot be used. This command provides support for +ssh, http) cannot be used. This command provides support for 'git fetch' and 'git pull' to operate by packaging objects and references in an archive at the originating machine, then importing those into another repository using 'git fetch' and 'git pull' diff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt index e94367a5ed..f60ee051f8 100644 --- a/Documentation/git-check-ignore.txt +++ b/Documentation/git-check-ignore.txt @@ -114,6 +114,7 @@ SEE ALSO linkgit:gitignore[5] linkgit:gitconfig[5] linkgit:git-ls-files[1] +GIT_TRACE_EXCLUDE in linkgit:git[1] GIT --- diff --git a/Documentation/git-clean.txt b/Documentation/git-clean.txt index 641681f61a..51a7e26a8e 100644 --- a/Documentation/git-clean.txt +++ b/Documentation/git-clean.txt @@ -37,9 +37,7 @@ OPTIONS to false, 'git clean' will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f - is given. This affects also git submodules where the storage area - of the removed submodule under .git/modules/ is not removed until - -f is given twice. + is given. -i:: --interactive:: diff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt index 789b668f77..b7c467a001 100644 --- a/Documentation/git-clone.txt +++ b/Documentation/git-clone.txt @@ -115,8 +115,7 @@ objects from the source repository into a pack in the cloned repository. --quiet:: -q:: Operate quietly. Progress is not reported to the standard - error stream. This flag is also passed to the `rsync' - command when given. + error stream. --verbose:: -v:: diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 2608ca74ac..242fa5d1bb 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -219,7 +219,9 @@ See also <<FILES>>. --[no-]includes:: Respect `include.*` directives in config files when looking up - values. Defaults to on. + values. Defaults to `off` when a specific file is given (e.g., + using `--file`, `--global`, etc) and `on` when searching all + config files. [[FILES]] FILES diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 32482cec42..669a357c81 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -277,6 +277,13 @@ origin +master` to force a push to the `master` branch). See the default is --verify, giving the hook a chance to prevent the push. With --no-verify, the hook is bypassed completely. +-4:: +--ipv4:: + Use IPv4 addresses only, ignoring IPv6 addresses. + +-6:: +--ipv6:: + Use IPv6 addresses only, ignoring IPv4 addresses. include::urls-remotes.txt[] diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt index 0e0bd363d6..af230d0647 100644 --- a/Documentation/git-repack.txt +++ b/Documentation/git-repack.txt @@ -133,7 +133,7 @@ By default, the command passes `--delta-base-offset` option to 'git pack-objects'; this typically results in slightly smaller packs, but the generated packs are incompatible with versions of Git older than version 1.4.4. If you need to share your repository with such ancient Git -versions, either directly or via the dumb http or rsync protocol, then you +versions, either directly or via the dumb http protocol, then you need to set the configuration variable `repack.UseDeltaBaseOffset` to "false" and repack. Access from old Git versions over the native protocol is unaffected by this option as the conversion is performed on the fly diff --git a/Documentation/git-update-index.txt b/Documentation/git-update-index.txt index f4e5a85351..c6cbed189c 100644 --- a/Documentation/git-update-index.txt +++ b/Documentation/git-update-index.txt @@ -18,7 +18,7 @@ SYNOPSIS [--[no-]skip-worktree] [--ignore-submodules] [--[no-]split-index] - [--[no-|force-]untracked-cache] + [--[no-|test-|force-]untracked-cache] [--really-refresh] [--unresolve] [--again | -g] [--info-only] [--index-info] [-z] [--stdin] [--index-version <n>] @@ -174,17 +174,30 @@ may not support it yet. --untracked-cache:: --no-untracked-cache:: - Enable or disable untracked cache extension. This could speed - up for commands that involve determining untracked files such - as `git status`. The underlying operating system and file - system must change `st_mtime` field of a directory if files - are added or deleted in that directory. + Enable or disable untracked cache feature. Please use + `--test-untracked-cache` before enabling it. ++ +These options take effect whatever the value of the `core.untrackedCache` +configuration variable (see linkgit:git-config[1]). But a warning is +emitted when the change goes against the configured value, as the +configured value will take effect next time the index is read and this +will remove the intended effect of the option. + +--test-untracked-cache:: + Only perform tests on the working directory to make sure + untracked cache can be used. You have to manually enable + untracked cache using `--untracked-cache` or + `--force-untracked-cache` or the `core.untrackedCache` + configuration variable afterwards if you really want to use + it. If a test fails the exit code is 1 and a message + explains what is not working as needed, otherwise the exit + code is 0 and OK is printed. --force-untracked-cache:: - For safety, `--untracked-cache` performs tests on the working - directory to make sure untracked cache can be used. These - tests can take a few seconds. `--force-untracked-cache` can be - used to skip the tests. + Same as `--untracked-cache`. Provided for backwards + compatibility with older versions of Git where + `--untracked-cache` used to imply `--test-untracked-cache` but + this option would enable the extension unconditionally. \--:: Do not interpret any more arguments as options. @@ -375,6 +388,37 @@ Although this bit looks similar to assume-unchanged bit, its goal is different from assume-unchanged bit's. Skip-worktree also takes precedence over assume-unchanged bit when both are set. +Untracked cache +--------------- + +This cache is meant to speed up commands that involve determining +untracked files such as `git status`. + +This feature works by recording the mtime of the working tree +directories and then omitting reading directories and stat calls +against files in those directories whose mtime hasn't changed. For +this to work the underlying operating system and file system must +change the `st_mtime` field of directories if files in the directory +are added, modified or deleted. + +You can test whether the filesystem supports that with the +`--test-untracked-cache` option. The `--untracked-cache` option used +to implicitly perform that test in older versions of Git, but that's +no longer the case. + +If you want to enable (or disable) this feature, it is easier to use +the `core.untrackedCache` configuration variable (see +linkgit:git-config[1]) than using the `--untracked-cache` option to +`git update-index` in each repository, especially if you want to do so +across all repositories you use, because you can set the configuration +variable to `true` (or `false`) in your `$HOME/.gitconfig` just once +and have it affect all repositories you touch. + +When the `core.untrackedCache` configuration variable is changed, the +untracked cache is added to or removed from the index the next time a +command reads the index; while when `--[no-|force-]untracked-cache` +are used, the untracked cache is immediately added to or removed from +the index. Configuration ------------- @@ -400,6 +444,9 @@ It can be useful when the inode change time is regularly modified by something outside Git (file system crawlers and backup systems use ctime for marking files processed) (see linkgit:git-config[1]). +The untracked cache extension can be enabled by the +`core.untrackedCache` configuration variable (see +linkgit:git-config[1]). SEE ALSO -------- diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt index 5b9ad0429c..62c76c1c89 100644 --- a/Documentation/git-worktree.txt +++ b/Documentation/git-worktree.txt @@ -32,11 +32,9 @@ The working tree's administrative files in the repository (see `git worktree prune` in the main or any linked working tree to clean up any stale administrative files. -If you move a linked working tree to another file system, or -within a file system that does not support hard links, you need to run -at least one git command inside the linked working tree -(e.g. `git status`) in order to update its administrative files in the -repository so that they do not get automatically pruned. +If you move a linked working tree, you need to manually update the +administrative files so that they do not get pruned automatically. See +section "DETAILS" for more information. If a linked working tree is stored on a portable device or network share which is not always mounted, you can prevent its administrative files from @@ -137,6 +135,13 @@ thumb is do not make any assumption about whether a path belongs to $GIT_DIR or $GIT_COMMON_DIR when you need to directly access something inside $GIT_DIR. Use `git rev-parse --git-path` to get the final path. +If you move a linked working tree, you need to update the 'gitdir' file +in the entry's directory. For example, if a linked working tree is moved +to `/newpath/test-next` and its `.git` file points to +`/path/main/.git/worktrees/test-next`, then update +`/path/main/.git/worktrees/test-next/gitdir` to reference `/newpath/test-next` +instead. + To prevent a $GIT_DIR/worktrees entry from being pruned (which can be useful in some situations, such as when the entry's working tree is stored on a portable device), add a file named diff --git a/Documentation/git.txt b/Documentation/git.txt index bff6302c0d..2754af8f77 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -43,9 +43,11 @@ unreleased) version of Git, that is available from the 'master' branch of the `git.git` repository. Documentation for older releases are available here: -* link:v2.7.0/git.html[documentation for release 2.7] +* link:v2.7.2/git.html[documentation for release 2.7.2] * release notes for + link:RelNotes/2.7.2.txt[2.7.2], + link:RelNotes/2.7.1.txt[2.7.1], link:RelNotes/2.7.0.txt[2.7]. * link:v2.6.5/git.html[documentation for release 2.6.5] @@ -1063,6 +1065,11 @@ of clones and fetches. cloning of shallow repositories. See 'GIT_TRACE' for available trace output options. +'GIT_TRACE_EXCLUDE':: + Enables trace messages that can help debugging .gitignore + processing. See 'GIT_TRACE' for available trace output + options. + 'GIT_LITERAL_PATHSPECS':: Setting this variable to `1` will cause Git to treat all pathspecs literally, rather than as glob patterns. For example, @@ -1123,8 +1130,6 @@ of clones and fetches. - `ssh`: git over ssh (including `host:path` syntax, `git+ssh://`, etc). - - `rsync`: git over rsync - - `http`: git over http, both "smart http" and "dumb http". Note that this does _not_ include `https`; if you want both, you should specify both as `http:https`. diff --git a/Documentation/gitcore-tutorial.txt b/Documentation/gitcore-tutorial.txt index 36e9ab3e16..15b3bfa8db 100644 --- a/Documentation/gitcore-tutorial.txt +++ b/Documentation/gitcore-tutorial.txt @@ -710,7 +710,7 @@ files). Again, this can all be simplified with ---------------- -$ git clone rsync://rsync.kernel.org/pub/scm/git/git.git/ my-git +$ git clone git://git.kernel.org/pub/scm/git/git.git/ my-git $ cd my-git $ git checkout ---------------- @@ -1011,20 +1011,6 @@ $ git fetch <remote-repository> One of the following transports can be used to name the repository to download from: -Rsync:: - `rsync://remote.machine/path/to/repo.git/` -+ -Rsync transport is usable for both uploading and downloading, -but is completely unaware of what git does, and can produce -unexpected results when you download from the public repository -while the repository owner is uploading into it via `rsync` -transport. Most notably, it could update the files under -`refs/` which holds the object name of the topmost commits -before uploading the files in `objects/` -- the downloader would -obtain head commit object name while that object itself is still -not available in the repository. For this reason, it is -considered deprecated. - SSH:: `remote.machine:/path/to/repo.git/` or + @@ -1430,7 +1416,7 @@ while, depending on how active your project is. When a repository is synchronized via `git push` and `git pull` objects packed in the source repository are usually stored -unpacked in the destination, unless rsync transport is used. +unpacked in the destination. While this allows you to use different packing strategies on both ends, it also means you may need to repack both repositories every once in a while. diff --git a/Documentation/gitignore.txt b/Documentation/gitignore.txt index 473623d631..3ded6fdc99 100644 --- a/Documentation/gitignore.txt +++ b/Documentation/gitignore.txt @@ -82,12 +82,12 @@ PATTERN FORMAT - An optional prefix "`!`" which negates the pattern; any matching file excluded by a previous pattern will become - included again. It is not possible to re-include a file if a parent - directory of that file is excluded. Git doesn't list excluded - directories for performance reasons, so any patterns on contained - files have no effect, no matter where they are defined. + included again. Put a backslash ("`\`") in front of the first "`!`" for patterns that begin with a literal "`!`", for example, "`\!important!.txt`". + It is possible to re-include a file if a parent directory of that + file is excluded if certain conditions are met. See section NOTES + for detail. - If the pattern ends with a slash, it is removed for the purpose of the following description, but it would only find @@ -141,6 +141,15 @@ not tracked by Git remain untracked. To stop tracking a file that is currently tracked, use 'git rm --cached'. +To re-include files or directories when their parent directory is +excluded, the following conditions must be met: + + - The rules to exclude a directory and re-include a subset back must + be in the same .gitignore file. + + - The directory part in the re-include rules must be literal (i.e. no + wildcards) + EXAMPLES -------- diff --git a/Documentation/gittutorial.txt b/Documentation/gittutorial.txt index b00c67df46..b3b58d324e 100644 --- a/Documentation/gittutorial.txt +++ b/Documentation/gittutorial.txt @@ -451,7 +451,7 @@ perform clones and pulls using the ssh protocol: bob$ git clone alice.org:/home/alice/project myrepo ------------------------------------- -Alternatively, Git has a native protocol, or can use rsync or http; +Alternatively, Git has a native protocol, or can use http; see linkgit:git-pull[1] for details. Git can also be used in a CVS-like mode, with a central repository diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt index fa4bdb208c..19314e3b7f 100644 --- a/Documentation/revisions.txt +++ b/Documentation/revisions.txt @@ -176,11 +176,12 @@ existing tag object. A colon, followed by a slash, followed by a text, names a commit whose commit message matches the specified regular expression. This name returns the youngest matching commit which is - reachable from any ref. If the commit message starts with a - '!' you have to repeat that; the special sequence ':/!', - followed by something else than '!', is reserved for now. - The regular expression can match any part of the commit message. To - match messages starting with a string, one can use e.g. ':/^foo'. + reachable from any ref. The regular expression can match any part of the + commit message. To match messages starting with a string, one can use + e.g. ':/^foo'. The special sequence ':/!' is reserved for modifiers to what + is matched. ':/!-foo' performs a negative match, while ':/!!foo' matches a + literal '!' character, followed by 'foo'. Any other sequence beginning with + ':/!' is reserved for now. '<rev>:<path>', e.g. 'HEAD:README', ':README', 'master:./README':: A suffix ':' followed by a path names the blob or tree diff --git a/Documentation/urls.txt b/Documentation/urls.txt index 9ccb24677e..b05da95788 100644 --- a/Documentation/urls.txt +++ b/Documentation/urls.txt @@ -7,9 +7,8 @@ Depending on the transport protocol, some of this information may be absent. Git supports ssh, git, http, and https protocols (in addition, ftp, -and ftps can be used for fetching and rsync can be used for fetching -and pushing, but these are inefficient and deprecated; do not use -them). +and ftps can be used for fetching, but this is inefficient and +deprecated; do not use it). The native transport (i.e. git:// URL) does no authentication and should be used with caution on unsecured networks. @@ -20,7 +19,6 @@ The following syntaxes may be used with them: - git://host.xz{startsb}:port{endsb}/path/to/repo.git/ - http{startsb}s{endsb}://host.xz{startsb}:port{endsb}/path/to/repo.git/ - ftp{startsb}s{endsb}://host.xz{startsb}:port{endsb}/path/to/repo.git/ -- rsync://host.xz/path/to/repo.git/ An alternative scp-like syntax may also be used with the ssh protocol: @@ -583,6 +583,7 @@ TEST_PROGRAMS_NEED_X += test-delta TEST_PROGRAMS_NEED_X += test-dump-cache-tree TEST_PROGRAMS_NEED_X += test-dump-split-index TEST_PROGRAMS_NEED_X += test-dump-untracked-cache +TEST_PROGRAMS_NEED_X += test-fake-ssh TEST_PROGRAMS_NEED_X += test-genrandom TEST_PROGRAMS_NEED_X += test-hashmap TEST_PROGRAMS_NEED_X += test-index-version diff --git a/builtin/am.c b/builtin/am.c index 259dc1cd11..d003939bc5 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -1806,7 +1806,7 @@ static int do_interactive(struct am_state *state) if (!pager) pager = "cat"; - argv_array_push(&cp.args, pager); + prepare_pager_args(&cp, pager); argv_array_push(&cp.args, am_path(state, "patch")); run_command(&cp); } diff --git a/builtin/apply.c b/builtin/apply.c index deb1364fa8..d61ac65dab 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -4464,16 +4464,6 @@ static int option_parse_p(const struct option *opt, return 0; } -static int option_parse_z(const struct option *opt, - const char *arg, int unset) -{ - if (unset) - line_termination = '\n'; - else - line_termination = 0; - return 0; -} - static int option_parse_space_change(const struct option *opt, const char *arg, int unset) { @@ -4546,9 +4536,9 @@ int cmd_apply(int argc, const char **argv, const char *prefix_) N_( "attempt three-way merge if a patch does not apply")), OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor, N_("build a temporary index based on embedded index information")), - { OPTION_CALLBACK, 'z', NULL, NULL, NULL, - N_("paths are separated with NUL character"), - PARSE_OPT_NOARG, option_parse_z }, + /* Think twice before adding "--nul" synonym to this */ + OPT_SET_INT('z', NULL, &line_termination, + N_("paths are separated with NUL character"), '\0'), OPT_INTEGER('C', NULL, &p_context, N_("ensure at least <n> lines of context match")), { OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"), diff --git a/builtin/check-attr.c b/builtin/check-attr.c index 087325ef69..53a5a18c16 100644 --- a/builtin/check-attr.c +++ b/builtin/check-attr.c @@ -72,24 +72,23 @@ static void check_attr(const char *prefix, int cnt, static void check_attr_stdin_paths(const char *prefix, int cnt, struct git_attr_check *check) { - struct strbuf buf, nbuf; + struct strbuf buf = STRBUF_INIT; + struct strbuf unquoted = STRBUF_INIT; strbuf_getline_fn getline_fn; getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; - strbuf_init(&buf, 0); - strbuf_init(&nbuf, 0); while (getline_fn(&buf, stdin) != EOF) { if (!nul_term_line && buf.buf[0] == '"') { - strbuf_reset(&nbuf); - if (unquote_c_style(&nbuf, buf.buf, NULL)) + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); - strbuf_swap(&buf, &nbuf); + strbuf_swap(&buf, &unquoted); } check_attr(prefix, cnt, check, buf.buf); maybe_flush_or_die(stdout, "attribute to stdout"); } strbuf_release(&buf); - strbuf_release(&nbuf); + strbuf_release(&unquoted); } static NORETURN void error_with_usage(const char *msg) diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c index 4f0b09e2db..1d73d3ca3d 100644 --- a/builtin/check-ignore.c +++ b/builtin/check-ignore.c @@ -115,20 +115,19 @@ static int check_ignore(struct dir_struct *dir, static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix) { - struct strbuf buf, nbuf; + struct strbuf buf = STRBUF_INIT; + struct strbuf unquoted = STRBUF_INIT; char *pathspec[2] = { NULL, NULL }; strbuf_getline_fn getline_fn; int num_ignored = 0; getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline_lf; - strbuf_init(&buf, 0); - strbuf_init(&nbuf, 0); while (getline_fn(&buf, stdin) != EOF) { if (!nul_term_line && buf.buf[0] == '"') { - strbuf_reset(&nbuf); - if (unquote_c_style(&nbuf, buf.buf, NULL)) + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); - strbuf_swap(&buf, &nbuf); + strbuf_swap(&buf, &unquoted); } pathspec[0] = buf.buf; num_ignored += check_ignore(dir, prefix, @@ -136,7 +135,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix) maybe_flush_or_die(stdout, "check-ignore to stdout"); } strbuf_release(&buf); - strbuf_release(&nbuf); + strbuf_release(&unquoted); return num_ignored; } diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c index ed888a5b9e..92c69672e9 100644 --- a/builtin/checkout-index.c +++ b/builtin/checkout-index.c @@ -130,33 +130,6 @@ static const char * const builtin_checkout_index_usage[] = { static struct lock_file lock_file; -static int option_parse_u(const struct option *opt, - const char *arg, int unset) -{ - int *newfd = opt->value; - - state.refresh_cache = 1; - state.istate = &the_index; - if (*newfd < 0) - *newfd = hold_locked_index(&lock_file, 1); - return 0; -} - -static int option_parse_z(const struct option *opt, - const char *arg, int unset) -{ - nul_term_line = !unset; - return 0; -} - -static int option_parse_prefix(const struct option *opt, - const char *arg, int unset) -{ - state.base_dir = arg; - state.base_dir_len = strlen(arg); - return 0; -} - static int option_parse_stage(const struct option *opt, const char *arg, int unset) { @@ -168,7 +141,7 @@ static int option_parse_stage(const struct option *opt, if ('1' <= ch && ch <= '3') checkout_stage = arg[0] - '0'; else - die("stage should be between 1 and 3 or all"); + die(_("stage should be between 1 and 3 or all")); } return 0; } @@ -181,6 +154,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) int read_from_stdin = 0; int prefix_length; int force = 0, quiet = 0, not_new = 0; + int index_opt = 0; struct option builtin_checkout_index_options[] = { OPT_BOOL('a', "all", &all, N_("check out all files in the index")), @@ -189,22 +163,19 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) N_("no warning for existing files and files not in index")), OPT_BOOL('n', "no-create", ¬_new, N_("don't checkout new files")), - { OPTION_CALLBACK, 'u', "index", &newfd, NULL, - N_("update stat information in the index file"), - PARSE_OPT_NOARG, option_parse_u }, - { OPTION_CALLBACK, 'z', NULL, NULL, NULL, - N_("paths are separated with NUL character"), - PARSE_OPT_NOARG, option_parse_z }, + OPT_BOOL('u', "index", &index_opt, + N_("update stat information in the index file")), + OPT_BOOL('z', NULL, &nul_term_line, + N_("paths are separated with NUL character")), OPT_BOOL(0, "stdin", &read_from_stdin, N_("read list of paths from the standard input")), OPT_BOOL(0, "temp", &to_tempfile, N_("write the content to temporary files")), - OPT_CALLBACK(0, "prefix", NULL, N_("string"), - N_("when creating files, prepend <string>"), - option_parse_prefix), - OPT_CALLBACK(0, "stage", NULL, NULL, + OPT_STRING(0, "prefix", &state.base_dir, N_("string"), + N_("when creating files, prepend <string>")), + { OPTION_CALLBACK, 0, "stage", NULL, "1-3|all", N_("copy out the files from named stage"), - option_parse_stage), + PARSE_OPT_NONEG, option_parse_stage }, OPT_END() }; @@ -212,7 +183,6 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) usage_with_options(builtin_checkout_index_usage, builtin_checkout_index_options); git_config(git_default_config, NULL); - state.base_dir = ""; prefix_length = prefix ? strlen(prefix) : 0; if (read_cache() < 0) { @@ -225,15 +195,17 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) state.quiet = quiet; state.not_new = not_new; - if (state.base_dir_len || to_tempfile) { - /* when --prefix is specified we do not - * want to update cache. - */ - if (state.refresh_cache) { - rollback_lock_file(&lock_file); - newfd = -1; - } - state.refresh_cache = 0; + if (!state.base_dir) + state.base_dir = ""; + state.base_dir_len = strlen(state.base_dir); + + /* + * when --prefix is specified we do not want to update cache. + */ + if (index_opt && !state.base_dir_len && !to_tempfile) { + state.refresh_cache = 1; + state.istate = &the_index; + newfd = hold_locked_index(&lock_file, 1); } /* Check out named files first */ @@ -251,7 +223,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) } if (read_from_stdin) { - struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; + struct strbuf unquoted = STRBUF_INIT; strbuf_getline_fn getline_fn; if (all) @@ -261,16 +234,16 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix) while (getline_fn(&buf, stdin) != EOF) { char *p; if (!nul_term_line && buf.buf[0] == '"') { - strbuf_reset(&nbuf); - if (unquote_c_style(&nbuf, buf.buf, NULL)) + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); - strbuf_swap(&buf, &nbuf); + strbuf_swap(&buf, &unquoted); } p = prefix_path(prefix, prefix_length, buf.buf); checkout_file(p, prefix); free(p); } - strbuf_release(&nbuf); + strbuf_release(&unquoted); strbuf_release(&buf); } diff --git a/builtin/checkout.c b/builtin/checkout.c index 5af84a3118..cfa66e25eb 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -982,7 +982,8 @@ static int parse_branchname_arg(int argc, const char **argv, */ int recover_with_dwim = dwim_new_local_branch_ok; - if (check_filename(NULL, arg) && !has_dash_dash) + if (!has_dash_dash && + (check_filename(NULL, arg) || !no_wildcard(arg))) recover_with_dwim = 0; /* * Accept "git checkout foo" and "git checkout foo --" diff --git a/builtin/clone.c b/builtin/clone.c index bcba0805e1..b8c39aa701 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -47,6 +47,7 @@ static const char *real_git_dir; static char *option_upload_pack = "git-upload-pack"; static int option_verbosity; static int option_progress = -1; +static enum transport_family family; static struct string_list option_config; static struct string_list option_reference; static int option_dissociate; @@ -92,6 +93,10 @@ static struct option builtin_clone_options[] = { N_("separate git dir from working tree")), OPT_STRING_LIST('c', "config", &option_config, N_("key=value"), N_("set config inside the new repository")), + OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"), + TRANSPORT_FAMILY_IPV4), + OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), + TRANSPORT_FAMILY_IPV6), OPT_END() }; @@ -970,6 +975,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) remote = remote_get(option_origin); transport = transport_get(remote, remote->url[0]); transport_set_verbosity(transport, option_verbosity, option_progress); + transport->family = family; path = get_repo_path(remote->url[0], &is_bundle); is_local = option_local != 0 && path && !is_bundle; diff --git a/builtin/fetch.c b/builtin/fetch.c index 81218300d8..48c45ea5e3 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -38,6 +38,7 @@ static int all, append, dry_run, force, keep, multiple, update_head_ok, verbosit static int progress = -1, recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int tags = TAGS_DEFAULT, unshallow, update_shallow; static int max_children = 1; +static enum transport_family family; static const char *depth; static const char *upload_pack; static struct strbuf default_rla = STRBUF_INIT; @@ -127,6 +128,10 @@ static struct option builtin_fetch_options[] = { N_("accept refs that update .git/shallow")), { OPTION_CALLBACK, 0, "refmap", NULL, N_("refmap"), N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg }, + OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"), + TRANSPORT_FAMILY_IPV4), + OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), + TRANSPORT_FAMILY_IPV6), OPT_END() }; @@ -864,6 +869,7 @@ static struct transport *prepare_transport(struct remote *remote) struct transport *transport; transport = transport_get(remote, NULL); transport_set_verbosity(transport, verbosity, progress); + transport->family = family; if (upload_pack) set_option(transport, TRANS_OPT_UPLOADPACK, upload_pack); if (keep) diff --git a/builtin/hash-object.c b/builtin/hash-object.c index ff20395c69..f7d3567dd0 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -58,20 +58,21 @@ static void hash_object(const char *path, const char *type, const char *vpath, static void hash_stdin_paths(const char *type, int no_filters, unsigned flags, int literally) { - struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; + struct strbuf unquoted = STRBUF_INIT; while (strbuf_getline(&buf, stdin) != EOF) { if (buf.buf[0] == '"') { - strbuf_reset(&nbuf); - if (unquote_c_style(&nbuf, buf.buf, NULL)) + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); - strbuf_swap(&buf, &nbuf); + strbuf_swap(&buf, &unquoted); } hash_object(buf.buf, type, no_filters ? NULL : buf.buf, flags, literally); } strbuf_release(&buf); - strbuf_release(&nbuf); + strbuf_release(&unquoted); } int cmd_hash_object(int argc, const char **argv, const char *prefix) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index dedf02dc70..f02e3d23bb 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -379,14 +379,6 @@ static const char * const ls_files_usage[] = { NULL }; -static int option_parse_z(const struct option *opt, - const char *arg, int unset) -{ - line_terminator = unset ? '\n' : '\0'; - - return 0; -} - static int option_parse_exclude(const struct option *opt, const char *arg, int unset) { @@ -428,9 +420,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) struct exclude_list *el; struct string_list exclude_list = STRING_LIST_INIT_NODUP; struct option builtin_ls_files_options[] = { - { OPTION_CALLBACK, 'z', NULL, NULL, NULL, - N_("paths are separated with NUL character"), - PARSE_OPT_NOARG, option_parse_z }, + /* Think twice before adding "--nul" synonym to this */ + OPT_SET_INT('z', NULL, &line_terminator, + N_("paths are separated with NUL character"), '\0'), OPT_BOOL('t', NULL, &show_tag, N_("identify the file status with tags")), OPT_BOOL('v', NULL, &show_valid_bit, diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 4dae5b11c2..a6609f19ff 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -2284,21 +2284,11 @@ static void show_commit(struct commit *commit, void *data) index_commit_for_bitmap(commit); } -static void show_object(struct object *obj, - const struct name_path *path, const char *last, - void *data) +static void show_object(struct object *obj, const char *name, void *data) { - char *name = path_name(path, last); - add_preferred_base_object(name); add_object_entry(obj->oid.hash, obj->type, name, 0); obj->flags |= OBJECT_ADDED; - - /* - * We will have generated the hash from the name, - * but not saved a pointer to it - we can free it - */ - free((char *)name); } static void show_edge(struct commit *commit) @@ -2480,8 +2470,7 @@ static int get_object_list_from_bitmap(struct rev_info *revs) } static void record_recent_object(struct object *obj, - const struct name_path *path, - const char *last, + const char *name, void *data) { sha1_array_append(&recent_objects, obj->oid.hash); diff --git a/builtin/push.c b/builtin/push.c index 960ffc31e1..6e13b3c90a 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -23,6 +23,7 @@ static const char *receivepack; static int verbosity; static int progress = -1; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; +static enum transport_family family; static struct push_cas_option cas; @@ -346,6 +347,7 @@ static int push_with_options(struct transport *transport, int flags) unsigned int reject_reasons; transport_set_verbosity(transport, verbosity, progress); + transport->family = family; if (receivepack) transport_set_option(transport, @@ -565,6 +567,10 @@ int cmd_push(int argc, const char **argv, const char *prefix) 0, "signed", &push_cert, "yes|no|if-asked", N_("GPG sign the push"), PARSE_OPT_OPTARG, option_parse_push_signed }, OPT_BIT(0, "atomic", &flags, N_("request atomic transaction on remote side"), TRANSPORT_PUSH_ATOMIC), + OPT_SET_INT('4', "ipv4", &family, N_("use IPv4 addresses only"), + TRANSPORT_FAMILY_IPV4), + OPT_SET_INT('6', "ipv6", &family, N_("use IPv6 addresses only"), + TRANSPORT_FAMILY_IPV6), OPT_END() }; diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 3aa89a1a3c..275da0d647 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -177,9 +177,7 @@ static void finish_commit(struct commit *commit, void *data) free_commit_buffer(commit); } -static void finish_object(struct object *obj, - const struct name_path *path, const char *name, - void *cb_data) +static void finish_object(struct object *obj, const char *name, void *cb_data) { struct rev_list_info *info = cb_data; if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) @@ -188,15 +186,13 @@ static void finish_object(struct object *obj, parse_object(obj->oid.hash); } -static void show_object(struct object *obj, - const struct name_path *path, const char *component, - void *cb_data) +static void show_object(struct object *obj, const char *name, void *cb_data) { struct rev_list_info *info = cb_data; - finish_object(obj, path, component, cb_data); + finish_object(obj, name, cb_data); if (info->flags & REV_LIST_QUIET) return; - show_object_with_name(stdout, obj, path, component); + show_object_with_name(stdout, obj, name); } static void show_edge(struct commit *commit) diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index bd16876df5..cf8487b3b9 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -763,7 +763,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--git-common-dir")) { - puts(get_git_common_dir()); + const char *pfx = prefix ? prefix : ""; + puts(prefix_filename(pfx, strlen(pfx), get_git_common_dir())); continue; } if (!strcmp(arg, "--resolve-git-dir")) { diff --git a/builtin/stripspace.c b/builtin/stripspace.c index 7ff8434f7c..15e716ef43 100644 --- a/builtin/stripspace.c +++ b/builtin/stripspace.c @@ -35,7 +35,7 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix) N_("skip and remove all lines starting with comment character"), STRIP_COMMENTS), OPT_CMDMODE('c', "comment-lines", &mode, - N_("prepend comment character and blank to each line"), + N_("prepend comment character and space to each line"), COMMENT_LINES), OPT_END() }; diff --git a/builtin/update-index.c b/builtin/update-index.c index 7c5c143de5..1c94ca59bf 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -35,6 +35,15 @@ static int mark_skip_worktree_only; #define UNMARK_FLAG 2 static struct strbuf mtime_dir = STRBUF_INIT; +/* Untracked cache mode */ +enum uc_mode { + UC_UNSPECIFIED = -1, + UC_DISABLE = 0, + UC_ENABLE, + UC_TEST, + UC_FORCE +}; + __attribute__((format (printf, 1, 2))) static void report(const char *fmt, ...) { @@ -121,7 +130,7 @@ static int test_if_untracked_cache_is_supported(void) if (!mkdtemp(mtime_dir.buf)) die_errno("Could not make temporary directory"); - fprintf(stderr, _("Testing ")); + fprintf(stderr, _("Testing mtime in '%s' "), xgetcwd()); atexit(remove_test_directory); xstat_mtime_dir(&st); fill_stat_data(&base, &st); @@ -904,7 +913,7 @@ static int reupdate_callback(struct parse_opt_ctx_t *ctx, int cmd_update_index(int argc, const char **argv, const char *prefix) { int newfd, entries, has_errors = 0, nul_term_line = 0; - int untracked_cache = -1; + enum uc_mode untracked_cache = UC_UNSPECIFIED; int read_from_stdin = 0; int prefix_length = prefix ? strlen(prefix) : 0; int preferred_index_format = 0; @@ -999,8 +1008,10 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) N_("enable or disable split index")), OPT_BOOL(0, "untracked-cache", &untracked_cache, N_("enable/disable untracked cache")), + OPT_SET_INT(0, "test-untracked-cache", &untracked_cache, + N_("test if the filesystem supports untracked cache"), UC_TEST), OPT_SET_INT(0, "force-untracked-cache", &untracked_cache, - N_("enable untracked cache without testing the filesystem"), 2), + N_("enable untracked cache without testing the filesystem"), UC_FORCE), OPT_END() }; @@ -1075,16 +1086,17 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) } if (read_from_stdin) { - struct strbuf buf = STRBUF_INIT, nbuf = STRBUF_INIT; + struct strbuf buf = STRBUF_INIT; + struct strbuf unquoted = STRBUF_INIT; setup_work_tree(); while (getline_fn(&buf, stdin) != EOF) { char *p; if (!nul_term_line && buf.buf[0] == '"') { - strbuf_reset(&nbuf); - if (unquote_c_style(&nbuf, buf.buf, NULL)) + strbuf_reset(&unquoted); + if (unquote_c_style(&unquoted, buf.buf, NULL)) die("line is badly quoted"); - strbuf_swap(&buf, &nbuf); + strbuf_swap(&buf, &unquoted); } p = prefix_path(prefix, prefix_length, buf.buf); update_one(p); @@ -1092,7 +1104,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) chmod_path(set_executable_bit, p); free(p); } - strbuf_release(&nbuf); + strbuf_release(&unquoted); strbuf_release(&buf); } @@ -1109,27 +1121,32 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) the_index.split_index = NULL; the_index.cache_changed |= SOMETHING_CHANGED; } - if (untracked_cache > 0) { - struct untracked_cache *uc; - if (untracked_cache < 2) { - setup_work_tree(); - if (!test_if_untracked_cache_is_supported()) - return 1; - } - if (!the_index.untracked) { - uc = xcalloc(1, sizeof(*uc)); - strbuf_init(&uc->ident, 100); - uc->exclude_per_dir = ".gitignore"; - /* should be the same flags used by git-status */ - uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; - the_index.untracked = uc; - } - add_untracked_ident(the_index.untracked); - the_index.cache_changed |= UNTRACKED_CHANGED; - } else if (!untracked_cache && the_index.untracked) { - the_index.untracked = NULL; - the_index.cache_changed |= UNTRACKED_CHANGED; + switch (untracked_cache) { + case UC_UNSPECIFIED: + break; + case UC_DISABLE: + if (git_config_get_untracked_cache() == 1) + warning("core.untrackedCache is set to true; " + "remove or change it, if you really want to " + "disable the untracked cache"); + remove_untracked_cache(&the_index); + report(_("Untracked cache disabled")); + break; + case UC_TEST: + setup_work_tree(); + return !test_if_untracked_cache_is_supported(); + case UC_ENABLE: + case UC_FORCE: + if (git_config_get_untracked_cache() == 0) + warning("core.untrackedCache is set to false; " + "remove or change it, if you really want to " + "enable the untracked cache"); + add_untracked_cache(&the_index); + report(_("Untracked cache enabled for '%s'"), get_git_work_tree()); + break; + default: + die("Bug: bad untracked_cache value: %d", untracked_cache); } if (active_cache_changed) { diff --git a/builtin/worktree.c b/builtin/worktree.c index 475b9581a5..20cf67a549 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -201,9 +201,7 @@ static int add_worktree(const char *path, const char *refname, die(_("'%s' already exists"), path); /* is 'refname' a branch or commit? */ - if (opts->force_new_branch) /* definitely a branch */ - ; - else if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) && + if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) && ref_exists(symref.buf)) { /* it's a branch */ if (!opts->force) die_if_checked_out(symref.buf); @@ -336,9 +334,18 @@ static int add(int ac, const char **av, const char *prefix) branch = ac < 2 ? "HEAD" : av[1]; opts.force_new_branch = !!new_branch_force; - if (opts.force_new_branch) + if (opts.force_new_branch) { + struct strbuf symref = STRBUF_INIT; + opts.new_branch = new_branch_force; + if (!opts.force && + !strbuf_check_branch_ref(&symref, opts.new_branch) && + ref_exists(symref.buf)) + die_if_checked_out(symref.buf); + strbuf_release(&symref); + } + if (ac < 2 && !opts.new_branch && !opts.detach) { int n; const char *s = worktree_basename(path, &n); @@ -229,7 +229,9 @@ struct cache_entry { #error "CE_EXTENDED_FLAGS out of range" #endif +/* Forward structure decls */ struct pathspec; +struct child_process; /* * Copy the sha1 and stat state of a cache entry from one to @@ -1624,6 +1626,14 @@ extern int git_config_get_bool(const char *key, int *dest); extern int git_config_get_bool_or_int(const char *key, int *is_bool, int *dest); extern int git_config_get_maybe_bool(const char *key, int *dest); extern int git_config_get_pathname(const char *key, const char **dest); +extern int git_config_get_untracked_cache(void); + +/* + * This is a hack for test programs like test-dump-untracked-cache to + * ensure that they do not modify the untracked cache when reading it. + * Do not use it otherwise! + */ +extern int ignore_untracked_cache_config; struct key_value_info { const char *filename; @@ -1677,6 +1687,7 @@ extern int pager_use_color; extern int term_columns(void); extern int decimal_width(uintmax_t); extern int check_pager_config(const char *cmd); +extern void prepare_pager_args(struct child_process *, const char *pager); extern const char *editor_program; extern const char *askpass_program; diff --git a/compat/mingw.c b/compat/mingw.c index 77a51d3f72..fbe69b874b 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -454,6 +454,39 @@ static inline time_t filetime_to_time_t(const FILETIME *ft) return (time_t)(filetime_to_hnsec(ft) / 10000000); } +/** + * Verifies that safe_create_leading_directories() would succeed. + */ +static int has_valid_directory_prefix(wchar_t *wfilename) +{ + int n = wcslen(wfilename); + + while (n > 0) { + wchar_t c = wfilename[--n]; + DWORD attributes; + + if (!is_dir_sep(c)) + continue; + + wfilename[n] = L'\0'; + attributes = GetFileAttributesW(wfilename); + wfilename[n] = c; + if (attributes == FILE_ATTRIBUTE_DIRECTORY || + attributes == FILE_ATTRIBUTE_DEVICE) + return 1; + if (attributes == INVALID_FILE_ATTRIBUTES) + switch (GetLastError()) { + case ERROR_PATH_NOT_FOUND: + continue; + case ERROR_FILE_NOT_FOUND: + /* This implies parent directory exists. */ + return 1; + } + return 0; + } + return 1; +} + /* We keep the do_lstat code in a separate function to avoid recursion. * When a path ends with a slash, the stat will fail with ENOENT. In * this case, we strip the trailing slashes and stat again. @@ -514,6 +547,12 @@ static int do_lstat(int follow, const char *file_name, struct stat *buf) case ERROR_NOT_ENOUGH_MEMORY: errno = ENOMEM; break; + case ERROR_PATH_NOT_FOUND: + if (!has_valid_directory_prefix(wfilename)) { + errno = ENOTDIR; + break; + } + /* fallthru */ default: errno = ENOENT; break; @@ -1603,7 +1642,12 @@ repeat: if (gle == ERROR_ACCESS_DENIED && (attrs = GetFileAttributesW(wpnew)) != INVALID_FILE_ATTRIBUTES) { if (attrs & FILE_ATTRIBUTE_DIRECTORY) { - errno = EISDIR; + DWORD attrsold = GetFileAttributesW(wpold); + if (attrsold == INVALID_FILE_ATTRIBUTES || + !(attrsold & FILE_ATTRIBUTE_DIRECTORY)) + errno = EISDIR; + else if (!_wrmdir(wpnew)) + goto repeat; return -1; } if ((attrs & FILE_ATTRIBUTE_READONLY) && @@ -2047,6 +2091,37 @@ int xwcstoutf(char *utf, const wchar_t *wcs, size_t utflen) return -1; } +static void setup_windows_environment() +{ + char *tmp = getenv("TMPDIR"); + + /* on Windows it is TMP and TEMP */ + if (!tmp) { + if (!(tmp = getenv("TMP"))) + tmp = getenv("TEMP"); + if (tmp) { + setenv("TMPDIR", tmp, 1); + tmp = getenv("TMPDIR"); + } + } + + if (tmp) { + /* + * Convert all dir separators to forward slashes, + * to help shell commands called from the Git + * executable (by not mistaking the dir separators + * for escape characters). + */ + for (; *tmp; tmp++) + if (*tmp == '\\') + *tmp = '/'; + } + + /* simulate TERM to enable auto-color (see color.c) */ + if (!getenv("TERM")) + setenv("TERM", "cygwin", 1); +} + /* * Disable MSVCRT command line wildcard expansion (__getmainargs called from * mingw startup code, see init.c in mingw runtime). @@ -2125,19 +2200,7 @@ void mingw_startup() qsort(environ, i, sizeof(char*), compareenv); /* fix Windows specific environment settings */ - - /* on Windows it is TMP and TEMP */ - if (!mingw_getenv("TMPDIR")) { - const char *tmp = mingw_getenv("TMP"); - if (!tmp) - tmp = mingw_getenv("TEMP"); - if (tmp) - setenv("TMPDIR", tmp, 1); - } - - /* simulate TERM to enable auto-color (see color.c) */ - if (!getenv("TERM")) - setenv("TERM", "cygwin", 1); + setup_windows_environment(); /* initialize critical section for waitpid pinfo_t list */ InitializeCriticalSection(&pinfo_cs); @@ -1594,6 +1594,30 @@ int git_config_get_pathname(const char *key, const char **dest) return ret; } +int git_config_get_untracked_cache(void) +{ + int val = -1; + const char *v; + + /* Hack for test programs like test-dump-untracked-cache */ + if (ignore_untracked_cache_config) + return -1; + + if (!git_config_get_maybe_bool("core.untrackedcache", &val)) + return val; + + if (!git_config_get_value("core.untrackedcache", &v)) { + if (!strcasecmp(v, "keep")) + return -1; + + error("unknown core.untrackedCache value '%s'; " + "using 'keep' default value", v); + return -1; + } + + return -1; /* default value */ +} + NORETURN void git_die_config_linenr(const char *key, const char *filename, int linenr) { diff --git a/config.mak.uname b/config.mak.uname index 4b2e1b807f..d6f7980bb9 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -560,7 +560,8 @@ else NO_R_TO_GCC_LINKER = YesPlease INTERNAL_QSORT = YesPlease HAVE_LIBCHARSET_H = YesPlease - NO_GETTEXT = YesPlease + NO_GETTEXT = + USE_GETTEXT_SCHEME = fallthrough USE_LIBPCRE= YesPlease NO_CURL = USE_NED_ALLOCATOR = YesPlease @@ -357,6 +357,10 @@ static int git_tcp_connect_sock(char *host, int flags) port = "<none>"; memset(&hints, 0, sizeof(hints)); + if (flags & CONNECT_IPV4) + hints.ai_family = AF_INET; + else if (flags & CONNECT_IPV6) + hints.ai_family = AF_INET6; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; @@ -783,6 +787,10 @@ struct child_process *git_connect(int fd[2], const char *url, } argv_array_push(&conn->args, ssh); + if (flags & CONNECT_IPV4) + argv_array_push(&conn->args, "-4"); + else if (flags & CONNECT_IPV6) + argv_array_push(&conn->args, "-6"); if (tortoiseplink) argv_array_push(&conn->args, "-batch"); if (port) { @@ -3,6 +3,8 @@ #define CONNECT_VERBOSE (1u << 0) #define CONNECT_DIAG_URL (1u << 1) +#define CONNECT_IPV4 (1u << 2) +#define CONNECT_IPV6 (1u << 3) extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags); extern int finish_connect(struct child_process *conn); extern int git_connection_is_socket(struct child_process *conn); diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 15ebba51dc..e3918c87e3 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -2060,6 +2060,7 @@ _git_config () core.sparseCheckout core.symlinks core.trustctime + core.untrackedCache core.warnAmbiguousRefs core.whitespace core.worktree @@ -2414,8 +2415,8 @@ _git_stash () show,--*|branch,--*) ;; branch,*) - if [ $cword -eq 3 ]; then - __gitcomp_nl "$(__git_refs)"; + if [ $cword -eq 3 ]; then + __gitcomp_nl "$(__git_refs)"; else __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ | sed -n -e 's/:.*//p')" @@ -434,7 +434,7 @@ static int apply_filter(const char *path, const char *src, size_t len, int fd, struct async async; struct filter_params params; - if (!cmd) + if (!cmd || !*cmd) return 0; if (!dst) @@ -53,6 +53,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, int check_only, const struct path_simplify *simplify); static int get_dtype(struct dirent *de, const char *path, int len); +static struct trace_key trace_exclude = TRACE_KEY_INIT(EXCLUDE); + /* helper string functions with support for the ignore_case flag */ int strcmp_icase(const char *a, const char *b) { @@ -519,6 +521,7 @@ void add_exclude(const char *string, const char *base, x->baselen = baselen; x->flags = flags; x->srcpos = srcpos; + string_list_init(&x->sticky_paths, 1); ALLOC_GROW(el->excludes, el->nr + 1, el->alloc); el->excludes[el->nr++] = x; x->el = el; @@ -559,8 +562,10 @@ void clear_exclude_list(struct exclude_list *el) { int i; - for (i = 0; i < el->nr; i++) + for (i = 0; i < el->nr; i++) { + string_list_clear(&el->excludes[i]->sticky_paths, 0); free(el->excludes[i]); + } free(el->excludes); free(el->filebuf); @@ -878,7 +883,7 @@ int match_pathname(const char *pathname, int pathlen, * then our prefix match is all we need; we * do not need to call fnmatch at all. */ - if (!patternlen && !namelen) + if (!patternlen && (!namelen || *name == '/')) return 1; } @@ -887,6 +892,113 @@ int match_pathname(const char *pathname, int pathlen, WM_PATHNAME) == 0; } +static void add_sticky(struct exclude *exc, const char *pathname, int pathlen) +{ + struct strbuf sb = STRBUF_INIT; + int i; + + for (i = exc->sticky_paths.nr - 1; i >= 0; i--) { + const char *sticky = exc->sticky_paths.items[i].string; + int len = strlen(sticky); + + if (pathlen < len && sticky[pathlen] == '/' && + !strncmp(pathname, sticky, pathlen)) + return; + } + + strbuf_add(&sb, pathname, pathlen); + string_list_append_nodup(&exc->sticky_paths, strbuf_detach(&sb, NULL)); +} + +static int match_sticky(struct exclude *exc, const char *pathname, int pathlen, int dtype) +{ + int i; + + for (i = exc->sticky_paths.nr - 1; i >= 0; i--) { + const char *sticky = exc->sticky_paths.items[i].string; + int len = strlen(sticky); + + if (pathlen == len && dtype == DT_DIR && + !strncmp(pathname, sticky, len)) + return 1; + + if (pathlen > len && pathname[len] == '/' && + !strncmp(pathname, sticky, len)) + return 1; + } + + return 0; +} + +static inline int different_decisions(const struct exclude *a, + const struct exclude *b) +{ + return (a->flags & EXC_FLAG_NEGATIVE) != (b->flags & EXC_FLAG_NEGATIVE); +} + +/* + * Return non-zero if pathname is a directory and an ancestor of the + * literal path in a pattern. + */ +static int match_directory_part(const char *pathname, int pathlen, + int *dtype, struct exclude *x) +{ + const char *base = x->base; + int baselen = x->baselen ? x->baselen - 1 : 0; + const char *pattern = x->pattern; + int prefix = x->nowildcardlen; + int patternlen = x->patternlen; + + if (*dtype == DT_UNKNOWN) + *dtype = get_dtype(NULL, pathname, pathlen); + if (*dtype != DT_DIR) + return 0; + + if (*pattern == '/') { + pattern++; + patternlen--; + prefix--; + } + + if (baselen) { + if (((pathlen < baselen && base[pathlen] == '/') || + pathlen == baselen) && + !strncmp_icase(pathname, base, pathlen)) + return 1; + pathname += baselen + 1; + pathlen -= baselen + 1; + } + + + if (prefix && + (((pathlen < prefix && pattern[pathlen] == '/') || + pathlen == prefix) && + !strncmp_icase(pathname, pattern, pathlen))) + return 1; + + return 0; +} + +static struct exclude *should_descend(const char *pathname, int pathlen, + int *dtype, struct exclude_list *el, + struct exclude *exc) +{ + int i; + + for (i = el->nr - 1; 0 <= i; i--) { + struct exclude *x = el->excludes[i]; + + if (x == exc) + break; + + if (!(x->flags & EXC_FLAG_NODIR) && + different_decisions(x, exc) && + match_directory_part(pathname, pathlen, dtype, x)) + return x; + } + return NULL; +} + /* * Scan the given exclude list in reverse to see whether pathname * should be ignored. The first match (i.e. the last on the list), if @@ -900,16 +1012,32 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname, struct exclude_list *el) { struct exclude *exc = NULL; /* undecided */ - int i; + int i, maybe_descend = 0; if (!el->nr) return NULL; /* undefined */ + trace_printf_key(&trace_exclude, "exclude: from %s\n", el->src); + for (i = el->nr - 1; 0 <= i; i--) { struct exclude *x = el->excludes[i]; const char *exclude = x->pattern; int prefix = x->nowildcardlen; + if (!maybe_descend && i < el->nr - 1 && + different_decisions(x, el->excludes[i+1])) + maybe_descend = 1; + + if (x->sticky_paths.nr) { + if (*dtype == DT_UNKNOWN) + *dtype = get_dtype(NULL, pathname, pathlen); + if (match_sticky(x, pathname, pathlen, *dtype)) { + exc = x; + break; + } + continue; + } + if (x->flags & EXC_FLAG_MUSTBEDIR) { if (*dtype == DT_UNKNOWN) *dtype = get_dtype(NULL, pathname, pathlen); @@ -936,6 +1064,45 @@ static struct exclude *last_exclude_matching_from_list(const char *pathname, break; } } + + if (!exc) { + trace_printf_key(&trace_exclude, "exclude: %.*s => n/a\n", + pathlen, pathname); + return NULL; + } + + /* + * We have found a matching pattern "exc" that may exclude whole + * directory. We also found that there may be a pattern that matches + * something inside the directory and reincludes stuff. + * + * Go through the patterns again, find that pattern and double check. + * If it's true, return "undecided" and keep descending in. "exc" is + * marked sticky so that it continues to match inside the directory. + */ + if (!(exc->flags & EXC_FLAG_NEGATIVE) && maybe_descend) { + struct exclude *x; + + if (*dtype == DT_UNKNOWN) + *dtype = get_dtype(NULL, pathname, pathlen); + + if (*dtype == DT_DIR && + (x = should_descend(pathname, pathlen, dtype, el, exc))) { + add_sticky(exc, pathname, pathlen); + trace_printf_key(&trace_exclude, + "exclude: %.*s vs %s at line %d => %s," + " forced open by %s at line %d => n/a\n", + pathlen, pathname, exc->pattern, exc->srcpos, + exc->flags & EXC_FLAG_NEGATIVE ? "no" : "yes", + x->pattern, x->srcpos); + return NULL; + } + } + + trace_printf_key(&trace_exclude, "exclude: %.*s vs %s at line %d => %s%s\n", + pathlen, pathname, exc->pattern, exc->srcpos, + exc->flags & EXC_FLAG_NEGATIVE ? "no" : "yes", + exc->sticky_paths.nr ? " (stuck)" : ""); return exc; } @@ -1683,9 +1850,13 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, struct cached_dir cdir; enum path_treatment state, subdir_state, dir_state = path_none; struct strbuf path = STRBUF_INIT; + static int level = 0; strbuf_add(&path, base, baselen); + trace_printf_key(&trace_exclude, "exclude: [%d] enter '%.*s'\n", + level++, baselen, base); + if (open_cached_dir(&cdir, dir, untracked, &path, check_only)) goto out; @@ -1749,6 +1920,8 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir, } close_cached_dir(&cdir); out: + trace_printf_key(&trace_exclude, "exclude: [%d] leave '%.*s'\n", + --level, baselen, base); strbuf_release(&path); return dir_state; @@ -1839,31 +2012,67 @@ static const char *get_ident_string(void) return sb.buf; if (uname(&uts) < 0) die_errno(_("failed to get kernel name and information")); - strbuf_addf(&sb, "Location %s, system %s %s %s", get_git_work_tree(), - uts.sysname, uts.release, uts.version); + strbuf_addf(&sb, "Location %s, system %s", get_git_work_tree(), + uts.sysname); return sb.buf; } static int ident_in_untracked(const struct untracked_cache *uc) { - const char *end = uc->ident.buf + uc->ident.len; - const char *p = uc->ident.buf; + /* + * Previous git versions may have saved many NUL separated + * strings in the "ident" field, but it is insane to manage + * many locations, so just take care of the first one. + */ - for (p = uc->ident.buf; p < end; p += strlen(p) + 1) - if (!strcmp(p, get_ident_string())) - return 1; - return 0; + return !strcmp(uc->ident.buf, get_ident_string()); } -void add_untracked_ident(struct untracked_cache *uc) +static void set_untracked_ident(struct untracked_cache *uc) { - if (ident_in_untracked(uc)) - return; + strbuf_reset(&uc->ident); strbuf_addstr(&uc->ident, get_ident_string()); - /* this strbuf contains a list of strings, save NUL too */ + + /* + * This strbuf used to contain a list of NUL separated + * strings, so save NUL too for backward compatibility. + */ strbuf_addch(&uc->ident, 0); } +static void new_untracked_cache(struct index_state *istate) +{ + struct untracked_cache *uc = xcalloc(1, sizeof(*uc)); + strbuf_init(&uc->ident, 100); + uc->exclude_per_dir = ".gitignore"; + /* should be the same flags used by git-status */ + uc->dir_flags = DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES; + set_untracked_ident(uc); + istate->untracked = uc; + istate->cache_changed |= UNTRACKED_CHANGED; +} + +void add_untracked_cache(struct index_state *istate) +{ + if (!istate->untracked) { + new_untracked_cache(istate); + } else { + if (!ident_in_untracked(istate->untracked)) { + free_untracked_cache(istate->untracked); + new_untracked_cache(istate); + } + } +} + +void remove_untracked_cache(struct index_state *istate) +{ + if (istate->untracked) { + free_untracked_cache(istate->untracked); + istate->untracked = NULL; + istate->cache_changed |= UNTRACKED_CHANGED; + } +} + static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir, int base_len, const struct pathspec *pathspec) @@ -1921,7 +2130,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d return NULL; if (!ident_in_untracked(dir->untracked)) { - warning(_("Untracked cache is disabled on this system.")); + warning(_("Untracked cache is disabled on this system or location.")); return NULL; } @@ -1949,6 +2158,25 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d return root; } +static void clear_sticky(struct dir_struct *dir) +{ + struct exclude_list_group *g; + struct exclude_list *el; + struct exclude *x; + int i, j, k; + + for (i = EXC_CMDL; i <= EXC_FILE; i++) { + g = &dir->exclude_list_group[i]; + for (j = g->nr - 1; j >= 0; j--) { + el = &g->el[j]; + for (k = el->nr - 1; 0 <= k; k--) { + x = el->excludes[k]; + string_list_clear(&x->sticky_paths, 0); + } + } + } +} + int read_directory(struct dir_struct *dir, const char *path, int len, const struct pathspec *pathspec) { struct path_simplify *simplify; @@ -1970,6 +2198,12 @@ int read_directory(struct dir_struct *dir, const char *path, int len, const stru return dir->nr; /* + * Stay on the safe side. if read_directory() has run once on + * "dir", some sticky flag may have been left. Clear them all. + */ + clear_sticky(dir); + + /* * exclude patterns are treated like positive ones in * create_simplify. Usually exclude patterns should be a * subset of positive ones, which has no impacts on @@ -4,6 +4,7 @@ /* See Documentation/technical/api-directory-listing.txt */ #include "strbuf.h" +#include "string-list.h" struct dir_entry { unsigned int len; @@ -34,6 +35,8 @@ struct exclude { * and from -1 decrementing for patterns from CLI args. */ int srcpos; + + struct string_list sticky_paths; }; /* @@ -307,5 +310,6 @@ void untracked_cache_add_to_index(struct index_state *, const char *); void free_untracked_cache(struct untracked_cache *); struct untracked_cache *read_untracked_extension(const void *data, unsigned long sz); void write_untracked_extension(struct strbuf *out, struct untracked_cache *untracked); -void add_untracked_ident(struct untracked_cache *); +void add_untracked_cache(struct index_state *istate); +void remove_untracked_cache(struct index_state *istate); #endif diff --git a/environment.c b/environment.c index 1cc4aab4ea..6dec9d0403 100644 --- a/environment.c +++ b/environment.c @@ -87,6 +87,13 @@ int auto_comment_line_char; /* Parallel index stat data preload? */ int core_preload_index = 1; +/* + * This is a hack for test programs like test-dump-untracked-cache to + * ensure that they do not modify the untracked cache when reading it. + * Do not use it otherwise! + */ +int ignore_untracked_cache_config; + /* This is set by setup_git_dir_gently() and/or git_default_config() */ char *git_work_tree_cfg; static char *work_tree; diff --git a/git-cvsserver.perl b/git-cvsserver.perl index 95e69b19a7..02c0445be1 100755 --- a/git-cvsserver.perl +++ b/git-cvsserver.perl @@ -2664,7 +2664,7 @@ sub argsfromdir # co # Obtain list directly. # remove # HERE: TEST: MAYBE client does the recursion for us, # # since it only makes sense to remove stuff already in - # # the sandobx? + # # the sandbox? # ci # HERE: Similar to remove... # # Don't try to implement the confusing/weird # # ci -r bug er.."feature". @@ -25,14 +25,14 @@ static const char *env_names[] = { GIT_PREFIX_ENVIRONMENT }; static char *orig_env[4]; -static int saved_env_before_alias; +static int save_restore_env_balance; static void save_env_before_alias(void) { int i; - if (saved_env_before_alias) - return; - saved_env_before_alias = 1; + + assert(save_restore_env_balance == 0); + save_restore_env_balance = 1; orig_cwd = xgetcwd(); for (i = 0; i < ARRAY_SIZE(env_names); i++) { orig_env[i] = getenv(env_names[i]); @@ -44,6 +44,9 @@ static void save_env_before_alias(void) static void restore_env(int external_alias) { int i; + + assert(save_restore_env_balance == 1); + save_restore_env_balance = 0; if (!external_alias && orig_cwd && chdir(orig_cwd)) die_errno("could not move to %s", orig_cwd); free(orig_cwd); @@ -51,10 +54,12 @@ static void restore_env(int external_alias) if (external_alias && !strcmp(env_names[i], GIT_PREFIX_ENVIRONMENT)) continue; - if (orig_env[i]) + if (orig_env[i]) { setenv(env_names[i], orig_env[i], 1); - else + free(orig_env[i]); + } else { unsetenv(env_names[i]); + } } } @@ -531,16 +536,8 @@ static void handle_builtin(int argc, const char **argv) } builtin = get_builtin(cmd); - if (builtin) { - /* - * XXX: if we can figure out cases where it is _safe_ - * to do, we can avoid spawning a new process when - * saved_env_before_alias is true - * (i.e. setup_git_dir* has been run once) - */ - if (!saved_env_before_alias) - exit(run_builtin(builtin, argc, argv)); - } + if (builtin) + exit(run_builtin(builtin, argc, argv)); } static void execv_dashed_external(const char **argv) @@ -584,8 +581,17 @@ static int run_argv(int *argcp, const char ***argv) int done_alias = 0; while (1) { - /* See if it's a builtin */ - handle_builtin(*argcp, *argv); + /* + * If we tried alias and futzed with our environment, + * it no longer is safe to invoke builtins directly in + * general. We have to spawn them as dashed externals. + * + * NEEDSWORK: if we can figure out cases + * where it is safe to do, we can avoid spawning a new + * process. + */ + if (!done_alias) + handle_builtin(*argcp, *argv); /* .. then try the external ones */ execv_dashed_external(*argv); diff --git a/http-push.c b/http-push.c index d857b131a8..bd60668707 100644 --- a/http-push.c +++ b/http-push.c @@ -1277,9 +1277,7 @@ static struct object_list **add_one_object(struct object *obj, struct object_lis } static struct object_list **process_blob(struct blob *blob, - struct object_list **p, - struct name_path *path, - const char *name) + struct object_list **p) { struct object *obj = &blob->object; @@ -1293,14 +1291,11 @@ static struct object_list **process_blob(struct blob *blob, } static struct object_list **process_tree(struct tree *tree, - struct object_list **p, - struct name_path *path, - const char *name) + struct object_list **p) { struct object *obj = &tree->object; struct tree_desc desc; struct name_entry entry; - struct name_path me; obj->flags |= LOCAL; @@ -1310,21 +1305,17 @@ static struct object_list **process_tree(struct tree *tree, die("bad tree object %s", oid_to_hex(&obj->oid)); obj->flags |= SEEN; - name = xstrdup(name); p = add_one_object(obj, p); - me.up = path; - me.elem = name; - me.elem_len = strlen(name); init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) switch (object_type(entry.mode)) { case OBJ_TREE: - p = process_tree(lookup_tree(entry.sha1), p, &me, name); + p = process_tree(lookup_tree(entry.sha1), p); break; case OBJ_BLOB: - p = process_blob(lookup_blob(entry.sha1), p, &me, name); + p = process_blob(lookup_blob(entry.sha1), p); break; default: /* Subproject commit - not in this repository */ @@ -1343,7 +1334,7 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock) int count = 0; while ((commit = get_revision(revs)) != NULL) { - p = process_tree(commit->tree, p, NULL, ""); + p = process_tree(commit->tree, p); commit->object.flags |= LOCAL; if (!(commit->object.flags & UNINTERESTING)) count += add_send_request(&commit->object, lock); @@ -1362,11 +1353,11 @@ static int get_delta(struct rev_info *revs, struct remote_lock *lock) continue; } if (obj->type == OBJ_TREE) { - p = process_tree((struct tree *)obj, p, NULL, name); + p = process_tree((struct tree *)obj, p); continue; } if (obj->type == OBJ_BLOB) { - p = process_blob((struct blob *)obj, p, NULL, name); + p = process_blob((struct blob *)obj, p); continue; } die("unknown pending object %s (%s)", oid_to_hex(&obj->oid), name); @@ -11,6 +11,11 @@ #include "gettext.h" #include "transport.h" +#if LIBCURL_VERSION_NUM >= 0x070a08 +long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER; +#else +long int git_curl_ipresolve; +#endif int active_requests; int http_is_verbose; size_t http_post_buffer = 16 * LARGE_PACKET_MAX; @@ -57,6 +62,9 @@ static const char *ssl_key; #if LIBCURL_VERSION_NUM >= 0x070908 static const char *ssl_capath; #endif +#if LIBCURL_VERSION_NUM >= 0x072c00 +static const char *ssl_pinnedkey; +#endif static const char *ssl_cainfo; static long curl_low_speed_limit = -1; static long curl_low_speed_time = -1; @@ -87,6 +95,7 @@ static int curl_save_cookies; struct credential http_auth = CREDENTIAL_INIT; static int http_proactive_auth; static const char *user_agent; +static int curl_empty_auth; #if LIBCURL_VERSION_NUM >= 0x071700 /* Use CURLOPT_KEYPASSWD as is */ @@ -299,14 +308,31 @@ static int http_options(const char *var, const char *value, void *cb) if (!strcmp("http.useragent", var)) return git_config_string(&user_agent, var, value); + if (!strcmp("http.emptyauth", var)) { + curl_empty_auth = git_config_bool(var, value); + return 0; + } + + if (!strcmp("http.pinnedpubkey", var)) { +#if LIBCURL_VERSION_NUM >= 0x072c00 + return git_config_pathname(&ssl_pinnedkey, var, value); +#else + warning(_("Public key pinning not supported with cURL < 7.44.0")); + return 0; +#endif + } + /* Fall back on the default ones */ return git_default_config(var, value, cb); } static void init_curl_http_auth(CURL *result) { - if (!http_auth.username) + if (!http_auth.username) { + if (curl_empty_auth) + curl_easy_setopt(result, CURLOPT_USERPWD, ":"); return; + } credential_fill(&http_auth); @@ -499,6 +525,10 @@ static CURL *get_curl_handle(void) if (ssl_capath != NULL) curl_easy_setopt(result, CURLOPT_CAPATH, ssl_capath); #endif +#if LIBCURL_VERSION_NUM >= 0x072c00 + if (ssl_pinnedkey != NULL) + curl_easy_setopt(result, CURLOPT_PINNEDPUBLICKEY, ssl_pinnedkey); +#endif if (ssl_cainfo != NULL) curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo); @@ -824,10 +854,14 @@ struct active_request_slot *get_active_slot(void) curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 1); curl_easy_setopt(slot->curl, CURLOPT_RANGE, NULL); + +#if LIBCURL_VERSION_NUM >= 0x070a08 + curl_easy_setopt(slot->curl, CURLOPT_IPRESOLVE, git_curl_ipresolve); +#endif #ifdef LIBCURL_CAN_HANDLE_AUTH_ANY curl_easy_setopt(slot->curl, CURLOPT_HTTPAUTH, http_auth_methods); #endif - if (http_auth.password) + if (http_auth.password || curl_empty_auth) init_curl_http_auth(slot->curl); return slot; @@ -107,6 +107,7 @@ extern void http_init(struct remote *remote, const char *url, int proactive_auth); extern void http_cleanup(void); +extern long int git_curl_ipresolve; extern int active_requests; extern int http_is_verbose; extern size_t http_post_buffer; @@ -13,11 +13,14 @@ static struct strbuf git_default_date = STRBUF_INIT; static int default_email_is_bogus; static int default_name_is_bogus; +static int ident_use_config_only; + #define IDENT_NAME_GIVEN 01 #define IDENT_MAIL_GIVEN 02 #define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN) static int committer_ident_explicitly_given; static int author_ident_explicitly_given; +static int ident_config_given; #ifdef NO_GECOS_IN_PWENT #define get_gecos(ignored) "&" @@ -345,32 +348,40 @@ const char *fmt_ident(const char *name, const char *email, int want_date = !(flag & IDENT_NO_DATE); int want_name = !(flag & IDENT_NO_NAME); - if (want_name && !name) - name = ident_default_name(); - if (!email) - email = ident_default_email(); - - if (want_name && !*name) { - struct passwd *pw; - - if (strict) { - if (name == git_default_name.buf) + if (want_name) { + int using_default = 0; + if (!name) { + name = ident_default_name(); + using_default = 1; + if (strict && default_name_is_bogus) { fputs(env_hint, stderr); - die("empty ident name (for <%s>) not allowed", email); + die("unable to auto-detect name (got '%s')", name); + } + if (strict && ident_use_config_only + && !(ident_config_given & IDENT_NAME_GIVEN)) + die("user.useConfigOnly set but no name given"); + } + if (!*name) { + struct passwd *pw; + if (strict) { + if (using_default) + fputs(env_hint, stderr); + die("empty ident name (for <%s>) not allowed", email); + } + pw = xgetpwuid_self(NULL); + name = pw->pw_name; } - pw = xgetpwuid_self(NULL); - name = pw->pw_name; - } - - if (want_name && strict && - name == git_default_name.buf && default_name_is_bogus) { - fputs(env_hint, stderr); - die("unable to auto-detect name (got '%s')", name); } - if (strict && email == git_default_email.buf && default_email_is_bogus) { - fputs(env_hint, stderr); - die("unable to auto-detect email address (got '%s')", email); + if (!email) { + email = ident_default_email(); + if (strict && default_email_is_bogus) { + fputs(env_hint, stderr); + die("unable to auto-detect email address (got '%s')", email); + } + if (strict && ident_use_config_only + && !(ident_config_given & IDENT_MAIL_GIVEN)) + die("user.useConfigOnly set but no mail given"); } strbuf_reset(&ident); @@ -444,6 +455,11 @@ int author_ident_sufficiently_given(void) int git_ident_config(const char *var, const char *value, void *data) { + if (!strcmp(var, "user.useconfigonly")) { + ident_use_config_only = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "user.name")) { if (!value) return config_error_nonbool(var); @@ -451,6 +467,7 @@ int git_ident_config(const char *var, const char *value, void *data) strbuf_addstr(&git_default_name, value); committer_ident_explicitly_given |= IDENT_NAME_GIVEN; author_ident_explicitly_given |= IDENT_NAME_GIVEN; + ident_config_given |= IDENT_NAME_GIVEN; return 0; } @@ -461,6 +478,7 @@ int git_ident_config(const char *var, const char *value, void *data) strbuf_addstr(&git_default_email, value); committer_ident_explicitly_given |= IDENT_MAIL_GIVEN; author_ident_explicitly_given |= IDENT_MAIL_GIVEN; + ident_config_given |= IDENT_MAIL_GIVEN; return 0; } diff --git a/list-objects.c b/list-objects.c index 11732d9388..917cc5d7c9 100644 --- a/list-objects.c +++ b/list-objects.c @@ -11,11 +11,12 @@ static void process_blob(struct rev_info *revs, struct blob *blob, show_object_fn show, - struct name_path *path, + struct strbuf *path, const char *name, void *cb_data) { struct object *obj = &blob->object; + size_t pathlen; if (!revs->blob_objects) return; @@ -24,7 +25,11 @@ static void process_blob(struct rev_info *revs, if (obj->flags & (UNINTERESTING | SEEN)) return; obj->flags |= SEEN; - show(obj, path, name, cb_data); + + pathlen = path->len; + strbuf_addstr(path, name); + show(obj, path->buf, cb_data); + strbuf_setlen(path, pathlen); } /* @@ -52,7 +57,7 @@ static void process_blob(struct rev_info *revs, static void process_gitlink(struct rev_info *revs, const unsigned char *sha1, show_object_fn show, - struct name_path *path, + struct strbuf *path, const char *name, void *cb_data) { @@ -62,7 +67,6 @@ static void process_gitlink(struct rev_info *revs, static void process_tree(struct rev_info *revs, struct tree *tree, show_object_fn show, - struct name_path *path, struct strbuf *base, const char *name, void *cb_data) @@ -70,7 +74,6 @@ static void process_tree(struct rev_info *revs, struct object *obj = &tree->object; struct tree_desc desc; struct name_entry entry; - struct name_path me; enum interesting match = revs->diffopt.pathspec.nr == 0 ? all_entries_interesting: entry_not_interesting; int baselen = base->len; @@ -86,17 +89,12 @@ static void process_tree(struct rev_info *revs, return; die("bad tree object %s", oid_to_hex(&obj->oid)); } + obj->flags |= SEEN; - show(obj, path, name, cb_data); - me.up = path; - me.elem = name; - me.elem_len = strlen(name); - - if (!match) { - strbuf_addstr(base, name); - if (base->len) - strbuf_addch(base, '/'); - } + strbuf_addstr(base, name); + show(obj, base->buf, cb_data); + if (base->len) + strbuf_addch(base, '/'); init_tree_desc(&desc, tree->buffer, tree->size); @@ -113,16 +111,16 @@ static void process_tree(struct rev_info *revs, if (S_ISDIR(entry.mode)) process_tree(revs, lookup_tree(entry.sha1), - show, &me, base, entry.path, + show, base, entry.path, cb_data); else if (S_ISGITLINK(entry.mode)) process_gitlink(revs, entry.sha1, - show, &me, entry.path, + show, base, entry.path, cb_data); else process_blob(revs, lookup_blob(entry.sha1), - show, &me, entry.path, + show, base, entry.path, cb_data); } strbuf_setlen(base, baselen); @@ -213,19 +211,19 @@ void traverse_commit_list(struct rev_info *revs, continue; if (obj->type == OBJ_TAG) { obj->flags |= SEEN; - show_object(obj, NULL, name, data); + show_object(obj, name, data); continue; } if (!path) path = ""; if (obj->type == OBJ_TREE) { process_tree(revs, (struct tree *)obj, show_object, - NULL, &base, path, data); + &base, path, data); continue; } if (obj->type == OBJ_BLOB) { process_blob(revs, (struct blob *)obj, show_object, - NULL, path, data); + &base, path, data); continue; } die("unknown pending object %s (%s)", diff --git a/list-objects.h b/list-objects.h index 136a1da5a6..0cebf8585c 100644 --- a/list-objects.h +++ b/list-objects.h @@ -2,7 +2,7 @@ #define LIST_OBJECTS_H typedef void (*show_commit_fn)(struct commit *, void *); -typedef void (*show_object_fn)(struct object *, const struct name_path *, const char *, void *); +typedef void (*show_object_fn)(struct object *, const char *, void *); void traverse_commit_list(struct rev_info *, show_commit_fn, show_object_fn, void *); typedef void (*show_edge_fn)(struct commit *); diff --git a/mergetools/vimdiff b/mergetools/vimdiff index 1ddfbfcd78..74ea6d5479 100644 --- a/mergetools/vimdiff +++ b/mergetools/vimdiff @@ -9,8 +9,8 @@ merge_cmd () { gvimdiff|vimdiff) if $base_present then - "$merge_tool_path" -f -d -c 'wincmd J' \ - "$MERGED" "$LOCAL" "$BASE" "$REMOTE" + "$merge_tool_path" -f -d -c '4wincmd w | wincmd J' \ + "$LOCAL" "$BASE" "$REMOTE" "$MERGED" else "$merge_tool_path" -f -d -c 'wincmd l' \ "$LOCAL" "$MERGED" "$REMOTE" diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 6bff970c90..c30bcd06cb 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -148,8 +148,7 @@ static uint32_t find_object_pos(const unsigned char *sha1) return entry->in_pack_pos; } -static void show_object(struct object *object, const struct name_path *path, - const char *last, void *data) +static void show_object(struct object *object, const char *name, void *data) { struct bitmap *base = data; bitmap_set(base, find_object_pos(object->oid.hash)); diff --git a/pack-bitmap.c b/pack-bitmap.c index dd8dc16e67..b949e51716 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -414,19 +414,15 @@ static int ext_index_add_object(struct object *object, const char *name) return bitmap_pos + bitmap_git.pack->num_objects; } -static void show_object(struct object *object, const struct name_path *path, - const char *last, void *data) +static void show_object(struct object *object, const char *name, void *data) { struct bitmap *base = data; int bitmap_pos; bitmap_pos = bitmap_position(object->oid.hash); - if (bitmap_pos < 0) { - char *name = path_name(path, last); + if (bitmap_pos < 0) bitmap_pos = ext_index_add_object(object, name); - free(name); - } bitmap_set(base, bitmap_pos); } @@ -894,9 +890,8 @@ struct bitmap_test_data { size_t seen; }; -static void test_show_object(struct object *object, - const struct name_path *path, - const char *last, void *data) +static void test_show_object(struct object *object, const char *name, + void *data) { struct bitmap_test_data *tdata = data; int bitmap_pos; @@ -11,7 +11,6 @@ * something different on Windows. */ -static const char *pager_argv[] = { NULL, NULL }; static struct child_process pager_process = CHILD_PROCESS_INIT; static void wait_for_pager(int in_signal) @@ -64,6 +63,16 @@ const char *git_pager(int stdout_is_tty) return pager; } +void prepare_pager_args(struct child_process *pager_process, const char *pager) +{ + argv_array_push(&pager_process->args, pager); + pager_process->use_shell = 1; + if (!getenv("LESS")) + argv_array_push(&pager_process->env_array, "LESS=FRX"); + if (!getenv("LV")) + argv_array_push(&pager_process->env_array, "LV=-c"); +} + void setup_pager(void) { const char *pager = git_pager(isatty(1)); @@ -80,14 +89,8 @@ void setup_pager(void) setenv("GIT_PAGER_IN_USE", "true", 1); /* spawn the pager */ - pager_argv[0] = pager; - pager_process.use_shell = 1; - pager_process.argv = pager_argv; + prepare_pager_args(&pager_process, pager); pager_process.in = -1; - if (!getenv("LESS")) - argv_array_push(&pager_process.env_array, "LESS=FRX"); - if (!getenv("LV")) - argv_array_push(&pager_process.env_array, "LV=-c"); argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE"); if (start_command(&pager_process)) return; diff --git a/perl/Git.pm b/perl/Git.pm index 19ef081103..49eb88af8d 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -188,7 +188,8 @@ sub repository { }; if ($dir) { - $dir =~ m#^/# or $dir = $opts{Directory} . '/' . $dir; + _verify_require(); + File::Spec->file_name_is_absolute($dir) or $dir = $opts{Directory} . '/' . $dir; $opts{Repository} = abs_path($dir); # If --git-dir went ok, this shouldn't die either. diff --git a/perl/Git/SVN/Editor.pm b/perl/Git/SVN/Editor.pm index c50176eec9..4c4199afec 100644 --- a/perl/Git/SVN/Editor.pm +++ b/perl/Git/SVN/Editor.pm @@ -41,6 +41,7 @@ sub new { "$self->{svn_path}/" : ''; $self->{config} = $opts->{config}; $self->{mergeinfo} = $opts->{mergeinfo}; + $self->{pathnameencoding} = Git::config('svn.pathnameencoding'); return $self; } @@ -143,11 +144,12 @@ sub repo_path { sub url_path { my ($self, $path) = @_; + $path = $self->repo_path($path); if ($self->{url} =~ m#^https?://#) { # characters are taken from subversion/libsvn_subr/path.c $path =~ s#([^~a-zA-Z0-9_./!$&'()*+,-])#sprintf("%%%02X",ord($1))#eg; } - $self->{url} . '/' . $self->repo_path($path); + $self->{url} . '/' . $path; } sub rmdirs { diff --git a/reachable.c b/reachable.c index 43616d49c7..ed35201896 100644 --- a/reachable.c +++ b/reachable.c @@ -43,15 +43,14 @@ static int add_one_ref(const char *path, const struct object_id *oid, * The traversal will have already marked us as SEEN, so we * only need to handle any progress reporting here. */ -static void mark_object(struct object *obj, const struct name_path *path, - const char *name, void *data) +static void mark_object(struct object *obj, const char *name, void *data) { update_progress(data); } static void mark_commit(struct commit *c, void *data) { - mark_object(&c->object, NULL, NULL, data); + mark_object(&c->object, NULL, data); } struct recent_data { diff --git a/read-cache.c b/read-cache.c index 5be7cd1dbf..d9fb78bc55 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1519,6 +1519,28 @@ static void check_ce_order(struct index_state *istate) } } +static void tweak_untracked_cache(struct index_state *istate) +{ + switch (git_config_get_untracked_cache()) { + case -1: /* keep: do nothing */ + break; + case 0: /* false */ + remove_untracked_cache(istate); + break; + case 1: /* true */ + add_untracked_cache(istate); + break; + default: /* unknown value: do nothing */ + break; + } +} + +static void post_read_index_from(struct index_state *istate) +{ + check_ce_order(istate); + tweak_untracked_cache(istate); +} + /* remember to discard_cache() before reading a different cache! */ int do_read_index(struct index_state *istate, const char *path, int must_exist) { @@ -1622,9 +1644,10 @@ int read_index_from(struct index_state *istate, const char *path) return istate->cache_nr; ret = do_read_index(istate, path, 0); + split_index = istate->split_index; if (!split_index || is_null_sha1(split_index->base_sha1)) { - check_ce_order(istate); + post_read_index_from(istate); return ret; } @@ -1642,7 +1665,7 @@ int read_index_from(struct index_state *istate, const char *path) sha1_to_hex(split_index->base_sha1)), sha1_to_hex(split_index->base->sha1)); merge_base_index(istate); - check_ce_order(istate); + post_read_index_from(istate); return ret; } diff --git a/remote-curl.c b/remote-curl.c index c7048575fb..2e2266b856 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -119,6 +119,19 @@ static int set_option(const char *name, const char *value) else return -1; return 0; + +#if LIBCURL_VERSION_NUM >= 0x070a08 + } else if (!strcmp(name, "family")) { + if (!strcmp(value, "ipv4")) + git_curl_ipresolve = CURL_IPRESOLVE_V4; + else if (!strcmp(value, "ipv6")) + git_curl_ipresolve = CURL_IPRESOLVE_V6; + else if (!strcmp(value, "all")) + git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER; + else + return -1; + return 0; +#endif /* LIBCURL_VERSION_NUM >= 0x070a08 */ } else { return 1 /* unsupported */; } @@ -439,8 +452,20 @@ static int run_slot(struct active_request_slot *slot, err = run_one_slot(slot, results); if (err != HTTP_OK && err != HTTP_REAUTH) { - error("RPC failed; result=%d, HTTP code = %ld", - results->curl_result, results->http_code); + struct strbuf msg = STRBUF_INIT; + if (results->http_code && results->http_code != 200) + strbuf_addf(&msg, "HTTP %ld", results->http_code); + if (results->curl_result != CURLE_OK) { + if (msg.len) + strbuf_addch(&msg, ' '); + strbuf_addf(&msg, "curl %d", results->curl_result); + if (curl_errorstr[0]) { + strbuf_addch(&msg, ' '); + strbuf_addstr(&msg, curl_errorstr); + } + } + error("RPC failed; %s", msg.buf); + strbuf_release(&msg); } return err; @@ -1534,11 +1534,8 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, } /* - * Bypass the usual "must fast-forward" check but - * replace it with a weaker "the old value must be - * this value we observed". If the remote ref has - * moved and is now different from what we expect, - * reject any push. + * If the remote ref has moved and is now different + * from what we expect, reject any push. * * It also is an error if the user told us to check * with the remote-tracking branch to find the value @@ -1549,10 +1546,14 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, if (ref->expect_old_no_trackback || oidcmp(&ref->old_oid, &ref->old_oid_expect)) reject_reason = REF_STATUS_REJECT_STALE; + else + /* If the ref isn't stale then force the update. */ + force_ref_update = 1; } /* - * The usual "must fast-forward" rules. + * If the update isn't already rejected then check + * the usual "must fast-forward" rules. * * Decide whether an individual refspec A:B can be * pushed. The push will succeed if any of the @@ -1571,7 +1572,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, * passing the --force argument */ - else if (!ref->deletion && !is_null_oid(&ref->old_oid)) { + if (!reject_reason && !ref->deletion && !is_null_oid(&ref->old_oid)) { if (starts_with(ref->name, "refs/tags/")) reject_reason = REF_STATUS_REJECT_ALREADY_EXISTS; else if (!has_object_file(&ref->old_oid)) @@ -48,7 +48,7 @@ static int has_rerere_resolution(const struct rerere_id *id) static struct rerere_id *new_rerere_id_hex(char *hex) { struct rerere_id *id = xmalloc(sizeof(*id)); - strcpy(id->hex, hex); + xsnprintf(id->hex, sizeof(id->hex), "%s", hex); return id; } @@ -904,7 +904,7 @@ int rerere_forget(struct pathspec *pathspec) static struct rerere_id *dirname_to_id(const char *name) { static struct rerere_id id; - strcpy(id.hex, name); + xsnprintf(id.hex, sizeof(id.hex), "%s", name); return &id; } diff --git a/revision.c b/revision.c index f24ead53d5..82f3ca44b3 100644 --- a/revision.c +++ b/revision.c @@ -25,69 +25,13 @@ volatile show_early_output_fn_t show_early_output; static const char *term_bad; static const char *term_good; -char *path_name(const struct name_path *path, const char *name) -{ - const struct name_path *p; - char *n, *m; - int nlen = strlen(name); - int len = nlen + 1; - - for (p = path; p; p = p->up) { - if (p->elem_len) - len += p->elem_len + 1; - } - n = xmalloc(len); - m = n + len - (nlen + 1); - memcpy(m, name, nlen + 1); - for (p = path; p; p = p->up) { - if (p->elem_len) { - m -= p->elem_len + 1; - memcpy(m, p->elem, p->elem_len); - m[p->elem_len] = '/'; - } - } - return n; -} - -static int show_path_component_truncated(FILE *out, const char *name, int len) -{ - int cnt; - for (cnt = 0; cnt < len; cnt++) { - int ch = name[cnt]; - if (!ch || ch == '\n') - return -1; - fputc(ch, out); - } - return len; -} - -static int show_path_truncated(FILE *out, const struct name_path *path) -{ - int emitted, ours; - - if (!path) - return 0; - emitted = show_path_truncated(out, path->up); - if (emitted < 0) - return emitted; - if (emitted) - fputc('/', out); - ours = show_path_component_truncated(out, path->elem, path->elem_len); - if (ours < 0) - return ours; - return ours || emitted; -} - -void show_object_with_name(FILE *out, struct object *obj, - const struct name_path *path, const char *component) +void show_object_with_name(FILE *out, struct object *obj, const char *name) { - struct name_path leaf; - leaf.up = (struct name_path *)path; - leaf.elem = component; - leaf.elem_len = strlen(component); + const char *p; fprintf(out, "%s ", oid_to_hex(&obj->oid)); - show_path_truncated(out, &leaf); + for (p = name; *p && *p != '\n'; p++) + fputc(*p, out); fputc('\n', out); } diff --git a/revision.h b/revision.h index 23857c0ed1..dca0d38171 100644 --- a/revision.h +++ b/revision.h @@ -257,16 +257,9 @@ extern void put_revision_mark(const struct rev_info *revs, extern void mark_parents_uninteresting(struct commit *commit); extern void mark_tree_uninteresting(struct tree *tree); -struct name_path { - struct name_path *up; - int elem_len; - const char *elem; -}; - -char *path_name(const struct name_path *path, const char *name); +char *path_name(struct strbuf *path, const char *name); -extern void show_object_with_name(FILE *, struct object *, - const struct name_path *, const char *); +extern void show_object_with_name(FILE *, struct object *, const char *); extern void add_pending_object(struct rev_info *revs, struct object *obj, const char *name); @@ -139,9 +139,7 @@ int check_filename(const char *prefix, const char *arg) if (arg[2] == '\0') /* ":/" is root dir, always exists */ return 1; name = arg + 2; - } else if (!no_wildcard(arg)) - return 1; - else if (prefix) + } else if (prefix) name = prefix_filename(prefix, strlen(prefix), arg); else name = arg; @@ -202,7 +200,7 @@ void verify_filename(const char *prefix, { if (*arg == '-') die("bad flag '%s' used after filename", arg); - if (check_filename(prefix, arg)) + if (check_filename(prefix, arg) || !no_wildcard(arg)) return; die_verify_filename(prefix, arg, diagnose_misspelt_rev); } @@ -451,17 +449,6 @@ static int check_repository_format_gently(const char *gitdir, int *nongit_ok) return ret; } -static void update_linked_gitdir(const char *gitfile, const char *gitdir) -{ - struct strbuf path = STRBUF_INIT; - struct stat st; - - strbuf_addf(&path, "%s/gitdir", gitdir); - if (stat(path.buf, &st) || st.st_mtime + 24 * 3600 < time(NULL)) - write_file(path.buf, "%s", gitfile); - strbuf_release(&path); -} - /* * Try to read the location of the git directory from the .git file, * return path to git directory if found. @@ -531,7 +518,6 @@ const char *read_gitfile_gently(const char *path, int *return_error_code) error_code = READ_GITFILE_ERR_NOT_A_REPO; goto cleanup_return; } - update_linked_gitdir(path, dir); path = real_path(dir); cleanup_return: diff --git a/sha1_name.c b/sha1_name.c index 892db21813..d0f844db89 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -848,8 +848,12 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l * through history and returning the first commit whose message starts * the given regular expression. * - * For future extension, ':/!' is reserved. If you want to match a message - * beginning with a '!', you have to repeat the exclamation mark. + * For negative-matching, prefix the pattern-part with '!-', like: ':/!-WIP'. + * + * For a literal '!' character at the beginning of a pattern, you have to repeat + * that, like: ':/!!foo' + * + * For future extension, all other sequences beginning with ':/!' are reserved. */ /* Remember to update object flag allocation in object.h */ @@ -878,16 +882,22 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1, { struct commit_list *backup = NULL, *l; int found = 0; + int negative = 0; regex_t regex; if (prefix[0] == '!') { - if (prefix[1] != '!') - die ("Invalid search pattern: %s", prefix); prefix++; + + if (prefix[0] == '-') { + prefix++; + negative = 1; + } else if (prefix[0] != '!') { + return -1; + } } if (regcomp(®ex, prefix, REG_EXTENDED)) - die("Invalid search pattern: %s", prefix); + return -1; for (l = list; l; l = l->next) { l->item->object.flags |= ONELINE_SEEN; @@ -903,7 +913,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1, continue; buf = get_commit_buffer(commit, NULL); p = strstr(buf, "\n\n"); - matches = p && !regexec(®ex, p + 2, 0, NULL, 0); + matches = negative ^ (p && !regexec(®ex, p + 2, 0, NULL, 0)); unuse_commit_buffer(commit, buf); if (matches) { diff --git a/t/Makefile b/t/Makefile index 43b15e36ae..18e2b28b26 100644 --- a/t/Makefile +++ b/t/Makefile @@ -27,7 +27,6 @@ PERL_PATH_SQ = $(subst ','\'',$(PERL_PATH)) TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) -TSVN = $(sort $(wildcard t91[0-9][0-9]-*.sh)) TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh)) THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) @@ -77,11 +76,6 @@ aggregate-results: echo "$$f"; \ done | '$(SHELL_PATH_SQ)' ./aggregate-results.sh -# we can test NO_OPTIMIZE_COMMITS independently of LC_ALL -full-svn-test: - $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C - $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8 - gitweb-test: $(MAKE) $(TGITWEB) diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh index bc4b3412fb..340534c064 100644 --- a/t/lib-git-daemon.sh +++ b/t/lib-git-daemon.sh @@ -23,6 +23,11 @@ then test_done fi +if test_have_prereq !PIPE +then + test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs" +fi + LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}} GIT_DAEMON_PID= diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index b0ec12ff6c..6a50b8793e 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -186,3 +186,15 @@ start_svnserve () { --listen-host 127.0.0.1 & } +prepare_a_utf8_locale () { + a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{ + p + q +}') + if test -n "$a_utf8_locale" + then + test_set_prereq UTF8 + else + say "# UTF-8 locale not available, some tests are skipped" + fi +} diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 4ef5ed484c..89544dd833 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -5,7 +5,7 @@ test_description=check-ignore . ./test-lib.sh init_vars () { - global_excludes="$(pwd)/global-excludes" + global_excludes="global-excludes" } enable_global_excludes () { diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 718efa04d3..7bac2bcf26 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -252,4 +252,20 @@ test_expect_success "filter: smudge empty file" ' test_cmp expected filtered-empty-in-repo ' +test_expect_success 'disable filter with empty override' ' + test_config_global filter.disable.smudge false && + test_config_global filter.disable.clean false && + test_config filter.disable.smudge false && + test_config filter.disable.clean false && + + echo "*.disable filter=disable" >.gitattributes && + + echo test >test.disable && + git -c filter.disable.clean= add test.disable 2>err && + test_must_be_empty err && + rm -f test.disable && + git -c filter.disable.smudge= checkout -- test.disable 2>err && + test_must_be_empty err +' + test_done diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index f0152a7ab4..8532a028e7 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -36,12 +36,21 @@ if test $rootoff = 2; then rootoff= # we are on Unix else rootoff=$(($rootoff-1)) + # In MSYS2, the root directory "/" is translated into a Windows + # directory *with* trailing slash. Let's test for that and adjust + # our expected longest ancestor length accordingly. + case "$(test-path-utils print_path /)" in + */) rootslash=1;; + *) rootslash=0;; + esac fi ancestor() { # We do some math with the expected ancestor length. expected=$3 if test -n "$rootoff" && test "x$expected" != x-1; then + expected=$(($expected-$rootslash)) + test $expected -lt 0 || expected=$(($expected+$rootoff)) fi test_expect_success "longest ancestor: $1 $2 => $expected" \ diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index 078e1195df..4a9964e9dc 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -35,7 +35,10 @@ test_expect_success 'setup' ' git checkout -b upstream-branch && test_commit upstream-one && test_commit upstream-two && - git checkout -b @/at-test && + if test_have_prereq !MINGW + then + git checkout -b @/at-test + fi && git checkout -b @@/at-test && git checkout -b @at-test && git checkout -b old-branch && @@ -64,6 +67,7 @@ check "@{-1}@{u}@{1}" commit master-one check "@" commit new-two check "@@{u}" ref refs/heads/upstream-branch check "@@/at-test" ref refs/heads/@@/at-test +test_have_prereq MINGW || check "@/at-test" ref refs/heads/@/at-test check "@at-test" ref refs/heads/@at-test nonsense "@{u}@{-1}" diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh index 7043ba7947..e0a49a651f 100755 --- a/t/t1511-rev-parse-caret.sh +++ b/t/t1511-rev-parse-caret.sh @@ -18,7 +18,18 @@ test_expect_success 'setup' ' git checkout master && echo modified >>a-blob && git add -u && - git commit -m Modified + git commit -m Modified && + git branch modref && + echo changed! >>a-blob && + git add -u && + git commit -m !Exp && + git branch expref && + echo changed >>a-blob && + git add -u && + git commit -m Changed && + echo changed-again >>a-blob && + git add -u && + git commit -m Changed-again ' test_expect_success 'ref^{non-existent}' ' @@ -77,4 +88,44 @@ test_expect_success 'ref^{/Initial}' ' test_cmp expected actual ' +test_expect_success 'ref^{/!Exp}' ' + test_must_fail git rev-parse master^{/!Exp} +' + +test_expect_success 'ref^{/!}' ' + test_must_fail git rev-parse master^{/!} +' + +test_expect_success 'ref^{/!!Exp}' ' + git rev-parse expref >expected && + git rev-parse master^{/!!Exp} >actual && + test_cmp expected actual +' + +test_expect_success 'ref^{/!-}' ' + test_must_fail git rev-parse master^{/!-} +' + +test_expect_success 'ref^{/!-.}' ' + test_must_fail git rev-parse master^{/!-.} +' + +test_expect_success 'ref^{/!-non-existent}' ' + git rev-parse master >expected && + git rev-parse master^{/!-non-existent} >actual && + test_cmp expected actual +' + +test_expect_success 'ref^{/!-Changed}' ' + git rev-parse expref >expected && + git rev-parse master^{/!-Changed} >actual && + test_cmp expected actual +' + +test_expect_success 'ref^{/!-!Exp}' ' + git rev-parse modref >expected && + git rev-parse expref^{/!-!Exp} >actual && + test_cmp expected actual +' + test_done diff --git a/t/t2019-checkout-ambiguous-ref.sh b/t/t2019-checkout-ambiguous-ref.sh index 199b22d85e..b99d5192a9 100755 --- a/t/t2019-checkout-ambiguous-ref.sh +++ b/t/t2019-checkout-ambiguous-ref.sh @@ -56,30 +56,4 @@ test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' ' test_i18ngrep ! "^HEAD is now at" stderr ' -test_expect_success 'wildcard ambiguation, paths win' ' - git init ambi && - ( - cd ambi && - echo a >a.c && - git add a.c && - echo b >a.c && - git checkout "*.c" && - echo a >expect && - test_cmp expect a.c - ) -' - -test_expect_success !MINGW 'wildcard ambiguation, refs lose' ' - git init ambi2 && - ( - cd ambi2 && - echo a >"*.c" && - git add . && - test_must_fail git show :"*.c" && - git show :"*.c" -- >actual && - echo a >expect && - test_cmp expect actual - ) -' - test_done diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh index 0a804dab63..cbfa41ec61 100755 --- a/t/t2025-worktree-add.sh +++ b/t/t2025-worktree-add.sh @@ -193,6 +193,21 @@ test_expect_success '"add" -B/--detach mutually exclusive' ' test_must_fail git worktree add -B poodle --detach bamboo master ' +test_expect_success '"add -B" fails if the branch is checked out' ' + git rev-parse newmaster >before && + test_must_fail git worktree add -B newmaster bamboo master && + git rev-parse newmaster >after && + test_cmp before after +' + +test_expect_success 'add -B' ' + git worktree add -B poodle bamboo2 master^ && + git -C bamboo2 symbolic-ref HEAD >actual && + echo refs/heads/poodle >expected && + test_cmp expected actual && + test_cmp_rev master^ poodle +' + test_expect_success 'local clone from linked checkout' ' git clone --local here here-clone && ( cd here-clone && git fsck ) diff --git a/t/t2027-worktree-list.sh b/t/t2027-worktree-list.sh index 75ebb1b4a0..1b1b65a6b0 100755 --- a/t/t2027-worktree-list.sh +++ b/t/t2027-worktree-list.sh @@ -8,6 +8,16 @@ test_expect_success 'setup' ' test_commit init ' +test_expect_success 'rev-parse --git-common-dir on main worktree' ' + git rev-parse --git-common-dir >actual && + echo .git >expected && + test_cmp expected actual && + mkdir sub && + git -C sub rev-parse --git-common-dir >actual2 && + echo sub/.git >expected2 && + test_cmp expected2 actual2 +' + test_expect_success '"list" all worktrees from main' ' echo "$(git rev-parse --show-toplevel) $(git rev-parse --short HEAD) [$(git symbolic-ref --short HEAD)]" >expect && test_when_finished "rm -rf here && git worktree prune" && diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 3fc484e8c3..d043078da5 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -175,13 +175,10 @@ test_expect_success 'negated exclude matches can override previous ones' ' grep "^a.1" output ' -test_expect_success 'excluded directory overrides content patterns' ' +test_expect_success 'excluded directory does not override content patterns' ' git ls-files --others --exclude="one" --exclude="!one/a.1" >output && - if grep "^one/a.1" output - then - false - fi + grep "^one/a.1" output ' test_expect_success 'negated directory doesn'\''t affect content patterns' ' diff --git a/t/t3007-ls-files-other-negative.sh b/t/t3007-ls-files-other-negative.sh new file mode 100755 index 0000000000..0797b86ad0 --- /dev/null +++ b/t/t3007-ls-files-other-negative.sh @@ -0,0 +1,153 @@ +#!/bin/sh + +test_description='test re-include patterns' + +. ./test-lib.sh + +test_expect_success 'setup' ' + mkdir -p fooo foo/bar tmp && + touch abc foo/def foo/bar/ghi foo/bar/bar +' + +test_expect_success 'no match, do not enter subdir and waste cycles' ' + cat >.gitignore <<-\EOF && + /tmp + /foo + !fooo/bar/bar + EOF + GIT_TRACE_EXCLUDE="$(pwd)/tmp/trace" git ls-files -o --exclude-standard >tmp/actual && + ! grep "enter .foo/.\$" tmp/trace && + cat >tmp/expected <<-\EOF && + .gitignore + abc + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by literal pathname pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + /foo + !foo/bar/bar + EOF + cat >fooo/.gitignore <<-\EOF && + !/* + EOF git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by wildcard pathname pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + /fo? + !foo/bar/bar + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by literal basename pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + foo + !foo/bar/bar + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by wildcard basename pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + fo? + !foo/bar/bar + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by literal mustbedir, basename pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + foo/ + !foo/bar/bar + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'match, excluded by literal mustbedir, pathname pattern' ' + cat >.gitignore <<-\EOF && + /tmp + /fooo + /foo/ + !foo/bar/bar + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + .gitignore + abc + foo/bar/bar + EOF + test_cmp tmp/expected tmp/actual +' + +test_expect_success 'prepare for nested negatives' ' + cat >.git/info/exclude <<-\EOF && + /.gitignore + /tmp + /foo + /abc + EOF + git ls-files -o --exclude-standard >tmp/actual && + test_must_be_empty tmp/actual && + mkdir -p 1/2/3/4 && + touch 1/f 1/2/f 1/2/3/f 1/2/3/4/f +' + +test_expect_success 'match, literal pathname, nested negatives' ' + cat >.gitignore <<-\EOF && + /1 + !1/2 + 1/2/3 + !1/2/3/4 + EOF + git ls-files -o --exclude-standard >tmp/actual && + cat >tmp/expected <<-\EOF && + 1/2/3/4/f + 1/2/f + EOF + test_cmp tmp/expected tmp/actual +' + +test_done diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 9a146f1335..04de03cad0 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -13,6 +13,7 @@ tree, index, and tree objects. HT=' ' +test_have_prereq MINGW || echo 2>/dev/null > "Name with an${HT}HT" if ! test -f "Name with an${HT}HT" then diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 2e47a2bfd8..d046d98aec 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -14,7 +14,7 @@ test_expect_success \ git add -- foo bar baz 'space embedded' -q && git commit -m 'add normal files'" -if touch -- 'tab embedded' 'newline +if test_have_prereq !MINGW && touch -- 'tab embedded' 'newline embedded' 2>/dev/null then test_set_prereq FUNNYNAMES diff --git a/t/t3703-add-magic-pathspec.sh b/t/t3703-add-magic-pathspec.sh index 5115de7036..3ef525a559 100755 --- a/t/t3703-add-magic-pathspec.sh +++ b/t/t3703-add-magic-pathspec.sh @@ -38,7 +38,7 @@ cat >expected <<EOF add 'sub/foo' EOF -if mkdir ":" 2>/dev/null +if test_have_prereq !MINGW && mkdir ":" 2>/dev/null then test_set_prereq COLON_DIR fi diff --git a/t/t3902-quoted.sh b/t/t3902-quoted.sh index 892f567844..f528008c36 100755 --- a/t/t3902-quoted.sh +++ b/t/t3902-quoted.sh @@ -12,6 +12,7 @@ GN='純' HT=' ' DQ='"' +test_have_prereq MINGW || echo foo 2>/dev/null > "Name and an${HT}HT" if ! test -f "Name and an${HT}HT" then diff --git a/t/t4016-diff-quote.sh b/t/t4016-diff-quote.sh index cd543ecc54..9c48e5c2c9 100755 --- a/t/t4016-diff-quote.sh +++ b/t/t4016-diff-quote.sh @@ -13,6 +13,7 @@ P1='pathname with HT' P2='pathname with SP' P3='pathname with LF' +test_have_prereq !MINGW && echo 2>/dev/null >"$P1" && test -f "$P1" && rm -f "$P1" || { skip_all='Your filesystem does not allow tabs in filenames' test_done diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh index bf5dc57286..27cb0009fb 100755 --- a/t/t4135-apply-weird-filenames.sh +++ b/t/t4135-apply-weird-filenames.sh @@ -19,7 +19,8 @@ test_expect_success 'setup' ' test_when_finished "rm -f \"tab embedded.txt\"" && test_when_finished "rm -f '\''\"quoteembedded\".txt'\''" && - if touch -- "tab embedded.txt" '\''"quoteembedded".txt'\'' + if test_have_prereq !MINGW && + touch -- "tab embedded.txt" '\''"quoteembedded".txt'\'' then test_set_prereq FUNNYNAMES fi diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 94079a0e63..949725e9bc 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -51,6 +51,11 @@ test_expect_success setup ' git clone one test ' +test_expect_success 'add remote whose URL agrees with url.<...>.insteadOf' ' + test_config url.git@host.com:team/repo.git.insteadOf myremote && + git remote add myremote git@host.com:team/repo.git +' + test_expect_success C_LOCALE_OUTPUT 'remote information for the origin' ' ( cd test && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 9203a6507f..0c10c856a9 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -314,42 +314,6 @@ test_expect_success 'bundle should be able to create a full history' ' ' -! rsync --help > /dev/null 2> /dev/null && -say 'Skipping rsync tests because rsync was not found' || { -test_expect_success 'fetch via rsync' ' - git pack-refs && - mkdir rsynced && - (cd rsynced && - git init --bare && - git fetch "rsync:../.git" master:refs/heads/master && - git gc --prune && - test $(git rev-parse master) = $(cd .. && git rev-parse master) && - git fsck --full) -' - -test_expect_success 'push via rsync' ' - mkdir rsynced2 && - (cd rsynced2 && - git init) && - (cd rsynced && - git push "rsync:../rsynced2/.git" master) && - (cd rsynced2 && - git gc --prune && - test $(git rev-parse master) = $(cd .. && git rev-parse master) && - git fsck --full) -' - -test_expect_success 'push via rsync' ' - mkdir rsynced3 && - (cd rsynced3 && - git init) && - git push --all "rsync:rsynced3/.git" && - (cd rsynced3 && - test $(git rev-parse master) = $(cd .. && git rev-parse master) && - git fsck --full) -' -} - test_expect_success 'fetch with a non-applying branch.<name>.merge' ' git config branch.master.remote yeti && git config branch.master.merge refs/heads/bigfoot && diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh index c402d8d3d7..c7320121ec 100755 --- a/t/t5533-push-cas.sh +++ b/t/t5533-push-cas.sh @@ -25,7 +25,8 @@ test_expect_success 'push to update (protected)' ' ( cd dst && test_commit D && - test_must_fail git push --force-with-lease=master:master origin master + test_must_fail git push --force-with-lease=master:master origin master 2>err && + grep "stale info" err ) && git ls-remote . refs/heads/master >expect && git ls-remote src refs/heads/master >actual && @@ -37,7 +38,8 @@ test_expect_success 'push to update (protected, forced)' ' ( cd dst && test_commit D && - git push --force --force-with-lease=master:master origin master + git push --force --force-with-lease=master:master origin master 2>err && + grep "forced update" err ) && git ls-remote dst refs/heads/master >expect && git ls-remote src refs/heads/master >actual && @@ -101,7 +103,8 @@ test_expect_success 'push to update (allowed, tracking)' ' ( cd dst && test_commit D && - git push --force-with-lease=master origin master + git push --force-with-lease=master origin master 2>err && + ! grep "forced update" err ) && git ls-remote dst refs/heads/master >expect && git ls-remote src refs/heads/master >actual && @@ -114,7 +117,8 @@ test_expect_success 'push to update (allowed even though no-ff)' ' cd dst && git reset --hard HEAD^ && test_commit D && - git push --force-with-lease=master origin master + git push --force-with-lease=master origin master 2>err && + grep "forced update" err ) && git ls-remote dst refs/heads/master >expect && git ls-remote src refs/heads/master >actual && @@ -147,7 +151,8 @@ test_expect_success 'push to delete (allowed)' ' setup_srcdst_basic && ( cd dst && - git push --force-with-lease=master origin :master + git push --force-with-lease=master origin :master 2>err && + grep deleted err ) && >expect && git ls-remote src refs/heads/master >actual && diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index d76269a8fc..225a022e8a 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -6,6 +6,12 @@ test_description='test fetching over git protocol' . "$TEST_DIRECTORY"/lib-git-daemon.sh start_git_daemon +check_verbose_connect () { + grep -F "Looking up 127.0.0.1 ..." stderr && + grep -F "Connecting to 127.0.0.1 (port " stderr && + grep -F "done." stderr +} + test_expect_success 'setup repository' ' git config push.default matching && echo content >file && @@ -24,7 +30,8 @@ test_expect_success 'create git-accessible bare repository' ' ' test_expect_success 'clone git repository' ' - git clone "$GIT_DAEMON_URL/repo.git" clone && + git clone -v "$GIT_DAEMON_URL/repo.git" clone 2>stderr && + check_verbose_connect && test_cmp file clone/file ' @@ -32,10 +39,21 @@ test_expect_success 'fetch changes via git protocol' ' echo content >>file && git commit -a -m two && git push public && - (cd clone && git pull) && + (cd clone && git pull -v) 2>stderr && + check_verbose_connect && test_cmp file clone/file ' +test_expect_success 'no-op fetch -v stderr is as expected' ' + (cd clone && git fetch -v) 2>stderr && + check_verbose_connect +' + +test_expect_success 'no-op fetch without "-v" is quiet' ' + (cd clone && git fetch) 2>stderr && + ! test -s stderr +' + test_expect_success 'remote detects correct HEAD' ' git push public master:other && (cd clone && diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 669ec9ba81..c1efb8e445 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -4,6 +4,9 @@ test_description=clone . ./test-lib.sh +X= +test_have_prereq !MINGW || X=.exe + test_expect_success setup ' rm -fr .git && @@ -305,14 +308,9 @@ test_expect_success 'clone checking out a tag' ' setup_ssh_wrapper () { test_expect_success 'setup ssh wrapper' ' - write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF && - echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" && - # throw away all but the last argument, which should be the - # command - while test $# -gt 1; do shift; done - eval "$1" - EOF - GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" && + cp "$GIT_BUILD_DIR/test-fake-ssh$X" \ + "$TRASH_DIRECTORY/ssh-wrapper$X" && + GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper$X" && export GIT_SSH && export TRASH_DIRECTORY && >"$TRASH_DIRECTORY"/ssh-output @@ -320,8 +318,8 @@ setup_ssh_wrapper () { } copy_ssh_wrapper_as () { - cp "$TRASH_DIRECTORY/ssh-wrapper" "$1" && - GIT_SSH="$1" && + cp "$TRASH_DIRECTORY/ssh-wrapper$X" "${1%$X}$X" && + GIT_SSH="${1%$X}$X" && export GIT_SSH } diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index 190ee903cf..20aee43f95 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -346,4 +346,17 @@ test_expect_success 'conflict at EOF without LF resolved by --union' \ printf "line1\nline2\nline3x\nline3y" >expect.txt && test_cmp expect.txt output.txt' +test_expect_success 'conflict sections match existing line endings' ' + printf "1\\r\\n2\\r\\n3" >crlf-orig.txt && + printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt && + printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt && + test_must_fail git -c core.eol=crlf merge-file -p \ + crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt && + test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 && + test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 && + test_must_fail git -c core.eol=crlf merge-file -p \ + nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt && + test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0 +' + test_done diff --git a/t/t6133-pathspec-rev-dwim.sh b/t/t6133-pathspec-rev-dwim.sh new file mode 100755 index 0000000000..a290ffca0d --- /dev/null +++ b/t/t6133-pathspec-rev-dwim.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +test_description='test dwim of revs versus pathspecs in revision parser' +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit base && + echo content >"br[ack]ets" && + git add . && + test_tick && + git commit -m brackets +' + +test_expect_success 'non-rev wildcard dwims to pathspec' ' + git log -- "*.t" >expect && + git log "*.t" >actual && + test_cmp expect actual +' + +test_expect_success 'tree:path with metacharacters dwims to rev' ' + git show "HEAD:br[ack]ets" -- >expect && + git show "HEAD:br[ack]ets" >actual && + test_cmp expect actual +' + +test_expect_success '^{foo} with metacharacters dwims to rev' ' + git log "HEAD^{/b.*}" -- >expect && + git log "HEAD^{/b.*}" >actual && + test_cmp expect actual +' + +test_expect_success '@{foo} with metacharacters dwims to rev' ' + git log "HEAD@{now [or thereabouts]}" -- >expect && + git log "HEAD@{now [or thereabouts]}" >actual && + test_cmp expect actual +' + +test_expect_success ':/*.t from a subdir dwims to a pathspec' ' + mkdir subdir && + ( + cd subdir && + git log -- ":/*.t" >expect && + git log ":/*.t" >actual && + test_cmp expect actual + ) +' + +test_done diff --git a/t/t7063-status-untracked-cache.sh b/t/t7063-status-untracked-cache.sh index 0e8d0d42f2..a971884cfd 100755 --- a/t/t7063-status-untracked-cache.sh +++ b/t/t7063-status-untracked-cache.sh @@ -8,10 +8,8 @@ avoid_racy() { sleep 1 } -# It's fine if git update-index returns an error code other than one, -# it'll be caught in the first test. test_lazy_prereq UNTRACKED_CACHE ' - { git update-index --untracked-cache; ret=$?; } && + { git update-index --test-untracked-cache; ret=$?; } && test $ret -ne 1 ' @@ -20,6 +18,10 @@ if ! test_have_prereq UNTRACKED_CACHE; then test_done fi +test_expect_success 'core.untrackedCache is unset' ' + test_must_fail git config --get core.untrackedCache +' + test_expect_success 'setup' ' git init worktree && cd worktree && @@ -32,13 +34,13 @@ test_expect_success 'setup' ' test_expect_success 'untracked cache is empty' ' test-dump-untracked-cache >../actual && - cat >../expect <<EOF && + cat >../expect-empty <<EOF && info/exclude 0000000000000000000000000000000000000000 core.excludesfile 0000000000000000000000000000000000000000 exclude_per_dir .gitignore flags 00000006 EOF - test_cmp ../expect ../actual + test_cmp ../expect-empty ../actual ' cat >../status.expect <<EOF && @@ -508,7 +510,7 @@ EOF test_expect_success 'verify untracked cache dump (sparse/subdirs)' ' test-dump-untracked-cache >../actual && - cat >../expect <<EOF && + cat >../expect-from-test-dump <<EOF && info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0 core.excludesfile 0000000000000000000000000000000000000000 exclude_per_dir .gitignore @@ -527,7 +529,7 @@ file /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid two EOF - test_cmp ../expect ../actual + test_cmp ../expect-from-test-dump ../actual ' test_expect_success 'test sparse status again with untracked cache and subdir' ' @@ -571,4 +573,77 @@ EOF test_cmp ../status.expect ../status.actual ' +test_expect_success '--no-untracked-cache removes the cache' ' + git update-index --no-untracked-cache && + test-dump-untracked-cache >../actual && + echo "no untracked cache" >../expect-no-uc && + test_cmp ../expect-no-uc ../actual +' + +test_expect_success 'git status does not change anything' ' + git status && + test-dump-untracked-cache >../actual && + test_cmp ../expect-no-uc ../actual +' + +test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' ' + git config core.untrackedCache true && + test-dump-untracked-cache >../actual && + test_cmp ../expect-no-uc ../actual && + git status && + test-dump-untracked-cache >../actual && + test_cmp ../expect-from-test-dump ../actual +' + +test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' ' + git update-index --no-untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-no-uc ../actual && + git update-index --untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-empty ../actual +' + +test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' ' + git config core.untrackedCache false && + test-dump-untracked-cache >../actual && + test_cmp ../expect-empty ../actual && + git status && + test-dump-untracked-cache >../actual && + test_cmp ../expect-no-uc ../actual +' + +test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' ' + git update-index --untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-empty ../actual +' + +test_expect_success 'setting core.untrackedCache to keep' ' + git config core.untrackedCache keep && + git update-index --untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-empty ../actual && + git status && + test-dump-untracked-cache >../actual && + test_cmp ../expect-from-test-dump ../actual && + git update-index --no-untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-no-uc ../actual && + git update-index --force-untracked-cache && + test-dump-untracked-cache >../actual && + test_cmp ../expect-empty ../actual && + git status && + test-dump-untracked-cache >../actual && + test_cmp ../expect-from-test-dump ../actual +' + +test_expect_success 'test ident field is working' ' + mkdir ../other_worktree && + cp -R done dthree dtwo four three ../other_worktree && + GIT_WORK_TREE=../other_worktree git status 2>../err && + echo "warning: Untracked cache is disabled on this system or location." >../expect && + test_cmp ../expect ../err +' + test_done diff --git a/t/t7517-per-repo-email.sh b/t/t7517-per-repo-email.sh new file mode 100755 index 0000000000..337e6e30c3 --- /dev/null +++ b/t/t7517-per-repo-email.sh @@ -0,0 +1,39 @@ +#!/bin/sh +# +# Copyright (c) 2016 Dan Aloni +# Copyright (c) 2016 Jeff King +# + +test_description='per-repo forced setting of email address' + +. ./test-lib.sh + +test_expect_success 'setup a likely user.useConfigOnly use case' ' + # we want to make sure a reflog is written, since that needs + # a non-strict ident. So be sure we have an actual commit. + test_commit foo && + + sane_unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL && + sane_unset GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL && + git config user.name "test" && + git config --global user.useConfigOnly true +' + +test_expect_success 'fails committing if clone email is not set' ' + test_must_fail git commit --allow-empty -m msg +' + +test_expect_success 'fails committing if clone email is not set, but EMAIL set' ' + test_must_fail env EMAIL=test@fail.com git commit --allow-empty -m msg +' + +test_expect_success 'succeeds committing if clone email is set' ' + test_config user.email "test@ok.com" && + git commit --allow-empty -m msg +' + +test_expect_success 'succeeds cloning if global email is not set' ' + git clone . clone +' + +test_done diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index ec8bc8c765..4e713f7aa5 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -430,11 +430,11 @@ EOF test_expect_success PERL,SYMLINKS 'difftool --dir-diff --symlink without unstaged changes' ' cat >expect <<-EOF && file - $(pwd)/file + $PWD/file file2 - $(pwd)/file2 + $PWD/file2 sub/sub - $(pwd)/sub/sub + $PWD/sub/sub EOF git difftool --dir-diff --symlink \ --extcmd "./.git/CHECK_SYMLINKS" branch HEAD && @@ -448,14 +448,14 @@ EOF run_dir_diff_test 'difftool --dir-diff syncs worktree with unstaged change' ' test_when_finished git reset --hard && echo "orig content" >file && - git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch && + git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch && echo "new content" >expect && test_cmp expect file ' run_dir_diff_test 'difftool --dir-diff syncs worktree without unstaged change' ' test_when_finished git reset --hard && - git difftool -d $symlinks --extcmd "$(pwd)/modify-right-file" branch && + git difftool -d $symlinks --extcmd "$PWD/modify-right-file" branch && echo "new content" >expect && test_cmp expect file ' @@ -466,7 +466,7 @@ EOF test_expect_success PERL 'difftool --no-symlinks does not overwrite working tree file ' ' echo "orig content" >file && - git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-file" branch && + git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-file" branch && echo "new content" >expect && test_cmp expect file ' @@ -482,7 +482,7 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' ' TMPDIR=$TRASH_DIRECTORY && export TMPDIR && echo "orig content" >file && - test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$(pwd)/modify-both-files" branch && + test_must_fail git difftool --dir-diff --no-symlinks --extcmd "$PWD/modify-both-files" branch && echo "wt content" >expect && test_cmp expect file && echo "tmp content" >expect && diff --git a/t/t9003-help-autocorrect.sh b/t/t9003-help-autocorrect.sh new file mode 100755 index 0000000000..dfe95c923b --- /dev/null +++ b/t/t9003-help-autocorrect.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='help.autocorrect finding a match' +. ./test-lib.sh + +test_expect_success 'setup' ' + # An alias + git config alias.lgf "log --format=%s --first-parent" && + + # A random user-defined command + write_script git-distimdistim <<-EOF && + echo distimdistim was called + EOF + + PATH="$PATH:." && + export PATH && + + git commit --allow-empty -m "a single log entry" && + + # Sanity check + git lgf >actual && + echo "a single log entry" >expect && + test_cmp expect actual && + + git distimdistim >actual && + echo "distimdistim was called" >expect && + test_cmp expect actual +' + +test_expect_success 'autocorrect showing candidates' ' + git config help.autocorrect 0 && + + test_must_fail git lfg 2>actual && + sed -e "1,/^Did you mean this/d" actual | grep lgf && + + test_must_fail git distimdist 2>actual && + sed -e "1,/^Did you mean this/d" actual | grep distimdistim +' + +test_expect_success 'autocorrect running commands' ' + git config help.autocorrect -1 && + + git lfg >actual && + echo "a single log entry" >expect && + test_cmp expect actual && + + git distimdist >actual && + echo "distimdistim was called" >expect && + test_cmp expect actual +' + +test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 258d9b8cef..22d8367ff3 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -117,7 +117,7 @@ test_expect_success "$name" ' name='remove executable bit from a file' -test_expect_success "$name" ' +test_expect_success POSIXPERM "$name" ' rm -f "$GIT_DIR"/index && git checkout -f -b mybranch5 ${remotes_git_svn} && chmod -x exec.sh && @@ -130,7 +130,7 @@ test_expect_success "$name" ' name='add executable bit back file' -test_expect_success "$name" ' +test_expect_success POSIXPERM "$name" ' chmod +x exec.sh && git update-index exec.sh && git commit -m "$name" && @@ -141,7 +141,7 @@ test_expect_success "$name" ' name='executable file becomes a symlink to file' -test_expect_success "$name" ' +test_expect_success SYMLINKS "$name" ' rm exec.sh && ln -s file exec.sh && git update-index exec.sh && @@ -153,7 +153,7 @@ test_expect_success "$name" ' name='new symlink is added to a file that was also just made executable' -test_expect_success "$name" ' +test_expect_success POSIXPERM,SYMLINKS "$name" ' chmod +x file && ln -s file exec-2.sh && git update-index --add file exec-2.sh && @@ -165,7 +165,7 @@ test_expect_success "$name" ' test -h "$SVN_TREE"/exec-2.sh' name='modify a symlink to become a file' -test_expect_success "$name" ' +test_expect_success POSIXPERM,SYMLINKS "$name" ' echo git help >help && rm exec-2.sh && cp help exec-2.sh && @@ -181,7 +181,8 @@ test_expect_success "$name" ' name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL" LC_ALL="$GIT_SVN_LC_ALL" export LC_ALL -test_expect_success UTF8 "$name" " +# This test relies on the previous test, hence requires POSIXPERM,SYMLINKS +test_expect_success UTF8,POSIXPERM,SYMLINKS "$name" " echo '# hello' >> exec-2.sh && git update-index exec-2.sh && git commit -m 'éï∏' && @@ -214,7 +215,7 @@ tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 EOF -test_expect_success "$name" "test_cmp a expected" +test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp a expected" test_expect_success 'exit if remote refs are ambigious' " git config --add svn-remote.svn.fetch \ diff --git a/t/t9115-git-svn-dcommit-funky-renames.sh b/t/t9115-git-svn-dcommit-funky-renames.sh index 6a48e40429..0990f8d235 100755 --- a/t/t9115-git-svn-dcommit-funky-renames.sh +++ b/t/t9115-git-svn-dcommit-funky-renames.sh @@ -77,11 +77,47 @@ test_expect_success 'make a commit to test rebase' ' ' test_expect_success 'git svn rebase works inside a fresh-cloned repository' ' - cd test-rebase && + ( + cd test-rebase && git svn rebase && test -e test-rebase-main && test -e test-rebase - ' + )' + +# Without this, LC_ALL=C as set in test-lib.sh, and Cygwin converts +# non-ASCII characters in filenames unexpectedly, and causes errors. +# https://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-specialchars +# > Some characters are disallowed in filenames on Windows filesystems. ... +# ... +# > ... All of the above characters, except for the backslash, are converted +# > to special UNICODE characters in the range 0xf000 to 0xf0ff (the +# > "Private use area") when creating or accessing files. +prepare_a_utf8_locale +test_expect_success UTF8 'svn.pathnameencoding=cp932 new file on dcommit' ' + LC_ALL=$a_utf8_locale && + export LC_ALL && + neq=$(printf "\201\202") && + git config svn.pathnameencoding cp932 && + echo neq >"$neq" && + git add "$neq" && + git commit -m "neq" && + git svn dcommit +' + +# See the comment on the above test for setting of LC_ALL. +test_expect_success 'svn.pathnameencoding=cp932 rename on dcommit' ' + LC_ALL=$a_utf8_locale && + export LC_ALL && + inf=$(printf "\201\207") && + git config svn.pathnameencoding cp932 && + echo inf >"$inf" && + git add "$inf" && + git commit -m "inf" && + git svn dcommit && + git mv "$inf" inf && + git commit -m "inf rename" && + git svn dcommit +' stop_httpd diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh index a2219154b8..ecb1fed147 100755 --- a/t/t9118-git-svn-funky-branch-names.sh +++ b/t/t9118-git-svn-funky-branch-names.sh @@ -23,8 +23,11 @@ test_expect_success 'setup svnrepo' ' "$svnrepo/pr ject/branches/$scary_uri" && svn_cmd cp -m "leading dot" "$svnrepo/pr ject/trunk" \ "$svnrepo/pr ject/branches/.leading_dot" && - svn_cmd cp -m "trailing dot" "$svnrepo/pr ject/trunk" \ - "$svnrepo/pr ject/branches/trailing_dot." && + if test_have_prereq !MINGW + then + svn_cmd cp -m "trailing dot" "$svnrepo/pr ject/trunk" \ + "$svnrepo/pr ject/branches/trailing_dot." + fi && svn_cmd cp -m "trailing .lock" "$svnrepo/pr ject/trunk" \ "$svnrepo/pr ject/branches/trailing_dotlock.lock" && svn_cmd cp -m "reflog" "$svnrepo/pr ject/trunk" \ @@ -45,7 +48,10 @@ test_expect_success 'test clone with funky branch names' ' git rev-parse "refs/remotes/origin/more%20fun%20plugin!" && git rev-parse "refs/remotes/origin/$scary_ref" && git rev-parse "refs/remotes/origin/%2Eleading_dot" && - git rev-parse "refs/remotes/origin/trailing_dot%2E" && + if test_have_prereq !MINGW + then + git rev-parse "refs/remotes/origin/trailing_dot%2E" + fi && git rev-parse "refs/remotes/origin/trailing_dotlock%2Elock" && git rev-parse "refs/remotes/origin/$non_reflog" ) diff --git a/t/t9124-git-svn-dcommit-auto-props.sh b/t/t9124-git-svn-dcommit-auto-props.sh index aa841e1299..9f7231d5b7 100755 --- a/t/t9124-git-svn-dcommit-auto-props.sh +++ b/t/t9124-git-svn-dcommit-auto-props.sh @@ -34,8 +34,7 @@ test_expect_success 'enable auto-props config' ' ' test_expect_success 'add files matching auto-props' ' - echo "#!$SHELL_PATH" >exec1.sh && - chmod +x exec1.sh && + write_script exec1.sh </dev/null && echo "hello" >hello.txt && echo bar >bar && git add exec1.sh hello.txt bar && @@ -48,8 +47,7 @@ test_expect_success 'disable auto-props config' ' ' test_expect_success 'add files matching disabled auto-props' ' - echo "#$SHELL_PATH" >exec2.sh && - chmod +x exec2.sh && + write_script exec2.sh </dev/null && echo "world" >world.txt && echo zot >zot && git add exec2.sh world.txt zot && @@ -65,7 +63,10 @@ test_expect_success 'check resulting svn repository' ' cd svnrepo && # Check properties from first commit. - test "x$(svn_cmd propget svn:executable exec1.sh)" = "x*" && + if test_have_prereq POSIXPERM + then + test "x$(svn_cmd propget svn:executable exec1.sh)" = "x*" + fi && test "x$(svn_cmd propget svn:mime-type exec1.sh)" = \ "xapplication/x-shellscript" && test "x$(svn_cmd propget svn:mime-type hello.txt)" = "xtext/plain" && @@ -73,7 +74,10 @@ test_expect_success 'check resulting svn repository' ' test "x$(svn_cmd propget svn:mime-type bar)" = "x" && # Check properties from second commit. - test "x$(svn_cmd propget svn:executable exec2.sh)" = "x*" && + if test_have_prereq POSIXPERM + then + test "x$(svn_cmd propget svn:executable exec2.sh)" = "x*" + fi && test "x$(svn_cmd propget svn:mime-type exec2.sh)" = "x" && test "x$(svn_cmd propget svn:mime-type world.txt)" = "x" && test "x$(svn_cmd propget svn:eol-style world.txt)" = "x" && diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh index 39b6bcb398..8dbd6476fa 100755 --- a/t/t9129-git-svn-i18n-commitencoding.sh +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -14,17 +14,7 @@ compare_git_head_with () { test_cmp current "$1" } -a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{ - p - q -}') - -if test -n "$a_utf8_locale" -then - test_set_prereq UTF8 -else - say "# UTF-8 locale not available, some tests are skipped" -fi +prepare_a_utf8_locale compare_svn_head_with () { # extract just the log message and strip out committer info. diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index d306b77c31..41264818cc 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -91,7 +91,7 @@ test_expect_success 'fetch continues after authors-file is fixed' ' ) ' -test_expect_success 'fresh clone with svn.authors-file in config' ' +test_expect_success !MINGW 'fresh clone with svn.authors-file in config' ' ( rm -r "$GIT_DIR" && test x = x"$(git config svn.authorsfile)" && diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index 812c9cd462..5cfb9cfc52 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -197,7 +197,7 @@ if p="Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" && then # This test contains UTF-8 characters -test_expect_success \ +test_expect_success !MINGW \ 'File with non-ascii file name' \ 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö && echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt && diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 6146c3fec2..d708cbf032 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -25,11 +25,11 @@ perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { test_done } -WORKDIR=$(pwd) -SERVERDIR=$(pwd)/gitcvs.git +WORKDIR=$PWD +SERVERDIR=$PWD/gitcvs.git git_config="$SERVERDIR/config" CVSROOT=":fork:$SERVERDIR" -CVSWORK="$(pwd)/cvswork" +CVSWORK="$PWD/cvswork" CVS_SERVER=git-cvsserver export CVSROOT CVS_SERVER diff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh index 5a4ed28e49..f324b9f010 100755 --- a/t/t9401-git-cvsserver-crlf.sh +++ b/t/t9401-git-cvsserver-crlf.sh @@ -74,11 +74,11 @@ perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { } unset GIT_DIR GIT_CONFIG -WORKDIR=$(pwd) -SERVERDIR=$(pwd)/gitcvs.git +WORKDIR=$PWD +SERVERDIR=$PWD/gitcvs.git git_config="$SERVERDIR/config" CVSROOT=":fork:$SERVERDIR" -CVSWORK="$(pwd)/cvswork" +CVSWORK="$PWD/cvswork" CVS_SERVER=git-cvsserver export CVSROOT CVS_SERVER diff --git a/t/t9402-git-cvsserver-refs.sh b/t/t9402-git-cvsserver-refs.sh index d00df08731..6d2d3c8739 100755 --- a/t/t9402-git-cvsserver-refs.sh +++ b/t/t9402-git-cvsserver-refs.sh @@ -82,11 +82,11 @@ perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { } unset GIT_DIR GIT_CONFIG -WORKDIR=$(pwd) -SERVERDIR=$(pwd)/gitcvs.git +WORKDIR=$PWD +SERVERDIR=$PWD/gitcvs.git git_config="$SERVERDIR/config" CVSROOT=":fork:$SERVERDIR" -CVSWORK="$(pwd)/cvswork" +CVSWORK="$PWD/cvswork" CVS_SERVER=git-cvsserver export CVSROOT CVS_SERVER diff --git a/t/t9700/test.pl b/t/t9700/test.pl index 1140767b50..7e8c40b97b 100755 --- a/t/t9700/test.pl +++ b/t/t9700/test.pl @@ -33,7 +33,7 @@ is($r->config_int("test.int"), 2048, "config_int: integer"); is($r->config_int("test.nonexistent"), undef, "config_int: nonexistent"); ok($r->config_bool("test.booltrue"), "config_bool: true"); ok(!$r->config_bool("test.boolfalse"), "config_bool: false"); -is($r->config_path("test.path"), $r->config("test.pathexpanded"), +is($r->config_path("test.path") =~ s/\\/\//gr, $r->config("test.pathexpanded"), "config_path: ~/foo expansion"); is_deeply([$r->config_path("test.pathmulti")], ["foo", "bar"], "config_path: multiple values"); diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index af82049f82..ffbfa0efb8 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -67,7 +67,7 @@ repo_with_newline='repo with newline' -if mkdir "$repo_with_newline" 2>/dev/null +if test_have_prereq !MINGW && mkdir "$repo_with_newline" 2>/dev/null then test_set_prereq FUNNYNAMES else diff --git a/t/test-lib.sh b/t/test-lib.sh index bd4b02e9db..0b47eb6bb2 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -907,9 +907,11 @@ yes () { y="$*" fi - while echo "$y" + i=0 + while test $i -lt 99 do - : + echo "$y" + i=$(($i+1)) done } @@ -998,7 +1000,7 @@ test_i18ngrep () { test_lazy_prereq PIPE ' # test whether the filesystem supports FIFOs case $(uname -s) in - CYGWIN*) + CYGWIN*|MINGW*) false ;; *) diff --git a/test-dump-untracked-cache.c b/test-dump-untracked-cache.c index 25d855d98b..0a1c285246 100644 --- a/test-dump-untracked-cache.c +++ b/test-dump-untracked-cache.c @@ -44,6 +44,10 @@ int main(int ac, char **av) { struct untracked_cache *uc; struct strbuf base = STRBUF_INIT; + + /* Hack to avoid modifying the untracked cache when we read it */ + ignore_untracked_cache_config = 1; + setup_git_directory(); if (read_cache() < 0) die("unable to read index file"); diff --git a/test-fake-ssh.c b/test-fake-ssh.c new file mode 100644 index 0000000000..980de216e1 --- /dev/null +++ b/test-fake-ssh.c @@ -0,0 +1,30 @@ +#include "git-compat-util.h" +#include "run-command.h" +#include "strbuf.h" + +int main(int argc, char **argv) +{ + const char *trash_directory = getenv("TRASH_DIRECTORY"); + struct strbuf buf = STRBUF_INIT; + FILE *f; + int i; + const char *child_argv[] = { NULL, NULL }; + + /* First, print all parameters into $TRASH_DIRECTORY/ssh-output */ + if (!trash_directory) + die("Need a TRASH_DIRECTORY!"); + strbuf_addf(&buf, "%s/ssh-output", trash_directory); + f = fopen(buf.buf, "w"); + if (!f) + die("Could not write to %s", buf.buf); + for (i = 0; i < argc; i++) + fprintf(f, "%s%s", i > 0 ? " " : "", i > 0 ? argv[i] : "ssh:"); + fprintf(f, "\n"); + fclose(f); + + /* Now, evaluate the *last* parameter */ + if (argc < 2) + return 0; + child_argv[0] = argv[argc - 1]; + return run_command_v_opt(child_argv, RUN_USING_SHELL); +} diff --git a/test-path-utils.c b/test-path-utils.c index c3adcd87b8..6232dfe661 100644 --- a/test-path-utils.c +++ b/test-path-utils.c @@ -56,7 +56,7 @@ static int test_function(struct test_data *data, char *(*func)(char *input), if (!data[i].from) to = func(NULL); else { - strcpy(buffer, data[i].from); + xsnprintf(buffer, sizeof(buffer), "%s", data[i].from); to = func(buffer); } if (!strcmp(to, data[i].to)) diff --git a/transport-helper.c b/transport-helper.c index a6bff8b308..b934183236 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -321,6 +321,21 @@ static void standard_options(struct transport *t) if (n >= sizeof(buf)) die("impossibly large verbosity value"); set_helper_option(t, "verbosity", buf); + + switch (t->family) { + case TRANSPORT_FAMILY_ALL: + /* + * this is already the default, + * do not break old remote helpers by setting "all" here + */ + break; + case TRANSPORT_FAMILY_IPV4: + set_helper_option(t, "family", "ipv4"); + break; + case TRANSPORT_FAMILY_IPV6: + set_helper_option(t, "family", "ipv6"); + break; + } } static int release_helper(struct transport *transport) diff --git a/transport.c b/transport.c index 67f366687c..e20bb771fa 100644 --- a/transport.c +++ b/transport.c @@ -17,133 +17,6 @@ #include "sha1-array.h" #include "sigchain.h" -/* rsync support */ - -/* - * We copy packed-refs and refs/ into a temporary file, then read the - * loose refs recursively (sorting whenever possible), and then inserting - * those packed refs that are not yet in the list (not validating, but - * assuming that the file is sorted). - * - * Appears refactoring this from refs.c is too cumbersome. - */ - -static int str_cmp(const void *a, const void *b) -{ - const char *s1 = a; - const char *s2 = b; - - return strcmp(s1, s2); -} - -/* path->buf + name_offset is expected to point to "refs/" */ - -static int read_loose_refs(struct strbuf *path, int name_offset, - struct ref **tail) -{ - DIR *dir = opendir(path->buf); - struct dirent *de; - struct { - char **entries; - int nr, alloc; - } list; - int i, pathlen; - - if (!dir) - return -1; - - memset (&list, 0, sizeof(list)); - - while ((de = readdir(dir))) { - if (is_dot_or_dotdot(de->d_name)) - continue; - ALLOC_GROW(list.entries, list.nr + 1, list.alloc); - list.entries[list.nr++] = xstrdup(de->d_name); - } - closedir(dir); - - /* sort the list */ - - qsort(list.entries, list.nr, sizeof(char *), str_cmp); - - pathlen = path->len; - strbuf_addch(path, '/'); - - for (i = 0; i < list.nr; i++, strbuf_setlen(path, pathlen + 1)) { - strbuf_addstr(path, list.entries[i]); - if (read_loose_refs(path, name_offset, tail)) { - int fd = open(path->buf, O_RDONLY); - char buffer[40]; - struct ref *next; - - if (fd < 0) - continue; - next = alloc_ref(path->buf + name_offset); - if (read_in_full(fd, buffer, 40) != 40 || - get_oid_hex(buffer, &next->old_oid)) { - close(fd); - free(next); - continue; - } - close(fd); - (*tail)->next = next; - *tail = next; - } - } - strbuf_setlen(path, pathlen); - - for (i = 0; i < list.nr; i++) - free(list.entries[i]); - free(list.entries); - - return 0; -} - -/* insert the packed refs for which no loose refs were found */ - -static void insert_packed_refs(const char *packed_refs, struct ref **list) -{ - FILE *f = fopen(packed_refs, "r"); - static char buffer[PATH_MAX]; - - if (!f) - return; - - for (;;) { - int cmp = 0; /* assigned before used */ - int len; - - if (!fgets(buffer, sizeof(buffer), f)) { - fclose(f); - return; - } - - if (!isxdigit(buffer[0])) - continue; - len = strlen(buffer); - if (len && buffer[len - 1] == '\n') - buffer[--len] = '\0'; - if (len < 41) - continue; - while ((*list)->next && - (cmp = strcmp(buffer + 41, - (*list)->next->name)) > 0) - list = &(*list)->next; - if (!(*list)->next || cmp < 0) { - struct ref *next = alloc_ref(buffer + 41); - buffer[40] = '\0'; - if (get_oid_hex(buffer, &next->old_oid)) { - warning ("invalid SHA-1: %s", buffer); - free(next); - continue; - } - next->next = (*list)->next; - (*list)->next = next; - list = &(*list)->next; - } - } -} - static void set_upstreams(struct transport *transport, struct ref *refs, int pretend) { @@ -192,205 +65,6 @@ static void set_upstreams(struct transport *transport, struct ref *refs, } } -static const char *rsync_url(const char *url) -{ - if (!starts_with(url, "rsync://")) - skip_prefix(url, "rsync:", &url); - return url; -} - -static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) -{ - struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT; - struct ref dummy = {NULL}, *tail = &dummy; - struct child_process rsync = CHILD_PROCESS_INIT; - const char *args[5]; - int temp_dir_len; - - if (for_push) - return NULL; - - /* copy the refs to the temporary directory */ - - strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); - if (!mkdtemp(temp_dir.buf)) - die_errno ("Could not make temporary directory"); - temp_dir_len = temp_dir.len; - - strbuf_addstr(&buf, rsync_url(transport->url)); - strbuf_addstr(&buf, "/refs"); - - rsync.argv = args; - rsync.stdout_to_stderr = 1; - args[0] = "rsync"; - args[1] = (transport->verbose > 1) ? "-rv" : "-r"; - args[2] = buf.buf; - args[3] = temp_dir.buf; - args[4] = NULL; - - if (run_command(&rsync)) - die ("Could not run rsync to get refs"); - - strbuf_reset(&buf); - strbuf_addstr(&buf, rsync_url(transport->url)); - strbuf_addstr(&buf, "/packed-refs"); - - args[2] = buf.buf; - - if (run_command(&rsync)) - die ("Could not run rsync to get refs"); - - /* read the copied refs */ - - strbuf_addstr(&temp_dir, "/refs"); - read_loose_refs(&temp_dir, temp_dir_len + 1, &tail); - strbuf_setlen(&temp_dir, temp_dir_len); - - tail = &dummy; - strbuf_addstr(&temp_dir, "/packed-refs"); - insert_packed_refs(temp_dir.buf, &tail); - strbuf_setlen(&temp_dir, temp_dir_len); - - if (remove_dir_recursively(&temp_dir, 0)) - warning ("Error removing temporary directory %s.", - temp_dir.buf); - - strbuf_release(&buf); - strbuf_release(&temp_dir); - - return dummy.next; -} - -static int fetch_objs_via_rsync(struct transport *transport, - int nr_objs, struct ref **to_fetch) -{ - struct child_process rsync = CHILD_PROCESS_INIT; - - rsync.stdout_to_stderr = 1; - argv_array_push(&rsync.args, "rsync"); - argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r"); - argv_array_push(&rsync.args, "--ignore-existing"); - argv_array_push(&rsync.args, "--exclude"); - argv_array_push(&rsync.args, "info"); - argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url)); - argv_array_push(&rsync.args, get_object_directory()); - - /* NEEDSWORK: handle one level of alternates */ - return run_command(&rsync); -} - -static int write_one_ref(const char *name, const struct object_id *oid, - int flags, void *data) -{ - struct strbuf *buf = data; - int len = buf->len; - - /* when called via for_each_ref(), flags is non-zero */ - if (flags && !starts_with(name, "refs/heads/") && - !starts_with(name, "refs/tags/")) - return 0; - - strbuf_addstr(buf, name); - if (safe_create_leading_directories(buf->buf) || - write_file_gently(buf->buf, "%s", oid_to_hex(oid))) - return error("problems writing temporary file %s: %s", - buf->buf, strerror(errno)); - strbuf_setlen(buf, len); - return 0; -} - -static int write_refs_to_temp_dir(struct strbuf *temp_dir, - int refspec_nr, const char **refspec) -{ - int i; - - for (i = 0; i < refspec_nr; i++) { - struct object_id oid; - char *ref; - - if (dwim_ref(refspec[i], strlen(refspec[i]), oid.hash, &ref) != 1) - return error("Could not get ref %s", refspec[i]); - - if (write_one_ref(ref, &oid, 0, temp_dir)) { - free(ref); - return -1; - } - free(ref); - } - return 0; -} - -static int rsync_transport_push(struct transport *transport, - int refspec_nr, const char **refspec, int flags) -{ - struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT; - int result = 0, i; - struct child_process rsync = CHILD_PROCESS_INIT; - const char *args[10]; - - if (flags & TRANSPORT_PUSH_MIRROR) - return error("rsync transport does not support mirror mode"); - - /* first push the objects */ - - strbuf_addstr(&buf, rsync_url(transport->url)); - strbuf_addch(&buf, '/'); - - rsync.argv = args; - rsync.stdout_to_stderr = 1; - i = 0; - args[i++] = "rsync"; - args[i++] = "-a"; - if (flags & TRANSPORT_PUSH_DRY_RUN) - args[i++] = "--dry-run"; - if (transport->verbose > 1) - args[i++] = "-v"; - args[i++] = "--ignore-existing"; - args[i++] = "--exclude"; - args[i++] = "info"; - args[i++] = get_object_directory(); - args[i++] = buf.buf; - args[i++] = NULL; - - if (run_command(&rsync)) - return error("Could not push objects to %s", - rsync_url(transport->url)); - - /* copy the refs to the temporary directory; they could be packed. */ - - strbuf_addstr(&temp_dir, git_path("rsync-refs-XXXXXX")); - if (!mkdtemp(temp_dir.buf)) - die_errno ("Could not make temporary directory"); - strbuf_addch(&temp_dir, '/'); - - if (flags & TRANSPORT_PUSH_ALL) { - if (for_each_ref(write_one_ref, &temp_dir)) - return -1; - } else if (write_refs_to_temp_dir(&temp_dir, refspec_nr, refspec)) - return -1; - - i = 2; - if (flags & TRANSPORT_PUSH_DRY_RUN) - args[i++] = "--dry-run"; - if (!(flags & TRANSPORT_PUSH_FORCE)) - args[i++] = "--ignore-existing"; - args[i++] = temp_dir.buf; - args[i++] = rsync_url(transport->url); - args[i++] = NULL; - if (run_command(&rsync)) - result = error("Could not push to %s", - rsync_url(transport->url)); - - if (remove_dir_recursively(&temp_dir, 0)) - warning ("Could not remove temporary directory %s.", - temp_dir.buf); - - strbuf_release(&buf); - strbuf_release(&temp_dir); - - return result; -} - struct bundle_transport_data { int fd; struct bundle_header header; @@ -481,17 +155,24 @@ static int set_git_option(struct git_transport_options *opts, return 1; } -static int connect_setup(struct transport *transport, int for_push, int verbose) +static int connect_setup(struct transport *transport, int for_push) { struct git_transport_data *data = transport->data; + int flags = transport->verbose > 0 ? CONNECT_VERBOSE : 0; if (data->conn) return 0; + switch (transport->family) { + case TRANSPORT_FAMILY_ALL: break; + case TRANSPORT_FAMILY_IPV4: flags |= CONNECT_IPV4; break; + case TRANSPORT_FAMILY_IPV6: flags |= CONNECT_IPV6; break; + } + data->conn = git_connect(data->fd, transport->url, for_push ? data->options.receivepack : data->options.uploadpack, - verbose ? CONNECT_VERBOSE : 0); + flags); return 0; } @@ -501,7 +182,7 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus struct git_transport_data *data = transport->data; struct ref *refs; - connect_setup(transport, for_push, 0); + connect_setup(transport, for_push); get_remote_heads(data->fd[0], NULL, 0, &refs, for_push ? REF_NORMAL : 0, &data->extra_have, @@ -536,7 +217,7 @@ static int fetch_refs_via_pack(struct transport *transport, args.update_shallow = data->options.update_shallow; if (!data->got_remote_heads) { - connect_setup(transport, 0, 0); + connect_setup(transport, 0); get_remote_heads(data->fd[0], NULL, 0, &refs_tmp, 0, NULL, &data->shallow); data->got_remote_heads = 1; @@ -812,7 +493,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re if (!data->got_remote_heads) { struct ref *tmp_refs; - connect_setup(transport, 1, 0); + connect_setup(transport, 1); get_remote_heads(data->fd[0], NULL, 0, &tmp_refs, REF_NORMAL, NULL, &data->shallow); @@ -984,11 +665,7 @@ struct transport *transport_get(struct remote *remote, const char *url) if (helper) { transport_helper_init(ret, helper); } else if (starts_with(url, "rsync:")) { - transport_check_allowed("rsync"); - ret->get_refs_list = get_refs_via_rsync; - ret->fetch = fetch_objs_via_rsync; - ret->push = rsync_transport_push; - ret->smart_options = NULL; + die("git-over-rsync is no longer supported"); } else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) { struct bundle_transport_data *data = xcalloc(1, sizeof(*data)); transport_check_allowed("file"); diff --git a/transport.h b/transport.h index 8ebaaf2cae..c68140892c 100644 --- a/transport.h +++ b/transport.h @@ -18,6 +18,12 @@ struct git_transport_options { struct push_cas_option *cas; }; +enum transport_family { + TRANSPORT_FAMILY_ALL = 0, + TRANSPORT_FAMILY_IPV4, + TRANSPORT_FAMILY_IPV6 +}; + struct transport { struct remote *remote; const char *url; @@ -110,6 +116,8 @@ struct transport { * actually turns out to be smart. */ struct git_transport_options *smart_options; + + enum transport_family family; }; #define TRANSPORT_PUSH_ALL 1 diff --git a/worktree.c b/worktree.c index 981f810e80..6181a66f1e 100644 --- a/worktree.c +++ b/worktree.c @@ -176,10 +176,10 @@ struct worktree **get_worktrees(void) if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; - if ((linked = get_linked_worktree(d->d_name))) { - ALLOC_GROW(list, counter + 1, alloc); - list[counter++] = linked; - } + if ((linked = get_linked_worktree(d->d_name))) { + ALLOC_GROW(list, counter + 1, alloc); + list[counter++] = linked; + } } closedir(dir); } diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c index 625198e058..d98f430c91 100644 --- a/xdiff/xmerge.c +++ b/xdiff/xmerge.c @@ -109,7 +109,7 @@ static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2, return 0; } -static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add_nl, char *dest) +static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) { xrecord_t **recs; int size = 0; @@ -125,6 +125,12 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add if (add_nl) { i = recs[count - 1]->size; if (i == 0 || recs[count - 1]->ptr[i - 1] != '\n') { + if (needs_cr) { + if (dest) + dest[size] = '\r'; + size++; + } + if (dest) dest[size] = '\n'; size++; @@ -133,14 +139,58 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int add return size; } -static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest) +static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) +{ + return xdl_recs_copy_0(0, xe, i, count, needs_cr, add_nl, dest); +} + +static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest) +{ + return xdl_recs_copy_0(1, xe, i, count, needs_cr, add_nl, dest); +} + +/* + * Returns 1 if the i'th line ends in CR/LF (if it is the last line and + * has no eol, the preceding line, if any), 0 if it ends in LF-only, and + * -1 if the line ending cannot be determined. + */ +static int is_eol_crlf(xdfile_t *file, int i) { - return xdl_recs_copy_0(0, xe, i, count, add_nl, dest); + long size; + + if (i < file->nrec - 1) + /* All lines before the last *must* end in LF */ + return (size = file->recs[i]->size) > 1 && + file->recs[i]->ptr[size - 2] == '\r'; + if (!file->nrec) + /* Cannot determine eol style from empty file */ + return -1; + if ((size = file->recs[i]->size) && + file->recs[i]->ptr[size - 1] == '\n') + /* Last line; ends in LF; Is it CR/LF? */ + return size > 1 && + file->recs[i]->ptr[size - 2] == '\r'; + if (!i) + /* The only line has no eol */ + return -1; + /* Determine eol from second-to-last line */ + return (size = file->recs[i - 1]->size) > 1 && + file->recs[i - 1]->ptr[size - 2] == '\r'; } -static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int add_nl, char *dest) +static int is_cr_needed(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m) { - return xdl_recs_copy_0(1, xe, i, count, add_nl, dest); + int needs_cr; + + /* Match post-images' preceding, or first, lines' end-of-line style */ + needs_cr = is_eol_crlf(&xe1->xdf2, m->i1 ? m->i1 - 1 : 0); + if (needs_cr) + needs_cr = is_eol_crlf(&xe2->xdf2, m->i2 ? m->i2 - 1 : 0); + /* Look at pre-image's first line, unless we already settled on LF */ + if (needs_cr) + needs_cr = is_eol_crlf(&xe1->xdf1, 0); + /* If still undecided, use LF-only */ + return needs_cr < 0 ? 0 : needs_cr; } static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, @@ -152,16 +202,17 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, int marker1_size = (name1 ? strlen(name1) + 1 : 0); int marker2_size = (name2 ? strlen(name2) + 1 : 0); int marker3_size = (name3 ? strlen(name3) + 1 : 0); + int needs_cr = is_cr_needed(xe1, xe2, m); if (marker_size <= 0) marker_size = DEFAULT_CONFLICT_MARKER_SIZE; /* Before conflicting part */ - size += xdl_recs_copy(xe1, i, m->i1 - i, 0, + size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0, dest ? dest + size : NULL); if (!dest) { - size += marker_size + 1 + marker1_size; + size += marker_size + 1 + needs_cr + marker1_size; } else { memset(dest + size, '<', marker_size); size += marker_size; @@ -170,17 +221,19 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, memcpy(dest + size + 1, name1, marker1_size - 1); size += marker1_size; } + if (needs_cr) + dest[size++] = '\r'; dest[size++] = '\n'; } /* Postimage from side #1 */ - size += xdl_recs_copy(xe1, m->i1, m->chg1, 1, + size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, 1, dest ? dest + size : NULL); if (style == XDL_MERGE_DIFF3) { /* Shared preimage */ if (!dest) { - size += marker_size + 1 + marker3_size; + size += marker_size + 1 + needs_cr + marker3_size; } else { memset(dest + size, '|', marker_size); size += marker_size; @@ -189,25 +242,29 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, memcpy(dest + size + 1, name3, marker3_size - 1); size += marker3_size; } + if (needs_cr) + dest[size++] = '\r'; dest[size++] = '\n'; } - size += xdl_orig_copy(xe1, m->i0, m->chg0, 1, + size += xdl_orig_copy(xe1, m->i0, m->chg0, needs_cr, 1, dest ? dest + size : NULL); } if (!dest) { - size += marker_size + 1; + size += marker_size + 1 + needs_cr; } else { memset(dest + size, '=', marker_size); size += marker_size; + if (needs_cr) + dest[size++] = '\r'; dest[size++] = '\n'; } /* Postimage from side #2 */ - size += xdl_recs_copy(xe2, m->i2, m->chg2, 1, + size += xdl_recs_copy(xe2, m->i2, m->chg2, needs_cr, 1, dest ? dest + size : NULL); if (!dest) { - size += marker_size + 1 + marker2_size; + size += marker_size + 1 + needs_cr + marker2_size; } else { memset(dest + size, '>', marker_size); size += marker_size; @@ -216,6 +273,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1, memcpy(dest + size + 1, name2, marker2_size - 1); size += marker2_size; } + if (needs_cr) + dest[size++] = '\r'; dest[size++] = '\n'; } return size; @@ -241,21 +300,24 @@ static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1, marker_size); else if (m->mode & 3) { /* Before conflicting part */ - size += xdl_recs_copy(xe1, i, m->i1 - i, 0, + size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0, dest ? dest + size : NULL); /* Postimage from side #1 */ - if (m->mode & 1) - size += xdl_recs_copy(xe1, m->i1, m->chg1, (m->mode & 2), + if (m->mode & 1) { + int needs_cr = is_cr_needed(xe1, xe2, m); + + size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, (m->mode & 2), dest ? dest + size : NULL); + } /* Postimage from side #2 */ if (m->mode & 2) - size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, + size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0, dest ? dest + size : NULL); } else continue; i = m->i1 + m->chg1; } - size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0, + size += xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0, 0, dest ? dest + size : NULL); return size; } |