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.

Git.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.api;
  44. import org.eclipse.jgit.lib.Repository;
  45. /**
  46. * Offers a "GitPorcelain"-like API to interact with a git repository.
  47. * <p>
  48. * The GitPorcelain commands are described in the <a href="http://www.kernel.org/pub/software/scm/git/docs/git.html#_high_level_commands_porcelain"
  49. * >Git Documentation</a>.
  50. * <p>
  51. * This class only offers methods to construct so-called command classes. Each
  52. * GitPorcelain command is represented by one command class.<br>
  53. * Example: this class offers a {@code commit()} method returning an instance of
  54. * the {@code CommitCommand} class. The {@code CommitCommand} class has setters
  55. * for all the arguments and options. The {@code CommitCommand} class also has a
  56. * {@code call} method to actually execute the commit. The following code show's
  57. * how to do a simple commit:
  58. *
  59. * <pre>
  60. * Git git = new Git(myRepo);
  61. * git.commit().setMessage(&quot;Fix393&quot;).setAuthor(developerIdent).call();
  62. * </pre>
  63. *
  64. * All mandatory parameters for commands have to be specified in the methods of
  65. * this class, the optional parameters have to be specified by the
  66. * setter-methods of the Command class.
  67. * <p>
  68. * This class is intended to be used internally (e.g. by JGit tests) or by
  69. * external components (EGit, third-party tools) when they need exactly the
  70. * functionality of a GitPorcelain command. There are use-cases where this class
  71. * is not optimal and where you should use the more low-level JGit classes. The
  72. * methods in this class may for example offer too much functionality or they
  73. * offer the functionality with the wrong arguments.
  74. */
  75. public class Git {
  76. /** The git repository this class is interacting with */
  77. private final Repository repo;
  78. /**
  79. * Constructs a new {@link Git} class which can interact with the specified
  80. * git repository. All command classes returned by methods of this class
  81. * will always interact with this git repository.
  82. *
  83. * @param repo
  84. * the git repository this class is interacting with.
  85. * {@code null} is not allowed
  86. */
  87. public Git(Repository repo) {
  88. if (repo == null)
  89. throw new NullPointerException();
  90. this.repo = repo;
  91. }
  92. /**
  93. * Returns a command class to execute a {@code Commit} command
  94. *
  95. * @see <a
  96. * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
  97. * >Git documentation about Commit</a>
  98. * @return a {@link CommitCommand} used to collect all optional parameters
  99. * and to finally execute the {@code Commit} command
  100. */
  101. public CommitCommand commit() {
  102. return new CommitCommand(repo);
  103. }
  104. /**
  105. * Returns a command class to execute a {@code Log} command
  106. *
  107. * @see <a
  108. * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
  109. * >Git documentation about Log</a>
  110. * @return a {@link LogCommand} used to collect all optional parameters and
  111. * to finally execute the {@code Log} command
  112. */
  113. public LogCommand log() {
  114. return new LogCommand(repo);
  115. }
  116. /**
  117. * @return the git repository this class is interacting with
  118. */
  119. public Repository getRepository() {
  120. return repo;
  121. }
  122. }