mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-25 17:53:37 +02:00
Implements the 'branches rename' command to rename a branch in a repository.
This wraps the Gitea API endpoint PATCH /repos/{owner}/{repo}/branches/{branch}.
Usage: tea branches rename <old_branch_name> <new_branch_name>
Example: tea branches rename -r owner/repo main factory
This resolves issue #938.
Reviewed-on: https://gitea.com/gitea/tea/pulls/939
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Matěj Cepl <mcepl@cepl.eu>
Co-committed-by: Matěj Cepl <mcepl@cepl.eu>
47 lines
868 B
Go
47 lines
868 B
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package branches
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestBranchesRenameArgs(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
args []string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "valid args",
|
|
args: []string{"main", "develop"},
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "missing both args",
|
|
args: []string{},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "missing new branch name",
|
|
args: []string{"main"},
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "too many args",
|
|
args: []string{"main", "develop", "extra"},
|
|
wantErr: true,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
err := ValidateRenameArgs(tt.args)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("ValidateRenameArgs() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|