@ -277,13 +277,17 @@ public class GitRepository {
return listFilesAtCommit ( commitId , path , - 1 ) . stream ( ) . map ( RepoFile : : path ) . toList ( ) ;
}
@SneakyThrows
public List < RepoFile > listFilesAtCommit ( String commitId , String path , int depth ) {
log . debug ( "Executing listFilesAtCommit [{}][{}][{}]" , settings . getRepositoryUri ( ) , commitId , path ) ;
RevCommit commit = resolveCommit ( commitId ) ;
return listFilesAtCommit ( commit , path , depth ) ;
}
@SneakyThrows
public List < RepoFile > listFilesAtCommit ( RevCommit commit , String path , int depth ) {
log . debug ( "Executing listFilesAtCommit [{}][{}][{}]" , settings . getRepositoryUri ( ) , commit , path ) ;
List < RepoFile > files = new ArrayList < > ( ) ;
RevCommit revCommit = resolveCommit ( commitId ) ;
try ( TreeWalk treeWalk = new TreeWalk ( git . getRepository ( ) ) ) {
treeWalk . reset ( revCommit . getTree ( ) . getId ( ) ) ;
treeWalk . reset ( c ommit. getTree ( ) . getId ( ) ) ;
if ( StringUtils . isNotEmpty ( path ) ) {
treeWalk . setFilter ( PathFilter . create ( path ) ) ;
}
@ -301,11 +305,15 @@ public class GitRepository {
return files ;
}
@SneakyThrows
public byte [ ] getFileContentAtCommit ( String file , String commitId ) {
log . debug ( "Executing getFileContentAtCommit [{}][{}][{}]" , settings . getRepositoryUri ( ) , commitId , file ) ;
RevCommit revCommit = resolveCommit ( commitId ) ;
try ( TreeWalk treeWalk = TreeWalk . forPath ( git . getRepository ( ) , file , revCommit . getTree ( ) ) ) {
RevCommit commit = resolveCommit ( commitId ) ;
return getFileContentAtCommit ( file , commit ) ;
}
@SneakyThrows
public byte [ ] getFileContentAtCommit ( String file , RevCommit commit ) {
log . debug ( "Executing getFileContentAtCommit [{}][{}][{}]" , settings . getRepositoryUri ( ) , commit , file ) ;
try ( TreeWalk treeWalk = TreeWalk . forPath ( git . getRepository ( ) , file , commit . getTree ( ) ) ) {
if ( treeWalk = = null ) {
throw new IllegalArgumentException ( "File not found" ) ;
}
@ -373,9 +381,9 @@ public class GitRepository {
for ( RemoteRefUpdate update : pushResult . getRemoteUpdates ( ) ) {
RemoteRefUpdate . Status status = update . getStatus ( ) ;
if ( status = = REJECTED_NONFASTFORWARD | | status = = REJECTED_NODELETE | |
status = = REJECTED_REMOTE_CHANGED | | status = = REJECTED_OTHER_REASON ) {
status = = REJECTED_REMOTE_CHANGED | | status = = REJECTED_OTHER_REASON ) {
throw new RuntimeException ( "Remote repository answered with error: " +
Optional . ofNullable ( update . getMessage ( ) ) . orElseGet ( status : : name ) ) ;
Optional . ofNullable ( update . getMessage ( ) ) . orElseGet ( status : : name ) ) ;
}
}
} ) ;
@ -450,7 +458,8 @@ public class GitRepository {
revCommit . getFullMessage ( ) , revCommit . getAuthorIdent ( ) . getName ( ) , revCommit . getAuthorIdent ( ) . getEmailAddress ( ) ) ;
}
private RevCommit resolveCommit ( String id ) throws IOException {
@SneakyThrows
public RevCommit resolveCommit ( String id ) {
return git . getRepository ( ) . parseCommit ( resolve ( id ) ) ;
}
@ -481,8 +490,8 @@ public class GitRepository {
private static final Function < PageLink , Comparator < RevCommit > > revCommitComparatorFunction = pageLink - > {
SortOrder sortOrder = pageLink . getSortOrder ( ) ;
if ( sortOrder ! = null
& & sortOrder . getProperty ( ) . equals ( "timestamp" )
& & SortOrder . Direction . ASC . equals ( sortOrder . getDirection ( ) ) ) {
& & sortOrder . getProperty ( ) . equals ( "timestamp" )
& & SortOrder . Direction . ASC . equals ( sortOrder . getDirection ( ) ) ) {
return Comparator . comparingInt ( RevCommit : : getCommitTime ) ;
}
return null ;