tea pr checkout: dont create local branches (#314)

This avoids creation of local branches, to avoid cluttering the local repo:
- if the commit already exists on the tip of a local branch, check that one out
- otherwise check out the remote tracking branch (`refs/remotes/<remote>/<head>`), and suggest what to do if you want to make changes.

I'm not certain this behaviour is actually better, I suggest leaving this open for a while for people to try out the new behaviour:
```
tea pr checkout 314
make install
```

fixes #293

Co-authored-by: Norwin Roosen <git@nroo.de>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/314
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Norwin <noerw@noreply.gitea.io>
Co-committed-by: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
Norwin
2021-03-02 21:50:11 +08:00
committed by Lunny Xiao
parent 3c1efd33e2
commit e96cfdbbe7
4 changed files with 41 additions and 22 deletions

View File

@ -12,6 +12,7 @@ import (
"code.gitea.io/sdk/gitea"
git_config "github.com/go-git/go-git/v5/config"
git_plumbing "github.com/go-git/go-git/v5/plumbing"
)
// PullClean deletes local & remote feature-branches for a closed pull
@ -76,7 +77,8 @@ call me again with the --ignore-sha flag`, remoteBranch)
}
if headRef.Name().Short() == branch.Name {
fmt.Printf("Checking out '%s' to delete local branch '%s'\n", defaultBranch, branch.Name)
if err = r.TeaCheckout(defaultBranch); err != nil {
ref := git_plumbing.NewBranchReferenceName(defaultBranch)
if err = r.TeaCheckout(ref); err != nil {
return err
}
}