[#104] Support setting the remote during lab mr checkout#120
[#104] Support setting the remote during lab mr checkout#120zaquestion merged 2 commits intozaquestion:masterfrom
lab mr checkout#120Conversation
Codecov Report
@@ Coverage Diff @@
## master #120 +/- ##
==========================================
- Coverage 62.12% 61.25% -0.87%
==========================================
Files 32 32
Lines 1270 1288 +18
==========================================
Hits 789 789
- Misses 317 333 +16
- Partials 164 166 +2
Continue to review full report at Codecov.
|
Works as follows:
```
lab mr checkout -t !mrID
```
When `-t` or `--track` is specified the following happens:
- Check for remote by the username of the MR author
- If the remote does not exist, add it add mr.Author.Username
- Instead of fetching to the configured branch, fetch to
`refs/remotes/mr.Author.Username/mr.sourceBranch` (`fetchToRef`)
- Create a local branch starting from `fetchToRef`
- Checkout that branch
f1320fa to
aff5e24
Compare
cmd/mrCheckout.go
Outdated
| fetchToRef = fmt.Sprintf("refs/remotes/%s/%s", mr.Author.Username, mr.SourceBranch) | ||
| } | ||
|
|
||
| // https://docs.gitlab.com/ee/user/project/merge_requests/#checkout-merge-requests-locally |
There was a problem hiding this comment.
Use the ce docs when possible https://docs.gitlab.com/ce/user/project/merge_requests/#checkout-merge-requests-locally.
There was a problem hiding this comment.
yikes, looks like I put that there 😊
cmd/mrCheckout.go
Outdated
| if mrCheckoutCfg.track { | ||
| // Create configured branch with tracking from fetchToRef | ||
| // git branch --flags <branchname> [<start-point>] | ||
| gitb := git.New("branch", "--track", mrCheckoutCfg.branch, fetchToRef) |
There was a problem hiding this comment.
It looks like the --track functionality can be used directly with git checkout. Is it worth combining the 2 commands?
There was a problem hiding this comment.
We would still need to check out this branch, as git checkout --track -b will track the new branch off of the previous branch. So if we use git checkout --track we need two git checkout commands.
I prefer this way personally.
| ) | ||
|
|
||
| // GetProject looks up a Gitlab project by ID. | ||
| func GetProject(projectID int) (*gitlab.Project, error) { |
There was a problem hiding this comment.
Maybe we should just update FindProject to accept an interface{} and switch for the type. go-gitlab will accept the interface form as well
There was a problem hiding this comment.
After putting 15min into this. I request some help. The problem is resolving the whole localProjects map.
How about I add a TODO? Maybe an issue as well? Or we could pair on it.
There was a problem hiding this comment.
After chatting with you more (in person) this is fine as is.
cmd/mrCheckout.go
Outdated
| } | ||
|
|
||
| // Check out branch | ||
| gitc := git.New("checkout", mrCheckoutCfg.branch) |
There was a problem hiding this comment.
Kind of a bad pattern on my part is looks like. These can really just be combined like
err := git.New("checkout", mrCheckoutCfg.branch).Run()
There was a problem hiding this comment.
Ooooooooooooooooooooooooooooo. I like that 👍
|
This just needs tests to merge. |
|
@adamryman you owe tests! :D |
Works as follows:
When
-tor--trackis specified the following happens.refs/remotes/mr.Author.Username/mr.sourceBranch(fetchToRef)fetchToRefTest on the way.
Closes #104