comparison cmdline/org/tmatesoft/hg/console/Pull.java @ 669:b1a3a056d7e6

Pull: sample command-line utility
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 20:49:33 +0200
parents
children
comparison
equal deleted inserted replaced
668:d25f0324a27a 669:b1a3a056d7e6
1 /*
2 * Copyright (c) 2013 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.console;
18
19 import java.util.Collections;
20
21 import org.tmatesoft.hg.core.HgPullCommand;
22 import org.tmatesoft.hg.core.HgRepoFacade;
23 import org.tmatesoft.hg.repo.HgLookup;
24 import org.tmatesoft.hg.repo.HgRemoteRepository;
25
26 /**
27 * Basic analog to 'hg pull' command line utility
28 * @since 1.2
29 * @author Artem Tikhomirov
30 * @author TMate Software Ltd.
31 */
32 public class Pull {
33
34 public static void main(String[] args) throws Exception {
35 Options cmdLineOpts = Options.parse(args, Collections.<String>emptySet());
36 HgRepoFacade hgRepo = new HgRepoFacade();
37 if (!hgRepo.init(cmdLineOpts.findRepository())) {
38 System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
39 return;
40 }
41 HgRemoteRepository hgRemote = new HgLookup().detectRemote(cmdLineOpts.getSingle(""), hgRepo.getRepository());
42 if (hgRemote.isInvalid()) {
43 System.err.printf("Remote repository %s is not valid", hgRemote.getLocation());
44 return;
45 }
46 HgPullCommand cmd = hgRepo.createPullCommand();
47 cmd.source(hgRemote);
48 cmd.execute();
49 System.out.printf("Sent %d changesets\n", cmd.getPulledRevisions().size());
50 }
51
52 }