summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2020-02-03 22:22:07 -0700
committerSean Whitton <spwhitton@spwhitton.name>2020-02-03 22:22:07 -0700
commit9d8392910d29a2aa4c4645557ab6b47c001df2f6 (patch)
treecbbbe30bf02b1383ce597ebb9bc6e35fa03dc92f /lib
parentf54ebfe13df04010b402710a146f302480aa9da1 (diff)
downloadp5-Git-Annex-9d8392910d29a2aa4c4645557ab6b47c001df2f6.tar.gz
rise to top of working tree on Git::Annex initialisation
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'lib')
-rw-r--r--lib/Git/Annex.pm22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Git/Annex.pm b/lib/Git/Annex.pm
index 6964b89..ad56ca8 100644
--- a/lib/Git/Annex.pm
+++ b/lib/Git/Annex.pm
@@ -288,7 +288,27 @@ sub _git_path {
around BUILDARGS => sub {
my (undef, undef, @args) = @_;
- { toplevel => $args[0] ? rel2abs($args[0]) : getcwd };
+
+ my $toplevel = $args[0] ? rel2abs($args[0]) : getcwd;
+
+ # if we're in a working tree, rise up to the root of the working
+ # tree -- for flexibility, don't require that we're actually in a
+ # git repo at all
+ my $pid = fork;
+ die "fork() failed: $!" unless defined $pid;
+ if ($pid) {
+ wait;
+ if ($?) {
+ chomp($toplevel = `git -C $toplevel rev-parse --show-toplevel`);
+ die "git rev-parse --show-toplevel failed" if $?;
+ }
+ } else {
+ close STDERR;
+ chomp(my $output = `git -C $toplevel rev-parse --is-inside-work-tree`);
+ exit ($output and $output eq "true");
+ }
+
+ return { toplevel => $toplevel };
};
1;