Changeset 10470


Ignore:
Timestamp:
01/03/11 03:54:12 (2 years ago)
Author:
GeorgeClark
Message:

Item9238: Locate git root of repository

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/RepositoryPlugin/lib/Foswiki/Plugins/RepositoryPlugin.pm

    r10469 r10470  
    160160    my $texit; 
    161161 
     162    my $repoRoot = _findRepoRoot ( $absfile ); 
     163    return "*Unable to find git root:* =$absfile= " unless ($repoRoot); 
     164 
     165    my $repoLoc = "--git-dir=$repoRoot/.git --work-tree=$repoRoot"; 
     166 
    162167    (my $topicStatus, $texit) =  
    163       Foswiki::Sandbox->sysCommand( "$gitbin status --porcelain  $absfile ", 
     168      Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc status --porcelain  $absfile ", 
    164169             ); 
    165170 
     
    178183 
    179184    (my $topicinfo, $texit) =  
    180       Foswiki::Sandbox->sysCommand( "$gitbin log -1  $absfile ", 
     185      Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc log -1  $absfile ", 
    181186             ); 
    182187 
    183188    my $report = 
    184         "*Repo file:* =$absfile= \n\n"; 
     189        "*Repo file:* =$absfile= \n\n*Repo root:* $repoRoot\n\n"; 
    185190  
    186191    $report .= "*File Status:* ($topicStatus) - $status\n\n"; 
     
    195200 
    196201    my ( $gitinfo, $gexit ) = 
    197       Foswiki::Sandbox->sysCommand( "$gitbin svn info ", 
     202      Foswiki::Sandbox->sysCommand( "$gitbin $repoLoc svn info ", 
    198203             ); 
    199204 
     
    201206 
    202207    my ( $svninfo, $sexit ) = 
    203       Foswiki::Sandbox->sysCommand( "$svnbin info ", 
     208      Foswiki::Sandbox->sysCommand( "$svnbin $repoLoc info ", 
    204209             ); 
    205210    $repoInfo{type} = 'svn' unless ($sexit || $svninfo =~ m/not a working copy/); 
     
    272277} 
    273278 
     279sub _findRepoRoot { 
     280 
     281    my $repoFile = shift;    # full path of a file in repo 
     282 
     283    my ($vol, $dir, $file) = File::Spec->splitpath( $repoFile ); 
     284    my @dirs = File::Spec->splitdir( $dir ); 
     285    my $repoRoot; 
     286 
     287    while ( scalar @dirs > 1 ) { 
     288       $repoRoot = File::Spec->catdir( @dirs );  
     289       #print STDERR "Trying $repoRoot \n"; 
     290       last if (-d "$repoRoot/.git"); 
     291       pop(@dirs); 
     292    } 
     293 
     294    return $repoRoot if (-d "$repoRoot/.git"); 
     295 
     296    return 0; 
     297} 
     298 
    2742991; 
    275300__END__ 
Note: See TracChangeset for help on using the changeset viewer.