2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit'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
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
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
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.
52
/// <summary>Offers a "GitPorcelain"-like API to interact with a git repository.</summary>
54
/// Offers a "GitPorcelain"-like API to interact with a git repository.
56
/// The GitPorcelain commands are described in the <a href="http://www.kernel.org/pub/software/scm/git/docs/git.html#_high_level_commands_porcelain"
57
/// >Git Documentation</a>.
59
/// This class only offers methods to construct so-called command classes. Each
60
/// GitPorcelain command is represented by one command class.<br />
61
/// Example: this class offers a
62
/// <code>commit()</code>
63
/// method returning an instance of
65
/// <code>CommitCommand</code>
67
/// <code>CommitCommand</code>
69
/// for all the arguments and options. The
70
/// <code>CommitCommand</code>
73
/// method to actually execute the commit. The following code show's
74
/// how to do a simple commit:
76
/// Git git = new Git(myRepo);
77
/// git.commit().setMessage("Fix393").setAuthor(developerIdent).call();
79
/// All mandatory parameters for commands have to be specified in the methods of
80
/// this class, the optional parameters have to be specified by the
81
/// setter-methods of the Command class.
83
/// This class is intended to be used internally (e.g. by JGit tests) or by
84
/// external components (EGit, third-party tools) when they need exactly the
85
/// functionality of a GitPorcelain command. There are use-cases where this class
86
/// is not optimal and where you should use the more low-level JGit classes. The
87
/// methods in this class may for example offer too much functionality or they
88
/// offer the functionality with the wrong arguments.
92
/// <summary>The git repository this class is interacting with</summary>
93
private readonly Repository repo;
95
/// <param name="dir">
96
/// the repository to open. May be either the GIT_DIR, or the
97
/// working tree directory that contains
103
/// <see cref="Git">Git</see>
104
/// object for the existing git repository
106
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
107
public static NGit.Api.Git Open(FilePath dir)
109
return Open(dir, FS.DETECTED);
112
/// <param name="dir">
113
/// the repository to open. May be either the GIT_DIR, or the
114
/// working tree directory that contains
115
/// <code>.git</code>
118
/// <param name="fs">filesystem abstraction to use when accessing the repository.</param>
121
/// <see cref="Git">Git</see>
122
/// object for the existing git repository
124
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
125
public static NGit.Api.Git Open(FilePath dir, FS fs)
127
RepositoryCache.FileKey key;
128
key = RepositoryCache.FileKey.Lenient(dir, fs);
129
return Wrap(new RepositoryBuilder().SetFS(fs).SetGitDir(key.GetFile()).SetMustExist
133
/// <param name="repo">
134
/// the git repository this class is interacting with.
135
/// <code>null</code>
140
/// <see cref="Git">Git</see>
141
/// object for the existing git repository
143
public static NGit.Api.Git Wrap(Repository repo)
145
return new NGit.Api.Git(repo);
149
/// Returns a command object to execute a
150
/// <code>clone</code>
154
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html"
155
/// * >Git documentation about clone</a></seealso>
158
/// <see cref="CloneCommand">CloneCommand</see>
159
/// used to collect all optional parameters
160
/// and to finally execute the
161
/// <code>clone</code>
164
public static CloneCommand CloneRepository()
166
return new CloneCommand();
170
/// Returns a command object to execute a
171
/// <code>init</code>
175
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html"
176
/// * >Git documentation about init</a></seealso>
179
/// <see cref="InitCommand">InitCommand</see>
180
/// used to collect all optional parameters and
181
/// to finally execute the
182
/// <code>init</code>
185
public static InitCommand Init()
187
return new InitCommand();
192
/// <see cref="Git">Git</see>
193
/// object which can interact with the specified
194
/// git repository. All command classes returned by methods of this class
195
/// will always interact with this git repository.
197
/// <param name="repo">
198
/// the git repository this class is interacting with.
199
/// <code>null</code>
202
public Git(Repository repo)
206
throw new ArgumentNullException();
212
/// Returns a command object to execute a
213
/// <code>Commit</code>
217
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
218
/// * >Git documentation about Commit</a></seealso>
221
/// <see cref="CommitCommand">CommitCommand</see>
222
/// used to collect all optional parameters
223
/// and to finally execute the
224
/// <code>Commit</code>
227
public virtual CommitCommand Commit()
229
return new CommitCommand(repo);
233
/// Returns a command object to execute a
238
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
239
/// * >Git documentation about Log</a></seealso>
242
/// <see cref="LogCommand">LogCommand</see>
243
/// used to collect all optional parameters and
244
/// to finally execute the
248
public virtual LogCommand Log()
250
return new LogCommand(repo);
254
/// Returns a command object to execute a
255
/// <code>Merge</code>
259
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
260
/// * >Git documentation about Merge</a></seealso>
263
/// <see cref="MergeCommand">MergeCommand</see>
264
/// used to collect all optional parameters
265
/// and to finally execute the
266
/// <code>Merge</code>
269
public virtual MergeCommand Merge()
271
return new MergeCommand(repo);
275
/// Returns a command object to execute a
276
/// <code>Pull</code>
281
/// <see cref="PullCommand">PullCommand</see>
283
public virtual PullCommand Pull()
285
return new PullCommand(repo);
288
/// <summary>Returns a command object used to create branches</summary>
291
/// <see cref="CreateBranchCommand">CreateBranchCommand</see>
293
public virtual CreateBranchCommand BranchCreate()
295
return new CreateBranchCommand(repo);
298
/// <summary>Returns a command object used to delete branches</summary>
301
/// <see cref="DeleteBranchCommand">DeleteBranchCommand</see>
303
public virtual DeleteBranchCommand BranchDelete()
305
return new DeleteBranchCommand(repo);
308
/// <summary>Returns a command object used to list branches</summary>
311
/// <see cref="ListBranchCommand">ListBranchCommand</see>
313
public virtual ListBranchCommand BranchList()
315
return new ListBranchCommand(repo);
318
/// <summary>Returns a command object used to rename branches</summary>
321
/// <see cref="RenameBranchCommand">RenameBranchCommand</see>
323
public virtual RenameBranchCommand BranchRename()
325
return new RenameBranchCommand(repo);
329
/// Returns a command object to execute a
334
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html"
335
/// * >Git documentation about Add</a></seealso>
338
/// <see cref="AddCommand">AddCommand</see>
339
/// used to collect all optional parameters
340
/// and to finally execute the
344
public virtual AddCommand Add()
346
return new AddCommand(repo);
350
/// Returns a command object to execute a
355
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html"
356
/// * >Git documentation about Tag</a></seealso>
359
/// <see cref="TagCommand">TagCommand</see>
360
/// used to collect all optional parameters
361
/// and to finally execute the
365
public virtual TagCommand Tag()
367
return new TagCommand(repo);
371
/// Returns a command object to execute a
372
/// <code>Fetch</code>
376
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html"
377
/// * >Git documentation about Fetch</a></seealso>
380
/// <see cref="FetchCommand">FetchCommand</see>
381
/// used to collect all optional parameters
382
/// and to finally execute the
383
/// <code>Fetch</code>
386
public virtual FetchCommand Fetch()
388
return new FetchCommand(repo);
392
/// Returns a command object to execute a
393
/// <code>Push</code>
397
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html"
398
/// * >Git documentation about Push</a></seealso>
401
/// <see cref="PushCommand">PushCommand</see>
402
/// used to collect all optional parameters and
403
/// to finally execute the
404
/// <code>Push</code>
407
public virtual PushCommand Push()
409
return new PushCommand(repo);
413
/// Returns a command object to execute a
414
/// <code>cherry-pick</code>
418
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html"
419
/// * >Git documentation about cherry-pick</a></seealso>
422
/// <see cref="CherryPickCommand">CherryPickCommand</see>
423
/// used to collect all optional
424
/// parameters and to finally execute the
425
/// <code>cherry-pick</code>
428
public virtual CherryPickCommand CherryPick()
430
return new CherryPickCommand(repo);
434
/// Returns a command object to execute a
435
/// <code>revert</code>
439
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html"
440
/// * >Git documentation about reverting changes</a></seealso>
443
/// <see cref="RevertCommand">RevertCommand</see>
444
/// used to collect all optional
445
/// parameters and to finally execute the
446
/// <code>cherry-pick</code>
449
public virtual RevertCommand Revert()
451
return new RevertCommand(repo);
455
/// Returns a command object to execute a
456
/// <code>Rebase</code>
460
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html"
461
/// * >Git documentation about rebase</a></seealso>
464
/// <see cref="RebaseCommand">RebaseCommand</see>
465
/// used to collect all optional parameters
466
/// and to finally execute the
467
/// <code>rebase</code>
470
public virtual RebaseCommand Rebase()
472
return new RebaseCommand(repo);
476
/// Returns a command object to execute a
481
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html"
482
/// * >Git documentation about rm</a></seealso>
485
/// <see cref="RmCommand">RmCommand</see>
486
/// used to collect all optional parameters and
487
/// to finally execute the
491
public virtual RmCommand Rm()
493
return new RmCommand(repo);
497
/// Returns a command object to execute a
498
/// <code>checkout</code>
502
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
503
/// * >Git documentation about checkout</a></seealso>
506
/// <see cref="CheckoutCommand">CheckoutCommand</see>
507
/// used to collect all optional parameters
508
/// and to finally execute the
509
/// <code>checkout</code>
512
public virtual CheckoutCommand Checkout()
514
return new CheckoutCommand(repo);
518
/// Returns a command object to execute a
519
/// <code>reset</code>
523
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html"
524
/// * >Git documentation about reset</a></seealso>
527
/// <see cref="ResetCommand">ResetCommand</see>
528
/// used to collect all optional parameters
529
/// and to finally execute the
530
/// <code>reset</code>
533
public virtual ResetCommand Reset()
535
return new ResetCommand(repo);
539
/// Returns a command object to execute a
540
/// <code>status</code>
544
/// * href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html"
545
/// * >Git documentation about status</a></seealso>
548
/// <see cref="StatusCommand">StatusCommand</see>
549
/// used to collect all optional parameters
550
/// and to finally execute the
551
/// <code>status</code>
554
public virtual StatusCommand Status()
556
return new StatusCommand(repo);
559
/// <returns>the git repository this class is interacting with</returns>
560
public virtual Repository GetRepository()