diff options
author | Stefan Beller <sbeller@google.com> | 2017-01-17 17:05:20 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-01-25 12:33:33 -0800 |
commit | 3d415425c7b6ca0d2243a4589672369e7a02fc2c (patch) | |
tree | 5203ddee03812e782602830b3f8862ce62a84900 /t | |
parent | 83587d5236cbb4f45d6c0c551d0f0669ba25b176 (diff) | |
download | git-3d415425c7b6ca0d2243a4589672369e7a02fc2c.tar.gz |
unpack-trees: support super-prefix optionsb/unpack-trees-super-prefix
In the future we want to support working tree operations within submodules,
e.g. "git checkout --recurse-submodules", which will update the submodule
to the commit as recorded in its superproject. In the submodule the
unpack-tree operation is carried out as usual, but the reporting to the
user needs to prefix any path with the superproject. The mechanism for
this is the super-prefix. (see 74866d757, git: make super-prefix option)
Add support for the super-prefix option for commands that unpack trees
by wrapping any path output in unpacking trees in the newly introduced
super_prefixed function. This new function prefixes any path with the
super-prefix if there is one. Assuming the submodule case doesn't happen
in the majority of the cases, we'd want to have a fast behavior for no
super prefix, i.e. no reallocation/copying, but just returning path.
Another aspect of introducing the `super_prefixed` function is to consider
who owns the memory and if this is the right place where the path gets
modified. As the super prefix ought to change the output behavior only and
not the actual unpack tree part, it is fine to be that late in the line.
As we get passed in 'const char *path', we cannot change the path itself,
which means in case of a super prefix we have to copy over the path.
We need two static buffers in that function as the error messages
contain at most two paths.
For testing purposes enable it in read-tree, which has no output
of paths other than an unpack-trees.c. These are all converted in
this patch.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't')
-rwxr-xr-x | t/t1001-read-tree-m-2way.sh | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 7b70089705..5ededd8e40 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -363,6 +363,14 @@ test_expect_success 'a/b (untracked) vs a, plus c/d case test.' ' test -f a/b ' +test_expect_success 'read-tree supports the super-prefix' ' + cat <<-EOF >expect && + error: Updating '\''fictional/a'\'' would lose untracked files in it + EOF + test_must_fail git --super-prefix fictional/ read-tree -u -m "$treeH" "$treeM" 2>actual && + test_cmp expect actual +' + test_expect_success 'a/b vs a, plus c/d case setup.' ' rm -f .git/index && rm -fr a && |