Commit 218e1bd7 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

subrepos: ignore and warn about any modifications to .gitmodules

Populating or modifying these from the Mercurial side of things seems
inherently unsafe. Not sure how this could happen in the wild, except
maybe with old clones.
parent cdf8447a7302
Pipeline #57977 passed with stages
in 31 minutes and 7 seconds
......@@ -133,6 +133,7 @@
ui = self._hg.ui
dangerous = False
for c in path.split(b'/'):
if encoding.hfsignoreclean(c) == b'.git':
dangerous = True
......@@ -163,6 +164,12 @@
# undocumented: just let anything else mean "skip"
ui.warn(b"warning: skipping invalid path '%s'\n" % prettypath)
return False
elif path == b'.gitmodules':
ui.warn(
b"warning: ignoring modifications to '%s' file; "
b"please use '.hgsub' instead\n" % path
)
return False
else:
return True
......@@ -219,6 +226,7 @@
# only export those.
dirty_trees = set()
gitmodules = b''
subadded, subremoved = [], []
for s in modified, added, removed:
......
Load commonly used test logic
$ . "$TESTDIR/testutil"
$ cat >> $HGRCPATH <<EOF
> [templates]
> info =
> commit: {rev}:{node|short} {desc|fill68}
> added: {file_adds}
> removed: {file_dels}\n
> EOF
Create a Git upstream
$ git init --quiet --bare repo.git
Create a Mercurial repository with a .gitmodules file:
$ hg clone repo.git hgrepo
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cd hgrepo
$ hg book master
$ touch this
$ fn_hg_commit -A -m 'add this'
$ cat > .gitmodules <<EOF
> [submodule "subrepo"]
> path = subrepo
> url = ../gitsubrepo
> EOF
$ hg add .gitmodules
$ fn_hg_commit -m "add .gitmodules file"
$ cd ..
What happens if we push that to Git?
$ hg -R hgrepo push
pushing to $TESTTMP/repo.git
warning: ignoring modifications to '.gitmodules' file; please use '.hgsub' instead
searching for changes
adding objects
added 2 commits with 1 trees and 1 blobs
adding reference refs/heads/master
But we don't get a warning if we don't touch .gitmodules:
$ cd hgrepo
$ touch that
$ fn_hg_commit -A -m 'add that'
$ hg push
pushing to $TESTTMP/repo.git
searching for changes
adding objects
added 1 commits with 1 trees and 0 blobs
updating reference refs/heads/master
$ cd ..
Check that it didn't silenty come through, or something:
$ git clone repo.git gitrepo
Cloning into 'gitrepo'...
done.
$ ls -A gitrepo
.git
that
this
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment