11
11
import java .net .SocketAddress ;
12
12
import java .net .URI ;
13
13
import java .nio .charset .StandardCharsets ;
14
- import java .util .*;
14
+ import java .util .ArrayList ;
15
+ import java .util .Collections ;
16
+ import java .util .HashSet ;
17
+ import java .util .List ;
18
+ import java .util .Set ;
15
19
16
20
import org .apache .commons .io .FileUtils ;
17
21
import org .apache .commons .io .IOUtils ;
26
30
import org .eclipse .jgit .diff .DiffEntry .ChangeType ;
27
31
import org .eclipse .jgit .diff .DiffEntry .Side ;
28
32
import org .eclipse .jgit .diff .DiffFormatter ;
29
- import org .eclipse .jgit .errors .IncorrectObjectTypeException ;
30
- import org .eclipse .jgit .errors .MissingObjectException ;
31
- import org .eclipse .jgit .errors .StopWalkException ;
32
- import org .eclipse .jgit .lib .*;
33
- import org .eclipse .jgit .revwalk .*;
34
- import org .eclipse .jgit .revwalk .filter .RevFilter ;
33
+ import org .eclipse .jgit .lib .Constants ;
34
+ import org .eclipse .jgit .lib .ObjectId ;
35
+ import org .eclipse .jgit .lib .ObjectReader ;
36
+ import org .eclipse .jgit .lib .Ref ;
37
+ import org .eclipse .jgit .lib .Repository ;
38
+ import org .eclipse .jgit .revwalk .RevCommit ;
39
+ import org .eclipse .jgit .revwalk .RevSort ;
40
+ import org .eclipse .jgit .revwalk .RevWalk ;
35
41
import org .eclipse .jgit .storage .file .FileRepositoryBuilder ;
36
42
import org .eclipse .jgit .transport .CredentialsProvider ;
37
43
import org .eclipse .jgit .transport .RefSpec ;
@@ -286,33 +292,36 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
286
292
public String getRepoUrl () {
287
293
return repo .getRepoUrl ();
288
294
}
289
-
290
- @ Override
291
- public String getFileContent (String branchName , String fileRelativePath , String encoding ) {
292
- File file ;
295
+
296
+ private File getFileFromRepo (String branchName , String fileRelativePath , String encoding ) {
293
297
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
294
- Git git = getLocalGit (wc );
295
- Repository gitRepo = git .getRepository ()) {
298
+ Git git = getLocalGit (wc );
299
+ Repository gitRepo = git .getRepository ()) {
296
300
297
- String bn = getRealBranchName (branchName );
298
- git
299
- .pull ()
300
- .setCredentialsProvider (credentials )
301
- .call ();
301
+ String bn = getRealBranchName (branchName );
302
+ git
303
+ .pull ()
304
+ .setCredentialsProvider (credentials )
305
+ .call ();
302
306
303
- git
304
- .checkout ()
305
- .setCreateBranch (gitRepo .exactRef ("refs/heads/" + bn ) == null )
306
- .addPath (fileRelativePath )
307
- .setName (bn )
308
- .call ();
307
+ git
308
+ .checkout ()
309
+ .setCreateBranch (gitRepo .exactRef ("refs/heads/" + bn ) == null )
310
+ .addPath (fileRelativePath )
311
+ .setName (bn )
312
+ .call ();
309
313
310
- file = new File (wc .getFolder (), fileRelativePath );
311
- } catch (GitAPIException e ) {
312
- throw new EVCSException (e );
313
- } catch (Exception e ) {
314
- throw new RuntimeException (e );
315
- }
314
+ return new File (wc .getFolder (), fileRelativePath );
315
+ } catch (GitAPIException e ) {
316
+ throw new EVCSException (e );
317
+ } catch (Exception e ) {
318
+ throw new RuntimeException (e );
319
+ }
320
+ }
321
+
322
+ @ Override
323
+ public String getFileContent (String branchName , String fileRelativePath , String encoding ) {
324
+ File file = getFileFromRepo (branchName , fileRelativePath , encoding );
316
325
if (!file .exists ()) {
317
326
throw new EVCSFileNotFound (String .format ("File %s is not found" , fileRelativePath ));
318
327
}
@@ -657,7 +666,7 @@ public List<VCSCommit> getCommitsRange(String branchName, String startFromCommit
657
666
}
658
667
}
659
668
660
- private RevCommit getBranchHeadCommit (String branchName ) {
669
+ private RevCommit getHeadRevCommit (String branchName ) {
661
670
try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
662
671
Git git = getLocalGit (wc );
663
672
Repository gitRepo = git .getRepository ();
@@ -681,7 +690,7 @@ private RevCommit getBranchHeadCommit (String branchName) {
681
690
682
691
@ Override
683
692
public VCSCommit getHeadCommit (String branchName ) {
684
- RevCommit branchHeadCommit = getBranchHeadCommit (getRealBranchName (branchName ));
693
+ RevCommit branchHeadCommit = getHeadRevCommit (getRealBranchName (branchName ));
685
694
return new VCSCommit (branchHeadCommit .getName (), branchHeadCommit .getFullMessage (),
686
695
branchHeadCommit .getAuthorIdent ().getName ());
687
696
}
@@ -693,7 +702,6 @@ public String toString() {
693
702
694
703
@ Override
695
704
public Boolean fileExists (String branchName , String filePath ) {
696
- // TODO Auto-generated method stub
697
- return null ;
705
+ return getFileFromRepo (branchName , filePath , StandardCharsets .UTF_8 .name ()).exists ();
698
706
}
699
707
}
0 commit comments