You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RemoteHelper.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2009, Constantine Plotnikov <constantine.plotnikov@gmail.com>
  3. * Copyright (C) 2008, Google Inc.
  4. * Copyright (C) 2010, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2010, Sasa Zivkov <sasa.zivkov@sap.com>
  6. * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
  7. * Copyright (C) 2016, Rüdiger Herrmann <ruediger.herrmann@gmx.de>
  8. * and other copyright owners as documented in the project's IP log.
  9. *
  10. * This program and the accompanying materials are made available
  11. * under the terms of the Eclipse Distribution License v1.0 which
  12. * accompanies this distribution, is reproduced below, and is
  13. * available at http://www.eclipse.org/org/documents/edl-v10.php
  14. *
  15. * All rights reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or
  18. * without modification, are permitted provided that the following
  19. * conditions are met:
  20. *
  21. * - Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. *
  24. * - Redistributions in binary form must reproduce the above
  25. * copyright notice, this list of conditions and the following
  26. * disclaimer in the documentation and/or other materials provided
  27. * with the distribution.
  28. *
  29. * - Neither the name of the Eclipse Foundation, Inc. nor the
  30. * names of its contributors may be used to endorse or promote
  31. * products derived from this software without specific prior
  32. * written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  38. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  39. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  43. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  44. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  45. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  46. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. */
  48. package org.eclipse.jgit.pgm;
  49. import org.eclipse.jgit.api.Git;
  50. import org.eclipse.jgit.integrate.remotehelper.RemoteHelperDriver;
  51. import org.eclipse.jgit.integrate.remotehelper.internal.RemoteHelperMain;
  52. import org.eclipse.jgit.integrate.remotehelper.internal.RemoteHelperTransport;
  53. import org.eclipse.jgit.lib.Repository;
  54. import org.eclipse.jgit.lib.TextProgressMonitor;
  55. import org.eclipse.jgit.transport.URIish;
  56. import org.kohsuke.args4j.Argument;
  57. import java.io.*;
  58. @Command(common = true, name = "remote-helper", usage = "usage_RemoteHelper")
  59. class RemoteHelper extends TextBuiltin {
  60. @Argument(index = 0, metaVar = "metaVar_remoteName")
  61. private String remote;
  62. @Argument(index = 1, metaVar = "metaVar_url")
  63. private String url;
  64. @Override
  65. protected final boolean requiresRepository() {
  66. return false;
  67. }
  68. @Override
  69. protected void run() throws Exception {
  70. String realUrl = url == null ? remote : url;
  71. String realRemote = url == null ? "" : remote;
  72. String dir = gitdir;
  73. if (dir == null) {
  74. dir = System.getenv("GIT_DIR");
  75. }
  76. if (dir == null) {
  77. dir = ".";
  78. }
  79. Repository repository = Git.open(new File(dir)).getRepository();
  80. init(repository, null);
  81. RemoteHelperDriver driver = new RemoteHelperDriver(
  82. repository,
  83. new URIish(realUrl),
  84. realRemote,
  85. new PrintWriter(outw),
  86. new TextProgressMonitor(errw)
  87. );
  88. driver.setProvider(new RemoteHelperTransport(driver));
  89. BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
  90. String line;
  91. while ((line = reader.readLine()) != null) {
  92. driver.handleLine(line);
  93. }
  94. }
  95. }