Browse Source

Do not apply pushInsteadOf to existing pushUris

Per the git config documentation[1], pushInsteadOf is ignored when
a remote has explicit pushUris.

Implement this, and adapt tests.

Up to now JGit mistakenly applied pushInsteadOf also to existing
pushUris. If some repositories had relied on this mis-feature,
pushes may newly suddenly fail (the uncritical case; the config
just needs to be fixed) or even still succeed but push to unexpected
places, namely to the non-rewritten pushUrls (the critical case).

The release notes should point out this change.

[1] https://git-scm.com/docs/git-config

Bug: 393170
Change-Id: I38c83204d2ac74f88f3d22d0550bf5ff7ee86daf
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.9
Thomas Wolf 7 years ago committed by Matthias Sohn
parent
commit
37908321c0
  1. 19
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java
  2. 18
      org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java

19
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RemoteConfigTest.java

@ -499,19 +499,30 @@ public class RemoteConfigTest {
} }
@Test @Test
public void singlePushInsteadOf() throws Exception { public void pushInsteadOfNotAppliedToPushUri() throws Exception {
config.setString("remote", "origin", "pushurl", "short:project.git"); config.setString("remote", "origin", "pushurl", "short:project.git");
config.setString("url", "https://server/repos/", "pushInsteadOf", config.setString("url", "https://server/repos/", "pushInsteadOf",
"short:"); "short:");
RemoteConfig rc = new RemoteConfig(config, "origin"); RemoteConfig rc = new RemoteConfig(config, "origin");
assertFalse(rc.getPushURIs().isEmpty()); assertFalse(rc.getPushURIs().isEmpty());
assertEquals("https://server/repos/project.git", rc.getPushURIs() assertEquals("short:project.git",
.get(0).toASCIIString()); rc.getPushURIs().get(0).toASCIIString());
}
@Test
public void pushInsteadOfAppliedToUri() throws Exception {
config.setString("remote", "origin", "url", "short:project.git");
config.setString("url", "https://server/repos/", "pushInsteadOf",
"short:");
RemoteConfig rc = new RemoteConfig(config, "origin");
assertFalse(rc.getPushURIs().isEmpty());
assertEquals("https://server/repos/project.git",
rc.getPushURIs().get(0).toASCIIString());
} }
@Test @Test
public void multiplePushInsteadOf() throws Exception { public void multiplePushInsteadOf() throws Exception {
config.setString("remote", "origin", "pushurl", "prefixproject.git"); config.setString("remote", "origin", "url", "prefixproject.git");
config.setStringList("url", "https://server/repos/", "pushInsteadOf", config.setStringList("url", "https://server/repos/", "pushInsteadOf",
Arrays.asList("pre", "prefix", "pref", "perf")); Arrays.asList("pre", "prefix", "pref", "perf"));
RemoteConfig rc = new RemoteConfig(config, "origin"); RemoteConfig rc = new RemoteConfig(config, "origin");

18
org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteConfig.java

@ -173,20 +173,22 @@ public class RemoteConfig implements Serializable {
for (final String s : vlst) { for (final String s : vlst) {
uris.add(new URIish(replaceUri(s, insteadOf))); uris.add(new URIish(replaceUri(s, insteadOf)));
} }
Map<String, String> pushInsteadOf = getReplacements(rc,
KEY_PUSHINSTEADOF);
String[] plst = rc.getStringList(SECTION, name, KEY_PUSHURL); String[] plst = rc.getStringList(SECTION, name, KEY_PUSHURL);
pushURIs = new ArrayList<>(plst.length); pushURIs = new ArrayList<>(plst.length);
for (final String s : plst) { for (final String s : plst) {
pushURIs.add(new URIish(replaceUri(s, pushInsteadOf))); pushURIs.add(new URIish(s));
} }
if (pushURIs.isEmpty() && !pushInsteadOf.isEmpty()) { if (pushURIs.isEmpty()) {
// Would default to the uris. If we have pushinsteadof, we must // Would default to the uris. If we have pushinsteadof, we must
// supply rewritten push uris. // supply rewritten push uris.
for (String s : vlst) { Map<String, String> pushInsteadOf = getReplacements(rc,
String replaced = replaceUri(s, pushInsteadOf); KEY_PUSHINSTEADOF);
if (!s.equals(replaced)) { if (!pushInsteadOf.isEmpty()) {
pushURIs.add(new URIish(replaced)); for (String s : vlst) {
String replaced = replaceUri(s, pushInsteadOf);
if (!s.equals(replaced)) {
pushURIs.add(new URIish(replaced));
}
} }
} }
} }

Loading…
Cancel
Save