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