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