Skip to content

Commit e824265

Browse files
Merge pull request magento#749 from omiroshnichenko/patch-1
Clone only latest commit in case branch checkout
2 parents ba77cab + 05448d7 commit e824265

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

src/Command/Dev/UpdateComposer/ComposerGenerator.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,24 @@ public function getInstallFromGitScripts(array $repoOptions): array
122122
$installFromGitScripts[] = 'rm -rf ' . implode(' ', array_keys($repoOptions));
123123

124124
foreach ($repoOptions as $repoName => $gitOption) {
125-
$gitRef = $gitOption['ref'] ?? $gitOption['branch'];
126-
$installFromGitScripts[] = sprintf(
127-
'git clone %s "%s" && git --git-dir="%s/.git" --work-tree="%s" checkout %s',
128-
$gitOption['repo'],
129-
$repoName,
130-
$repoName,
131-
$repoName,
132-
$gitRef
133-
);
125+
if (!empty($gitOption['ref'])) {
126+
$script = sprintf(
127+
'git clone %s "%s" && git --git-dir="%s/.git" --work-tree="%s" checkout %s',
128+
$gitOption['repo'],
129+
$repoName,
130+
$repoName,
131+
$repoName,
132+
$gitOption['ref']
133+
);
134+
} else {
135+
$script = sprintf(
136+
'git clone -b %s --single-branch --depth 1 %s %s',
137+
$gitOption['branch'],
138+
$gitOption['repo'],
139+
$repoName
140+
);
141+
}
142+
$installFromGitScripts[] = $script;
134143
}
135144

136145
return $installFromGitScripts;

src/Test/Unit/Command/Dev/UpdateComposer/ComposerGeneratorTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ class ComposerGeneratorTest extends TestCase
2929
],
3030
'repo2' => [
3131
'repo' => 'path_to_repo2',
32+
'ref' => '',
3233
'branch' => '2.0.0',
3334
],
3435
'repo3' => [
3536
'repo' => 'path_to_repo3',
37+
'ref' => 'test',
3638
'branch' => '3.0.0',
3739
],
3840
'repo4' => [
3941
'repo' => 'path_to_repo4',
40-
'branch' => '4.0.0',
42+
'ref' => 'test',
4143
]
4244
];
4345

@@ -105,10 +107,10 @@ private function assertInstallFromGitScripts(array $actual): void
105107
[
106108
'php -r"@mkdir(__DIR__ . \'/app/etc\', 0777, true);"',
107109
'rm -rf repo1 repo2 repo3 repo4',
108-
'git clone path_to_repo1 "repo1" && git --git-dir="repo1/.git" --work-tree="repo1" checkout 1.0.0',
109-
'git clone path_to_repo2 "repo2" && git --git-dir="repo2/.git" --work-tree="repo2" checkout 2.0.0',
110-
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout 3.0.0',
111-
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout 4.0.0',
110+
'git clone -b 1.0.0 --single-branch --depth 1 path_to_repo1 repo1',
111+
'git clone -b 2.0.0 --single-branch --depth 1 path_to_repo2 repo2',
112+
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout test',
113+
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout test',
112114
],
113115
$actual
114116
);

src/Test/Unit/Command/Dev/UpdateComposer/_files/expected_composer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@
4444
'install-from-git' => [
4545
'php -r"@mkdir(__DIR__ . \'/app/etc\', 0777, true);"',
4646
'rm -rf repo1 repo2 repo3 repo4',
47-
'git clone path_to_repo1 "repo1" && git --git-dir="repo1/.git" --work-tree="repo1" checkout 1.0.0',
48-
'git clone path_to_repo2 "repo2" && git --git-dir="repo2/.git" --work-tree="repo2" checkout 2.0.0',
49-
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout 3.0.0',
50-
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout 4.0.0',
47+
'git clone -b 1.0.0 --single-branch --depth 1 path_to_repo1 repo1',
48+
'git clone -b 2.0.0 --single-branch --depth 1 path_to_repo2 repo2',
49+
'git clone path_to_repo3 "repo3" && git --git-dir="repo3/.git" --work-tree="repo3" checkout test',
50+
'git clone path_to_repo4 "repo4" && git --git-dir="repo4/.git" --work-tree="repo4" checkout test',
5151
],
5252
'pre-install-cmd' => [
5353
'@install-from-git',

0 commit comments

Comments
 (0)