aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2012-09-21 20:10:41 +0200
committerChristian Weiske <cweiske@cweiske.de>2012-09-21 20:10:41 +0200
commit52de444faa10f37c4174e9fe2c75e77484342549 (patch)
tree8bceafadf43822d03c9ea4e26ce90b9f3b544db7
parent813d3f5367c15dd21091af6eb7d263e1d98c4c17 (diff)
downloadphorkie-52de444faa10f37c4174e9fe2c75e77484342549.tar.gz
phorkie-52de444faa10f37c4174e9fe2c75e77484342549.zip
remote forking: use the original http/https url in description
-rw-r--r--data/templates/fork-remote-multiple.htm1
-rw-r--r--src/phorkie/ForkRemote.php24
-rw-r--r--src/phorkie/Forker.php6
-rw-r--r--www/fork-remote.php5
4 files changed, 29 insertions, 7 deletions
diff --git a/data/templates/fork-remote-multiple.htm b/data/templates/fork-remote-multiple.htm
index f5a95b2..8709f11 100644
--- a/data/templates/fork-remote-multiple.htm
+++ b/data/templates/fork-remote-multiple.htm
@@ -1,4 +1,5 @@
<form method="post" action="/fork-remote" enctype="multipart/form-data" class="well form-inline form-horizontal">
+ <input type="hidden" name="orig_url" value="{{remote_url}}" />
<div class="control-group">
<p>
The URL you provided contains links to several Git repositories.
diff --git a/src/phorkie/ForkRemote.php b/src/phorkie/ForkRemote.php
index c9ed748..d2b077b 100644
--- a/src/phorkie/ForkRemote.php
+++ b/src/phorkie/ForkRemote.php
@@ -22,13 +22,15 @@ class ForkRemote
public function parse()
{
- $arUrl = parse_url($this->url);
+ $arUrl = parse_url($this->url);
$scheme = $arUrl['scheme'] ?: '';
+
if ($scheme == 'https' && isset($arUrl['host'])
&& $arUrl['host'] == 'gist.github.com'
) {
- $scheme = 'git';
- $this->url = 'git://gist.github.com/'. ltrim($arUrl['path'], '/') . '.git';
+ $this->arGitUrls[][] = 'git://gist.github.com/'
+ . ltrim($arUrl['path'], '/') . '.git';
+ return true;
}
switch ($scheme) {
@@ -113,6 +115,22 @@ class ForkRemote
return $this->arGitUrls;
}
+ /**
+ * Get the URL from which the git URL was derived, often
+ * the HTTP URL.
+ *
+ * @return string
+ */
+ public function getUrl()
+ {
+ return $this->url;
+ }
+
+ public function setUrl($url)
+ {
+ $this->url = $url;
+ }
+
public function isSupported($url)
{
return parse_url($url, PHP_URL_SCHEME) == 'git';
diff --git a/src/phorkie/Forker.php b/src/phorkie/Forker.php
index 3425a72..f4901ed 100644
--- a/src/phorkie/Forker.php
+++ b/src/phorkie/Forker.php
@@ -10,12 +10,12 @@ class Forker
return $new;
}
- public function forkRemote($url)
+ public function forkRemote($cloneUrl, $originalUrl)
{
- $new = $this->fork($url);
+ $new = $this->fork($cloneUrl);
file_put_contents(
$new->gitDir . '/description',
- 'Fork of ' . $url
+ 'Fork of ' . $originalUrl
);
return $new;
}
diff --git a/www/fork-remote.php b/www/fork-remote.php
index 374c8b8..0567748 100644
--- a/www/fork-remote.php
+++ b/www/fork-remote.php
@@ -14,8 +14,11 @@ if (isset($_POST['remote_url'])) {
//no url found
$error = 'No git:// clone URL found';
} else if (false !== ($gitUrl = $fr->getUniqueGitUrl())) {
+ if (isset($_POST['orig_url'])) {
+ $fr->setUrl($_POST['orig_url']);
+ }
$forker = new Forker();
- $new = $forker->forkRemote($gitUrl);
+ $new = $forker->forkRemote($gitUrl, $fr->getUrl());
redirect($new->getLink('display'));
} else {
//multiple urls found