sysutils/git-backup: add force push option (#4981)

This commit is contained in:
Hleb Shauchenka
2025-10-19 13:34:31 +02:00
committed by GitHub
parent ddbb31c579
commit 2d9ad0e5f5
3 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
PLUGIN_NAME= git-backup
PLUGIN_VERSION= 1.0
PLUGIN_REVISION= 3
PLUGIN_REVISION= 4
PLUGIN_COMMENT= Track config changes using git
PLUGIN_DEPENDS= git
PLUGIN_MAINTAINER= ad@opnsense.org
@@ -66,6 +66,13 @@ class Git extends Base implements IBackupProvider
"help" => gettext("Target branch to push to."),
"value" => null
],
[
"name" => "force_push",
"type" => "checkbox",
"label" => gettext("Force Push"),
"help" => gettext("When enabled, force push to origin if diverged (e.g., after restoring from an earlier backup). Use with caution as this overwrites remote history."),
"value" => null
],
[
"name" => "privkey",
"type" => "passwordarea",
@@ -161,8 +168,9 @@ class Git extends Base implements IBackupProvider
}
exec("cd {$targetdir} && {$git} remote remove origin");
exec("cd {$targetdir} && {$git} remote add origin " . escapeshellarg($url));
$force_flag = (string)$mdl->force_push === "1" ? "--force-with-lease " : "";
$pushtxt = shell_exec(
"(cd {$targetdir} && {$git} push origin " . escapeshellarg("master:{$mdl->branch}") .
"(cd {$targetdir} && {$git} push {$force_flag}origin " . escapeshellarg("master:{$mdl->branch}") .
" && echo '__exit_ok__') 2>&1"
);
if (strpos($pushtxt, '__exit_ok__')) {
@@ -33,6 +33,10 @@
<Default>master</Default>
<Required>Y</Required>
</branch>
<force_push type="BooleanField">
<Default>0</Default>
<Required>Y</Required>
</force_push>
<privkey type="TextField">
<Required>N</Required>
</privkey>