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

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