~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric

« back to all changes in this revision

Viewing changes to contrib/NGit/NGit.Api/Git.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2011-06-27 17:03:13 UTC
  • mto: (1.8.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 54.
  • Revision ID: james.westby@ubuntu.com-20110627170313-6cvz3s19x6e9hqe9
ImportĀ upstreamĀ versionĀ 2.5.92+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
This code is derived from jgit (http://eclipse.org/jgit).
 
3
Copyright owners are documented in jgit's IP log.
 
4
 
 
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
 
9
 
 
10
All rights reserved.
 
11
 
 
12
Redistribution and use in source and binary forms, with or
 
13
without modification, are permitted provided that the following
 
14
conditions are met:
 
15
 
 
16
- Redistributions of source code must retain the above copyright
 
17
  notice, this list of conditions and the following disclaimer.
 
18
 
 
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.
 
23
 
 
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.
 
28
 
 
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.
 
42
*/
 
43
 
 
44
using System;
 
45
using NGit;
 
46
using NGit.Api;
 
47
using NGit.Util;
 
48
using Sharpen;
 
49
 
 
50
namespace NGit.Api
 
51
{
 
52
        /// <summary>Offers a "GitPorcelain"-like API to interact with a git repository.</summary>
 
53
        /// <remarks>
 
54
        /// Offers a "GitPorcelain"-like API to interact with a git repository.
 
55
        /// <p>
 
56
        /// The GitPorcelain commands are described in the &lt;a href="http://www.kernel.org/pub/software/scm/git/docs/git.html#_high_level_commands_porcelain"
 
57
        /// &gt;Git Documentation</a>.
 
58
        /// <p>
 
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
 
64
        /// the
 
65
        /// <code>CommitCommand</code>
 
66
        /// class. The
 
67
        /// <code>CommitCommand</code>
 
68
        /// class has setters
 
69
        /// for all the arguments and options. The
 
70
        /// <code>CommitCommand</code>
 
71
        /// class also has a
 
72
        /// <code>call</code>
 
73
        /// method to actually execute the commit. The following code show's
 
74
        /// how to do a simple commit:
 
75
        /// <pre>
 
76
        /// Git git = new Git(myRepo);
 
77
        /// git.commit().setMessage(&quot;Fix393&quot;).setAuthor(developerIdent).call();
 
78
        /// </pre>
 
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.
 
82
        /// <p>
 
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.
 
89
        /// </remarks>
 
90
        public class Git
 
91
        {
 
92
                /// <summary>The git repository this class is interacting with</summary>
 
93
                private readonly Repository repo;
 
94
 
 
95
                /// <param name="dir">
 
96
                /// the repository to open. May be either the GIT_DIR, or the
 
97
                /// working tree directory that contains
 
98
                /// <code>.git</code>
 
99
                /// .
 
100
                /// </param>
 
101
                /// <returns>
 
102
                /// a
 
103
                /// <see cref="Git">Git</see>
 
104
                /// object for the existing git repository
 
105
                /// </returns>
 
106
                /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 
107
                public static NGit.Api.Git Open(FilePath dir)
 
108
                {
 
109
                        return Open(dir, FS.DETECTED);
 
110
                }
 
111
 
 
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>
 
116
                /// .
 
117
                /// </param>
 
118
                /// <param name="fs">filesystem abstraction to use when accessing the repository.</param>
 
119
                /// <returns>
 
120
                /// a
 
121
                /// <see cref="Git">Git</see>
 
122
                /// object for the existing git repository
 
123
                /// </returns>
 
124
                /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 
125
                public static NGit.Api.Git Open(FilePath dir, FS fs)
 
126
                {
 
127
                        RepositoryCache.FileKey key;
 
128
                        key = RepositoryCache.FileKey.Lenient(dir, fs);
 
129
                        return Wrap(new RepositoryBuilder().SetFS(fs).SetGitDir(key.GetFile()).SetMustExist
 
130
                                (true).Build());
 
131
                }
 
132
 
 
133
                /// <param name="repo">
 
134
                /// the git repository this class is interacting with.
 
135
                /// <code>null</code>
 
136
                /// is not allowed
 
137
                /// </param>
 
138
                /// <returns>
 
139
                /// a
 
140
                /// <see cref="Git">Git</see>
 
141
                /// object for the existing git repository
 
142
                /// </returns>
 
143
                public static NGit.Api.Git Wrap(Repository repo)
 
144
                {
 
145
                        return new NGit.Api.Git(repo);
 
146
                }
 
147
 
 
148
                /// <summary>
 
149
                /// Returns a command object to execute a
 
150
                /// <code>clone</code>
 
151
                /// command
 
152
                /// </summary>
 
153
                /// <seealso><a
 
154
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html"
 
155
                /// *      >Git documentation about clone</a></seealso>
 
156
                /// <returns>
 
157
                /// a
 
158
                /// <see cref="CloneCommand">CloneCommand</see>
 
159
                /// used to collect all optional parameters
 
160
                /// and to finally execute the
 
161
                /// <code>clone</code>
 
162
                /// command
 
163
                /// </returns>
 
164
                public static CloneCommand CloneRepository()
 
165
                {
 
166
                        return new CloneCommand();
 
167
                }
 
168
 
 
169
                /// <summary>
 
170
                /// Returns a command object to execute a
 
171
                /// <code>init</code>
 
172
                /// command
 
173
                /// </summary>
 
174
                /// <seealso><a
 
175
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-init.html"
 
176
                /// *      >Git documentation about init</a></seealso>
 
177
                /// <returns>
 
178
                /// a
 
179
                /// <see cref="InitCommand">InitCommand</see>
 
180
                /// used to collect all optional parameters and
 
181
                /// to finally execute the
 
182
                /// <code>init</code>
 
183
                /// command
 
184
                /// </returns>
 
185
                public static InitCommand Init()
 
186
                {
 
187
                        return new InitCommand();
 
188
                }
 
189
 
 
190
                /// <summary>
 
191
                /// Constructs a new
 
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.
 
196
                /// </summary>
 
197
                /// <param name="repo">
 
198
                /// the git repository this class is interacting with.
 
199
                /// <code>null</code>
 
200
                /// is not allowed
 
201
                /// </param>
 
202
                public Git(Repository repo)
 
203
                {
 
204
                        if (repo == null)
 
205
                        {
 
206
                                throw new ArgumentNullException();
 
207
                        }
 
208
                        this.repo = repo;
 
209
                }
 
210
 
 
211
                /// <summary>
 
212
                /// Returns a command object to execute a
 
213
                /// <code>Commit</code>
 
214
                /// command
 
215
                /// </summary>
 
216
                /// <seealso><a
 
217
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html"
 
218
                /// *      >Git documentation about Commit</a></seealso>
 
219
                /// <returns>
 
220
                /// a
 
221
                /// <see cref="CommitCommand">CommitCommand</see>
 
222
                /// used to collect all optional parameters
 
223
                /// and to finally execute the
 
224
                /// <code>Commit</code>
 
225
                /// command
 
226
                /// </returns>
 
227
                public virtual CommitCommand Commit()
 
228
                {
 
229
                        return new CommitCommand(repo);
 
230
                }
 
231
 
 
232
                /// <summary>
 
233
                /// Returns a command object to execute a
 
234
                /// <code>Log</code>
 
235
                /// command
 
236
                /// </summary>
 
237
                /// <seealso><a
 
238
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-log.html"
 
239
                /// *      >Git documentation about Log</a></seealso>
 
240
                /// <returns>
 
241
                /// a
 
242
                /// <see cref="LogCommand">LogCommand</see>
 
243
                /// used to collect all optional parameters and
 
244
                /// to finally execute the
 
245
                /// <code>Log</code>
 
246
                /// command
 
247
                /// </returns>
 
248
                public virtual LogCommand Log()
 
249
                {
 
250
                        return new LogCommand(repo);
 
251
                }
 
252
 
 
253
                /// <summary>
 
254
                /// Returns a command object to execute a
 
255
                /// <code>Merge</code>
 
256
                /// command
 
257
                /// </summary>
 
258
                /// <seealso><a
 
259
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html"
 
260
                /// *      >Git documentation about Merge</a></seealso>
 
261
                /// <returns>
 
262
                /// a
 
263
                /// <see cref="MergeCommand">MergeCommand</see>
 
264
                /// used to collect all optional parameters
 
265
                /// and to finally execute the
 
266
                /// <code>Merge</code>
 
267
                /// command
 
268
                /// </returns>
 
269
                public virtual MergeCommand Merge()
 
270
                {
 
271
                        return new MergeCommand(repo);
 
272
                }
 
273
 
 
274
                /// <summary>
 
275
                /// Returns a command object to execute a
 
276
                /// <code>Pull</code>
 
277
                /// command
 
278
                /// </summary>
 
279
                /// <returns>
 
280
                /// a
 
281
                /// <see cref="PullCommand">PullCommand</see>
 
282
                /// </returns>
 
283
                public virtual PullCommand Pull()
 
284
                {
 
285
                        return new PullCommand(repo);
 
286
                }
 
287
 
 
288
                /// <summary>Returns a command object used to create branches</summary>
 
289
                /// <returns>
 
290
                /// a
 
291
                /// <see cref="CreateBranchCommand">CreateBranchCommand</see>
 
292
                /// </returns>
 
293
                public virtual CreateBranchCommand BranchCreate()
 
294
                {
 
295
                        return new CreateBranchCommand(repo);
 
296
                }
 
297
 
 
298
                /// <summary>Returns a command object used to delete branches</summary>
 
299
                /// <returns>
 
300
                /// a
 
301
                /// <see cref="DeleteBranchCommand">DeleteBranchCommand</see>
 
302
                /// </returns>
 
303
                public virtual DeleteBranchCommand BranchDelete()
 
304
                {
 
305
                        return new DeleteBranchCommand(repo);
 
306
                }
 
307
 
 
308
                /// <summary>Returns a command object used to list branches</summary>
 
309
                /// <returns>
 
310
                /// a
 
311
                /// <see cref="ListBranchCommand">ListBranchCommand</see>
 
312
                /// </returns>
 
313
                public virtual ListBranchCommand BranchList()
 
314
                {
 
315
                        return new ListBranchCommand(repo);
 
316
                }
 
317
 
 
318
                /// <summary>Returns a command object used to rename branches</summary>
 
319
                /// <returns>
 
320
                /// a
 
321
                /// <see cref="RenameBranchCommand">RenameBranchCommand</see>
 
322
                /// </returns>
 
323
                public virtual RenameBranchCommand BranchRename()
 
324
                {
 
325
                        return new RenameBranchCommand(repo);
 
326
                }
 
327
 
 
328
                /// <summary>
 
329
                /// Returns a command object to execute a
 
330
                /// <code>Add</code>
 
331
                /// command
 
332
                /// </summary>
 
333
                /// <seealso><a
 
334
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-add.html"
 
335
                /// *      >Git documentation about Add</a></seealso>
 
336
                /// <returns>
 
337
                /// a
 
338
                /// <see cref="AddCommand">AddCommand</see>
 
339
                /// used to collect all optional parameters
 
340
                /// and to finally execute the
 
341
                /// <code>Add</code>
 
342
                /// command
 
343
                /// </returns>
 
344
                public virtual AddCommand Add()
 
345
                {
 
346
                        return new AddCommand(repo);
 
347
                }
 
348
 
 
349
                /// <summary>
 
350
                /// Returns a command object to execute a
 
351
                /// <code>Tag</code>
 
352
                /// command
 
353
                /// </summary>
 
354
                /// <seealso><a
 
355
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html"
 
356
                /// *      >Git documentation about Tag</a></seealso>
 
357
                /// <returns>
 
358
                /// a
 
359
                /// <see cref="TagCommand">TagCommand</see>
 
360
                /// used to collect all optional parameters
 
361
                /// and to finally execute the
 
362
                /// <code>Tag</code>
 
363
                /// command
 
364
                /// </returns>
 
365
                public virtual TagCommand Tag()
 
366
                {
 
367
                        return new TagCommand(repo);
 
368
                }
 
369
 
 
370
                /// <summary>
 
371
                /// Returns a command object to execute a
 
372
                /// <code>Fetch</code>
 
373
                /// command
 
374
                /// </summary>
 
375
                /// <seealso><a
 
376
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-fetch.html"
 
377
                /// *      >Git documentation about Fetch</a></seealso>
 
378
                /// <returns>
 
379
                /// a
 
380
                /// <see cref="FetchCommand">FetchCommand</see>
 
381
                /// used to collect all optional parameters
 
382
                /// and to finally execute the
 
383
                /// <code>Fetch</code>
 
384
                /// command
 
385
                /// </returns>
 
386
                public virtual FetchCommand Fetch()
 
387
                {
 
388
                        return new FetchCommand(repo);
 
389
                }
 
390
 
 
391
                /// <summary>
 
392
                /// Returns a command object to execute a
 
393
                /// <code>Push</code>
 
394
                /// command
 
395
                /// </summary>
 
396
                /// <seealso><a
 
397
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html"
 
398
                /// *      >Git documentation about Push</a></seealso>
 
399
                /// <returns>
 
400
                /// a
 
401
                /// <see cref="PushCommand">PushCommand</see>
 
402
                /// used to collect all optional parameters and
 
403
                /// to finally execute the
 
404
                /// <code>Push</code>
 
405
                /// command
 
406
                /// </returns>
 
407
                public virtual PushCommand Push()
 
408
                {
 
409
                        return new PushCommand(repo);
 
410
                }
 
411
 
 
412
                /// <summary>
 
413
                /// Returns a command object to execute a
 
414
                /// <code>cherry-pick</code>
 
415
                /// command
 
416
                /// </summary>
 
417
                /// <seealso><a
 
418
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-cherry-pick.html"
 
419
                /// *      >Git documentation about cherry-pick</a></seealso>
 
420
                /// <returns>
 
421
                /// a
 
422
                /// <see cref="CherryPickCommand">CherryPickCommand</see>
 
423
                /// used to collect all optional
 
424
                /// parameters and to finally execute the
 
425
                /// <code>cherry-pick</code>
 
426
                /// command
 
427
                /// </returns>
 
428
                public virtual CherryPickCommand CherryPick()
 
429
                {
 
430
                        return new CherryPickCommand(repo);
 
431
                }
 
432
 
 
433
                /// <summary>
 
434
                /// Returns a command object to execute a
 
435
                /// <code>revert</code>
 
436
                /// command
 
437
                /// </summary>
 
438
                /// <seealso><a
 
439
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-revert.html"
 
440
                /// *      >Git documentation about reverting changes</a></seealso>
 
441
                /// <returns>
 
442
                /// a
 
443
                /// <see cref="RevertCommand">RevertCommand</see>
 
444
                /// used to collect all optional
 
445
                /// parameters and to finally execute the
 
446
                /// <code>cherry-pick</code>
 
447
                /// command
 
448
                /// </returns>
 
449
                public virtual RevertCommand Revert()
 
450
                {
 
451
                        return new RevertCommand(repo);
 
452
                }
 
453
 
 
454
                /// <summary>
 
455
                /// Returns a command object to execute a
 
456
                /// <code>Rebase</code>
 
457
                /// command
 
458
                /// </summary>
 
459
                /// <seealso><a
 
460
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html"
 
461
                /// *      >Git documentation about rebase</a></seealso>
 
462
                /// <returns>
 
463
                /// a
 
464
                /// <see cref="RebaseCommand">RebaseCommand</see>
 
465
                /// used to collect all optional parameters
 
466
                /// and to finally execute the
 
467
                /// <code>rebase</code>
 
468
                /// command
 
469
                /// </returns>
 
470
                public virtual RebaseCommand Rebase()
 
471
                {
 
472
                        return new RebaseCommand(repo);
 
473
                }
 
474
 
 
475
                /// <summary>
 
476
                /// Returns a command object to execute a
 
477
                /// <code>rm</code>
 
478
                /// command
 
479
                /// </summary>
 
480
                /// <seealso><a
 
481
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-rm.html"
 
482
                /// *      >Git documentation about rm</a></seealso>
 
483
                /// <returns>
 
484
                /// a
 
485
                /// <see cref="RmCommand">RmCommand</see>
 
486
                /// used to collect all optional parameters and
 
487
                /// to finally execute the
 
488
                /// <code>rm</code>
 
489
                /// command
 
490
                /// </returns>
 
491
                public virtual RmCommand Rm()
 
492
                {
 
493
                        return new RmCommand(repo);
 
494
                }
 
495
 
 
496
                /// <summary>
 
497
                /// Returns a command object to execute a
 
498
                /// <code>checkout</code>
 
499
                /// command
 
500
                /// </summary>
 
501
                /// <seealso><a
 
502
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
 
503
                /// *      >Git documentation about checkout</a></seealso>
 
504
                /// <returns>
 
505
                /// a
 
506
                /// <see cref="CheckoutCommand">CheckoutCommand</see>
 
507
                /// used to collect all optional parameters
 
508
                /// and to finally execute the
 
509
                /// <code>checkout</code>
 
510
                /// command
 
511
                /// </returns>
 
512
                public virtual CheckoutCommand Checkout()
 
513
                {
 
514
                        return new CheckoutCommand(repo);
 
515
                }
 
516
 
 
517
                /// <summary>
 
518
                /// Returns a command object to execute a
 
519
                /// <code>reset</code>
 
520
                /// command
 
521
                /// </summary>
 
522
                /// <seealso><a
 
523
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-reset.html"
 
524
                /// *      >Git documentation about reset</a></seealso>
 
525
                /// <returns>
 
526
                /// a
 
527
                /// <see cref="ResetCommand">ResetCommand</see>
 
528
                /// used to collect all optional parameters
 
529
                /// and to finally execute the
 
530
                /// <code>reset</code>
 
531
                /// command
 
532
                /// </returns>
 
533
                public virtual ResetCommand Reset()
 
534
                {
 
535
                        return new ResetCommand(repo);
 
536
                }
 
537
 
 
538
                /// <summary>
 
539
                /// Returns a command object to execute a
 
540
                /// <code>status</code>
 
541
                /// command
 
542
                /// </summary>
 
543
                /// <seealso><a
 
544
                /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html"
 
545
                /// *      >Git documentation about status</a></seealso>
 
546
                /// <returns>
 
547
                /// a
 
548
                /// <see cref="StatusCommand">StatusCommand</see>
 
549
                /// used to collect all optional parameters
 
550
                /// and to finally execute the
 
551
                /// <code>status</code>
 
552
                /// command
 
553
                /// </returns>
 
554
                public virtual StatusCommand Status()
 
555
                {
 
556
                        return new StatusCommand(repo);
 
557
                }
 
558
 
 
559
                /// <returns>the git repository this class is interacting with</returns>
 
560
                public virtual Repository GetRepository()
 
561
                {
 
562
                        return repo;
 
563
                }
 
564
        }
 
565
}