Add a merge command to the jgit API
[jgit.git] / org.eclipse.jgit / src / org / eclipse / jgit / api / Git.java
blob28946e5fe701c07f1d098ac1aebab9fcfa258005
1 /*
2 * Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com>
3 * and other copyright owners as documented in the project's IP log.
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 package org.eclipse.jgit.api;
45 import org.eclipse.jgit.lib.Repository;
47 /**
48 * Offers a "GitPorcelain"-like API to interact with a git repository.
49 * <p>
50 * The GitPorcelain commands are described in the <a href="http://www.kernel.org/pub/software/scm/git/docs/git.html#_high_level_commands_porcelain"
51 * >Git Documentation</a>.
52 * <p>
53 * This class only offers methods to construct so-called command classes. Each
54 * GitPorcelain command is represented by one command class.<br>
55 * Example: this class offers a {@code commit()} method returning an instance of
56 * the {@code CommitCommand} class. The {@code CommitCommand} class has setters
57 * for all the arguments and options. The {@code CommitCommand} class also has a
58 * {@code call} method to actually execute the commit. The following code show's
59 * how to do a simple commit:
61 * <pre>
62 * Git git = new Git(myRepo);
63 * git.commit().setMessage(&quot;Fix393&quot;).setAuthor(developerIdent).call();
64 * </pre>
66 * All mandatory parameters for commands have to be specified in the methods of
67 * this class, the optional parameters have to be specified by the
68 * setter-methods of the Command class.
69 * <p>
70 * This class is intended to be used internally (e.g. by JGit tests) or by
71 * external components (EGit, third-party tools) when they need exactly the
72 * functionality of a GitPorcelain command. There are use-cases where this class
73 * is not optimal and where you should use the more low-level JGit classes. The
74 * methods in this class may for example offer too much functionality or they
75 * offer the functionality with the wrong arguments.
77 public class Git {
78 /** The git repository this class is interacting with */
79 private final Repository repo;
81 /**
82 * Constructs a new {@link Git} class which can interact with the specified
83 * git repository. All command classes returned by methods of this class
84 * will always interact with this git repository.
86 * @param repo
87 * the git repository this class is interacting with.
88 * {@code null} is not allowed
90 public Git(Repository repo) {
91 if (repo == null)
92 throw new NullPointerException();
93 this.repo = repo;
96 /**
97 * Returns a command class to execute a {@code Commit} command
99 * @see <a
100 * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
101 * >Git documentation about Commit</a>
102 * @return a {@link CommitCommand} used to collect all optional parameters
103 * and to finally execute the {@code Commit} command
105 public CommitCommand commit() {
106 return new CommitCommand(repo);
110 * Returns a command class to execute a {@code Log} command
112 * @see <a
113 * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
114 * >Git documentation about Log</a>
115 * @return a {@link LogCommand} used to collect all optional parameters and
116 * to finally execute the {@code Log} command
118 public LogCommand log() {
119 return new LogCommand(repo);
123 * Returns a command class to execute a {@code Merge} command
125 * @see <a
126 * href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
127 * >Git documentation about Merge</a>
128 * @return a {@link MergeCommand} used to collect all optional parameters
129 * and to finally execute the {@code Merge} command
131 public MergeCommand merge() {
132 return new MergeCommand(repo);
136 * @return the git repository this class is interacting with
138 public Repository getRepository() {
139 return repo;