Skip to content

Commit da8bb1a

Browse files
committed
Fix deploy:update_code
Now default target is HEAD, also better at switching repository url.
1 parent 8f64933 commit da8bb1a

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

recipe/deploy/update_code.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,10 @@
88
* If not specified, will get current git HEAD branch as default branch to deploy.
99
*/
1010
set('branch', function () {
11-
try {
12-
$branch = runLocally('git rev-parse --abbrev-ref HEAD');
13-
} catch (\Throwable $e) {
14-
$branch = null;
15-
}
16-
1711
if (input()->hasOption('branch') && !empty(input()->getOption('branch'))) {
18-
$branch = input()->getOption('branch');
12+
return input()->getOption('branch');
1913
}
20-
21-
return $branch;
14+
return null;
2215
});
2316

2417
/**
@@ -30,7 +23,7 @@
3023
$branch = get('branch');
3124
$git = get('bin/git');
3225

33-
$at = '';
26+
$at = 'HEAD';
3427
if (!empty($branch)) {
3528
$at = $branch;
3629
}
@@ -62,15 +55,21 @@
6255
}
6356
}
6457

65-
// Clone the repository to a bare repo.
6658
$bare = parse('{{deploy_path}}/.dep/repo');
59+
60+
start:
61+
// Clone the repository to a bare repo.
6762
run("[ -d $bare ] || mkdir -p $bare");
6863
run("[ -f $bare/HEAD ] || $git clone --mirror $repository $bare 2>&1");
6964

7065
cd($bare);
7166

72-
// If remote url changed, update it in `.git/repo` as well.
73-
run("[[ $($git remote get-url origin) == '$repository' ]] || $git remote set-url origin $repository ");
67+
// If remote url changed, drop `.git/repo` and reinstall.
68+
if (run("$git remote get-url origin") !== $repository) {
69+
cd('{{deploy_path}}');
70+
run("rm -rf $bare");
71+
goto start;
72+
}
7473

7574
// Copy to release_path.
7675
run("$git remote update 2>&1");

0 commit comments

Comments
 (0)