Commit Graph

100 Commits

Author SHA1 Message Date
Dmitry Lobanov
54a524524c tests: submodule git lookup can be dupped test comments have been changed. 2021-06-15 17:33:29 +03:00
Dmitry Lobanov
11452ca143 tests: submodule git lookup can be dupped test has been added. 2021-06-03 11:14:58 +03:00
Edward Thomson
cad7a1bad4 clar: include the function name 2020-06-05 08:49:07 +01:00
Edward Thomson
51eff5a58b strarray: we should dispose instead of free
We _dispose_ the contents of objects; we _free_ objects (and their
contents).  Update `git_strarray_free` to be `git_strarray_dispose`.
`git_strarray_free` remains as a deprecated proxy function.
2020-06-01 22:50:28 +01:00
Patrick Steinhardt
11e8ee1ffe tests: submodule: verify setup of relative URLs
When setting up relative URLs for a submodule, then we resolve it to
the actual location and write that into ".git/config" instead of
writing the relative value. We do not yet have a test to nail down this
behaviour, which is now being added by this commit.
2020-01-06 15:41:18 +01:00
Patrick Steinhardt
73e9535d02 tests: submodule: test cloning edge cases
Add two more tests that verify our behaviour in some edge cases, notably
when cloning into a non-empty directory and when cloning the same
submodule twice.
2019-10-17 13:43:26 +02:00
Patrick Steinhardt
de412fc299 tests: submodule: make use of sandboxes to clean repos
The test submodule::add::submodule_clone doesn't use a sandbox, and thus
the created repo will not get deleted after the test has finished.
Convert the test to use the empty standard repo sandbox instead to fix
this.
2019-10-17 13:37:25 +02:00
Patrick Steinhardt
09b1ac11b4 tests: submodule: fix tests for cloning submodules
The test submodule::add::homemade_clone unfortunately doesn't test
what's expected, but does instead clone the submodule to a directory
that is outside of the parent repository. Fixing this by cloning to the
correct location isn't possible, though, as `git_submodule_add_setup`
will have pre-created a ".git" file already, which will cause
`git_clone` to error out.

As it's not possible to perform the clone without fiddling around with
the repo's layout, let's just remove this test as that is in fact what
the new `git_submodule_clone` function is for.
2019-10-17 13:35:30 +02:00
Etienne Samson
3c5d78bd7e submodule: provide a wrapper for simple submodule clone steps 2019-10-17 13:09:39 +02:00
Patrick Steinhardt
e54343a402 fileops: rename to "futils.h" to match function signatures
Our file utils functions all have a "futils" prefix, e.g.
`git_futils_touch`. One would thus naturally guess that their
definitions and implementation would live in files "futils.h" and
"futils.c", respectively, but in fact they live in "fileops.h".

Rename the files to match expectations.
2019-07-20 19:11:20 +02:00
Edward Thomson
168fe39bea object_type: use new enumeration names
Use the new object_type enumeration names within the codebase.
2018-12-01 11:54:57 +00:00
Carlos Martín Nieto
4e0bdaa877 submodule: add failing test for option-injection protection in url and path 2018-10-05 19:50:13 +02:00
Patrick Steinhardt
ecf4f33a4e Convert usage of git_buf_free to new git_buf_dispose 2018-06-10 19:34:37 +02:00
Patrick Steinhardt
8178c70ff4 tests: submodule: do not rely on config iteration order
The test submodule::lookup::duplicated_path, which tries to verify that
we detect submodules with duplicated paths, currently relies on the
gitmodules file of "submod2_target". While this file has two gitmodules
with the same path, one of these gitmodules has an empty name and thus
does not pass `git_submodule_name_is_valid`. Because of this, the test
is in fact dependent on the iteration order in which we process the
submodules. In fact the "valid" submodule comes first, the "invalid"
submodule will cause the desired error. In fact the "invalid" submodule
comes first, it will be skipped due to its name being invalid, and we
will not see the desired error. While this works on the master branch
just right due to the refactoring of our config code, where iteration
order is now deterministic, this breaks on all older maintenance
branches.

Fix the issue by simply using `cl_git_rewritefile` to rewrite the
gitmodules file. This greatly simplifies the test and also makes the
intentions of it much clearer.
2018-06-06 11:32:14 +02:00
Patrick Steinhardt
b2a389c870 submodule: detect duplicated submodule paths
When loading submodule names, we build a map of submodule paths and
their respective names. While looping over the configuration keys,
we do not check though whether a submodule path was seen already. This
leads to a memory leak in case we have multiple submodules with the same
path, as we just overwrite the old value in the map in that case.

Fix the error by verifying that the path to be added is not yet part of
the string map. Git does not allow to have multiple submodules for a
path anyway, so we now do the same and detect this duplication,
reporting it to the user.
2018-05-30 10:35:12 +02:00
Carlos Martín Nieto
9e723db877 submodule: plug leaks from the escape detection 2018-05-24 20:28:36 +02:00
Carlos Martín Nieto
397abe9832 submodule: also validate Windows-separated paths for validity
Otherwise we would also admit `..\..\foo\bar` as a valid path and fail to
protect Windows users.

Ideally we would check for both separators without the need for the copied
string, but this'll get us over the RCE.
2018-05-14 17:30:59 +02:00
Carlos Martín Nieto
6b15ceac0a submodule: ignore submodules which include path traversal in their name
If the we decide that the "name" of the submodule (i.e. its path inside
`.git/modules/`) is trying to escape that directory or otherwise trick us, we
ignore the configuration for that submodule.

This leaves us with a half-configured submodule when looking it up by path, but
it's the same result as if the configuration really were missing.

The name check is potentially more strict than it needs to be, but it lets us
re-use the check we're doing for the checkout. The function that encapsulates
this logic is ready to be exported but we don't want to do that in a security
release so it remains internal for now.
2018-05-09 20:29:49 +02:00
Carlos Martín Nieto
7553763aca submodule: add a failing test for a submodule escaping .git/modules
We should pretend such submdules do not exist as it can lead to RCE.
2018-04-30 13:03:44 +02:00
Edward Thomson
286a6765f8 Merge pull request #4522 from csware/submodules-should-report-parse-errors
Submodules-API should report .gitmodules parse errors instead of ignoring them
2018-04-17 14:32:56 +01:00
Carson Howard
69a282da27 submodule: add more robust error handling when a submodule path is found on add 2018-03-28 06:48:55 -07:00
Sven Strickroth
e55b5373fb Submodule API should report .gitmodules parse errors
Signed-off-by: Sven Strickroth <email@cs-ware.de>
2018-03-27 19:03:19 +02:00
Carson Howard
677d393c0b tests: submodule: insert index entries directly into index 2018-03-27 07:29:04 -07:00
Carson Howard
ef9a77491c submodule: update index check to check path before directory and fix tests 2018-03-27 07:29:04 -07:00
Carson Howard
9371149f1d submodule: fix styling errors 2018-03-27 07:29:04 -07:00
Carson Howard
3e500fc8d2 test: submodule: add: join path without slashes 2018-03-27 07:29:04 -07:00
Carson Howard
0a74f391be test: submodule: add: use p_mkdir to create directories 2018-03-27 07:29:04 -07:00
Carson Howard
ad1c435054 submodule: check index for prefix before adding submodule
submodule: check path and prefix before adding submodule


submodule: fix test errors
2018-03-27 07:29:04 -07:00
Patrick Steinhardt
477b3e0474 submodule: refuse lookup in bare repositories
While it is technically possible to look up submodules inside of a
bare repository by reading the submodule configuration of a specific
commit, we do not offer this functionality right now. As such, calling
both `git_submodule_lookup` and `git_submodule_foreach` should error out
early when these functions encounter a bare repository. While
`git_submodule_lookup` already does return an error due to not being
able to parse the configuration, `git_submodule_foreach` simply returns
success and never invokes the callback function.

Fix the issue by having both functions check whether the repository is
bare and returning an error in that case.
2017-08-25 18:15:12 +02:00
Patrick Steinhardt
a889c05f2a tests: submodule: add explicit cleanup function in lookup tests 2017-08-25 18:05:48 +02:00
Patrick Steinhardt
64d1e0b37c tests: submodule: fix declaration of test
The testcase "submodule::lookup::cached" was declared with a single
underscore separating the test suide and test name, only. As the clar
parser only catches tests with two underscores, it was never executed.
Add in the second underscore to actually have it detected and executed.
2017-08-25 18:05:48 +02:00
Patrick Steinhardt
2696c5c3ec repository: make check if repo is a worktree more strict
To determine if a repository is a worktree or not, we currently check
for the existence of a "gitdir" file inside of the repository's gitdir.
While this is sufficient for non-broken repositories, we have at least
one case of a subtly broken repository where there exists a gitdir file
inside of a gitmodule. This will cause us to misidentify the submodule
as a worktree.

While this is not really a fault of ours, we can do better here by
observing that a repository can only ever be a worktree iff its common
directory and dotgit directory are different. This allows us to make our
check whether a repo is a worktree or not more strict by doing a simple
string comparison of these two directories. This will also allow us to
do the right thing in the above case of a broken repository, as for
submodules these directories will be the same. At the same time, this
allows us to skip the `stat` check for the "gitdir" file for most
repositories.
2017-05-19 09:44:44 +02:00
Patrick Steinhardt
e526fbc703 tests: add test suite for opening submodules 2017-05-17 09:41:48 +02:00
Edward Thomson
a1dcc83030 tests: provide better pass/failure error messages
Provide more detailed messages when conditions pass or fail
unexpectedly.  In particular, this provides the error messages when a
test fails with a different error code than was expected.
2017-02-17 12:58:57 +00:00
Brock Peabody
4d99c4cfc6 Allow for caching of submodules.
Added `git_repository_submodule_cache_all` to initialze a cache of
submodules on the repository so that operations looking up N
submodules are O(N) and not O(N^2).  Added a
`git_repository_submodule_cache_clear` function to remove the cache.

Also optimized the function that loads all submodules as it was itself
O(N^2) w.r.t the number of submodules, having to loop through the
`.gitmodules` file once per submodule.  I changed it to process the
`.gitmodules` file once, into a map.

Signed-off-by: David Turner <dturner@twosigma.com>
2017-01-20 17:33:56 -05:00
Edward Thomson
74ab5f2cd0 status: test submodules with mixed case 2016-03-31 17:58:43 -04:00
Dmitriy Olshevskiy
91f0d186b4 typos in comments 2015-12-21 22:18:07 +03:00
Edward Thomson
790012ce78 submodule: test updating a submodule w/ a path
Test that `git_submodule_update` can handle a submodule that is
freshly cloned and has a path differing from its name.
2015-11-04 16:53:41 -05:00
Carlos Martín Nieto
aebddbe736 Merge pull request #3434 from ethomson/reservednames
Win32 Reserved names: don't reserve names outside the working directory
2015-09-21 06:01:03 +02:00
Edward Thomson
e8ddd8d76c repo::reservedname: test a submodule update
Test an initial submodule update, where we are trying to checkout
the submodule for the first time, and placing a file within the
submodule working directory with the same name as the submodule
(and consequently, the same name as the repository itself).
2015-09-18 12:17:49 -04:00
Carlos Martín Nieto
dfe2856d0f Fix a couple of warnings 2015-09-18 12:06:55 +02:00
Edward Thomson
ac2fba0ecd git_futils_mkdir_*: make a relative-to-base mkdir
Untangle git_futils_mkdir from git_futils_mkdir_ext - the latter
assumes that we own everything beneath the base, as if it were
being called with a base of the repository or working directory,
and is tailored towards checkout and ensuring that there is no
bogosity beneath the base that must be cleaned up.

This is (at best) slow and (at worst) unsafe in the larger context
of a filesystem where we do not own things and cannot do things like
unlink symlinks that are in our way.
2015-09-17 10:00:35 -04:00
Carlos Martín Nieto
a3b9731ff8 submodule: add a test for a renamed submdoule dir 2015-09-10 21:23:03 +02:00
Edward Thomson
ed1c64464a iterator: use an options struct instead of args 2015-08-28 18:39:47 -04:00
Edward Thomson
2dfd5eae33 Merge pull request #3307 from libgit2/cmn/submodule-backslash
Normalize submodule urls before looking at them
2015-07-24 15:05:16 -05:00
Edward Thomson
759b2230a5 Merge pull request #3303 from libgit2/cmn/index-add-submodule
Allow adding a submodule through git_index_add_bypath
2015-07-24 15:04:20 -05:00
Carlos Martín Nieto
aa51fa1e03 submodule: add failing test for backslash in url 2015-07-13 08:39:35 +02:00
Carlos Martín Nieto
0d98af0911 blob: fail to create a blob from a dir with EDIRECTORY
This also affects `git_index_add_bypath()` by providing a better error
message and a specific error code when a directory is passed.
2015-07-12 12:11:22 +02:00
Carlos Martín Nieto
a34c4f8dce submdule: reproduce double-reporting of a submodule in foreach
When we rename a submodule, we should be merging two sets of information
based on whether their path is the same. We currently only deduplicate
on equal name, which causes us to double-report.
2015-07-11 13:32:57 +02:00
Carlos Martín Nieto
e8e848a8da submodule: add failing test for loading the wrong submodule
When two submodules are fairly similar, we may end up loading the wrong
one.
2015-07-01 21:14:55 +02:00