diff --git a/lib/scm/gitea.class.php b/lib/scm/gitea.class.php index 26a1b3a3b9..d64adf54d9 100644 --- a/lib/scm/gitea.class.php +++ b/lib/scm/gitea.class.php @@ -21,7 +21,14 @@ class Gitea $this->client = $client; $this->root = rtrim($root, DIRECTORY_SEPARATOR); - $this->branch = isset($_COOKIE['repoBranch']) ? 'origin/' . $_COOKIE['repoBranch'] : ''; + + $branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : ''; + if($branch) + { + $branches = $this->branch(); + if(isset($branches[$branch])) $branch = "origin/$branch"; + } + $this->branch = $branch; chdir($this->root); exec("{$this->client} config core.quotepath false"); diff --git a/lib/scm/gitrepo.class.php b/lib/scm/gitrepo.class.php index 1e947489ad..bb39bcb417 100644 --- a/lib/scm/gitrepo.class.php +++ b/lib/scm/gitrepo.class.php @@ -21,7 +21,14 @@ class GitRepo $this->client = $client; $this->root = rtrim($root, DIRECTORY_SEPARATOR); - $this->branch = isset($_COOKIE['repoBranch']) ? 'origin/' . $_COOKIE['repoBranch'] : ''; + + $branch = isset($_COOKIE['repoBranch']) ? $_COOKIE['repoBranch'] : ''; + if($branch) + { + $branches = $this->branch(); + if(isset($branches[$branch])) $branch = "origin/$branch"; + } + $this->branch = $branch; chdir($this->root); exec("{$this->client} config core.quotepath false");