3131import com .projectkaiser .scm .vcs .api .exceptions .EVCSException ;
3232import com .projectkaiser .scm .vcs .api .exceptions .EVCSFileNotFound ;
3333import com .projectkaiser .scm .vcs .api .workingcopy .IVCSLockedWorkingCopy ;
34- import com .projectkaiser .scm .vcs .api .workingcopy .IVCSRepository ;
34+ import com .projectkaiser .scm .vcs .api .workingcopy .IVCSRepositoryWorkspace ;
3535
3636public class GitVCS implements IVCS {
3737
3838 private CredentialsProvider credentials ;
3939
40- IVCSRepository repo ;
40+ IVCSRepositoryWorkspace repo ;
4141
4242 public CredentialsProvider getCredentials () {
4343 return credentials ;
4444 }
4545
46- public GitVCS (IVCSRepository repo ) {
46+ public GitVCS (IVCSRepositoryWorkspace repo ) {
4747 this .repo = repo ;
4848 }
4949
@@ -77,6 +77,7 @@ public void createBranch(String srcBranchName, String newBranchName, String comm
7777 .setRefSpecs (refSpec )
7878 .setCredentialsProvider (credentials )
7979 .call ();
80+ git .getRepository ().close ();
8081 }
8182 }
8283 } catch (RefAlreadyExistsException e ) {
@@ -119,6 +120,7 @@ public void deleteBranch(String branchName, String commitMessage) {
119120 .setRemote ("origin" )
120121 .setCredentialsProvider (credentials )
121122 .call ();
123+ git .getRepository ().close ();
122124 }
123125 }
124126 } catch (GitAPIException e ) {
@@ -149,14 +151,15 @@ public Git getLocalGit(IVCSLockedWorkingCopy wc) {
149151 .setURI (repo .getRepoUrl ())
150152 .setCredentialsProvider (credentials )
151153 .setNoCheckout (true )
152- .call ();
154+ .call ()
155+ .close ();
153156 } catch (GitAPIException e ) {
154157 throw new EVCSException (e );
155158 }
156159
157160 }
158-
159- return new Git ( gitRepo );
161+ Git res = new Git ( gitRepo );
162+ return res ;
160163 }
161164
162165 @ Override
@@ -170,7 +173,11 @@ public PKVCSMergeResult merge(String sourceBranchUrl, String destBranchUrl, Stri
170173 .setCredentialsProvider (credentials )
171174 .call ();
172175
173- checkout (destBranchUrl , git );
176+ git
177+ .checkout ()
178+ .setCreateBranch (false )
179+ .setName (destBranchUrl )
180+ .call ();
174181
175182 MergeResult mr = git
176183 .merge ()
@@ -195,7 +202,7 @@ public PKVCSMergeResult merge(String sourceBranchUrl, String destBranchUrl, Stri
195202 .setMode (ResetType .HARD )
196203 .call ();
197204 } catch (Exception e ) {
198- wc .setCorrupt (true );
205+ wc .setCorrupted (true );
199206 }
200207 } else {
201208 git
@@ -205,7 +212,7 @@ public PKVCSMergeResult merge(String sourceBranchUrl, String destBranchUrl, Stri
205212 .setCredentialsProvider (credentials )
206213 .call ();
207214 }
208-
215+ git . getRepository (). close ();
209216 return res ;
210217 }
211218 }
@@ -216,14 +223,6 @@ public PKVCSMergeResult merge(String sourceBranchUrl, String destBranchUrl, Stri
216223 }
217224 }
218225
219- private void checkout (String destBranchUrl , Git git ) throws GitAPIException {
220- git
221- .checkout ()
222- .setCreateBranch (false )
223- .setName (destBranchUrl )
224- .call ();
225- }
226-
227226 @ Override
228227 public void setCredentials (String user , String password ) {
229228 credentials = new UsernamePasswordCredentialsProvider (user , password );
@@ -237,7 +236,7 @@ public void setProxy(final String host, final int port, String proxyUser, String
237236
238237 @ Override
239238 public List <Proxy > select (URI uri ) {
240- if (uri .toString ().contains (repo .getRepoUrl ())) {
239+ if (uri .toString ().toLowerCase (). contains (repo .getRepoUrl (). toLowerCase ())) {
241240 return Arrays .asList (new Proxy (Type .HTTP , InetSocketAddress
242241 .createUnresolved (host , port )));
243242 } else {
@@ -276,6 +275,8 @@ public String getFileContent(String branchName, String fileRelativePath, String
276275 .addPath (fileRelativePath )
277276 .setName (branchName )
278277 .call ();
278+ git .getRepository ().close ();
279+
279280 File file = new File (wc .getFolder (), fileRelativePath );
280281
281282 try {
@@ -330,6 +331,7 @@ public void setFileContent(String branchName, String filePath, String content, S
330331 .setRemote ("origin" )
331332 .setCredentialsProvider (credentials )
332333 .call ();
334+ git .getRepository ().close ();
333335 }
334336 }
335337 } catch (GitAPIException e ) {
0 commit comments