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