Skip to content

Fix build when pointed at a worktree #860

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

Merged
merged 2 commits into from
May 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build_docs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@ sub _guess_opts_from_file {

my %edit_urls = ();
my $doc_toplevel = _find_toplevel($index->parent);
if ( $doc_toplevel ) {
$Opts->{root_dir} = $doc_toplevel;
my $edit_url = _guess_edit_url($doc_toplevel);
@edit_urls{ $doc_toplevel } = $edit_url if $edit_url;
} else {
unless ( $doc_toplevel ) {
$Opts->{root_dir} = $index->parent;
# If we can't find the edit url for the document then we're never
# going to find it for anyone.
return;
}
$Opts->{root_dir} = $doc_toplevel;
my $edit_url = _guess_edit_url($doc_toplevel);
@edit_urls{ $doc_toplevel } = $edit_url if $edit_url;
for my $resource ( @{ $Opts->{resource} } ) {
my $resource_toplevel = _find_toplevel($resource);
next unless $resource_toplevel;
Expand Down
8 changes: 8 additions & 0 deletions integtest/spec/helper/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,12 @@ def init
end
end
end

##
# Create a worktree at `dest` for the branch `branch`.
def create_worktree(dest, branch)
Dir.chdir @root do
sh "git worktree add #{dest} #{branch}"
end
end
end
28 changes: 28 additions & 0 deletions integtest/spec/single_book_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'fileutils'

RSpec.describe 'building a single book' do
HEADER = <<~ASCIIDOC
= Title
Expand Down Expand Up @@ -366,4 +368,30 @@ def self.xpack_tag_test_asciidoc(onpart, onchapter, onfloater, onsection)
file_context 'images/icons/callouts/1.png'
file_context 'images/icons/callouts/2.png'
end

##
# When you point `build_docs` to a worktree it doesn't properly share the
# worktree's parent into the docker container. This test simulates *that*.
context 'when building a book in a worktree without its parent' do
convert_before do |src, dest|
repo = src.repo('src')
repo.write 'index.asciidoc', <<~ASCIIDOC
#{HEADER}
I am in a worktree.
ASCIIDOC
src.init_repos
worktree = src.path 'worktree'
repo.create_worktree worktree, 'HEAD'
FileUtils.rm_rf repo.root
dest.convert_single "#{worktree}/index.asciidoc", '.', asciidoctor: true
end
page_context 'chapter.html' do
it 'complains about not being able to find the repo toplevel' do
expect(outputs[0]).to include("Couldn't find repo toplevel for /tmp/")
end
it 'has the worktree text' do
expect(body).to include('I am in a worktree.')
end
end
end
end
4 changes: 2 additions & 2 deletions lib/ES/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sub build_chunked {
# Use ` to delimit monospaced literals because our docs
# expect that
'-a' => 'compat-mode=legacy',
$private ? () : ( '-a' => "edit_urls=" .
$private || !$edit_urls ? () : ( '-a' => "edit_urls=" .
edit_urls_for_asciidoctor($edit_urls) ),
# Disable warning on missing attributes because we have
# missing attributes!
Expand Down Expand Up @@ -230,7 +230,7 @@ sub build_single {
'-d' => $type,
'-a' => 'showcomments=1',
'-a' => "lang=$lang",
$private ? () : ( '-a' => "edit_urls=" .
$private || !$edit_urls ? () : ( '-a' => "edit_urls=" .
edit_urls_for_asciidoctor($edit_urls) ),
'-a' => 'asciidoc-dir=' . $asciidoc_dir,
'-a' => 'resources=' . join(',', @$resources),
Expand Down