-
Notifications
You must be signed in to change notification settings - Fork 352
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
use correct reference when using strip_component #1240
Conversation
This fix makes sense. Could you add a test, maybe in here, showing that your new |
eb51c5e
to
51c9856
Compare
Sorry for the delay, have updated with additional rspec test now |
So I was testing this out, and I think you're missing a line in the sample config you give. It should also have |
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.
Other than that small but important update to the commit message, I think this looks good! It definitely fixes the issue.
The current implmnetation sets the environment name to the "striped" version of the name, this is then later used as the git reference when syncing environments. With the following configuration ```yaml sources: b4ldr: strip_component: "wmcs/" ignore_branch_prefixes: - production - ops - sandbox - pontoon remote: https://github.com/b4ldr/puppet-1 ``` where upstream has a branch with wmcs/production then we see the following error Unable to sync repo to unresolvable ref 'production' at /etc/puppet/code/environments/production/.git If upstream also has a production branch then the above configuration ends up syncing /etc/puppet/code/environments/production/ with the remote production branch. even thought it should be striped via `ignore_branch_prefixes` This PR updates the name object to keep hold of the original name and store it as the ref
yes, updated |
51c9856
to
64c8c87
Compare
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.
Would you mind adding an entry to the 'Unreleased' section of the CHANGELOG describing this fix?
lib/r10k/environment/name.rb
Outdated
attr_reader :name, :ref | ||
attr_reader :name, :ref |
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.
This doesn't need to be here twice.
lib/r10k/environment/name.rb
Outdated
# @!attribute [r] name | ||
# @return [String] The unmodified name of the environment | ||
attr_reader :name | ||
# @return [String] The name of the environment (with component striped) |
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.
What does 'component' refer to?
@@ -149,6 +165,8 @@ | |||
it "replaces invalid characters in #{branch} with underscores" do | |||
bn = described_class.new(branch.dup, {:correct => true}) | |||
expect(bn.dirname).to eq branch.gsub(/\W/, '_') | |||
expect(bn.name).to eq 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.
huh, I would have thought this would also get corrected, but I guess I'm not totally sure where all the name
is used.
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.
Yeah. After taking a look through it, I realized that it's currently inconsistent. The original implementation of strip_component
introduced the inconsistency. I'll take responsibility for that. There would ideally be a clear separation between the input value given to R10K::Environment::Name
and the derived code-environment name on disk (currently called #dirname
). Bit of work to clean it all up at this point.
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.
ahh. Do you think it's a worthwhile bit of work to do eventually? If so, would you mind opening a ticket for it?
As I'm thinking about this I have some thoughts on how to clarify what's going on here, without mixing in an assumption in |
The utility value is in being able to differentiate between the string used to create the R10K::Environment::Name object, and the #name attribute return value, which may have been transformed or modified from the original input. In order not to build in assumptions about where the original name came from (it isn't necessarily related to Git), use the general method `original_name` to differentiate from `name` (rather than the Git-specific term `ref`). This commit also changes some method names in R10K::Source::Git to clarify there the difference between a branch name and an environment name.
@b4ldr I've suggested some generalizations in 6c95162. The biggest changes:
The rest of the changes in the commit are just renaming some variables in Unless you have any objections or feedback we'll keep the process moving forward. 🙂 |
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.
I have a commit in here myself now so somebody should sign off on that, but I'm 👍 overall
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.
Thanks for weighing in here, Reid, I agree, this is better.
Dang, was really hoping git would be able to resolve that without a conflict :P |
Let us know what you think of these changes, @b4ldr ! And if you wouldn't mind rebasing to resolve the merge conflicts in the CHANGELOG, that would be appreciated (we didn't want to force-push to your branch)! |
changes all good with me, think i have rebased and unblocked but let me know if not |
Looks good, we'll get this in! |
The current implmnetation sets the environment name to the "striped"
version of the name, this is then later used as the git reference when
syncing environments.
With the following configuration
where upstream has a branch with wmcs/production then we see the
following error
Unable to sync repo to unresolvable ref 'production' at
/etc/puppet/code/environments/production/.git
If upstream also has a production branch then the above configuration
ends up syncing /etc/puppet/code/environments/production/ with the
remote production branch. even thought it should be striped via
ignore_branch_prefixes
This PR updates the name object to keep hold of the original name and
store it as the ref