Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Construct a proper SSH URI #1068

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -173,7 +173,7 @@ public String name() {
@Override
public URI url() {
if (gitLabHost.useSsh()) {
return URI.create("ssh://git@" + gitLabHost.getPat().orElseThrow().username() + "." + gitLabHost.getUri().getHost() + ":" + projectName + ".git");
return URI.create("ssh://git@" + gitLabHost.getPat().orElseThrow().username() + "." + gitLabHost.getUri().getHost() + "/" + projectName + ".git");
} else {
var builder = URIBuilder
.base(gitLabHost.getUri())
@@ -495,7 +495,7 @@ public Hash fetch(URI uri, String refspec, boolean includeTags) throws IOExcepti
} else {
cmd.add("--no-tags");
}
cmd.add(decodeUri(uri));
cmd.add(uri.toString());
cmd.add(refspec);
try (var p = capture(cmd)) {
await(p);
@@ -505,7 +505,7 @@ public Hash fetch(URI uri, String refspec, boolean includeTags) throws IOExcepti

@Override
public void fetchAll(URI uri, boolean includeTags) throws IOException {
var cmd = new ArrayList<>(List.of("git", "fetch", "--recurse-submodules=on-demand", "--prune", decodeUri(uri)));
var cmd = new ArrayList<>(List.of("git", "fetch", "--recurse-submodules=on-demand", "--prune", uri.toString()));
cmd.add("+refs/heads/*:refs/heads/*");
if (includeTags) {
cmd.add("+refs/tags/*:refs/tags/*");
@@ -579,7 +579,7 @@ public Repository init() throws IOException {

@Override
public void pushAll(URI uri) throws IOException {
try (var p = capture("git", "push", "--mirror", decodeUri(uri))) {
try (var p = capture("git", "push", "--mirror", uri.toString())) {
await(p);
}
}
@@ -592,7 +592,7 @@ public void push(Hash hash, URI uri, String ref, boolean force) throws IOExcepti
}
refspec += hash.hex() + ":" + ref;

try (var p = capture("git", "push", decodeUri(uri), refspec)) {
try (var p = capture("git", "push", uri.toString(), refspec)) {
await(p);
}
}
@@ -1357,14 +1357,6 @@ public Optional<String> upstreamFor(Branch b) throws IOException {
}
}

private static String decodeUri(URI from) {
if (from.getScheme().equals("ssh")) {
return from.toString().substring(6);
} else {
return from.toString();
}
}

public static Repository clone(URI from, Path to, boolean isBare, Path seed) throws IOException {
var cmd = new ArrayList<String>();
cmd.addAll(List.of("git", "clone"));
@@ -1377,7 +1369,7 @@ public static Repository clone(URI from, Path to, boolean isBare, Path seed) thr
cmd.add("--reference-if-able");
cmd.add(seed.toString());
}
cmd.addAll(List.of(decodeUri(from), to.toString()));
cmd.addAll(List.of(from.toString(), to.toString()));
try (var p = capture(Path.of("").toAbsolutePath(), cmd)) {
await(p);
}
@@ -1386,7 +1378,7 @@ public static Repository clone(URI from, Path to, boolean isBare, Path seed) thr

public static Repository mirror(URI from, Path to) throws IOException {
var cwd = Path.of("").toAbsolutePath();
try (var p = capture(cwd, "git", "clone", "--mirror", decodeUri(from), to.toString())) {
try (var p = capture(cwd, "git", "clone", "--mirror", from.toString(), to.toString())) {
await(p);
}
return new GitRepository(to);