Skip to content

Commit f884092

Browse files
authored
Only push to new target branches if there changes (#899)
Before this commit if you add `--target_branch` and the branch is *new* then we pushed to it regardless of if there were changes. This felt nice and consistent but we're going to end up with a lot of branches that way.
1 parent 46e5515 commit f884092

File tree

3 files changed

+7
-34
lines changed

3 files changed

+7
-34
lines changed

build_docs.pl

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -555,20 +555,11 @@ sub push_changes {
555555
$build_dir->file('revision.txt')
556556
->spew( iomode => '>:utf8', ES::Repo->all_repo_branches );
557557

558-
# Check if there are changes before committing and save that because if
559-
# there are changes we'll commit them. Once we've committed them checking
560-
# if there are changes will say "no" because there aren't changes
561-
# *any more*. Thus we build $has_changes and $should_push here and not
562-
# in the `if` statements below.
563-
my $has_changes = $target_repo->outstanding_changes;
564-
my $should_push = $has_changes || $target_repo->new_branch;
565-
if ( $has_changes ) {
558+
if ( $target_repo->outstanding_changes ) {
566559
say 'Preparing commit';
567560
build_sitemap($build_dir);
568561
say "Commiting changes";
569562
$target_repo->commit;
570-
}
571-
if ( $should_push ) {
572563
say "Pushing changes";
573564
$target_repo->push_changes;
574565
} else {

integtest/spec/all_books_change_detection_spec.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
RSpec.describe 'building all books' do
77
class Config
88
attr_accessor :target_branch
9+
attr_accessor :checkout_branch
910

1011
def initialize
1112
@target_branch = nil
13+
@checkout_branch = nil
1214
end
1315
end
1416
describe 'change detection' do
@@ -31,7 +33,8 @@ def self.build_twice(
3133
dest.convert_all src.conf, target_branch: config.target_branch
3234

3335
# Checkout the files so we can assert about them.
34-
dest.checkout_conversion branch: config.target_branch
36+
checkout = config.checkout_branch || config.target_branch
37+
dest.checkout_conversion branch: checkout
3538
end
3639
include_context 'build one book twice'
3740
end
@@ -129,26 +132,13 @@ def self.build_one_book_out_of_two_repos_twice(
129132
include_examples 'second build is noop'
130133
end
131134
context 'even when there is a new target branch' do
132-
# Adding a new target branch will cause us to fork it from the
133-
# master branch which so we won't have to rebuild the book *but*
134-
# we push anyway so the new target branch is available.
135135
build_one_book_out_of_one_repo_twice(
136136
before_second_build: lambda do |_src, config|
137137
config.target_branch = 'new_target'
138+
config.checkout_branch = 'master'
138139
end
139140
)
140-
context 'the second build' do
141-
let(:out) { outputs[1] }
142-
it "doesn't print that it is building any books" do
143-
expect(out).not_to include(': Building ')
144-
end
145-
it "doesn't print that it is commiting changes" do
146-
expect(out).not_to include('Commiting changes')
147-
end
148-
it 'prints that it is pushing changes' do
149-
expect(out).to include('Pushing changes')
150-
end
151-
end
141+
include_examples 'second build is noop'
152142
end
153143
end
154144
context "when the second build isn't a noop" do

lib/ES/TargetRepo.pm

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ sub checkout_minimal {
7575
printf(" - %20s: Forking <%s> from master\n",
7676
'target_repo', $self->{branch});
7777
run qw(git checkout -b), $self->{branch};
78-
$self->{new_branch} = 1;
7978
1;
8079
} or die "Error checking out repo <target_repo>: $@";
8180
chdir $original_pwd;
@@ -140,13 +139,6 @@ sub push_changes {
140139
run qw(git push origin), $self->{branch};
141140
}
142141

143-
#===================================
144-
# Is this a new branch?
145-
#===================================
146-
sub new_branch {
147-
return shift->{new_branch};
148-
}
149-
150142
#===================================
151143
# Write a sparse checkout config for the repo.
152144
#===================================

0 commit comments

Comments
 (0)