From 2c653141a83eb5bc3fb1baaff0449195b9e1f6a6 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Wed, 18 Nov 2015 19:32:23 -0500 Subject: #1742 Update default branch in git repository while change in web view --- modules/git/error.go | 22 ++++++++++++++++++++++ modules/git/repo_branch.go | 13 +++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 modules/git/error.go (limited to 'modules/git') diff --git a/modules/git/error.go b/modules/git/error.go new file mode 100644 index 00000000..c86c56e5 --- /dev/null +++ b/modules/git/error.go @@ -0,0 +1,22 @@ +// Copyright 2015 The Gogs Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package git + +import ( + "fmt" +) + +type ErrUnsupportedVersion struct { + Required string +} + +func IsErrUnsupportedVersion(err error) bool { + _, ok := err.(ErrUnsupportedVersion) + return ok +} + +func (err ErrUnsupportedVersion) Error() string { + return fmt.Sprintf("Operation requires higher version [required: %s]", err.Required) +} diff --git a/modules/git/repo_branch.go b/modules/git/repo_branch.go index a4e06053..86c4f538 100644 --- a/modules/git/repo_branch.go +++ b/modules/git/repo_branch.go @@ -35,3 +35,16 @@ func (repo *Repository) GetBranches() ([]string, error) { } return branches, nil } + +// SetDefaultBranch sets default branch of repository. +func (repo *Repository) SetDefaultBranch(branchName string) error { + if gitVer.LessThan(MustParseVersion("1.7.10")) { + return ErrUnsupportedVersion{"1.7.10"} + } + + _, stderr, err := com.ExecCmdDir(repo.Path, "git", "symbolic-ref", "HEAD", "refs/heads/"+branchName) + if err != nil { + return concatenateError(err, stderr) + } + return nil +} -- cgit v1.2.3