~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ngit/NGit/NGit.Api/CheckoutCommand.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
using NGit.Revwalk;
53
53
using NGit.Treewalk;
54
54
using NGit.Treewalk.Filter;
 
55
using NGit.Util;
55
56
using Sharpen;
56
57
 
57
58
namespace NGit.Api
58
59
{
59
 
        /// <summary>Checkout a branch to the working tree</summary>
 
60
        /// <summary>Checkout a branch to the working tree.</summary>
 
61
        /// <remarks>
 
62
        /// Checkout a branch to the working tree.
 
63
        /// <p>
 
64
        /// Examples (<code>git</code> is a
 
65
        /// <see cref="Git">Git</see>
 
66
        /// instance):
 
67
        /// <p>
 
68
        /// Check out an existing branch:
 
69
        /// <pre>
 
70
        /// git.checkout().setName(&quot;feature&quot;).call();
 
71
        /// </pre>
 
72
        /// <p>
 
73
        /// Check out paths from the index:
 
74
        /// <pre>
 
75
        /// git.checkout().addPath(&quot;file1.txt&quot;).addPath(&quot;file2.txt&quot;).call();
 
76
        /// </pre>
 
77
        /// <p>
 
78
        /// Check out a path from a commit:
 
79
        /// <pre>
 
80
        /// git.checkout().setStartPoint(&quot;HEAD&circ;&quot;).addPath(&quot;file1.txt&quot;).call();
 
81
        /// </pre>
 
82
        /// <p>
 
83
        /// Create a new branch and check it out:
 
84
        /// <pre>
 
85
        /// git.checkout().setCreateBranch(true).setName(&quot;newbranch&quot;).call();
 
86
        /// </pre>
 
87
        /// <p>
 
88
        /// Create a new tracking branch for a remote branch and check it out:
 
89
        /// <pre>
 
90
        /// git.checkout().setCreateBranch(true).setName(&quot;stable&quot;)
 
91
        /// .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
 
92
        /// .setStartPoint(&quot;origin/stable&quot;).call();
 
93
        /// </pre>
 
94
        /// </remarks>
60
95
        /// <seealso><a
61
96
        /// *      href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html"
62
97
        /// *      >Git documentation about Checkout</a></seealso>
96
131
                /// if the provided name is <code>null</code> or otherwise
97
132
                /// invalid
98
133
                /// </exception>
 
134
                /// <exception cref="NGit.Api.Errors.CheckoutConflictException">if the checkout results in a conflict
 
135
                ///     </exception>
99
136
                /// <returns>the newly created branch</returns>
100
 
                /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
101
 
                /// <exception cref="NGit.Api.Errors.CheckoutConflictException"></exception>
 
137
                /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
102
138
                public override Ref Call()
103
139
                {
104
140
                        CheckCallable();
108
144
                                if (checkoutAllPaths || !paths.IsEmpty())
109
145
                                {
110
146
                                        CheckoutPaths();
111
 
                                        status = CheckoutResult.OK_RESULT;
 
147
                                        status = new CheckoutResult(CheckoutResult.Status.OK, paths);
112
148
                                        SetCallable(false);
113
149
                                        return null;
114
150
                                }
213
249
                                }
214
250
                                else
215
251
                                {
216
 
                                        status = CheckoutResult.OK_RESULT;
 
252
                                        status = new CheckoutResult(new AList<string>(dco.GetUpdated().Keys), dco.GetRemoved
 
253
                                                ());
217
254
                                }
218
255
                                return @ref;
219
256
                        }
239
276
                        return Repository.ShortenRefName(headRef.GetTarget().GetName());
240
277
                }
241
278
 
242
 
                /// <param name="path">Path to update in the working tree and index.</param>
 
279
                /// <summary>Add a single path to the list of paths to check out.</summary>
 
280
                /// <remarks>
 
281
                /// Add a single path to the list of paths to check out. To check out all
 
282
                /// paths, use
 
283
                /// <see cref="SetAllPaths(bool)">SetAllPaths(bool)</see>
 
284
                /// .
 
285
                /// <p>
 
286
                /// If this option is set, neither the
 
287
                /// <see cref="SetCreateBranch(bool)">SetCreateBranch(bool)</see>
 
288
                /// nor
 
289
                /// <see cref="SetName(string)">SetName(string)</see>
 
290
                /// option is considered. In other words, these
 
291
                /// options are exclusive.
 
292
                /// </remarks>
 
293
                /// <param name="path">path to update in the working tree and index</param>
243
294
                /// <returns>
244
295
                /// 
245
296
                /// <code>this</code>
251
302
                        return this;
252
303
                }
253
304
 
254
 
                /// <summary>
255
 
                /// Set whether to checkout all paths
 
305
                /// <summary>Set whether to checkout all paths.</summary>
 
306
                /// <remarks>
 
307
                /// Set whether to checkout all paths.
256
308
                /// <p>
257
309
                /// This options should be used when you want to do a path checkout on the
258
310
                /// entire repository and so calling
259
311
                /// <see cref="AddPath(string)">AddPath(string)</see>
260
312
                /// is not possible
261
313
                /// since empty paths are not allowed.
262
 
                /// </summary>
263
 
                /// <param name="all">true to checkout all paths, false otherwise</param>
 
314
                /// <p>
 
315
                /// If this option is set, neither the
 
316
                /// <see cref="SetCreateBranch(bool)">SetCreateBranch(bool)</see>
 
317
                /// nor
 
318
                /// <see cref="SetName(string)">SetName(string)</see>
 
319
                /// option is considered. In other words, these
 
320
                /// options are exclusive.
 
321
                /// </remarks>
 
322
                /// <param name="all">
 
323
                /// <code>true</code> to checkout all paths, <code>false</code>
 
324
                /// otherwise
 
325
                /// </param>
264
326
                /// <returns>
265
327
                /// 
266
328
                /// <code>this</code>
267
329
                /// </returns>
 
330
                /// <since>2.0</since>
268
331
                public virtual NGit.Api.CheckoutCommand SetAllPaths(bool all)
269
332
                {
270
333
                        checkoutAllPaths = all;
306
369
                                        {
307
370
                                                ObjectId blobId = startWalk.GetObjectId(0);
308
371
                                                FileMode mode = startWalk.GetFileMode(0);
309
 
                                                editor.Add(new _PathEdit_292(this, blobId, mode, workTree, r, startWalk.PathString
310
 
                                                        ));
 
372
                                                editor.Add(new _PathEdit_349(this, checkoutIndex, blobId, mode, workTree, r, startWalk
 
373
                                                        .PathString));
311
374
                                        }
312
375
                                        editor.Commit();
313
376
                                }
325
388
                        return this;
326
389
                }
327
390
 
328
 
                private sealed class _PathEdit_292 : DirCacheEditor.PathEdit
 
391
                private sealed class _PathEdit_349 : DirCacheEditor.PathEdit
329
392
                {
330
 
                        public _PathEdit_292(CheckoutCommand _enclosing, ObjectId blobId, FileMode mode, 
331
 
                                FilePath workTree, ObjectReader r, string baseArg1) : base(baseArg1)
 
393
                        public _PathEdit_349(CheckoutCommand _enclosing, bool checkoutIndex, ObjectId blobId
 
394
                                , FileMode mode, FilePath workTree, ObjectReader r, string baseArg1) : base(baseArg1
 
395
                                )
332
396
                        {
333
397
                                this._enclosing = _enclosing;
 
398
                                this.checkoutIndex = checkoutIndex;
334
399
                                this.blobId = blobId;
335
400
                                this.mode = mode;
336
401
                                this.workTree = workTree;
339
404
 
340
405
                        public override void Apply(DirCacheEntry ent)
341
406
                        {
 
407
                                if (checkoutIndex && ent.Stage > DirCacheEntry.STAGE_0)
 
408
                                {
 
409
                                        UnmergedPathException e = new UnmergedPathException(ent);
 
410
                                        throw new JGitInternalException(e.Message, e);
 
411
                                }
342
412
                                ent.SetObjectId(blobId);
343
413
                                ent.FileMode = mode;
 
414
                                FilePath file = new FilePath(workTree, ent.PathString);
 
415
                                FilePath parentDir = file.GetParentFile();
344
416
                                try
345
417
                                {
346
 
                                        DirCacheCheckout.CheckoutEntry(this._enclosing.repo, new FilePath(workTree, ent.PathString
347
 
                                                ), ent, r);
 
418
                                        FileUtils.Mkdirs(parentDir, true);
 
419
                                        DirCacheCheckout.CheckoutEntry(this._enclosing.repo, file, ent, r);
348
420
                                }
349
421
                                catch (IOException e)
350
422
                                {
355
427
 
356
428
                        private readonly CheckoutCommand _enclosing;
357
429
 
 
430
                        private readonly bool checkoutIndex;
 
431
 
358
432
                        private readonly ObjectId blobId;
359
433
 
360
434
                        private readonly FileMode mode;
401
475
                        }
402
476
                }
403
477
 
404
 
                /// <param name="name">the name of the new branch</param>
 
478
                /// <summary>
 
479
                /// Specify the name of the branch or commit to check out, or the new branch
 
480
                /// name.
 
481
                /// </summary>
 
482
                /// <remarks>
 
483
                /// Specify the name of the branch or commit to check out, or the new branch
 
484
                /// name.
 
485
                /// <p>
 
486
                /// When only checking out paths and not switching branches, use
 
487
                /// <see cref="SetStartPoint(string)">SetStartPoint(string)</see>
 
488
                /// or
 
489
                /// <see cref="SetStartPoint(NGit.Revwalk.RevCommit)">SetStartPoint(NGit.Revwalk.RevCommit)
 
490
                ///     </see>
 
491
                /// to
 
492
                /// specify from which branch or commit to check out files.
 
493
                /// <p>
 
494
                /// When
 
495
                /// <see cref="SetCreateBranch(bool)">SetCreateBranch(bool)</see>
 
496
                /// is set to <code>true</code>, use
 
497
                /// this method to set the name of the new branch to create and
 
498
                /// <see cref="SetStartPoint(string)">SetStartPoint(string)</see>
 
499
                /// or
 
500
                /// <see cref="SetStartPoint(NGit.Revwalk.RevCommit)">SetStartPoint(NGit.Revwalk.RevCommit)
 
501
                ///     </see>
 
502
                /// to
 
503
                /// specify the start point of the branch.
 
504
                /// </remarks>
 
505
                /// <param name="name">the name of the branch or commit</param>
405
506
                /// <returns>this instance</returns>
406
507
                public virtual NGit.Api.CheckoutCommand SetName(string name)
407
508
                {
410
511
                        return this;
411
512
                }
412
513
 
 
514
                /// <summary>Specify whether to create a new branch.</summary>
 
515
                /// <remarks>
 
516
                /// Specify whether to create a new branch.
 
517
                /// <p>
 
518
                /// If <code>true</code> is used, the name of the new branch must be set
 
519
                /// using
 
520
                /// <see cref="SetName(string)">SetName(string)</see>
 
521
                /// . The commit at which to start the new
 
522
                /// branch can be set using
 
523
                /// <see cref="SetStartPoint(string)">SetStartPoint(string)</see>
 
524
                /// or
 
525
                /// <see cref="SetStartPoint(NGit.Revwalk.RevCommit)">SetStartPoint(NGit.Revwalk.RevCommit)
 
526
                ///     </see>
 
527
                /// ; if not specified, HEAD is used. Also
 
528
                /// see
 
529
                /// <see cref="SetUpstreamMode(SetupUpstreamMode)">SetUpstreamMode(SetupUpstreamMode)
 
530
                ///     </see>
 
531
                /// for setting up branch tracking.
 
532
                /// </remarks>
413
533
                /// <param name="createBranch">
414
534
                /// if <code>true</code> a branch will be created as part of the
415
535
                /// checkout and set to the specified start point
422
542
                        return this;
423
543
                }
424
544
 
 
545
                /// <summary>Specify to force the ref update in case of a branch switch.</summary>
 
546
                /// <remarks>Specify to force the ref update in case of a branch switch.</remarks>
425
547
                /// <param name="force">
426
548
                /// if <code>true</code> and the branch with the given name
427
549
                /// already exists, the start-point of an existing branch will be
436
558
                        return this;
437
559
                }
438
560
 
439
 
                /// <param name="startPoint">
440
 
                /// corresponds to the start-point option; if <code>null</code>,
441
 
                /// the current HEAD will be used
442
 
                /// </param>
 
561
                /// <summary>Set the name of the commit that should be checked out.</summary>
 
562
                /// <remarks>
 
563
                /// Set the name of the commit that should be checked out.
 
564
                /// <p>
 
565
                /// When checking out files and this is not specified or <code>null</code>,
 
566
                /// the index is used.
 
567
                /// <p>
 
568
                /// When creating a new branch, this will be used as the start point. If not
 
569
                /// specified or <code>null</code>, the current HEAD is used.
 
570
                /// </remarks>
 
571
                /// <param name="startPoint">commit name to check out</param>
443
572
                /// <returns>this instance</returns>
444
573
                public virtual NGit.Api.CheckoutCommand SetStartPoint(string startPoint)
445
574
                {
449
578
                        return this;
450
579
                }
451
580
 
452
 
                /// <param name="startCommit">
453
 
                /// corresponds to the start-point option; if <code>null</code>,
454
 
                /// the current HEAD will be used
455
 
                /// </param>
 
581
                /// <summary>Set the commit that should be checked out.</summary>
 
582
                /// <remarks>
 
583
                /// Set the commit that should be checked out.
 
584
                /// <p>
 
585
                /// When creating a new branch, this will be used as the start point. If not
 
586
                /// specified or <code>null</code>, the current HEAD is used.
 
587
                /// <p>
 
588
                /// When checking out files and this is not specified or <code>null</code>,
 
589
                /// the index is used.
 
590
                /// </remarks>
 
591
                /// <param name="startCommit">commit to check out</param>
456
592
                /// <returns>this instance</returns>
457
593
                public virtual NGit.Api.CheckoutCommand SetStartPoint(RevCommit startCommit)
458
594
                {
462
598
                        return this;
463
599
                }
464
600
 
 
601
                /// <summary>
 
602
                /// When creating a branch with
 
603
                /// <see cref="SetCreateBranch(bool)">SetCreateBranch(bool)</see>
 
604
                /// , this can
 
605
                /// be used to configure branch tracking.
 
606
                /// </summary>
465
607
                /// <param name="mode">
466
608
                /// corresponds to the --track/--no-track options; may be
467
609
                /// <code>null</code>
475
617
                        return this;
476
618
                }
477
619
 
478
 
                /// <returns>the result</returns>
 
620
                /// <returns>the result, never <code>null</code></returns>
479
621
                public virtual CheckoutResult GetResult()
480
622
                {
481
623
                        if (status == null)