-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#104] Support setting the remote during lab mr checkout
#120
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -81,6 +81,18 @@ var ( | |||
localProjects map[string]*gitlab.Project = make(map[string]*gitlab.Project) | |||
) | |||
|
|||
// GetProject looks up a Gitlab project by ID. | |||
func GetProject(projectID int) (*gitlab.Project, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooooooooooooooooooooooooooooo. I like that 👍
This just needs tests to merge. |
@adamryman you owe tests! :D |
Works as follows:
When
-t
or--track
is specified the following happens.refs/remotes/mr.Author.Username/mr.sourceBranch
(fetchToRef
)fetchToRef
Test on the way.
Closes #104