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 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
  3. * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.api;
  45. import java.io.File;
  46. import java.io.IOException;
  47. import org.eclipse.jgit.lib.Repository;
  48. import org.eclipse.jgit.lib.RepositoryBuilder;
  49. import org.eclipse.jgit.lib.RepositoryCache;
  50. import org.eclipse.jgit.util.FS;
  51. /**
  52. * Offers a "GitPorcelain"-like API to interact with a git repository.
  53. * <p>
  54. * The GitPorcelain commands are described in the <a href=
  55. * "http://www.kernel.org/pub/software/scm/git/docs/git.html#_high_level_commands_porcelain"
  56. * >Git Documentation</a>.
  57. * <p>
  58. * This class only offers methods to construct so-called command classes. Each
  59. * GitPorcelain command is represented by one command class.<br>
  60. * Example: this class offers a {@code commit()} method returning an instance of
  61. * the {@code CommitCommand} class. The {@code CommitCommand} class has setters
  62. * for all the arguments and options. The {@code CommitCommand} class also has a
  63. * {@code call} method to actually execute the commit. The following code show's
  64. * how to do a simple commit:
  65. *
  66. * <pre>
  67. * Git git = new Git(myRepo);
  68. * git.commit().setMessage(&quot;Fix393&quot;).setAuthor(developerIdent).call();
  69. * </pre>
  70. *
  71. * All mandatory parameters for commands have to be specified in the methods of
  72. * this class, the optional parameters have to be specified by the
  73. * setter-methods of the Command class.
  74. * <p>
  75. * This class is intended to be used internally (e.g. by JGit tests) or by
  76. * external components (EGit, third-party tools) when they need exactly the
  77. * functionality of a GitPorcelain command. There are use-cases where this class
  78. * is not optimal and where you should use the more low-level JGit classes. The
  79. * methods in this class may for example offer too much functionality or they
  80. * offer the functionality with the wrong arguments.
  81. */
  82. public class Git implements AutoCloseable {
  83. /** The git repository this class is interacting with */
  84. private final Repository repo;
  85. private final boolean closeRepo;
  86. /**
  87. * @param dir
  88. * the repository to open. May be either the GIT_DIR, or the
  89. * working tree directory that contains {@code .git}.
  90. * @return a {@link Git} object for the existing git repository
  91. * @throws IOException
  92. */
  93. public static Git open(File dir) throws IOException {
  94. return open(dir, FS.DETECTED);
  95. }
  96. /**
  97. * @param dir
  98. * the repository to open. May be either the GIT_DIR, or the
  99. * working tree directory that contains {@code .git}.
  100. * @param fs
  101. * filesystem abstraction to use when accessing the repository.
  102. * @return a {@link Git} object for the existing git repository. Closing this
  103. * instance will close the repo.
  104. * @throws IOException
  105. */
  106. public static Git open(File dir, FS fs) throws IOException {
  107. RepositoryCache.FileKey key;
  108. key = RepositoryCache.FileKey.lenient(dir, fs);
  109. Repository db = new RepositoryBuilder().setFS(fs).setGitDir(key.getFile())
  110. .setMustExist(true).build();
  111. return new Git(db, true);
  112. }
  113. /**
  114. * @param repo
  115. * the git repository this class is interacting with;
  116. * {@code null} is not allowed.
  117. * @return a {@link Git} object for the existing git repository. The caller is
  118. * responsible for closing the repository; {@link #close()} on this
  119. * instance does not close the repo.
  120. */
  121. public static Git wrap(Repository repo) {
  122. return new Git(repo);
  123. }
  124. /**
  125. * Frees resources associated with this instance.
  126. * <p>
  127. * If the repository was opened by a static factory method in this class, then
  128. * this method calls {@link Repository#close()} on the underlying repository
  129. * instance. (Whether this actually releases underlying resources, such as
  130. * file handles, may vary; see {@link Repository} for more details.)
  131. * <p>
  132. * If the repository was created by a caller and passed into {@link
  133. * #Git(Repository)} or a static factory method in this class, then this
  134. * method does not call close on the underlying repository.
  135. * <p>
  136. * In all cases, after calling this method you should not use this {@link Git}
  137. * instance anymore.
  138. *
  139. * @since 3.2
  140. */
  141. public void close() {
  142. if (closeRepo)
  143. repo.close();
  144. }
  145. /**
  146. * Returns a command object to execute a {@code clone} command
  147. *
  148. * @see <a
  149. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html"
  150. * >Git documentation about clone</a>
  151. * @return a {@link CloneCommand} used to collect all optional parameters
  152. * and to finally execute the {@code clone} command
  153. */
  154. public static CloneCommand cloneRepository() {
  155. return new CloneCommand();
  156. }
  157. /**
  158. * Returns a command to list remote branches/tags without a local
  159. * repository.
  160. *
  161. * @return a {@link LsRemoteCommand}
  162. * @since 3.1
  163. */
  164. public static LsRemoteCommand lsRemoteRepository() {
  165. return new LsRemoteCommand(null);
  166. }
  167. /**
  168. * Returns a command object to execute a {@code init} command
  169. *
  170. * @see <a
  171. * href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html"
  172. * >Git documentation about init</a>
  173. * @return a {@link InitCommand} used to collect all optional parameters and
  174. * to finally execute the {@code init} command
  175. */
  176. public static InitCommand init() {
  177. return new InitCommand();
  178. }
  179. /**
  180. * Constructs a new {@link Git} object which can interact with the specified
  181. * git repository.
  182. * <p>
  183. * All command classes returned by methods of this class will always interact
  184. * with this git repository.
  185. * <p>
  186. * The caller is responsible for closing the repository; {@link #close()} on
  187. * this instance does not close the repo.
  188. *
  189. * @param repo
  190. * the git repository this class is interacting with;
  191. * {@code null} is not allowed.
  192. */
  193. public Git(Repository repo) {
  194. this(repo, false);
  195. }
  196. private Git(Repository repo, boolean closeRepo) {
  197. if (repo == null)
  198. throw new NullPointerException();
  199. this.repo = repo;
  200. this.closeRepo = closeRepo;
  201. }
  202. /**
  203. * Returns a command object to execute a {@code Commit} command
  204. *
  205. * @see <a
  206. * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
  207. * >Git documentation about Commit</a>
  208. * @return a {@link CommitCommand} used to collect all optional parameters
  209. * and to finally execute the {@code Commit} command
  210. */
  211. public CommitCommand commit() {
  212. return new CommitCommand(repo);
  213. }
  214. /**
  215. * Returns a command object to execute a {@code Log} command
  216. *
  217. * @see <a
  218. * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
  219. * >Git documentation about Log</a>
  220. * @return a {@link LogCommand} used to collect all optional parameters and
  221. * to finally execute the {@code Log} command
  222. */
  223. public LogCommand log() {
  224. return new LogCommand(repo);
  225. }
  226. /**
  227. * Returns a command object to execute a {@code Merge} command
  228. *
  229. * @see <a
  230. * href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
  231. * >Git documentation about Merge</a>
  232. * @return a {@link MergeCommand} used to collect all optional parameters
  233. * and to finally execute the {@code Merge} command
  234. */
  235. public MergeCommand merge() {
  236. return new MergeCommand(repo);
  237. }
  238. /**
  239. * Returns a command object to execute a {@code Pull} command
  240. *
  241. * @return a {@link PullCommand}
  242. */
  243. public PullCommand pull() {
  244. return new PullCommand(repo);
  245. }
  246. /**
  247. * Returns a command object used to create branches
  248. *
  249. * @return a {@link CreateBranchCommand}
  250. */
  251. public CreateBranchCommand branchCreate() {
  252. return new CreateBranchCommand(repo);
  253. }
  254. /**
  255. * Returns a command object used to delete branches
  256. *
  257. * @return a {@link DeleteBranchCommand}
  258. */
  259. public DeleteBranchCommand branchDelete() {
  260. return new DeleteBranchCommand(repo);
  261. }
  262. /**
  263. * Returns a command object used to list branches
  264. *
  265. * @return a {@link ListBranchCommand}
  266. */
  267. public ListBranchCommand branchList() {
  268. return new ListBranchCommand(repo);
  269. }
  270. /**
  271. *
  272. * Returns a command object used to list tags
  273. *
  274. * @return a {@link ListTagCommand}
  275. */
  276. public ListTagCommand tagList() {
  277. return new ListTagCommand(repo);
  278. }
  279. /**
  280. * Returns a command object used to rename branches
  281. *
  282. * @return a {@link RenameBranchCommand}
  283. */
  284. public RenameBranchCommand branchRename() {
  285. return new RenameBranchCommand(repo);
  286. }
  287. /**
  288. * Returns a command object to execute a {@code Add} command
  289. *
  290. * @see <a
  291. * href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html"
  292. * >Git documentation about Add</a>
  293. * @return a {@link AddCommand} used to collect all optional parameters and
  294. * to finally execute the {@code Add} command
  295. */
  296. public AddCommand add() {
  297. return new AddCommand(repo);
  298. }
  299. /**
  300. * Returns a command object to execute a {@code Tag} command
  301. *
  302. * @see <a
  303. * href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html"
  304. * >Git documentation about Tag</a>
  305. * @return a {@link TagCommand} used to collect all optional parameters and
  306. * to finally execute the {@code Tag} command
  307. */
  308. public TagCommand tag() {
  309. return new TagCommand(repo);
  310. }
  311. /**
  312. * Returns a command object to execute a {@code Fetch} command
  313. *
  314. * @see <a
  315. * href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html"
  316. * >Git documentation about Fetch</a>
  317. * @return a {@link FetchCommand} used to collect all optional parameters
  318. * and to finally execute the {@code Fetch} command
  319. */
  320. public FetchCommand fetch() {
  321. return new FetchCommand(repo);
  322. }
  323. /**
  324. * Returns a command object to execute a {@code Push} command
  325. *
  326. * @see <a
  327. * href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html"
  328. * >Git documentation about Push</a>
  329. * @return a {@link PushCommand} used to collect all optional parameters and
  330. * to finally execute the {@code Push} command
  331. */
  332. public PushCommand push() {
  333. return new PushCommand(repo);
  334. }
  335. /**
  336. * Returns a command object to execute a {@code cherry-pick} command
  337. *
  338. * @see <a
  339. * href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html"
  340. * >Git documentation about cherry-pick</a>
  341. * @return a {@link CherryPickCommand} used to collect all optional
  342. * parameters and to finally execute the {@code cherry-pick} command
  343. */
  344. public CherryPickCommand cherryPick() {
  345. return new CherryPickCommand(repo);
  346. }
  347. /**
  348. * Returns a command object to execute a {@code revert} command
  349. *
  350. * @see <a
  351. * href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html"
  352. * >Git documentation about reverting changes</a>
  353. * @return a {@link RevertCommand} used to collect all optional parameters
  354. * and to finally execute the {@code cherry-pick} command
  355. */
  356. public RevertCommand revert() {
  357. return new RevertCommand(repo);
  358. }
  359. /**
  360. * Returns a command object to execute a {@code Rebase} command
  361. *
  362. * @see <a
  363. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html"
  364. * >Git documentation about rebase</a>
  365. * @return a {@link RebaseCommand} used to collect all optional parameters
  366. * and to finally execute the {@code rebase} command
  367. */
  368. public RebaseCommand rebase() {
  369. return new RebaseCommand(repo);
  370. }
  371. /**
  372. * Returns a command object to execute a {@code rm} command
  373. *
  374. * @see <a
  375. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html"
  376. * >Git documentation about rm</a>
  377. * @return a {@link RmCommand} used to collect all optional parameters and
  378. * to finally execute the {@code rm} command
  379. */
  380. public RmCommand rm() {
  381. return new RmCommand(repo);
  382. }
  383. /**
  384. * Returns a command object to execute a {@code checkout} command
  385. *
  386. * @see <a
  387. * href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
  388. * >Git documentation about checkout</a>
  389. * @return a {@link CheckoutCommand} used to collect all optional parameters
  390. * and to finally execute the {@code checkout} command
  391. */
  392. public CheckoutCommand checkout() {
  393. return new CheckoutCommand(repo);
  394. }
  395. /**
  396. * Returns a command object to execute a {@code reset} command
  397. *
  398. * @see <a
  399. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html"
  400. * >Git documentation about reset</a>
  401. * @return a {@link ResetCommand} used to collect all optional parameters
  402. * and to finally execute the {@code reset} command
  403. */
  404. public ResetCommand reset() {
  405. return new ResetCommand(repo);
  406. }
  407. /**
  408. * Returns a command object to execute a {@code status} command
  409. *
  410. * @see <a
  411. * href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html"
  412. * >Git documentation about status</a>
  413. * @return a {@link StatusCommand} used to collect all optional parameters
  414. * and to finally execute the {@code status} command
  415. */
  416. public StatusCommand status() {
  417. return new StatusCommand(repo);
  418. }
  419. /**
  420. * Returns a command to create an archive from a tree
  421. *
  422. * @return a {@link ArchiveCommand}
  423. * @since 3.1
  424. */
  425. public ArchiveCommand archive() {
  426. return new ArchiveCommand(repo);
  427. }
  428. /**
  429. * Returns a command to add notes to an object
  430. *
  431. * @return a {@link AddNoteCommand}
  432. */
  433. public AddNoteCommand notesAdd() {
  434. return new AddNoteCommand(repo);
  435. }
  436. /**
  437. * Returns a command to remove notes on an object
  438. *
  439. * @return a {@link RemoveNoteCommand}
  440. */
  441. public RemoveNoteCommand notesRemove() {
  442. return new RemoveNoteCommand(repo);
  443. }
  444. /**
  445. * Returns a command to list all notes
  446. *
  447. * @return a {@link ListNotesCommand}
  448. */
  449. public ListNotesCommand notesList() {
  450. return new ListNotesCommand(repo);
  451. }
  452. /**
  453. * Returns a command to show notes on an object
  454. *
  455. * @return a {@link ShowNoteCommand}
  456. */
  457. public ShowNoteCommand notesShow() {
  458. return new ShowNoteCommand(repo);
  459. }
  460. /**
  461. * Returns a command object to execute a {@code ls-remote} command
  462. *
  463. * @see <a
  464. * href="http://www.kernel.org/pub/software/scm/git/docs/git-ls-remote.html"
  465. * >Git documentation about ls-remote</a>
  466. * @return a {@link LsRemoteCommand} used to collect all optional parameters
  467. * and to finally execute the {@code status} command
  468. */
  469. public LsRemoteCommand lsRemote() {
  470. return new LsRemoteCommand(repo);
  471. }
  472. /**
  473. * Returns a command object to execute a {@code clean} command
  474. *
  475. * @see <a
  476. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clean.html"
  477. * >Git documentation about Clean</a>
  478. * @return a {@link CleanCommand} used to collect all optional parameters
  479. * and to finally execute the {@code clean} command
  480. */
  481. public CleanCommand clean() {
  482. return new CleanCommand(repo);
  483. }
  484. /**
  485. * Returns a command object to execute a {@code blame} command
  486. *
  487. * @see <a
  488. * href="http://www.kernel.org/pub/software/scm/git/docs/git-blame.html"
  489. * >Git documentation about Blame</a>
  490. * @return a {@link BlameCommand} used to collect all optional parameters
  491. * and to finally execute the {@code blame} command
  492. */
  493. public BlameCommand blame() {
  494. return new BlameCommand(repo);
  495. }
  496. /**
  497. * Returns a command object to execute a {@code reflog} command
  498. *
  499. * @see <a
  500. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reflog.html"
  501. * >Git documentation about reflog</a>
  502. * @return a {@link ReflogCommand} used to collect all optional parameters
  503. * and to finally execute the {@code reflog} command
  504. */
  505. public ReflogCommand reflog() {
  506. return new ReflogCommand(repo);
  507. }
  508. /**
  509. * Returns a command object to execute a {@code diff} command
  510. *
  511. * @see <a
  512. * href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html"
  513. * >Git documentation about diff</a>
  514. * @return a {@link DiffCommand} used to collect all optional parameters and
  515. * to finally execute the {@code diff} command
  516. */
  517. public DiffCommand diff() {
  518. return new DiffCommand(repo);
  519. }
  520. /**
  521. * Returns a command object used to delete tags
  522. *
  523. * @return a {@link DeleteTagCommand}
  524. */
  525. public DeleteTagCommand tagDelete() {
  526. return new DeleteTagCommand(repo);
  527. }
  528. /**
  529. * Returns a command object to execute a {@code submodule add} command
  530. *
  531. * @return a {@link SubmoduleAddCommand} used to add a new submodule to a
  532. * parent repository
  533. */
  534. public SubmoduleAddCommand submoduleAdd() {
  535. return new SubmoduleAddCommand(repo);
  536. }
  537. /**
  538. * Returns a command object to execute a {@code submodule init} command
  539. *
  540. * @return a {@link SubmoduleInitCommand} used to initialize the
  541. * repository's config with settings from the .gitmodules file in
  542. * the working tree
  543. */
  544. public SubmoduleInitCommand submoduleInit() {
  545. return new SubmoduleInitCommand(repo);
  546. }
  547. /**
  548. * Returns a command object to execute a {@code submodule status} command
  549. *
  550. * @return a {@link SubmoduleStatusCommand} used to report the status of a
  551. * repository's configured submodules
  552. */
  553. public SubmoduleStatusCommand submoduleStatus() {
  554. return new SubmoduleStatusCommand(repo);
  555. }
  556. /**
  557. * Returns a command object to execute a {@code submodule sync} command
  558. *
  559. * @return a {@link SubmoduleSyncCommand} used to update the URL of a
  560. * submodule from the parent repository's .gitmodules file
  561. */
  562. public SubmoduleSyncCommand submoduleSync() {
  563. return new SubmoduleSyncCommand(repo);
  564. }
  565. /**
  566. * Returns a command object to execute a {@code submodule update} command
  567. *
  568. * @return a {@link SubmoduleUpdateCommand} used to update the submodules in
  569. * a repository to the configured revision
  570. */
  571. public SubmoduleUpdateCommand submoduleUpdate() {
  572. return new SubmoduleUpdateCommand(repo);
  573. }
  574. /**
  575. * Returns a command object used to list stashed commits
  576. *
  577. * @return a {@link StashListCommand}
  578. */
  579. public StashListCommand stashList() {
  580. return new StashListCommand(repo);
  581. }
  582. /**
  583. * Returns a command object used to create a stashed commit
  584. *
  585. * @return a {@link StashCreateCommand}
  586. * @since 2.0
  587. */
  588. public StashCreateCommand stashCreate() {
  589. return new StashCreateCommand(repo);
  590. }
  591. /**
  592. * Returns a command object used to apply a stashed commit
  593. *
  594. * @return a {@link StashApplyCommand}
  595. * @since 2.0
  596. */
  597. public StashApplyCommand stashApply() {
  598. return new StashApplyCommand(repo);
  599. }
  600. /**
  601. * Returns a command object used to drop a stashed commit
  602. *
  603. * @return a {@link StashDropCommand}
  604. * @since 2.0
  605. */
  606. public StashDropCommand stashDrop() {
  607. return new StashDropCommand(repo);
  608. }
  609. /**
  610. * Returns a command object to execute a {@code apply} command
  611. *
  612. * @see <a
  613. * href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html"
  614. * >Git documentation about apply</a>
  615. *
  616. * @return a {@link ApplyCommand} used to collect all optional parameters
  617. * and to finally execute the {@code apply} command
  618. * @since 2.0
  619. */
  620. public ApplyCommand apply() {
  621. return new ApplyCommand(repo);
  622. }
  623. /**
  624. * Returns a command object to execute a {@code gc} command
  625. *
  626. * @see <a
  627. * href="http://www.kernel.org/pub/software/scm/git/docs/git-gc.html"
  628. * >Git documentation about gc</a>
  629. *
  630. * @return a {@link GarbageCollectCommand} used to collect all optional
  631. * parameters and to finally execute the {@code gc} command
  632. * @since 2.2
  633. */
  634. public GarbageCollectCommand gc() {
  635. return new GarbageCollectCommand(repo);
  636. }
  637. /**
  638. * Returns a command object to find human-readable names of revisions.
  639. *
  640. * @return a {@link NameRevCommand}.
  641. * @since 3.0
  642. */
  643. public NameRevCommand nameRev() {
  644. return new NameRevCommand(repo);
  645. }
  646. /**
  647. * Returns a command object to come up with a short name that describes a
  648. * commit in terms of the nearest git tag.
  649. *
  650. * @return a {@link DescribeCommand}.
  651. * @since 3.2
  652. */
  653. public DescribeCommand describe() {
  654. return new DescribeCommand(repo);
  655. }
  656. /**
  657. * @return the git repository this class is interacting with; see {@link
  658. * #close()} for notes on closing this repository.
  659. */
  660. public Repository getRepository() {
  661. return repo;
  662. }
  663. @Override
  664. public String toString() {
  665. return "Git[" + repo + "]"; //$NON-NLS-1$//$NON-NLS-2$
  666. }
  667. }