mirror of
https://github.com/netbirdio/plugins.git
synced 2026-05-22 18:44:07 -07:00
sysutils/git-backup: add force push option (#4981)
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user