|
|
@ -7,6 +7,7 @@ package git |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
|
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
) |
|
|
@ -72,7 +73,14 @@ func (repo *Repository) SetDefaultBranch(name string) error { |
|
|
|
// GetDefaultBranch gets default branch of repository.
|
|
|
|
// GetDefaultBranch gets default branch of repository.
|
|
|
|
func (repo *Repository) GetDefaultBranch() (string, error) { |
|
|
|
func (repo *Repository) GetDefaultBranch() (string, error) { |
|
|
|
stdout, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repo.Path}) |
|
|
|
stdout, _, err := NewCommand(repo.Ctx, "symbolic-ref", "HEAD").RunStdString(&RunOpts{Dir: repo.Path}) |
|
|
|
return stdout, err |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return "", err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
stdout = strings.TrimSpace(stdout) |
|
|
|
|
|
|
|
if !strings.HasPrefix(stdout, BranchPrefix) { |
|
|
|
|
|
|
|
return "", errors.New("the HEAD is not a branch: " + stdout) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return strings.TrimPrefix(stdout, BranchPrefix), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetBranch returns a branch by it's name
|
|
|
|
// GetBranch returns a branch by it's name
|
|
|
|