@@ -64,17 +64,17 @@ private String getRealBranchName(String branchName) {
6464 return branchName == null ? MASTER_BRANCH_NAME : branchName ;
6565 }
6666
67- public Git getLocalGit (IVCSLockedWorkingCopy wc ) throws Exception {
67+ protected Git getLocalGit (String folder ) throws Exception {
6868 Repository gitRepo = new FileRepositoryBuilder ()
69- .setGitDir (new File (wc . getFolder () , ".git" ))
69+ .setGitDir (new File (folder , ".git" ))
7070 .build ();
7171 Boolean repoInited = gitRepo
7272 .getObjectDatabase ()
7373 .exists ();
7474 if (!repoInited ) {
7575 Git
7676 .cloneRepository ()
77- .setDirectory (wc . getFolder ( ))
77+ .setDirectory (new File ( folder ))
7878 .setURI (repo .getRepoUrl ())
7979 .setCredentialsProvider (credentials )
8080 .setNoCheckout (true )
@@ -85,6 +85,10 @@ public Git getLocalGit(IVCSLockedWorkingCopy wc) throws Exception {
8585 return new Git (gitRepo );
8686 }
8787
88+ protected Git getLocalGit (IVCSLockedWorkingCopy wc ) throws Exception {
89+ return getLocalGit (wc .getFolder ().getPath ());
90+ }
91+
8892 public VCSChangeType gitChangeTypeToVCSChangeType (ChangeType changeType ) {
8993 switch (changeType ) {
9094 case ADD :
@@ -765,6 +769,20 @@ public void removeTag(String tagName) {
765769 throw new EVCSException (e );
766770 } catch (Exception e ) {
767771 throw new RuntimeException (e );
768- }
772+ }
773+ }
774+
775+ @ Override
776+ public void checkout (String branchName , String targetPath ) {
777+ try (Git git = getLocalGit (targetPath );
778+ Repository gitRepo = git .getRepository ()) {
779+
780+ checkout (git , gitRepo , branchName );
781+
782+ } catch (GitAPIException e ) {
783+ throw new EVCSException (e );
784+ } catch (Exception e ) {
785+ throw new RuntimeException (e );
786+ }
769787 }
770788}
0 commit comments