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

« back to all changes in this revision

Viewing changes to external/ngit/NGit/NGit.Api/CommitCommand.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:
119
119
                ///     </exception>
120
120
                /// <exception cref="NGit.Api.Errors.NoMessageException">when called without specifying a commit message
121
121
                ///     </exception>
122
 
                /// <exception cref="NGit.Errors.UnmergedPathException">when the current index contained unmerged paths (conflicts)
 
122
                /// <exception cref="NGit.Api.Errors.UnmergedPathsException">when the current index contained unmerged paths (conflicts)
123
123
                ///     </exception>
 
124
                /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException">
 
125
                /// when HEAD or branch ref is updated concurrently by someone
 
126
                /// else
 
127
                /// </exception>
124
128
                /// <exception cref="NGit.Api.Errors.WrongRepositoryStateException">when repository is not in the right state for committing
125
129
                ///     </exception>
126
 
                /// <exception cref="NGit.Api.Errors.JGitInternalException">
127
 
                /// a low-level exception of JGit has occurred. The original
128
 
                /// exception can be retrieved by calling
129
 
                /// <see cref="System.Exception.InnerException()">System.Exception.InnerException()</see>
130
 
                /// . Expect only
131
 
                /// <code>IOException's</code>
132
 
                /// to be wrapped. Subclasses of
133
 
                /// <see cref="System.IO.IOException">System.IO.IOException</see>
134
 
                /// (e.g.
135
 
                /// <see cref="NGit.Errors.UnmergedPathException">NGit.Errors.UnmergedPathException</see>
136
 
                /// ) are
137
 
                /// typically not wrapped here but thrown as original exception
138
 
                /// </exception>
139
 
                /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
 
130
                /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
140
131
                public override RevCommit Call()
141
132
                {
142
133
                        CheckCallable();
170
161
                                }
171
162
                                // determine the current HEAD and the commit it is referring to
172
163
                                ObjectId headId = repo.Resolve(Constants.HEAD + "^{commit}");
 
164
                                if (headId == null && amend)
 
165
                                {
 
166
                                        throw new WrongRepositoryStateException(JGitText.Get().commitAmendOnInitialNotPossible
 
167
                                                );
 
168
                                }
173
169
                                if (headId != null)
174
170
                                {
175
171
                                        if (amend)
180
176
                                                {
181
177
                                                        parents.Add(0, p[i].Id);
182
178
                                                }
 
179
                                                if (author == null)
 
180
                                                {
 
181
                                                        author = previousCommit.GetAuthorIdent();
 
182
                                                }
183
183
                                        }
184
184
                                        else
185
185
                                        {
294
294
                        }
295
295
                        catch (UnmergedPathException e)
296
296
                        {
297
 
                                // since UnmergedPathException is a subclass of IOException
298
 
                                // which should not be wrapped by a JGitInternalException we
299
 
                                // have to catch and re-throw it here
300
 
                                throw;
 
297
                                throw new UnmergedPathsException(e);
301
298
                        }
302
299
                        catch (IOException e)
303
300
                        {
407
404
                                                        }
408
405
                                                }
409
406
                                                // update index
410
 
                                                dcEditor.Add(new _PathEdit_373(dcEntry, path));
 
407
                                                dcEditor.Add(new _PathEdit_375(dcEntry, path));
411
408
                                                // add to temporary in-core index
412
409
                                                dcBuilder.Add(dcEntry);
413
410
                                                if (emptyCommit && (hTree == null || !hTree.IdEqual(fTree) || hTree.EntryRawMode 
467
464
                        return inCoreIndex;
468
465
                }
469
466
 
470
 
                private sealed class _PathEdit_373 : DirCacheEditor.PathEdit
 
467
                private sealed class _PathEdit_375 : DirCacheEditor.PathEdit
471
468
                {
472
 
                        public _PathEdit_373(DirCacheEntry dcEntry, string baseArg1) : base(baseArg1)
 
469
                        public _PathEdit_375(DirCacheEntry dcEntry, string baseArg1) : base(baseArg1)
473
470
                        {
474
471
                                this.dcEntry = dcEntry;
475
472
                        }
534
531
                        {
535
532
                                committer = new PersonIdent(repo);
536
533
                        }
537
 
                        if (author == null)
 
534
                        if (author == null && !amend)
538
535
                        {
539
536
                                author = committer;
540
537
                        }
563
560
                                        }
564
561
                                }
565
562
                        }
 
563
                        else
 
564
                        {
 
565
                                if (state == RepositoryState.SAFE && message == null)
 
566
                                {
 
567
                                        try
 
568
                                        {
 
569
                                                message = repo.ReadSquashCommitMsg();
 
570
                                                if (message != null)
 
571
                                                {
 
572
                                                        repo.WriteSquashCommitMsg(null);
 
573
                                                }
 
574
                                        }
 
575
                                        catch (IOException e)
 
576
                                        {
 
577
                                                throw new JGitInternalException(MessageFormat.Format(JGitText.Get().exceptionOccurredDuringReadingOfGIT_DIR
 
578
                                                        , Constants.MERGE_MSG, e), e);
 
579
                                        }
 
580
                                }
 
581
                        }
566
582
                        if (message == null)
567
583
                        {
568
 
                                // as long as we don't suppport -C option we have to have
 
584
                                // as long as we don't support -C option we have to have
569
585
                                // an explicit message
570
586
                                throw new NoMessageException(JGitText.Get().commitMessageNotSpecified);
571
587
                        }
620
636
                /// Sets the committer for this
621
637
                /// <code>commit</code>
622
638
                /// . If no committer is explicitly
623
 
                /// specified because this method is never called or called with
624
 
                /// <code>null</code>
625
 
                /// value then the committer will be deduced from config info in repository,
626
 
                /// with current time.
 
639
                /// specified because this method is never called then the committer will be
 
640
                /// deduced from config info in repository, with current time.
627
641
                /// </summary>
628
642
                /// <param name="name">
629
643
                /// the name of the committer used for the
665
679
                /// . If no author is explicitly
666
680
                /// specified because this method is never called or called with
667
681
                /// <code>null</code>
668
 
                /// value then the author will be set to the committer.
 
682
                /// value then the author will be set to the committer or to the original
 
683
                /// author when amending.
669
684
                /// </summary>
670
685
                /// <param name="author">
671
686
                /// the author used for the
686
701
                /// Sets the author for this
687
702
                /// <code>commit</code>
688
703
                /// . If no author is explicitly
689
 
                /// specified because this method is never called or called with
690
 
                /// <code>null</code>
691
 
                /// value then the author will be set to the committer.
 
704
                /// specified because this method is never called then the author will be set
 
705
                /// to the committer or to the original author when amending.
692
706
                /// </summary>
693
707
                /// <param name="name">
694
708
                /// the name of the author used for the