Skip to content
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

Honor repo default branch #142

Merged
merged 6 commits into from
Feb 25, 2018
Merged

Honor repo default branch #142

merged 6 commits into from
Feb 25, 2018

Conversation

asedge
Copy link
Contributor

@asedge asedge commented Jan 13, 2018

Fixes #133 #76.

I had to disable Metrics/ModuleLength because it was over by 11 lines but Modulesync::Git could use some refactoring I think. I wasn't sure how far I should go with it so I figured I would file the PR and see where the discussion leads.

@@ -18,7 +18,17 @@ def self.remote_branch_differ?(repo, local_branch, remote_branch)
repo.diff("#{local_branch}..origin/#{remote_branch}").any?
end

def self.default_branch(repo)
symbolic_ref = repo.branches.find { |b| b.full =~ %r{remotes/origin/HEAD} }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes you use origin as a remote. I always use upstream as a remote so I'd appreciate if that was overridable somehow but I do see that assumption is already present in a few places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it is hard coded in a number of places. Shall we handle it in this PR or a future one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's pre-existing code I'd handle it in a separate PR.

@@ -100,6 +110,7 @@ def self.update(name, files, options)
module_root = "#{options[:project_root]}/#{name}"
message = options[:message]
repo = ::Git.open(module_root)
options[:branch] ||= (repo.current_branch || 'master')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike changing options this way and think a local variable is cleaner. Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, that's crap. I started to change it to a local variable and then put it back to this for some reason. I know that I had some questions about why the branch is being checked out again here and in update_noop after switch_branch is called in pull. Looking over the code in ModuleSync::update again I suppose ModuleSync::Git::update_noop could be called in offline mode so you may need to check out a branch then.

… and checkout to a helper method so Rubocop does not complain about cyclomatic complexity or the ABC metric on ModuleSync::Git::update.
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think this looks good. I'd be happy if you could have a look at my last comments but otherwise I think it can be merged.

@@ -53,8 +53,8 @@ class Base < Thor
:desc => 'A regular expression to skip repositories.'
class_option :branch,
:aliases => '-b',
:desc => 'Branch name to make the changes in. Defaults to master.',
:default => CLI.defaults[:branch] || 'master'
:desc => 'Branch name to make the changes in. Defaults to the default branch of the upstream repository.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And falls back to master, right?

@@ -95,12 +105,18 @@ def self.tag(repo, version, tag_pattern)
repo.push('origin', tag)
end

def self.checkout_branch(repo, branch)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is quite similar to switch_branch. Maybe this should be a private method to clearly indicate it's a helper?

@asedge
Copy link
Contributor Author

asedge commented Jan 17, 2018

@ekohl I have made those changed you requested.

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to leave this up for others to review until tomorrow.

@asedge
Copy link
Contributor Author

asedge commented Feb 4, 2018

@ekohl It's been a couple weeks. Either it's fine or nobody cares. I suppose both could be true. 😄

@asedge
Copy link
Contributor Author

asedge commented Feb 25, 2018

@ekohl I'm fine if you want to get others to review this. Just want to make sure it's not forgotten. Thanks!

@ekohl
Copy link
Member

ekohl commented Feb 25, 2018

Apologies, it's been a very busy couple of weeks.

@ekohl ekohl merged commit cc935f9 into voxpupuli:master Feb 25, 2018
@ekohl
Copy link
Member

ekohl commented Feb 25, 2018

Thanks a lot!

@asedge asedge deleted the honor_repo_default_branch branch February 26, 2018 02:01
@alexjfisher alexjfisher mentioned this pull request Feb 26, 2018
@asedge
Copy link
Contributor Author

asedge commented Feb 26, 2018

I can appreciate that, thanks for the review/merge and for (I assume) volunteering your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants