Skip to content

Commit 5a33c45

Browse files
committed
Check the validity of a git url without cloning it
1 parent 09d51b5 commit 5a33c45

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Gitonomy/Git/Admin.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ public static function init($path, $bare = true, array $options = array())
6060
return new Repository($path, $options);
6161
}
6262

63+
/**
64+
* Checks the validity of a git repository url without cloning it.
65+
*
66+
* This will use the `ls-remote` command of git against the given url.
67+
* Usually, this command returns 0 when successful, and 128 when the
68+
* repository is not found.
69+
*
70+
* @param string $url url of repository to check
71+
* @param array $options options for Repository creation
72+
*
73+
* @return boolean true if url is valid
74+
*/
75+
public static function isValidRepository($url, array $options = array())
76+
{
77+
$command = isset($options['command']) ? $options['command'] : 'git';
78+
$builder = ProcessBuilder::create(array($command, 'ls-remote'));
79+
$builder->add($url);
80+
81+
$process = $builder->getProcess();
82+
$process->run();
83+
84+
return $process->isSuccessFul();
85+
}
86+
6387
/**
6488
* Clone a repository to a local path.
6589
*

0 commit comments

Comments
 (0)