kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.console; kitaev@213: kitaev@213: import java.io.File; kitaev@213: import java.util.List; kitaev@213: kitaev@213: import org.tmatesoft.hg.core.HgCloneCommand; kitaev@213: import org.tmatesoft.hg.repo.HgLookup; kitaev@213: import org.tmatesoft.hg.repo.HgRemoteRepository; kitaev@213: kitaev@213: /** kitaev@213: * Initial clone of a repository. Creates a brand new repository and populates it from specified source. kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public class Clone { kitaev@213: kitaev@213: // ran with args: svnkit c:\temp\hg\test-clone kitaev@213: public static void main(String[] args) throws Exception { kitaev@213: Options cmdLineOpts = Options.parse(args); kitaev@213: List noOptsArgs = cmdLineOpts.getList(""); kitaev@213: if (noOptsArgs.isEmpty()) { kitaev@213: System.err.println("Need at least one argument pointing to remote server to pull changes from"); kitaev@213: return; kitaev@213: } kitaev@213: HgCloneCommand cmd = new HgCloneCommand(); kitaev@213: String remoteRepo = noOptsArgs.get(0); kitaev@213: HgRemoteRepository hgRemote = new HgLookup().detectRemote(remoteRepo, null); kitaev@213: if (hgRemote.isInvalid()) { kitaev@213: System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); kitaev@213: return; kitaev@213: } kitaev@213: cmd.source(hgRemote); kitaev@213: if (noOptsArgs.size() > 1) { kitaev@213: cmd.destination(new File(noOptsArgs.get(1))); kitaev@213: } else { kitaev@213: cmd.destination(new File(System.getProperty("user.dir"))); kitaev@213: } kitaev@213: cmd.execute(); kitaev@213: } kitaev@213: }