You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the target file doesn't exist but a .encrypted version does,
offer to decrypt it before syncing and re-encrypt it afterwards.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/Commands/EnvsyncCommand.php
+62-2Lines changed: 62 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ public function handle(): int
15
15
{
16
16
$sourceFile = '.env';
17
17
$targetFile = $this->option('path');
18
+
$wasDecrypted = false;
18
19
19
20
// Check if source file exists
20
21
if (!File::exists($sourceFile)) {
@@ -24,8 +25,33 @@ public function handle(): int
24
25
25
26
// Check if target file exists
26
27
if (!File::exists($targetFile)) {
27
-
$this->error("Target file '{$targetFile}' does not exist.");
28
-
returnself::FAILURE;
28
+
$encryptedFile = $targetFile . '.encrypted';
29
+
30
+
if (File::exists($encryptedFile)) {
31
+
if ($this->option('no-interaction')) {
32
+
$this->error("Target file '{$targetFile}' does not exist, but '{$encryptedFile}' was found. Run 'php artisan env:decrypt --env=" . $this->getEnvFromPath($targetFile) . "' to decrypt it first.");
33
+
returnself::FAILURE;
34
+
}
35
+
36
+
if ($this->confirm("Target file '{$targetFile}' does not exist, but '{$encryptedFile}' was found. Would you like to decrypt it?")) {
37
+
$exitCode = $this->call('env:decrypt', [
38
+
'--env' => $this->getEnvFromPath($targetFile),
39
+
]);
40
+
41
+
if ($exitCode !== 0 || !File::exists($targetFile)) {
42
+
$this->error("Failed to decrypt '{$encryptedFile}'.");
43
+
returnself::FAILURE;
44
+
}
45
+
46
+
$this->info("Successfully decrypted '{$encryptedFile}' to '{$targetFile}'.");
47
+
$wasDecrypted = true;
48
+
} else {
49
+
returnself::FAILURE;
50
+
}
51
+
} else {
52
+
$this->error("Target file '{$targetFile}' does not exist.");
53
+
returnself::FAILURE;
54
+
}
29
55
}
30
56
31
57
$this->info("Syncing '{$sourceFile}' with '{$targetFile}'");
@@ -108,6 +134,26 @@ public function handle(): int
108
134
}
109
135
}
110
136
137
+
// Offer to re-encrypt if we decrypted at the start
138
+
if ($wasDecrypted && !$this->option('no-interaction')) {
139
+
if ($this->confirm("Would you like to re-encrypt '{$targetFile}'?", true)) {
0 commit comments