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