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