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

blame: Compute the origin of lines in a result file BlameGenerator digs through history and discovers the origin of each line of some result file. BlameResult consumes the stream of regions created by the generator and lays them out in a table for applications to display alongside of source lines. Applications may optionally push in the working tree copy of a file using the push(String, byte[]) method, allowing the application to receive accurate line annotations for the working tree version. Lines that are uncommitted (difference between HEAD and working tree) will show up with the description given by the application as the author, or "Not Committed Yet" as a default string. Applications may also run the BlameGenerator in reverse mode using the reverse(AnyObjectId, AnyObjectId) method instead of push(). When running in the reverse mode the generator annotates lines by the commit they are removed in, rather than the commit they were added in. This allows a user to discover where a line disappeared from when they are looking at an older revision in the repository. For example: blame --reverse 16e810b2..master -L 1080, org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefDirectoryTest.java ( 1080) } 2302a6d3 (Christian Halstrick 2011-05-20 11:18:20 +0200 1081) 2302a6d3 (Christian Halstrick 2011-05-20 11:18:20 +0200 1082) /** 2302a6d3 (Christian Halstrick 2011-05-20 11:18:20 +0200 1083) * Kick the timestamp of a local file. Above we learn that line 1080 (a closing curly brace of the prior method) still exists in branch master, but the Javadoc comment below it has been removed by Christian Halstrick on May 20th as part of commit 2302a6d3. This result differs considerably from that of C Git's blame --reverse feature. JGit tells the reader which commit performed the delete, while C Git tells the reader the last commit that still contained the line, leaving it an exercise to the reader to discover the descendant that performed the removal. This is still only a basic implementation. Quite notably it is missing support for the smart block copy/move detection that the C implementation of `git blame` is well known for. Despite being incremental, the BlameGenerator can only be run once. After the generator runs it cannot be reused. A better implementation would support applications browsing through history efficiently. In regards to CQ 5110, only a little of the original code survives. CQ: 5110 Bug: 306161 Change-Id: I84b8ea4838bb7d25f4fcdd540547884704661b8f Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
13 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  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 {
  83. /** The git repository this class is interacting with */
  84. private final Repository repo;
  85. /**
  86. * @param dir
  87. * the repository to open. May be either the GIT_DIR, or the
  88. * working tree directory that contains {@code .git}.
  89. * @return a {@link Git} object for the existing git repository
  90. * @throws IOException
  91. */
  92. public static Git open(File dir) throws IOException {
  93. return open(dir, FS.DETECTED);
  94. }
  95. /**
  96. * @param dir
  97. * the repository to open. May be either the GIT_DIR, or the
  98. * working tree directory that contains {@code .git}.
  99. * @param fs
  100. * filesystem abstraction to use when accessing the repository.
  101. * @return a {@link Git} object for the existing git repository
  102. * @throws IOException
  103. */
  104. public static Git open(File dir, FS fs) throws IOException {
  105. RepositoryCache.FileKey key;
  106. key = RepositoryCache.FileKey.lenient(dir, fs);
  107. return wrap(new RepositoryBuilder().setFS(fs).setGitDir(key.getFile())
  108. .setMustExist(true).build());
  109. }
  110. /**
  111. * @param repo
  112. * the git repository this class is interacting with.
  113. * {@code null} is not allowed
  114. * @return a {@link Git} object for the existing git repository
  115. */
  116. public static Git wrap(Repository repo) {
  117. return new Git(repo);
  118. }
  119. /**
  120. * Frees resources held by the underlying {@link Repository} instance. It is
  121. * recommended to call this method as soon as you don't need a reference to
  122. * this {@link Git} instance and the underlying {@link Repository} instance
  123. * anymore. This method closes the underlying object and ref databases. This
  124. * will free memory and file handles. E.g. on Windows the repository will
  125. * keep file handles on pack files unless you call this method. Such open
  126. * file handles may for example prevent that the repository folder in the
  127. * filesystem can be deleted.
  128. * <p>
  129. * After calling close() you should not use this {@link Git} instance and
  130. * the underlying {@link Repository} instance anymore.
  131. *
  132. * @since 3.2
  133. */
  134. public void close() {
  135. if (repo != null)
  136. repo.close();
  137. }
  138. /**
  139. * Returns a command object to execute a {@code clone} command
  140. *
  141. * @see <a
  142. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html"
  143. * >Git documentation about clone</a>
  144. * @return a {@link CloneCommand} used to collect all optional parameters
  145. * and to finally execute the {@code clone} command
  146. */
  147. public static CloneCommand cloneRepository() {
  148. return new CloneCommand();
  149. }
  150. /**
  151. * Returns a command to list remote branches/tags without a local
  152. * repository.
  153. *
  154. * @return a {@link LsRemoteCommand}
  155. * @since 3.1
  156. */
  157. public static LsRemoteCommand lsRemoteRepository() {
  158. return new LsRemoteCommand(null);
  159. }
  160. /**
  161. * Returns a command object to execute a {@code init} command
  162. *
  163. * @see <a
  164. * href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html"
  165. * >Git documentation about init</a>
  166. * @return a {@link InitCommand} used to collect all optional parameters and
  167. * to finally execute the {@code init} command
  168. */
  169. public static InitCommand init() {
  170. return new InitCommand();
  171. }
  172. /**
  173. * Constructs a new {@link Git} object which can interact with the specified
  174. * git repository. All command classes returned by methods of this class
  175. * will always interact with this git repository.
  176. *
  177. * @param repo
  178. * the git repository this class is interacting with.
  179. * {@code null} is not allowed
  180. */
  181. public Git(Repository repo) {
  182. if (repo == null)
  183. throw new NullPointerException();
  184. this.repo = repo;
  185. }
  186. /**
  187. * Returns a command object to execute a {@code Commit} command
  188. *
  189. * @see <a
  190. * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
  191. * >Git documentation about Commit</a>
  192. * @return a {@link CommitCommand} used to collect all optional parameters
  193. * and to finally execute the {@code Commit} command
  194. */
  195. public CommitCommand commit() {
  196. return new CommitCommand(repo);
  197. }
  198. /**
  199. * Returns a command object to execute a {@code Log} command
  200. *
  201. * @see <a
  202. * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
  203. * >Git documentation about Log</a>
  204. * @return a {@link LogCommand} used to collect all optional parameters and
  205. * to finally execute the {@code Log} command
  206. */
  207. public LogCommand log() {
  208. return new LogCommand(repo);
  209. }
  210. /**
  211. * Returns a command object to execute a {@code Merge} command
  212. *
  213. * @see <a
  214. * href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
  215. * >Git documentation about Merge</a>
  216. * @return a {@link MergeCommand} used to collect all optional parameters
  217. * and to finally execute the {@code Merge} command
  218. */
  219. public MergeCommand merge() {
  220. return new MergeCommand(repo);
  221. }
  222. /**
  223. * Returns a command object to execute a {@code Pull} command
  224. *
  225. * @return a {@link PullCommand}
  226. */
  227. public PullCommand pull() {
  228. return new PullCommand(repo);
  229. }
  230. /**
  231. * Returns a command object used to create branches
  232. *
  233. * @return a {@link CreateBranchCommand}
  234. */
  235. public CreateBranchCommand branchCreate() {
  236. return new CreateBranchCommand(repo);
  237. }
  238. /**
  239. * Returns a command object used to delete branches
  240. *
  241. * @return a {@link DeleteBranchCommand}
  242. */
  243. public DeleteBranchCommand branchDelete() {
  244. return new DeleteBranchCommand(repo);
  245. }
  246. /**
  247. * Returns a command object used to list branches
  248. *
  249. * @return a {@link ListBranchCommand}
  250. */
  251. public ListBranchCommand branchList() {
  252. return new ListBranchCommand(repo);
  253. }
  254. /**
  255. *
  256. * Returns a command object used to list tags
  257. *
  258. * @return a {@link ListTagCommand}
  259. */
  260. public ListTagCommand tagList() {
  261. return new ListTagCommand(repo);
  262. }
  263. /**
  264. * Returns a command object used to rename branches
  265. *
  266. * @return a {@link RenameBranchCommand}
  267. */
  268. public RenameBranchCommand branchRename() {
  269. return new RenameBranchCommand(repo);
  270. }
  271. /**
  272. * Returns a command object to execute a {@code Add} command
  273. *
  274. * @see <a
  275. * href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html"
  276. * >Git documentation about Add</a>
  277. * @return a {@link AddCommand} used to collect all optional parameters and
  278. * to finally execute the {@code Add} command
  279. */
  280. public AddCommand add() {
  281. return new AddCommand(repo);
  282. }
  283. /**
  284. * Returns a command object to execute a {@code Tag} command
  285. *
  286. * @see <a
  287. * href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html"
  288. * >Git documentation about Tag</a>
  289. * @return a {@link TagCommand} used to collect all optional parameters and
  290. * to finally execute the {@code Tag} command
  291. */
  292. public TagCommand tag() {
  293. return new TagCommand(repo);
  294. }
  295. /**
  296. * Returns a command object to execute a {@code Fetch} command
  297. *
  298. * @see <a
  299. * href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html"
  300. * >Git documentation about Fetch</a>
  301. * @return a {@link FetchCommand} used to collect all optional parameters
  302. * and to finally execute the {@code Fetch} command
  303. */
  304. public FetchCommand fetch() {
  305. return new FetchCommand(repo);
  306. }
  307. /**
  308. * Returns a command object to execute a {@code Push} command
  309. *
  310. * @see <a
  311. * href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html"
  312. * >Git documentation about Push</a>
  313. * @return a {@link PushCommand} used to collect all optional parameters and
  314. * to finally execute the {@code Push} command
  315. */
  316. public PushCommand push() {
  317. return new PushCommand(repo);
  318. }
  319. /**
  320. * Returns a command object to execute a {@code cherry-pick} command
  321. *
  322. * @see <a
  323. * href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html"
  324. * >Git documentation about cherry-pick</a>
  325. * @return a {@link CherryPickCommand} used to collect all optional
  326. * parameters and to finally execute the {@code cherry-pick} command
  327. */
  328. public CherryPickCommand cherryPick() {
  329. return new CherryPickCommand(repo);
  330. }
  331. /**
  332. * Returns a command object to execute a {@code revert} command
  333. *
  334. * @see <a
  335. * href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html"
  336. * >Git documentation about reverting changes</a>
  337. * @return a {@link RevertCommand} used to collect all optional parameters
  338. * and to finally execute the {@code cherry-pick} command
  339. */
  340. public RevertCommand revert() {
  341. return new RevertCommand(repo);
  342. }
  343. /**
  344. * Returns a command object to execute a {@code Rebase} command
  345. *
  346. * @see <a
  347. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html"
  348. * >Git documentation about rebase</a>
  349. * @return a {@link RebaseCommand} used to collect all optional parameters
  350. * and to finally execute the {@code rebase} command
  351. */
  352. public RebaseCommand rebase() {
  353. return new RebaseCommand(repo);
  354. }
  355. /**
  356. * Returns a command object to execute a {@code rm} command
  357. *
  358. * @see <a
  359. * href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html"
  360. * >Git documentation about rm</a>
  361. * @return a {@link RmCommand} used to collect all optional parameters and
  362. * to finally execute the {@code rm} command
  363. */
  364. public RmCommand rm() {
  365. return new RmCommand(repo);
  366. }
  367. /**
  368. * Returns a command object to execute a {@code checkout} command
  369. *
  370. * @see <a
  371. * href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
  372. * >Git documentation about checkout</a>
  373. * @return a {@link CheckoutCommand} used to collect all optional parameters
  374. * and to finally execute the {@code checkout} command
  375. */
  376. public CheckoutCommand checkout() {
  377. return new CheckoutCommand(repo);
  378. }
  379. /**
  380. * Returns a command object to execute a {@code reset} command
  381. *
  382. * @see <a
  383. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html"
  384. * >Git documentation about reset</a>
  385. * @return a {@link ResetCommand} used to collect all optional parameters
  386. * and to finally execute the {@code reset} command
  387. */
  388. public ResetCommand reset() {
  389. return new ResetCommand(repo);
  390. }
  391. /**
  392. * Returns a command object to execute a {@code status} command
  393. *
  394. * @see <a
  395. * href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html"
  396. * >Git documentation about status</a>
  397. * @return a {@link StatusCommand} used to collect all optional parameters
  398. * and to finally execute the {@code status} command
  399. */
  400. public StatusCommand status() {
  401. return new StatusCommand(repo);
  402. }
  403. /**
  404. * Returns a command to create an archive from a tree
  405. *
  406. * @return a {@link ArchiveCommand}
  407. * @since 3.1
  408. */
  409. public ArchiveCommand archive() {
  410. return new ArchiveCommand(repo);
  411. }
  412. /**
  413. * Returns a command to add notes to an object
  414. *
  415. * @return a {@link AddNoteCommand}
  416. */
  417. public AddNoteCommand notesAdd() {
  418. return new AddNoteCommand(repo);
  419. }
  420. /**
  421. * Returns a command to remove notes on an object
  422. *
  423. * @return a {@link RemoveNoteCommand}
  424. */
  425. public RemoveNoteCommand notesRemove() {
  426. return new RemoveNoteCommand(repo);
  427. }
  428. /**
  429. * Returns a command to list all notes
  430. *
  431. * @return a {@link ListNotesCommand}
  432. */
  433. public ListNotesCommand notesList() {
  434. return new ListNotesCommand(repo);
  435. }
  436. /**
  437. * Returns a command to show notes on an object
  438. *
  439. * @return a {@link ShowNoteCommand}
  440. */
  441. public ShowNoteCommand notesShow() {
  442. return new ShowNoteCommand(repo);
  443. }
  444. /**
  445. * Returns a command object to execute a {@code ls-remote} command
  446. *
  447. * @see <a
  448. * href="http://www.kernel.org/pub/software/scm/git/docs/git-ls-remote.html"
  449. * >Git documentation about ls-remote</a>
  450. * @return a {@link LsRemoteCommand} used to collect all optional parameters
  451. * and to finally execute the {@code status} command
  452. */
  453. public LsRemoteCommand lsRemote() {
  454. return new LsRemoteCommand(repo);
  455. }
  456. /**
  457. * Returns a command object to execute a {@code clean} command
  458. *
  459. * @see <a
  460. * href="http://www.kernel.org/pub/software/scm/git/docs/git-clean.html"
  461. * >Git documentation about Clean</a>
  462. * @return a {@link CleanCommand} used to collect all optional parameters
  463. * and to finally execute the {@code clean} command
  464. */
  465. public CleanCommand clean() {
  466. return new CleanCommand(repo);
  467. }
  468. /**
  469. * Returns a command object to execute a {@code blame} command
  470. *
  471. * @see <a
  472. * href="http://www.kernel.org/pub/software/scm/git/docs/git-blame.html"
  473. * >Git documentation about Blame</a>
  474. * @return a {@link BlameCommand} used to collect all optional parameters
  475. * and to finally execute the {@code blame} command
  476. */
  477. public BlameCommand blame() {
  478. return new BlameCommand(repo);
  479. }
  480. /**
  481. * Returns a command object to execute a {@code reflog} command
  482. *
  483. * @see <a
  484. * href="http://www.kernel.org/pub/software/scm/git/docs/git-reflog.html"
  485. * >Git documentation about reflog</a>
  486. * @return a {@link ReflogCommand} used to collect all optional parameters
  487. * and to finally execute the {@code reflog} command
  488. */
  489. public ReflogCommand reflog() {
  490. return new ReflogCommand(repo);
  491. }
  492. /**
  493. * Returns a command object to execute a {@code diff} command
  494. *
  495. * @see <a
  496. * href="http://www.kernel.org/pub/software/scm/git/docs/git-diff.html"
  497. * >Git documentation about diff</a>
  498. * @return a {@link DiffCommand} used to collect all optional parameters and
  499. * to finally execute the {@code diff} command
  500. */
  501. public DiffCommand diff() {
  502. return new DiffCommand(repo);
  503. }
  504. /**
  505. * Returns a command object used to delete tags
  506. *
  507. * @return a {@link DeleteTagCommand}
  508. */
  509. public DeleteTagCommand tagDelete() {
  510. return new DeleteTagCommand(repo);
  511. }
  512. /**
  513. * Returns a command object to execute a {@code submodule add} command
  514. *
  515. * @return a {@link SubmoduleAddCommand} used to add a new submodule to a
  516. * parent repository
  517. */
  518. public SubmoduleAddCommand submoduleAdd() {
  519. return new SubmoduleAddCommand(repo);
  520. }
  521. /**
  522. * Returns a command object to execute a {@code submodule init} command
  523. *
  524. * @return a {@link SubmoduleInitCommand} used to initialize the
  525. * repository's config with settings from the .gitmodules file in
  526. * the working tree
  527. */
  528. public SubmoduleInitCommand submoduleInit() {
  529. return new SubmoduleInitCommand(repo);
  530. }
  531. /**
  532. * Returns a command object to execute a {@code submodule status} command
  533. *
  534. * @return a {@link SubmoduleStatusCommand} used to report the status of a
  535. * repository's configured submodules
  536. */
  537. public SubmoduleStatusCommand submoduleStatus() {
  538. return new SubmoduleStatusCommand(repo);
  539. }
  540. /**
  541. * Returns a command object to execute a {@code submodule sync} command
  542. *
  543. * @return a {@link SubmoduleSyncCommand} used to update the URL of a
  544. * submodule from the parent repository's .gitmodules file
  545. */
  546. public SubmoduleSyncCommand submoduleSync() {
  547. return new SubmoduleSyncCommand(repo);
  548. }
  549. /**
  550. * Returns a command object to execute a {@code submodule update} command
  551. *
  552. * @return a {@link SubmoduleUpdateCommand} used to update the submodules in
  553. * a repository to the configured revision
  554. */
  555. public SubmoduleUpdateCommand submoduleUpdate() {
  556. return new SubmoduleUpdateCommand(repo);
  557. }
  558. /**
  559. * Returns a command object used to list stashed commits
  560. *
  561. * @return a {@link StashListCommand}
  562. */
  563. public StashListCommand stashList() {
  564. return new StashListCommand(repo);
  565. }
  566. /**
  567. * Returns a command object used to create a stashed commit
  568. *
  569. * @return a {@link StashCreateCommand}
  570. * @since 2.0
  571. */
  572. public StashCreateCommand stashCreate() {
  573. return new StashCreateCommand(repo);
  574. }
  575. /**
  576. * Returns a command object used to apply a stashed commit
  577. *
  578. * @return a {@link StashApplyCommand}
  579. * @since 2.0
  580. */
  581. public StashApplyCommand stashApply() {
  582. return new StashApplyCommand(repo);
  583. }
  584. /**
  585. * Returns a command object used to drop a stashed commit
  586. *
  587. * @return a {@link StashDropCommand}
  588. * @since 2.0
  589. */
  590. public StashDropCommand stashDrop() {
  591. return new StashDropCommand(repo);
  592. }
  593. /**
  594. * Returns a command object to execute a {@code apply} command
  595. *
  596. * @see <a
  597. * href="http://www.kernel.org/pub/software/scm/git/docs/git-apply.html"
  598. * >Git documentation about apply</a>
  599. *
  600. * @return a {@link ApplyCommand} used to collect all optional parameters
  601. * and to finally execute the {@code apply} command
  602. * @since 2.0
  603. */
  604. public ApplyCommand apply() {
  605. return new ApplyCommand(repo);
  606. }
  607. /**
  608. * Returns a command object to execute a {@code gc} command
  609. *
  610. * @see <a
  611. * href="http://www.kernel.org/pub/software/scm/git/docs/git-gc.html"
  612. * >Git documentation about gc</a>
  613. *
  614. * @return a {@link GarbageCollectCommand} used to collect all optional
  615. * parameters and to finally execute the {@code gc} command
  616. * @since 2.2
  617. */
  618. public GarbageCollectCommand gc() {
  619. return new GarbageCollectCommand(repo);
  620. }
  621. /**
  622. * Returns a command object to find human-readable names of revisions.
  623. *
  624. * @return a {@link NameRevCommand}.
  625. * @since 3.0
  626. */
  627. public NameRevCommand nameRev() {
  628. return new NameRevCommand(repo);
  629. }
  630. /**
  631. * Returns a command object to come up with a short name that describes a
  632. * commit in terms of the nearest git tag.
  633. *
  634. * @return a {@link DescribeCommand}.
  635. * @since 3.2
  636. */
  637. public DescribeCommand describe() {
  638. return new DescribeCommand(repo);
  639. }
  640. /**
  641. * @return the git repository this class is interacting with
  642. */
  643. public Repository getRepository() {
  644. return repo;
  645. }
  646. }