fix checkout location
Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/aee511fe Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/aee511fe Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/aee511fe Branch: refs/heads/master Commit: aee511feb181fe8782af74e87c55c8637568f893 Parents: cdbe6ed Author: imod <d...@fortysix.ch> Authored: Wed Jun 19 05:02:42 2013 +0200 Committer: imod <d...@fortysix.ch> Committed: Wed Jun 19 05:02:42 2013 +0200 ---------------------------------------------------------------------- .../command/checkout/JGitCheckOutCommand.java | 118 ++++++++----------- 1 file changed, 50 insertions(+), 68 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-scm/blob/aee511fe/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java index 59e1951..61eb85c 100644 --- a/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java +++ b/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java @@ -43,74 +43,56 @@ import org.eclipse.jgit.transport.URIish; * @author <a href="mailto:strub...@yahoo.de">Mark Struberg</a> * @version $Id: JGitCheckOutCommand.java 894145 2009-12-28 10:13:39Z struberg $ */ -public class JGitCheckOutCommand - extends AbstractCheckOutCommand - implements GitCommand -{ - /** - * For git, the given repository is a remote one. - * We have to clone it first if the working directory does not contain a git repo yet, - * otherwise we have to git-pull it. - * - * {@inheritDoc} - */ - protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet, - ScmVersion version, boolean recursive ) - throws ScmException - { - GitScmProviderRepository repository = (GitScmProviderRepository) repo; +public class JGitCheckOutCommand extends AbstractCheckOutCommand implements GitCommand { + /** + * For git, the given repository is a remote one. We have to clone it first + * if the working directory does not contain a git repo yet, otherwise we + * have to git-pull it. + * + * {@inheritDoc} + */ + protected CheckOutScmResult executeCheckOutCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion version, boolean recursive) throws ScmException { + GitScmProviderRepository repository = (GitScmProviderRepository) repo; - if ( GitScmProviderRepository.PROTOCOL_FILE.equals( repository.getFetchInfo().getProtocol() ) - && repository.getFetchInfo().getPath().indexOf( fileSet.getBasedir().getPath() ) >= 0 ) - { - throw new ScmException( "remote repository must not be the working directory" ); - } - - try { - - ProgressMonitor monitor = JGitUtils.getMonitor( getLogger() ); - - String branch = version.getName(); - - if ( !fileSet.getBasedir().exists() || !( new File( fileSet.getBasedir(), ".git" ).exists() ) ) - { - if ( fileSet.getBasedir().exists() ) - { - // git refuses to clone otherwise - fileSet.getBasedir().delete(); - } - - // no git repo seems to exist, let's clone the original repo - CredentialsProvider credentials = JGitUtils.getCredentials((GitScmProviderRepository) repo); - Git.cloneRepository().setURI(repository.getFetchUrl()).setCredentialsProvider(credentials).setBranchesToClone(Collections.singleton(branch)).setDirectory(fileSet.getBasedir().getParentFile()).setProgressMonitor(monitor).call(); - - } - else - { - Git git = Git.open(fileSet.getBasedir()); - // switch branch if we currently are not on the proper one - git.checkout().setName(branch).call(); - - - URIish uri = new URIish(repository.getFetchUrl()); - git.fetch().setRemote(repository.getFetchUrl()).call(); - git.pull().call(); - } - - List<ScmFile> listedFiles = new ArrayList<ScmFile>(); - // TODO collect checkedout files -// List<StatusEntry> fileEntries = srep.status(true, false); -// for (StatusEntry entry : fileEntries) -// { -// listedFiles.add( new ScmFile(entry.getFilePath(), JGitUtils.getScmFileStatus( entry ) ) ); -// } - - return new CheckOutScmResult("checkout via JGit", listedFiles ); - } - catch (Exception e) - { - throw new ScmException( "JGit checkout failure!", e ); - } - } + if (GitScmProviderRepository.PROTOCOL_FILE.equals(repository.getFetchInfo().getProtocol()) && repository.getFetchInfo().getPath().indexOf(fileSet.getBasedir().getPath()) >= 0) { + throw new ScmException("remote repository must not be the working directory"); + } + + try { + + ProgressMonitor monitor = JGitUtils.getMonitor(getLogger()); + + String branch = version.getName(); + + if (!fileSet.getBasedir().exists() || !(new File(fileSet.getBasedir(), ".git").exists())) { + if (fileSet.getBasedir().exists()) { + // git refuses to clone otherwise + fileSet.getBasedir().delete(); + } + + // no git repo seems to exist, let's clone the original repo + CredentialsProvider credentials = JGitUtils.getCredentials((GitScmProviderRepository) repo); + getLogger().info("cloning [" + branch + "] to " + fileSet.getBasedir()); + Git.cloneRepository().setURI(repository.getFetchUrl()).setCredentialsProvider(credentials).setBranchesToClone(Collections.singleton(branch)).setDirectory(fileSet.getBasedir()).setProgressMonitor(monitor).call(); + + } else { + Git git = Git.open(fileSet.getBasedir()); + // switch branch if we currently are not on the proper one + getLogger().info("checkout [" + branch + "] to " + fileSet.getBasedir()); + git.checkout().setName(branch).call(); + + URIish uri = new URIish(repository.getFetchUrl()); + git.fetch().setRemote(repository.getFetchUrl()).call(); + git.pull().call(); + } + + List<ScmFile> listedFiles = new ArrayList<ScmFile>(); + // TODO collect checkedout files + + return new CheckOutScmResult("checkout via JGit", listedFiles); + } catch (Exception e) { + throw new ScmException("JGit checkout failure!", e); + } + } }