Skip to content

Commit b02f5ae

Browse files
committed
Merge branch 'jl/submodule-mv'
"git mv A B" when moving a submodule A does "the right thing", inclusing relocating its working tree and adjusting the paths in the .gitmodules file. * jl/submodule-mv: (53 commits) rm: delete .gitmodules entry of submodules removed from the work tree mv: update the path entry in .gitmodules for moved submodules submodule.c: add .gitmodules staging helper functions mv: move submodules using a gitfile mv: move submodules together with their work trees rm: do not set a variable twice without intermediate reading. t6131 - skip tests if on case-insensitive file system parse_pathspec: accept :(icase)path syntax pathspec: support :(glob) syntax pathspec: make --literal-pathspecs disable pathspec magic pathspec: support :(literal) syntax for noglob pathspec kill limit_pathspec_to_literal() as it's only used by parse_pathspec() parse_pathspec: preserve prefix length via PATHSPEC_PREFIX_ORIGIN parse_pathspec: make sure the prefix part is wildcard-free rename field "raw" to "_raw" in struct pathspec tree-diff: remove the use of pathspec's raw[] in follow-rename codepath remove match_pathspec() in favor of match_pathspec_depth() remove init_pathspec() in favor of parse_pathspec() remove diff_tree_{setup,release}_paths convert common_prefix() to use struct pathspec ...
2 parents de9a253 + 95c1641 commit b02f5ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1891
-881
lines changed

Documentation/git-mv.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ SYNOPSIS
1313

1414
DESCRIPTION
1515
-----------
16-
This script is used to move or rename a file, directory or symlink.
16+
Move or rename a file, directory or symlink.
1717

1818
git mv [-v] [-f] [-n] [-k] <source> <destination>
1919
git mv [-v] [-f] [-n] [-k] <source> ... <destination directory>
@@ -44,6 +44,14 @@ OPTIONS
4444
--verbose::
4545
Report the names of files as they are moved.
4646

47+
SUBMODULES
48+
----------
49+
Moving a submodule using a gitfile (which means they were cloned
50+
with a Git version 1.7.8 or newer) will update the gitfile and
51+
core.worktree setting to make the submodule work in the new location.
52+
It also will attempt to update the submodule.<name>.path setting in
53+
the linkgit:gitmodules[5] file and stage that file (unless -n is used).
54+
4755
GIT
4856
---
4957
Part of the linkgit:git[1] suite

Documentation/git-rm.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ use the following command:
134134
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
135135
----------------
136136

137-
Submodules
138-
~~~~~~~~~~
137+
SUBMODULES
138+
----------
139139
Only submodules using a gitfile (which means they were cloned
140140
with a Git version 1.7.8 or newer) will be removed from the work
141141
tree, as their repository lives inside the .git directory of the
142142
superproject. If a submodule (or one of those nested inside it)
143143
still uses a .git directory, `git rm` will fail - no matter if forced
144-
or not - to protect the submodule's history.
144+
or not - to protect the submodule's history. If it exists the
145+
submodule.<name> section in the linkgit:gitmodules[5] file will also
146+
be removed and that file will be staged (unless --cached or -n are used).
145147

146148
A submodule is considered up-to-date when the HEAD is the same as
147149
recorded in the index, no tracked files are modified and no untracked

Documentation/git.txt

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,25 @@ help ...`.
457457
linkgit:git-replace[1] for more information.
458458

459459
--literal-pathspecs::
460-
Treat pathspecs literally, rather than as glob patterns. This is
461-
equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
460+
Treat pathspecs literally (i.e. no globbing, no pathspec magic).
461+
This is equivalent to setting the `GIT_LITERAL_PATHSPECS` environment
462462
variable to `1`.
463463

464+
--glob-pathspecs:
465+
Add "glob" magic to all pathspec. This is equivalent to setting
466+
the `GIT_GLOB_PATHSPECS` environment variable to `1`. Disabling
467+
globbing on individual pathspecs can be done using pathspec
468+
magic ":(literal)"
469+
470+
--noglob-pathspecs:
471+
Add "literal" magic to all pathspec. This is equivalent to setting
472+
the `GIT_NOGLOB_PATHSPECS` environment variable to `1`. Enabling
473+
globbing on individual pathspecs can be done using pathspec
474+
magic ":(glob)"
475+
476+
--icase-pathspecs:
477+
Add "icase" magic to all pathspec. This is equivalent to setting
478+
the `GIT_ICASE_PATHSPECS` environment variable to `1`.
464479

465480
GIT COMMANDS
466481
------------
@@ -867,6 +882,18 @@ GIT_LITERAL_PATHSPECS::
867882
literal paths to Git (e.g., paths previously given to you by
868883
`git ls-tree`, `--raw` diff output, etc).
869884

885+
GIT_GLOB_PATHSPECS::
886+
Setting this variable to `1` will cause Git to treat all
887+
pathspecs as glob patterns (aka "glob" magic).
888+
889+
GIT_NOGLOB_PATHSPECS::
890+
Setting this variable to `1` will cause Git to treat all
891+
pathspecs as literal (aka "literal" magic).
892+
893+
GIT_ICASE_PATHSPECS::
894+
Setting this variable to `1` will cause Git to treat all
895+
pathspecs as case-insensitive.
896+
870897

871898
Discussion[[Discussion]]
872899
------------------------

Documentation/glossary-content.txt

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,54 @@ and a close parentheses `)`, and the remainder is the pattern to match
322322
against the path.
323323
+
324324
The "magic signature" consists of an ASCII symbol that is not
325-
alphanumeric. Currently only the slash `/` is recognized as a
326-
"magic signature": it makes the pattern match from the root of
327-
the working tree, even when you are running the command from
328-
inside a subdirectory.
325+
alphanumeric.
326+
+
327+
--
328+
top `/`;;
329+
The magic word `top` (mnemonic: `/`) makes the pattern match
330+
from the root of the working tree, even when you are running
331+
the command from inside a subdirectory.
332+
333+
literal;;
334+
Wildcards in the pattern such as `*` or `?` are treated
335+
as literal characters.
336+
337+
icase;;
338+
Case insensitive match.
339+
340+
glob;;
341+
Git treats the pattern as a shell glob suitable for
342+
consumption by fnmatch(3) with the FNM_PATHNAME flag:
343+
wildcards in the pattern will not match a / in the pathname.
344+
For example, "Documentation/{asterisk}.html" matches
345+
"Documentation/git.html" but not "Documentation/ppc/ppc.html"
346+
or "tools/perf/Documentation/perf.html".
347+
+
348+
Two consecutive asterisks ("`**`") in patterns matched against
349+
full pathname may have special meaning:
350+
351+
- A leading "`**`" followed by a slash means match in all
352+
directories. For example, "`**/foo`" matches file or directory
353+
"`foo`" anywhere, the same as pattern "`foo`". "**/foo/bar"
354+
matches file or directory "`bar`" anywhere that is directly
355+
under directory "`foo`".
356+
357+
- A trailing "/**" matches everything inside. For example,
358+
"abc/**" matches all files inside directory "abc", relative
359+
to the location of the `.gitignore` file, with infinite depth.
360+
361+
- A slash followed by two consecutive asterisks then a slash
362+
matches zero or more directories. For example, "`a/**/b`"
363+
matches "`a/b`", "`a/x/b`", "`a/x/y/b`" and so on.
364+
365+
- Other consecutive asterisks are considered invalid.
366+
+
367+
Glob magic is incompatible with literal magic.
368+
--
369+
+
370+
Currently only the slash `/` is recognized as the "magic signature",
371+
but it is envisioned that we will support more types of magic in later
372+
versions of Git.
329373
+
330374
A pathspec with only a colon means "there is no pathspec". This form
331375
should not be combined with other pathspec.

Documentation/technical/api-setup.txt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,42 @@ Talk about
88
* is_inside_git_dir()
99
* is_inside_work_tree()
1010
* setup_work_tree()
11-
* get_pathspec()
1211

1312
(Dscho)
13+
14+
Pathspec
15+
--------
16+
17+
See glossary-context.txt for the syntax of pathspec. In memory, a
18+
pathspec set is represented by "struct pathspec" and is prepared by
19+
parse_pathspec(). This function takes several arguments:
20+
21+
- magic_mask specifies what features that are NOT supported by the
22+
following code. If a user attempts to use such a feature,
23+
parse_pathspec() can reject it early.
24+
25+
- flags specifies other things that the caller wants parse_pathspec to
26+
perform.
27+
28+
- prefix and args come from cmd_* functions
29+
30+
get_pathspec() is obsolete and should never be used in new code.
31+
32+
parse_pathspec() helps catch unsupported features and reject them
33+
politely. At a lower level, different pathspec-related functions may
34+
not support the same set of features. Such pathspec-sensitive
35+
functions are guarded with GUARD_PATHSPEC(), which will die in an
36+
unfriendly way when an unsupported feature is requested.
37+
38+
The command designers are supposed to make sure that GUARD_PATHSPEC()
39+
never dies. They have to make sure all unsupported features are caught
40+
by parse_pathspec(), not by GUARD_PATHSPEC. grepping GUARD_PATHSPEC()
41+
should give the designers all pathspec-sensitive codepaths and what
42+
features they support.
43+
44+
A similar process is applied when a new pathspec magic is added. The
45+
designer lifts the GUARD_PATHSPEC restriction in the functions that
46+
support the new magic. At the same time (s)he has to make sure this
47+
new feature will be caught at parse_pathspec() in commands that cannot
48+
handle the new magic in some cases. grepping parse_pathspec() should
49+
help.

archive.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ int write_archive_entries(struct archiver_args *args,
151151
struct archiver_context context;
152152
struct unpack_trees_options opts;
153153
struct tree_desc t;
154-
struct pathspec pathspec;
155154
int err;
156155

157156
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -186,10 +185,8 @@ int write_archive_entries(struct archiver_args *args,
186185
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
187186
}
188187

189-
init_pathspec(&pathspec, args->pathspec);
190-
err = read_tree_recursive(args->tree, "", 0, 0, &pathspec,
188+
err = read_tree_recursive(args->tree, "", 0, 0, &args->pathspec,
191189
write_archive_entry, &context);
192-
free_pathspec(&pathspec);
193190
if (err == READ_TREE_RECURSIVE)
194191
err = 0;
195192
return err;
@@ -222,7 +219,7 @@ static int path_exists(struct tree *tree, const char *path)
222219
struct pathspec pathspec;
223220
int ret;
224221

225-
init_pathspec(&pathspec, paths);
222+
parse_pathspec(&pathspec, 0, 0, "", paths);
226223
ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
227224
free_pathspec(&pathspec);
228225
return ret != 0;
@@ -231,11 +228,18 @@ static int path_exists(struct tree *tree, const char *path)
231228
static void parse_pathspec_arg(const char **pathspec,
232229
struct archiver_args *ar_args)
233230
{
234-
ar_args->pathspec = pathspec = get_pathspec("", pathspec);
231+
/*
232+
* must be consistent with parse_pathspec in path_exists()
233+
* Also if pathspec patterns are dependent, we're in big
234+
* trouble as we test each one separately
235+
*/
236+
parse_pathspec(&ar_args->pathspec, 0,
237+
PATHSPEC_PREFER_FULL,
238+
"", pathspec);
235239
if (pathspec) {
236240
while (*pathspec) {
237241
if (**pathspec && !path_exists(ar_args->tree, *pathspec))
238-
die("path not found: %s", *pathspec);
242+
die(_("pathspec '%s' did not match any files"), *pathspec);
239243
pathspec++;
240244
}
241245
}

archive.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
#ifndef ARCHIVE_H
22
#define ARCHIVE_H
33

4+
#include "pathspec.h"
5+
46
struct archiver_args {
57
const char *base;
68
size_t baselen;
79
struct tree *tree;
810
const unsigned char *commit_sha1;
911
const struct commit *commit;
1012
time_t time;
11-
const char **pathspec;
13+
struct pathspec pathspec;
1214
unsigned int verbose : 1;
1315
unsigned int worktree_attributes : 1;
1416
unsigned int convert : 1;

0 commit comments

Comments
 (0)