tikhomirov@669: /* tikhomirov@669: * Copyright (c) 2013 TMate Software Ltd tikhomirov@669: * tikhomirov@669: * This program is free software; you can redistribute it and/or modify tikhomirov@669: * it under the terms of the GNU General Public License as published by tikhomirov@669: * the Free Software Foundation; version 2 of the License. tikhomirov@669: * tikhomirov@669: * This program is distributed in the hope that it will be useful, tikhomirov@669: * but WITHOUT ANY WARRANTY; without even the implied warranty of tikhomirov@669: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the tikhomirov@669: * GNU General Public License for more details. tikhomirov@669: * tikhomirov@669: * For information on how to redistribute this software under tikhomirov@669: * the terms of a license other than GNU General Public License tikhomirov@669: * contact TMate Software at support@hg4j.com tikhomirov@669: */ tikhomirov@669: package org.tmatesoft.hg.console; tikhomirov@669: tikhomirov@669: import java.util.Collections; tikhomirov@669: tikhomirov@669: import org.tmatesoft.hg.core.HgPullCommand; tikhomirov@669: import org.tmatesoft.hg.core.HgRepoFacade; tikhomirov@669: import org.tmatesoft.hg.repo.HgLookup; tikhomirov@669: import org.tmatesoft.hg.repo.HgRemoteRepository; tikhomirov@669: tikhomirov@669: /** tikhomirov@669: * Basic analog to 'hg pull' command line utility tikhomirov@669: * @since 1.2 tikhomirov@669: * @author Artem Tikhomirov tikhomirov@669: * @author TMate Software Ltd. tikhomirov@669: */ tikhomirov@669: public class Pull { tikhomirov@669: tikhomirov@669: public static void main(String[] args) throws Exception { tikhomirov@669: Options cmdLineOpts = Options.parse(args, Collections.emptySet()); tikhomirov@669: HgRepoFacade hgRepo = new HgRepoFacade(); tikhomirov@669: if (!hgRepo.init(cmdLineOpts.findRepository())) { tikhomirov@669: System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation()); tikhomirov@669: return; tikhomirov@669: } tikhomirov@669: HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository()); tikhomirov@669: if (hgRemote.isInvalid()) { tikhomirov@669: System.err.printf("Remote repository %s is not valid", hgRemote.getLocation()); tikhomirov@669: return; tikhomirov@669: } tikhomirov@669: HgPullCommand cmd = hgRepo.createPullCommand(); tikhomirov@669: cmd.source(hgRemote); tikhomirov@669: cmd.execute(); tikhomirov@669: System.out.printf("Sent %d changesets\n", cmd.getPulledRevisions().size()); tikhomirov@669: } tikhomirov@669: tikhomirov@669: }