-
Notifications
You must be signed in to change notification settings - Fork 280
Add SubmoduleStatus post-checkout, post-commit, post-merge, and post-rewrite hooks #164
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
2ce6651
Add SubmoduleStatus post-checkout hook
jawshooah 8c84f7a
Add SubmoduleStatus post-commit hook
jawshooah 7048892
Add SubmoduleStatus post-merge hook
jawshooah d82d114
Add SubmoduleStatus post-rewrite hook
jawshooah 10d0b28
Add specs for SubmoduleStatus post-checkout hook
jawshooah de263fa
Add specs for SubmoduleStatus post-commit hook
jawshooah cf89917
Add specs for SubmoduleStatus post-merge hook
jawshooah 8319ca5
Add specs for SubmoduleStatus post-rewrite hook
jawshooah 4b4e01f
Add SubmoduleStatus struct, regex and helpers to GitRepo
jawshooah 125e816
Use GitRepo#submodule_statuses in SubmoduleStatus hooks
jawshooah a46e01a
Make 'recursive' a config option for SubmoduleStatus
jawshooah 1e3b0a8
Update specs with changes to SubmoduleStatus hooks
jawshooah a3b6ab0
Run SubmoduleStatus hooks silently
jawshooah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module Overcommit::Hook::PostCheckout | ||
| # Checks the status of submodules in the current repository and | ||
| # notifies the user if any are uninitialized, out of date with | ||
| # the current index, or contain merge conflicts. | ||
| class SubmoduleStatus < Base | ||
| def run | ||
| messages = [] | ||
| submodule_statuses.each do |submodule_status| | ||
| path = submodule_status.path | ||
| if submodule_status.uninitialized? | ||
| messages << "Submodule #{path} is uninitialized." | ||
| elsif submodule_status.outdated? | ||
| messages << "Submodule #{path} is out of date with the current index." | ||
| elsif submodule_status.merge_conflict? | ||
| messages << "Submodule #{path} has merge conflicts." | ||
| end | ||
| end | ||
|
|
||
| return :pass if messages.empty? | ||
|
|
||
| [:warn, messages.join("\n")] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def submodule_statuses | ||
| Overcommit::GitRepo.submodule_statuses(recursive: config['recursive']) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module Overcommit::Hook::PostCommit | ||
| # Checks the status of submodules in the current repository and | ||
| # notifies the user if any are uninitialized, out of date with | ||
| # the current index, or contain merge conflicts. | ||
| class SubmoduleStatus < Base | ||
| def run | ||
| messages = [] | ||
| submodule_statuses.each do |submodule_status| | ||
| path = submodule_status.path | ||
| if submodule_status.uninitialized? | ||
| messages << "Submodule #{path} is uninitialized." | ||
| elsif submodule_status.outdated? | ||
| messages << "Submodule #{path} is out of date with the current index." | ||
| elsif submodule_status.merge_conflict? | ||
| messages << "Submodule #{path} has merge conflicts." | ||
| end | ||
| end | ||
|
|
||
| return :pass if messages.empty? | ||
|
|
||
| [:warn, messages.join("\n")] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def submodule_statuses | ||
| Overcommit::GitRepo.submodule_statuses(recursive: config['recursive']) | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module Overcommit::Hook::PostMerge | ||
| # Checks the status of submodules in the current repository and | ||
| # notifies the user if any are uninitialized, out of date with | ||
| # the current index, or contain merge conflicts. | ||
| class SubmoduleStatus < Base | ||
| def run | ||
| messages = [] | ||
| submodule_statuses.each do |submodule_status| | ||
| path = submodule_status.path | ||
| if submodule_status.uninitialized? | ||
| messages << "Submodule #{path} is uninitialized." | ||
| elsif submodule_status.outdated? | ||
| messages << "Submodule #{path} is out of date with the current index." | ||
| elsif submodule_status.merge_conflict? | ||
| messages << "Submodule #{path} has merge conflicts." | ||
| end | ||
| end | ||
|
|
||
| return :pass if messages.empty? | ||
|
|
||
| [:warn, messages.join("\n")] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def submodule_statuses | ||
| Overcommit::GitRepo.submodule_statuses(recursive: config['recursive']) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| module Overcommit::Hook::PostRewrite | ||
| # Checks the status of submodules in the current repository and | ||
| # notifies the user if any are uninitialized, out of date with | ||
| # the current index, or contain merge conflicts. | ||
| class SubmoduleStatus < Base | ||
| def run | ||
| messages = [] | ||
| submodule_statuses.each do |submodule_status| | ||
| path = submodule_status.path | ||
| if submodule_status.uninitialized? | ||
| messages << "Submodule #{path} is uninitialized." | ||
| elsif submodule_status.outdated? | ||
| messages << "Submodule #{path} is out of date with the current index." | ||
| elsif submodule_status.merge_conflict? | ||
| messages << "Submodule #{path} has merge conflicts." | ||
| end | ||
| end | ||
|
|
||
| return :pass if messages.empty? | ||
|
|
||
| [:warn, messages.join("\n")] | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def submodule_statuses | ||
| Overcommit::GitRepo.submodule_statuses(recursive: config['recursive']) | ||
| end | ||
| end | ||
| end |
54 changes: 54 additions & 0 deletions
54
spec/overcommit/hook/post_checkout/submodule_status_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Overcommit::Hook::PostCheckout::SubmoduleStatus do | ||
| let(:config) { Overcommit::ConfigurationLoader.default_configuration } | ||
| let(:context) { double('context') } | ||
| subject { described_class.new(config, context) } | ||
|
|
||
| let(:submodule_status) { double('submodule_status') } | ||
|
|
||
| before do | ||
| submodule_status.stub(:path).and_return('sub') | ||
| subject.stub(:submodule_statuses).and_return([submodule_status]) | ||
| end | ||
|
|
||
| context 'when submodule is up to date' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should pass } | ||
| end | ||
|
|
||
| context 'when submodule is uninitialized' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: true, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/uninitialized/) } | ||
| end | ||
|
|
||
| context 'when submodule is outdated' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: true, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/out of date/) } | ||
| end | ||
|
|
||
| context 'when submodule has merge conflicts' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: true) | ||
| end | ||
|
|
||
| it { should warn(/merge conflicts/) } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Overcommit::Hook::PostCommit::SubmoduleStatus do | ||
| let(:config) { Overcommit::ConfigurationLoader.default_configuration } | ||
| let(:context) { double('context') } | ||
| subject { described_class.new(config, context) } | ||
|
|
||
| let(:submodule_status) { double('submodule_status') } | ||
|
|
||
| before do | ||
| submodule_status.stub(:path).and_return('sub') | ||
| subject.stub(:submodule_statuses).and_return([submodule_status]) | ||
| end | ||
|
|
||
| context 'when submodule is up to date' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should pass } | ||
| end | ||
|
|
||
| context 'when submodule is uninitialized' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: true, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/uninitialized/) } | ||
| end | ||
|
|
||
| context 'when submodule is outdated' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: true, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/out of date/) } | ||
| end | ||
|
|
||
| context 'when submodule has merge conflicts' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: true) | ||
| end | ||
|
|
||
| it { should warn(/merge conflicts/) } | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| require 'spec_helper' | ||
|
|
||
| describe Overcommit::Hook::PostMerge::SubmoduleStatus do | ||
| let(:config) { Overcommit::ConfigurationLoader.default_configuration } | ||
| let(:context) { double('context') } | ||
| subject { described_class.new(config, context) } | ||
|
|
||
| let(:submodule_status) { double('submodule_status') } | ||
|
|
||
| before do | ||
| submodule_status.stub(:path).and_return('sub') | ||
| subject.stub(:submodule_statuses).and_return([submodule_status]) | ||
| end | ||
|
|
||
| context 'when submodule is up to date' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should pass } | ||
| end | ||
|
|
||
| context 'when submodule is uninitialized' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: true, | ||
| outdated?: false, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/uninitialized/) } | ||
| end | ||
|
|
||
| context 'when submodule is outdated' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: true, | ||
| merge_conflict?: false) | ||
| end | ||
|
|
||
| it { should warn(/out of date/) } | ||
| end | ||
|
|
||
| context 'when submodule has merge conflicts' do | ||
| before do | ||
| submodule_status.stub(uninitialized?: false, | ||
| outdated?: false, | ||
| merge_conflict?: true) | ||
| end | ||
|
|
||
| it { should warn(/merge conflicts/) } | ||
| end | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since we're duplicating this helper
Structacross each of these hooks, and since submodules are agitprimitive of sorts, it seems appropriate to extract the regex, struct, and helpers into theGitRepomodule. That would allow us to DRY up a lot of this.What do you think?
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.
Agreed, I've extracted the regex, struct, and helper to
GitRepo. Also maderecursivea config setting.