|
|
44325a |
From 90243e8192574f43bb84be01528504ec230d7fd3 Mon Sep 17 00:00:00 2001
|
|
|
44325a |
From: Pavel Cahyna <pcahyna@redhat.com>
|
|
|
44325a |
Date: Fri, 19 Oct 2018 10:55:43 +0200
|
|
|
44325a |
Subject: [PATCH 2/2] submodule-config: ban submodule urls that start with dash
|
|
|
44325a |
- tests
|
|
|
44325a |
|
|
|
44325a |
Our tests cover two cases:
|
|
|
44325a |
|
|
|
44325a |
1. A file url with "./" continues to work, showing that
|
|
|
44325a |
there's an escape hatch for people with truly silly
|
|
|
44325a |
repo names.
|
|
|
44325a |
|
|
|
44325a |
2. A url starting with "-" is rejected.
|
|
|
44325a |
|
|
|
44325a |
Note that we expect case (2) to fail, but it would have done
|
|
|
44325a |
so even without this commit, for the reasons given above.
|
|
|
44325a |
So instead of just expecting failure, let's also check for
|
|
|
44325a |
the magic word "ignoring" on stderr. That lets us know that
|
|
|
44325a |
we failed for the right reason.
|
|
|
44325a |
|
|
|
44325a |
[pc: backported to 1.8.3.1 by avoiding -C in tests]
|
|
|
44325a |
|
|
|
44325a |
submodule-config: ban submodule paths that start with a dash - test
|
|
|
44325a |
|
|
|
44325a |
There are two minor differences to the tests in t7416 (that
|
|
|
44325a |
covered urls):
|
|
|
44325a |
|
|
|
44325a |
1. We don't have a "./-sub" escape hatch to make this
|
|
|
44325a |
work, since the submodule code expects to be able to
|
|
|
44325a |
match canonical index names to the path field (so you
|
|
|
44325a |
are free to add submodule config with that path, but we
|
|
|
44325a |
would never actually use it, since an index entry would
|
|
|
44325a |
never start with "./").
|
|
|
44325a |
|
|
|
44325a |
2. After this patch, cloning actually succeeds. Since we
|
|
|
44325a |
ignore the submodule.*.path value, we fail to find a
|
|
|
44325a |
config stanza for our submodule at all, and simply
|
|
|
44325a |
treat it as inactive. We still check for the "ignoring"
|
|
|
44325a |
message.
|
|
|
44325a |
|
|
|
44325a |
[jn:
|
|
|
44325a |
- the original patch expects 'git clone' to succeed in
|
|
|
44325a |
the test because v2.13.0-rc0~10^2~3 (clone: teach
|
|
|
44325a |
--recurse-submodules to optionally take a pathspec,
|
|
|
44325a |
2017-03-17) makes 'git clone' skip invalid submodules.
|
|
|
44325a |
Updated the test to pass in older Git versions where the
|
|
|
44325a |
submodule name check makes 'git clone' fail.]
|
|
|
44325a |
|
|
|
44325a |
[pc:
|
|
|
44325a |
- avoid -C in tests
|
|
|
44325a |
- reimplement git mv of a submodule, git mv gained that functionality later.]
|
|
|
44325a |
|
|
|
44325a |
fsck: detect submodule urls starting with dash - tests
|
|
|
44325a |
|
|
|
44325a |
[pc: backported to 1.8.3.1 by avoiding -C in tests ]
|
|
|
44325a |
|
|
|
44325a |
fsck: detect submodule paths starting with dash - test
|
|
|
44325a |
|
|
|
44325a |
commit 1a7fd1fb2998002da6e9ff2ee46e1bdd25ee8404 upstream.
|
|
|
44325a |
|
|
|
44325a |
[pc: backported to 1.8.3.1 by avoiding -C in tests ]
|
|
|
44325a |
---
|
|
|
44325a |
t/t7416-submodule-dash-url.sh | 49 +++++++++++++++++++++++++++++++++++++++++++
|
|
|
44325a |
t/t7417-submodule-path-url.sh | 32 ++++++++++++++++++++++++++++
|
|
|
44325a |
2 files changed, 81 insertions(+)
|
|
|
44325a |
create mode 100755 t/t7416-submodule-dash-url.sh
|
|
|
44325a |
create mode 100755 t/t7417-submodule-path-url.sh
|
|
|
44325a |
|
|
|
44325a |
diff --git a/t/t7416-submodule-dash-url.sh b/t/t7416-submodule-dash-url.sh
|
|
|
44325a |
new file mode 100755
|
|
|
44325a |
index 000000000..e85f2e9d2
|
|
|
44325a |
--- /dev/null
|
|
|
44325a |
+++ b/t/t7416-submodule-dash-url.sh
|
|
|
44325a |
@@ -0,0 +1,49 @@
|
|
|
44325a |
+#!/bin/sh
|
|
|
44325a |
+
|
|
|
44325a |
+test_description='check handling of .gitmodule url with dash'
|
|
|
44325a |
+. ./test-lib.sh
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'create submodule with protected dash in url' '
|
|
|
44325a |
+ git init upstream &&
|
|
|
44325a |
+ ( cd upstream && git commit --allow-empty -m base ) &&
|
|
|
44325a |
+ mv upstream ./-upstream &&
|
|
|
44325a |
+ git submodule add ./-upstream sub &&
|
|
|
44325a |
+ git add sub .gitmodules &&
|
|
|
44325a |
+ git commit -m submodule
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'clone can recurse submodule' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ git clone --recurse-submodules . dst &&
|
|
|
44325a |
+ echo base >expect &&
|
|
|
44325a |
+ ( cd dst/sub && git log -1 --format=%s ) >actual &&
|
|
|
44325a |
+ test_cmp expect actual
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'fsck accepts protected dash' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ git init --bare dst &&
|
|
|
44325a |
+ ( cd dst && git config transfer.fsckObjects true ) &&
|
|
|
44325a |
+ git push dst HEAD
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'remove ./ protection from .gitmodules url' '
|
|
|
44325a |
+ perl -i -pe "s{\./}{}" .gitmodules &&
|
|
|
44325a |
+ git commit -am "drop protection"
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'clone rejects unprotected dash' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ test_must_fail git clone --recurse-submodules . dst 2>err &&
|
|
|
44325a |
+ test_i18ngrep "may be interpreted as a command-line option" err
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'fsck rejects unprotected dash' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ git init --bare dst &&
|
|
|
44325a |
+ ( cd dst && git config transfer.fsckObjects true ) &&
|
|
|
44325a |
+ test_must_fail git push dst HEAD 2>err &&
|
|
|
44325a |
+ test_i18ngrep "disallowed submodule url" err
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_done
|
|
|
44325a |
diff --git a/t/t7417-submodule-path-url.sh b/t/t7417-submodule-path-url.sh
|
|
|
44325a |
new file mode 100755
|
|
|
44325a |
index 000000000..141b42a11
|
|
|
44325a |
--- /dev/null
|
|
|
44325a |
+++ b/t/t7417-submodule-path-url.sh
|
|
|
44325a |
@@ -0,0 +1,32 @@
|
|
|
44325a |
+#!/bin/sh
|
|
|
44325a |
+
|
|
|
44325a |
+test_description='check handling of .gitmodule path with dash'
|
|
|
44325a |
+. ./test-lib.sh
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'create submodule with dash in path' '
|
|
|
44325a |
+ git init upstream &&
|
|
|
44325a |
+ ( cd upstream && git commit --allow-empty -m base ) &&
|
|
|
44325a |
+ git submodule add ./upstream sub &&
|
|
|
44325a |
+ mv -- sub -sub &&
|
|
|
44325a |
+ git rm --cached sub &&
|
|
|
44325a |
+ sed -i -e "/=.*sub$/s/sub/-sub/" .git/modules/sub/config &&
|
|
|
44325a |
+ sed -i -e "/=.*sub$/s/sub/-sub/" .gitmodules &&
|
|
|
44325a |
+ git add -- -sub .git/modules/sub/config .gitmodules &&
|
|
|
44325a |
+ git commit -m submodule
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'clone rejects unprotected dash' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ test_might_fail git clone --recurse-submodules . dst 2>err &&
|
|
|
44325a |
+ test_i18ngrep "may be interpreted as a command-line option" err
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_expect_success 'fsck rejects unprotected dash' '
|
|
|
44325a |
+ test_when_finished "rm -rf dst" &&
|
|
|
44325a |
+ git init --bare dst &&
|
|
|
44325a |
+ ( cd dst && git config transfer.fsckObjects true ) &&
|
|
|
44325a |
+ test_must_fail git push dst HEAD 2>err &&
|
|
|
44325a |
+ test_i18ngrep "disallowed submodule path" err
|
|
|
44325a |
+'
|
|
|
44325a |
+
|
|
|
44325a |
+test_done
|
|
|
44325a |
--
|
|
|
44325a |
2.14.4
|
|
|
44325a |
|