-
Notifications
You must be signed in to change notification settings - Fork 339
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
Support running docs builds against worktrees #2130
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ sub _guess_opts { | |
my $toplevel = _find_toplevel( $index->parent ); | ||
my $remote = _pick_best_remote( $toplevel ); | ||
my $branch = _guess_branch( $toplevel ); | ||
my $repo_name = _guess_repo_name( $remote ); | ||
my $repo_name = _guess_repo_name( $remote, $toplevel ); | ||
# We couldn't find the top level so lets make a wild guess. | ||
$toplevel = $index->parent unless $toplevel; | ||
printf "Guessed toplevel=[%s] remote=[%s] branch=[%s] repo=[%s]\n", $toplevel, $remote, $branch, $repo_name; | ||
|
@@ -169,7 +169,7 @@ sub _guess_opts { | |
$toplevel = _find_toplevel( $resource ); | ||
$remote = _pick_best_remote( $toplevel ); | ||
$branch = _guess_branch( $toplevel ); | ||
$repo_name = _guess_repo_name( $remote ); | ||
$repo_name = _guess_repo_name( $remote, $toplevel ); | ||
# We couldn't find the top level so lets make a wild guess. | ||
$toplevel = $resource unless $toplevel; | ||
$Opts->{roots}{ $repo_name } = $toplevel; | ||
|
@@ -188,6 +188,23 @@ sub _find_toplevel { | |
chdir $docpath; | ||
my $toplevel = eval { run qw(git rev-parse --show-toplevel) }; | ||
chdir $original_pwd; | ||
return $toplevel if $toplevel; | ||
|
||
my $d = $docpath; | ||
while ($d) { | ||
printf "Checking for .git directory (or file) in '%s'\n", $d; | ||
my $git = $d->file(".git"); | ||
my $git_stat = $git->stat(); | ||
return $git->parent if $git_stat; | ||
my $p = $d->parent; | ||
if ($p eq $d) { | ||
# Root of this filesystem | ||
$d = undef; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just break here? Or print an error and return immediately? Is there any other way |
||
} else { | ||
$d = $p; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we get rid of the |
||
|
||
say "Couldn't find repo toplevel for $docpath" unless $toplevel; | ||
return $toplevel || 0; | ||
} | ||
|
@@ -252,9 +269,12 @@ sub _guess_branch { | |
#=================================== | ||
sub _guess_repo_name { | ||
#=================================== | ||
my ( $remote ) = @_; | ||
my ( $remote, $toplevel ) = @_; | ||
|
||
return 'repo' unless $remote; | ||
if ( not $remote ) { | ||
return 'repo' unless $toplevel; | ||
return dir($toplevel)->basename; | ||
} | ||
|
||
$remote = dir( $remote )->basename; | ||
$remote =~ s/\.git$//; | ||
|
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 seems like a pretty safe way to detect "repo names" that include a
-<version branch>
suffix, and is unlikely to inadvertently catch a non-worktree repo name; the only repo that contains a digit right now iscloud-on-k8s
.Is this pattern for worktree names (
elasticsearch
,elasticsearch-7.x
,elasticsearch-6.x
) pretty universal and documented anywhere? I wouldn't want to have a partial solution that only works for this specific setup if it's not universal; if I understand correctly, any other worktrees that don't match this pattern would still fail, right?Would it be possible to parse the
.git
file (which on my machine seems to contain something likegitdir: /absolute/path/to/elasticsearch/.git/worktrees/elasticsearch-7.x
and find the repo name by looking at the path component before.git
?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 don't think this would match the pattern I am using for my work trees. I am not aware of any conventions/documentation for how to create these (I have a tiny bash script for personal use)
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 is the format that we recommend in the ES development docs
I'll try and pick this PR up again and see if I can make it agnostic to the worktree name.
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.. i had missed those. Not a big fan of that layout and the instructions needed updating anyway ... so I am taking a swing at changing the recommendation : https://github.com/elastic/elasticsearch-team/pull/882