|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the GitElephant package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Matteo Giachino <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* Just for fun... |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace GitElephant\Command; |
|
15
|
|
|
|
|
16
|
|
|
use GitElephant\TestCase; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* CloneCommandTest |
|
20
|
|
|
* |
|
21
|
|
|
* @author Matteo Giachino <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
class CloneCommandTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
private $binaryVersion; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* set up |
|
33
|
|
|
*/ |
|
34
|
|
|
public function setUp(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->initRepository(); |
|
37
|
|
|
$this->binaryVersion = exec('git --version | cut -d " " -f 3'); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* set up |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testCloneUrl(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$cc = CloneCommand::getInstance($this->getRepository()); |
|
46
|
|
|
$this->assertEquals( |
|
47
|
|
|
"clone 'git://github.com/matteosister/GitElephant.git'", |
|
48
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git') |
|
49
|
|
|
); |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
"clone 'git://github.com/matteosister/GitElephant.git' 'test'", |
|
52
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git', 'test') |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
if (version_compare($this->binaryVersion, '1.8.3.1', '<')) { |
|
56
|
|
|
// Will fail if tested on git version 1.8.3.0 or lower |
|
57
|
|
|
$this->expectException(\RuntimeException::class); |
|
58
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git', 'test', 'master'); |
|
59
|
|
|
} else { |
|
60
|
|
|
$this->assertEquals( |
|
61
|
|
|
"clone '--branch=master' 'git://github.com/matteosister/GitElephant.git' 'test'", |
|
62
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git', 'test', 'master') |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
$this->assertEquals( |
|
67
|
|
|
"clone '--depth=1' 'git://github.com/matteosister/GitElephant.git' 'test'", |
|
68
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git', 'test', null, 1) |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
// Output depends on git version used |
|
72
|
|
|
if (version_compare($this->binaryVersion, '2.9.0', '<')) { |
|
73
|
|
|
$expected = "clone '--depth=1' '--recursive' 'git://github.com/matteosister/GitElephant.git' 'test'"; |
|
74
|
|
|
} else { |
|
75
|
|
|
$expected = "clone '--depth=1' '--shallow-submodules' '--recursive' 'git://github.com/matteosister/GitElephant.git' 'test'"; |
|
76
|
|
|
} |
|
77
|
|
|
$this->assertEquals( |
|
78
|
|
|
$expected, |
|
79
|
|
|
$cc->cloneUrl('git://github.com/matteosister/GitElephant.git', 'test', null, 1, true) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|