Skip to content

Commit

Permalink
Item9238: Locate git root of repository
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/RepositoryPlugin@10470 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
GeorgeClark authored and GeorgeClark committed Jan 3, 2011
1 parent 99af3d9 commit 81dd155
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions lib/Foswiki/Plugins/RepositoryPlugin.pm
Expand Up @@ -159,8 +159,13 @@ sub _REPO {
$absfile ||= $thisfile;
my $texit;

my $repoRoot = _findRepoRoot ( $absfile );
return "*Unable to find git root:* =$absfile= " unless ($repoRoot);

my $repoLoc = "--git-dir=$repoRoot/.git --work-tree=$repoRoot";

(my $topicStatus, $texit) =
Foswiki::Sandbox->sysCommand( "$gitbin status --porcelain $absfile ",
Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc status --porcelain $absfile ",
);

$topicStatus = substr( $topicStatus, 0, 2);
Expand All @@ -177,11 +182,11 @@ sub _REPO {
: 'unknown';

(my $topicinfo, $texit) =
Foswiki::Sandbox->sysCommand( "$gitbin log -1 $absfile ",
Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc log -1 $absfile ",
);

my $report =
"*Repo file:* =$absfile= \n\n";
"*Repo file:* =$absfile= \n\n*Repo root:* $repoRoot\n\n";

$report .= "*File Status:* ($topicStatus) - $status\n\n";

Expand All @@ -194,13 +199,13 @@ sub _REPO {


my ( $gitinfo, $gexit ) =
Foswiki::Sandbox->sysCommand( "$gitbin svn info ",
Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc svn info ",
);

$repoInfo{type} = 'git' unless ($gexit || $gitinfo =~ m/Not a git repository/);

my ( $svninfo, $sexit ) =
Foswiki::Sandbox->sysCommand( "$svnbin info ",
Foswiki::Sandbox->sysCommand( "$svnbin $repoLoc info ",
);
$repoInfo{type} = 'svn' unless ($sexit || $svninfo =~ m/not a working copy/);

Expand Down Expand Up @@ -271,6 +276,26 @@ sub _REPO {

}

sub _findRepoRoot {

my $repoFile = shift; # full path of a file in repo

my ($vol, $dir, $file) = File::Spec->splitpath( $repoFile );
my @dirs = File::Spec->splitdir( $dir );
my $repoRoot;

while ( scalar @dirs > 1 ) {
$repoRoot = File::Spec->catdir( @dirs );
#print STDERR "Trying $repoRoot \n";
last if (-d "$repoRoot/.git");
pop(@dirs);
}

return $repoRoot if (-d "$repoRoot/.git");

return 0;
}

1;
__END__
This copyright information applies to the RepositoryPlugin:
Expand Down

0 comments on commit 81dd155

Please sign in to comment.