From a51a7ceab485472dc83add55d1a574bd5c0b1210 Mon Sep 17 00:00:00 2001 From: VisableSampling Date: Fri, 29 Nov 2024 23:36:33 -0800 Subject: [PATCH] backup: improve git branch handling - Create configured branch on git init instead of default master - Use configured branch for both source and destination in push command - Fixes issues with non-master branch names --- .../src/opnsense/mvc/app/library/OPNsense/Backup/Git.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sysutils/git-backup/src/opnsense/mvc/app/library/OPNsense/Backup/Git.php b/sysutils/git-backup/src/opnsense/mvc/app/library/OPNsense/Backup/Git.php index a109a1adc9..252b8cd218 100644 --- a/sysutils/git-backup/src/opnsense/mvc/app/library/OPNsense/Backup/Git.php +++ b/sysutils/git-backup/src/opnsense/mvc/app/library/OPNsense/Backup/Git.php @@ -137,6 +137,7 @@ public function backup() } if (!is_dir('{$targetdir}/.git')) { exec("{$git} init {$targetdir}"); + exec("cd {$targetdir} && {$git} checkout -b {$mdl->branch}"); } // XXX: since our git backup is plain text and already contains the private key, it doesn't really matter // to keep the same key in the git directory (we're not going to push it) @@ -162,7 +163,7 @@ public function backup() exec("cd {$targetdir} && {$git} remote remove origin"); exec("cd {$targetdir} && {$git} remote add origin " . escapeshellarg($url)); $pushtxt = shell_exec( - "(cd {$targetdir} && {$git} push origin " . escapeshellarg("master:{$mdl->branch}") . + "(cd {$targetdir} && {$git} push origin " . escapeshellarg("{$mdl->branch}:{$mdl->branch}") . " && echo '__exit_ok__') 2>&1" ); if (strpos($pushtxt, '__exit_ok__')) {