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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. @Override
  142. public void close() {
  143. if (closeRepo)
  144. repo.close();
  145. }
  146. /**
  147. * Returns a command object to execute a {@code clone} command
  148. *
  149. * @see <a
  150. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html"
  151. * >Git documentation about clone</a>
  152. * @return a {@link CloneCommand} used to collect all optional parameters
  153. * and to finally execute the {@code clone} command
  154. */
  155. public static CloneCommand cloneRepository() {
  156. return new CloneCommand();
  157. }
  158. /**
  159. * Returns a command to list remote branches/tags without a local
  160. * repository.
  161. *
  162. * @return a {@link LsRemoteCommand}
  163. * @since 3.1
  164. */
  165. public static LsRemoteCommand lsRemoteRepository() {
  166. return new LsRemoteCommand(null);
  167. }
  168. /**
  169. * Returns a command object to execute a {@code init} command
  170. *
  171. * @see <a
  172. * href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html"
  173. * >Git documentation about init</a>
  174. * @return a {@link InitCommand} used to collect all optional parameters and
  175. * to finally execute the {@code init} command
  176. */
  177. public static InitCommand init() {
  178. return new InitCommand();
  179. }
  180. /**
  181. * Constructs a new {@link Git} object which can interact with the specified
  182. * git repository.
  183. * <p>
  184. * All command classes returned by methods of this class will always interact
  185. * with this git repository.
  186. * <p>
  187. * The caller is responsible for closing the repository; {@link #close()} on
  188. * this instance does not close the repo.
  189. *
  190. * @param repo
  191. * the git repository this class is interacting with;
  192. * {@code null} is not allowed.
  193. */
  194. public Git(Repository repo) {
  195. this(repo, false);
  196. }
  197. Git(Repository repo, boolean closeRepo) {
  198. if (repo == null)
  199. throw new NullPointerException();
  200. this.repo = repo;
  201. this.closeRepo = closeRepo;
  202. }
  203. /**
  204. * Returns a command object to execute a {@code Commit} command
  205. *
  206. * @see <a
  207. * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
  208. * >Git documentation about Commit</a>
  209. * @return a {@link CommitCommand} used to collect all optional parameters
  210. * and to finally execute the {@code Commit} command
  211. */
  212. public CommitCommand commit() {
  213. return new CommitCommand(repo);
  214. }
  215. /**
  216. * Returns a command object to execute a {@code Log} command
  217. *
  218. * @see <a
  219. * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
  220. * >Git documentation about Log</a>
  221. * @return a {@link LogCommand} used to collect all optional parameters and
  222. * to finally execute the {@code Log} command
  223. */
  224. public LogCommand log() {
  225. return new LogCommand(repo);
  226. }
  227. /**
  228. * Returns a command object to execute a {@code Merge} command
  229. *
  230. * @see <a
  231. * href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
  232. * >Git documentation about Merge</a>
  233. * @return a {@link MergeCommand} used to collect all optional parameters
  234. * and to finally execute the {@code Merge} command
  235. */
  236. public MergeCommand merge() {
  237. return new MergeCommand(repo);
  238. }
  239. /**
  240. * Returns a command object to execute a {@code Pull} command
  241. *
  242. * @return a {@link PullCommand}
  243. */
  244. public PullCommand pull() {
  245. return new PullCommand(repo);
  246. }
  247. /**
  248. * Returns a command object used to create branches
  249. *
  250. * @return a {@link CreateBranchCommand}
  251. */
  252. public CreateBranchCommand branchCreate() {
  253. return new CreateBranchCommand(repo);
  254. }
  255. /**
  256. * Returns a command object used to delete branches
  257. *
  258. * @return a {@link DeleteBranchCommand}
  259. */
  260. public DeleteBranchCommand branchDelete() {
  261. return new DeleteBranchCommand(repo);
  262. }
  263. /**
  264. * Returns a command object used to list branches
  265. *
  266. * @return a {@link ListBranchCommand}
  267. */
  268. public ListBranchCommand branchList() {
  269. return new ListBranchCommand(repo);
  270. }
  271. /**
  272. *
  273. * Returns a command object used to list tags
  274. *
  275. * @return a {@link ListTagCommand}
  276. */
  277. public ListTagCommand tagList() {
  278. return new ListTagCommand(repo);
  279. }
  280. /**
  281. * Returns a command object used to rename branches
  282. *
  283. * @return a {@link RenameBranchCommand}
  284. */
  285. public RenameBranchCommand branchRename() {
  286. return new RenameBranchCommand(repo);
  287. }
  288. /**
  289. * Returns a command object to execute a {@code Add} command
  290. *
  291. * @see <a
  292. * href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html"
  293. * >Git documentation about Add</a>
  294. * @return a {@link AddCommand} used to collect all optional parameters and
  295. * to finally execute the {@code Add} command
  296. */
  297. public AddCommand add() {
  298. return new AddCommand(repo);
  299. }
  300. /**
  301. * Returns a command object to execute a {@code Tag} command
  302. *
  303. * @see <a
  304. * href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html"
  305. * >Git documentation about Tag</a>
  306. * @return a {@link TagCommand} used to collect all optional parameters and
  307. * to finally execute the {@code Tag} command
  308. */
  309. public TagCommand tag() {
  310. return new TagCommand(repo);
  311. }
  312. /**
  313. * Returns a command object to execute a {@code Fetch} command
  314. *
  315. * @see <a
  316. * href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html"
  317. * >Git documentation about Fetch</a>
  318. * @return a {@link FetchCommand} used to collect all optional parameters
  319. * and to finally execute the {@code Fetch} command
  320. */
  321. public FetchCommand fetch() {
  322. return new FetchCommand(repo);
  323. }
  324. /**
  325. * Returns a command object to execute a {@code Push} command
  326. *
  327. * @see <a
  328. * href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html"
  329. * >Git documentation about Push</a>
  330. * @return a {@link PushCommand} used to collect all optional parameters and
  331. * to finally execute the {@code Push} command
  332. */
  333. public PushCommand push() {
  334. return new PushCommand(repo);
  335. }
  336. /**
  337. * Returns a command object to execute a {@code cherry-pick} command
  338. *
  339. * @see <a
  340. * href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html"
  341. * >Git documentation about cherry-pick</a>
  342. * @return a {@link CherryPickCommand} used to collect all optional
  343. * parameters and to finally execute the {@code cherry-pick} command
  344. */
  345. public CherryPickCommand cherryPick() {
  346. return new CherryPickCommand(repo);
  347. }
  348. /**
  349. * Returns a command object to execute a {@code revert} command
  350. *
  351. * @see <a
  352. * href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html"
  353. * >Git documentation about reverting changes</a>
  354. * @return a {@link RevertCommand} used to collect all optional parameters
  355. * and to finally execute the {@code cherry-pick} command
  356. */
  357. public RevertCommand revert() {
  358. return new RevertCommand(repo);
  359. }
  360. /**
  361. * Returns a command object to execute a {@code Rebase} command
  362. *
  363. * @see <a
  364. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html"
  365. * >Git documentation about rebase</a>
  366. * @return a {@link RebaseCommand} used to collect all optional parameters
  367. * and to finally execute the {@code rebase} command
  368. */
  369. public RebaseCommand rebase() {
  370. return new RebaseCommand(repo);
  371. }
  372. /**
  373. * Returns a command object to execute a {@code rm} command
  374. *
  375. * @see <a
  376. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html"
  377. * >Git documentation about rm</a>
  378. * @return a {@link RmCommand} used to collect all optional parameters and
  379. * to finally execute the {@code rm} command
  380. */
  381. public RmCommand rm() {
  382. return new RmCommand(repo);
  383. }
  384. /**
  385. * Returns a command object to execute a {@code checkout} command
  386. *
  387. * @see <a
  388. * href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
  389. * >Git documentation about checkout</a>
  390. * @return a {@link CheckoutCommand} used to collect all optional parameters
  391. * and to finally execute the {@code checkout} command
  392. */
  393. public CheckoutCommand checkout() {
  394. return new CheckoutCommand(repo);
  395. }
  396. /**
  397. * Returns a command object to execute a {@code reset} command
  398. *
  399. * @see <a
  400. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html"
  401. * >Git documentation about reset</a>
  402. * @return a {@link ResetCommand} used to collect all optional parameters
  403. * and to finally execute the {@code reset} command
  404. */
  405. public ResetCommand reset() {
  406. return new ResetCommand(repo);
  407. }
  408. /**
  409. * Returns a command object to execute a {@code status} command
  410. *
  411. * @see <a
  412. * href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html"
  413. * >Git documentation about status</a>
  414. * @return a {@link StatusCommand} used to collect all optional parameters
  415. * and to finally execute the {@code status} command
  416. */
  417. public StatusCommand status() {
  418. return new StatusCommand(repo);
  419. }
  420. /**
  421. * Returns a command to create an archive from a tree
  422. *
  423. * @return a {@link ArchiveCommand}
  424. * @since 3.1
  425. */
  426. public ArchiveCommand archive() {
  427. return new ArchiveCommand(repo);
  428. }
  429. /**
  430. * Returns a command to add notes to an object
  431. *
  432. * @return a {@link AddNoteCommand}
  433. */
  434. public AddNoteCommand notesAdd() {
  435. return new AddNoteCommand(repo);
  436. }
  437. /**
  438. * Returns a command to remove notes on an object
  439. *
  440. * @return a {@link RemoveNoteCommand}
  441. */
  442. public RemoveNoteCommand notesRemove() {
  443. return new RemoveNoteCommand(repo);
  444. }
  445. /**
  446. * Returns a command to list all notes
  447. *
  448. * @return a {@link ListNotesCommand}
  449. */
  450. public ListNotesCommand notesList() {
  451. return new ListNotesCommand(repo);
  452. }
  453. /**
  454. * Returns a command to show notes on an object
  455. *
  456. * @return a {@link ShowNoteCommand}
  457. */
  458. public ShowNoteCommand notesShow() {
  459. return new ShowNoteCommand(repo);
  460. }
  461. /**
  462. * Returns a command object to execute a {@code ls-remote} command
  463. *
  464. * @see <a
  465. * href="http://www.kernel.org/pub/software/scm/git/docs/git-ls-remote.html"
  466. * >Git documentation about ls-remote</a>
  467. * @return a {@link LsRemoteCommand} used to collect all optional parameters
  468. * and to finally execute the {@code status} command
  469. */
  470. public LsRemoteCommand lsRemote() {
  471. return new LsRemoteCommand(repo);
  472. }
  473. /**
  474. * Returns a command object to execute a {@code clean} command
  475. *
  476. * @see <a
  477. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clean.html"
  478. * >Git documentation about Clean</a>
  479. * @return a {@link CleanCommand} used to collect all optional parameters
  480. * and to finally execute the {@code clean} command
  481. */
  482. public CleanCommand clean() {
  483. return new CleanCommand(repo);
  484. }
  485. /**
  486. * Returns a command object to execute a {@code blame} command
  487. *
  488. * @see <a
  489. * href="http://www.kernel.org/pub/software/scm/git/docs/git-blame.html"
  490. * >Git documentation about Blame</a>
  491. * @return a {@link BlameCommand} used to collect all optional parameters
  492. * and to finally execute the {@code blame} command
  493. */
  494. public BlameCommand blame() {
  495. return new BlameCommand(repo);
  496. }
  497. /**
  498. * Returns a command object to execute a {@code reflog} command
  499. *
  500. * @see <a
  501. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reflog.html"
  502. * >Git documentation about reflog</a>
  503. * @return a {@link ReflogCommand} used to collect all optional parameters
  504. * and to finally execute the {@code reflog} command
  505. */
  506. public ReflogCommand reflog() {
  507. return new ReflogCommand(repo);
  508. }
  509. /**
  510. * Returns a command object to execute a {@code diff} command
  511. *
  512. * @see <a
  513. * href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html"
  514. * >Git documentation about diff</a>
  515. * @return a {@link DiffCommand} used to collect all optional parameters and
  516. * to finally execute the {@code diff} command
  517. */
  518. public DiffCommand diff() {
  519. return new DiffCommand(repo);
  520. }
  521. /**
  522. * Returns a command object used to delete tags
  523. *
  524. * @return a {@link DeleteTagCommand}
  525. */
  526. public DeleteTagCommand tagDelete() {
  527. return new DeleteTagCommand(repo);
  528. }
  529. /**
  530. * Returns a command object to execute a {@code submodule add} command
  531. *
  532. * @return a {@link SubmoduleAddCommand} used to add a new submodule to a
  533. * parent repository
  534. */
  535. public SubmoduleAddCommand submoduleAdd() {
  536. return new SubmoduleAddCommand(repo);
  537. }
  538. /**
  539. * Returns a command object to execute a {@code submodule init} command
  540. *
  541. * @return a {@link SubmoduleInitCommand} used to initialize the
  542. * repository's config with settings from the .gitmodules file in
  543. * the working tree
  544. */
  545. public SubmoduleInitCommand submoduleInit() {
  546. return new SubmoduleInitCommand(repo);
  547. }
  548. /**
  549. * Returns a command object to execute a {@code submodule status} command
  550. *
  551. * @return a {@link SubmoduleStatusCommand} used to report the status of a
  552. * repository's configured submodules
  553. */
  554. public SubmoduleStatusCommand submoduleStatus() {
  555. return new SubmoduleStatusCommand(repo);
  556. }
  557. /**
  558. * Returns a command object to execute a {@code submodule sync} command
  559. *
  560. * @return a {@link SubmoduleSyncCommand} used to update the URL of a
  561. * submodule from the parent repository's .gitmodules file
  562. */
  563. public SubmoduleSyncCommand submoduleSync() {
  564. return new SubmoduleSyncCommand(repo);
  565. }
  566. /**
  567. * Returns a command object to execute a {@code submodule update} command
  568. *
  569. * @return a {@link SubmoduleUpdateCommand} used to update the submodules in
  570. * a repository to the configured revision
  571. */
  572. public SubmoduleUpdateCommand submoduleUpdate() {
  573. return new SubmoduleUpdateCommand(repo);
  574. }
  575. /**
  576. * Returns a command object used to list stashed commits
  577. *
  578. * @return a {@link StashListCommand}
  579. */
  580. public StashListCommand stashList() {
  581. return new StashListCommand(repo);
  582. }
  583. /**
  584. * Returns a command object used to create a stashed commit
  585. *
  586. * @return a {@link StashCreateCommand}
  587. * @since 2.0
  588. */
  589. public StashCreateCommand stashCreate() {
  590. return new StashCreateCommand(repo);
  591. }
  592. /**
  593. * Returns a command object used to apply a stashed commit
  594. *
  595. * @return a {@link StashApplyCommand}
  596. * @since 2.0
  597. */
  598. public StashApplyCommand stashApply() {
  599. return new StashApplyCommand(repo);
  600. }
  601. /**
  602. * Returns a command object used to drop a stashed commit
  603. *
  604. * @return a {@link StashDropCommand}
  605. * @since 2.0
  606. */
  607. public StashDropCommand stashDrop() {
  608. return new StashDropCommand(repo);
  609. }
  610. /**
  611. * Returns a command object to execute a {@code apply} command
  612. *
  613. * @see <a
  614. * href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html"
  615. * >Git documentation about apply</a>
  616. *
  617. * @return a {@link ApplyCommand} used to collect all optional parameters
  618. * and to finally execute the {@code apply} command
  619. * @since 2.0
  620. */
  621. public ApplyCommand apply() {
  622. return new ApplyCommand(repo);
  623. }
  624. /**
  625. * Returns a command object to execute a {@code gc} command
  626. *
  627. * @see <a
  628. * href="http://www.kernel.org/pub/software/scm/git/docs/git-gc.html"
  629. * >Git documentation about gc</a>
  630. *
  631. * @return a {@link GarbageCollectCommand} used to collect all optional
  632. * parameters and to finally execute the {@code gc} command
  633. * @since 2.2
  634. */
  635. public GarbageCollectCommand gc() {
  636. return new GarbageCollectCommand(repo);
  637. }
  638. /**
  639. * Returns a command object to find human-readable names of revisions.
  640. *
  641. * @return a {@link NameRevCommand}.
  642. * @since 3.0
  643. */
  644. public NameRevCommand nameRev() {
  645. return new NameRevCommand(repo);
  646. }
  647. /**
  648. * Returns a command object to come up with a short name that describes a
  649. * commit in terms of the nearest git tag.
  650. *
  651. * @return a {@link DescribeCommand}.
  652. * @since 3.2
  653. */
  654. public DescribeCommand describe() {
  655. return new DescribeCommand(repo);
  656. }
  657. /**
  658. * Return a command used to list the available remotes.
  659. *
  660. * @return a {@link RemoteListCommand}
  661. * @since 4.2
  662. */
  663. public RemoteListCommand remoteList() {
  664. return new RemoteListCommand(repo);
  665. }
  666. /**
  667. * Return a command used to add a new remote.
  668. *
  669. * @return a {@link RemoteAddCommand}
  670. * @since 4.2
  671. */
  672. public RemoteAddCommand remoteAdd() {
  673. return new RemoteAddCommand(repo);
  674. }
  675. /**
  676. * Return a command used to remove an existing remote.
  677. *
  678. * @return a {@link RemoteRemoveCommand}
  679. * @since 4.2
  680. */
  681. public RemoteRemoveCommand remoteRemove() {
  682. return new RemoteRemoveCommand(repo);
  683. }
  684. /**
  685. * Return a command used to change the URL of an existing remote.
  686. *
  687. * @return a {@link RemoteSetUrlCommand}
  688. * @since 4.2
  689. */
  690. public RemoteSetUrlCommand remoteSetUrl() {
  691. return new RemoteSetUrlCommand(repo);
  692. }
  693. /**
  694. * @return the git repository this class is interacting with; see
  695. * {@link #close()} for notes on closing this repository.
  696. */
  697. public Repository getRepository() {
  698. return repo;
  699. }
  700. @Override
  701. public String toString() {
  702. return "Git[" + repo + "]"; //$NON-NLS-1$//$NON-NLS-2$
  703. }
  704. }