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

« back to all changes in this revision

Viewing changes to external/ngit/NGit/NGit.Api/MergeCommand.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:
76
76
 
77
77
                private IList<Ref> commits = new List<Ref>();
78
78
 
 
79
                private bool squash;
 
80
 
79
81
                /// <param name="repo"></param>
80
82
                protected internal MergeCommand(Repository repo) : base(repo)
81
83
                {
92
94
                /// of the command. Don't call this method twice on an instance.
93
95
                /// </summary>
94
96
                /// <returns>the result of the merge</returns>
 
97
                /// <exception cref="NGit.Api.Errors.GitAPIException"></exception>
95
98
                /// <exception cref="NGit.Api.Errors.NoHeadException"></exception>
96
99
                /// <exception cref="NGit.Api.Errors.ConcurrentRefUpdateException"></exception>
97
100
                /// <exception cref="NGit.Api.Errors.CheckoutConflictException"></exception>
168
171
                                                        Tree);
169
172
                                                dco.SetFailOnConflict(true);
170
173
                                                dco.Checkout();
171
 
                                                UpdateHead(refLogMessage, srcCommit, headId);
 
174
                                                string msg = null;
 
175
                                                ObjectId newHead;
 
176
                                                ObjectId @base = null;
 
177
                                                MergeStatus mergeStatus = null;
 
178
                                                if (!squash)
 
179
                                                {
 
180
                                                        UpdateHead(refLogMessage, srcCommit, headId);
 
181
                                                        newHead = @base = srcCommit;
 
182
                                                        mergeStatus = MergeStatus.FAST_FORWARD;
 
183
                                                }
 
184
                                                else
 
185
                                                {
 
186
                                                        msg = JGitText.Get().squashCommitNotUpdatingHEAD;
 
187
                                                        newHead = @base = headId;
 
188
                                                        mergeStatus = MergeStatus.FAST_FORWARD_SQUASHED;
 
189
                                                        IList<RevCommit> squashedCommits = RevWalkUtils.Find(revWalk, srcCommit, headCommit
 
190
                                                                );
 
191
                                                        string squashMessage = new SquashMessageFormatter().Format(squashedCommits, head);
 
192
                                                        repo.WriteSquashCommitMsg(squashMessage);
 
193
                                                }
172
194
                                                SetCallable(false);
173
 
                                                return new MergeCommandResult(srcCommit, srcCommit, new ObjectId[] { headCommit, 
174
 
                                                        srcCommit }, MergeStatus.FAST_FORWARD, mergeStrategy, null, null);
 
195
                                                return new MergeCommandResult(newHead, @base, new ObjectId[] { headCommit, srcCommit
 
196
                                                         }, mergeStatus, mergeStrategy, null, msg);
175
197
                                        }
176
198
                                        else
177
199
                                        {
178
 
                                                string mergeMessage = new MergeMessageFormatter().Format(commits, head);
179
 
                                                repo.WriteMergeCommitMsg(mergeMessage);
180
 
                                                repo.WriteMergeHeads(Arrays.AsList(@ref.GetObjectId()));
 
200
                                                string mergeMessage = string.Empty;
 
201
                                                if (!squash)
 
202
                                                {
 
203
                                                        mergeMessage = new MergeMessageFormatter().Format(commits, head);
 
204
                                                        repo.WriteMergeCommitMsg(mergeMessage);
 
205
                                                        repo.WriteMergeHeads(Arrays.AsList(@ref.GetObjectId()));
 
206
                                                }
 
207
                                                else
 
208
                                                {
 
209
                                                        IList<RevCommit> squashedCommits = RevWalkUtils.Find(revWalk, srcCommit, headCommit
 
210
                                                                );
 
211
                                                        string squashMessage = new SquashMessageFormatter().Format(squashedCommits, head);
 
212
                                                        repo.WriteSquashCommitMsg(squashMessage);
 
213
                                                }
181
214
                                                Merger merger = mergeStrategy.NewMerger(repo);
182
215
                                                bool noProblems;
183
216
                                                IDictionary<string, MergeResult<NGit.Diff.Sequence>> lowLevelResults = null;
206
239
                                                                ());
207
240
                                                        dco.SetFailOnConflict(true);
208
241
                                                        dco.Checkout();
209
 
                                                        RevCommit newHead = new Git(GetRepository()).Commit().SetReflogComment(refLogMessage
210
 
                                                                .ToString()).Call();
 
242
                                                        string msg = null;
 
243
                                                        RevCommit newHead = null;
 
244
                                                        MergeStatus mergeStatus = null;
 
245
                                                        if (!squash)
 
246
                                                        {
 
247
                                                                newHead = new Git(GetRepository()).Commit().SetReflogComment(refLogMessage.ToString
 
248
                                                                        ()).Call();
 
249
                                                                mergeStatus = MergeStatus.MERGED;
 
250
                                                        }
 
251
                                                        else
 
252
                                                        {
 
253
                                                                msg = JGitText.Get().squashCommitNotUpdatingHEAD;
 
254
                                                                newHead = headCommit;
 
255
                                                                mergeStatus = MergeStatus.MERGED_SQUASHED;
 
256
                                                        }
211
257
                                                        return new MergeCommandResult(newHead.Id, null, new ObjectId[] { headCommit.Id, srcCommit
212
 
                                                                .Id }, MergeStatus.MERGED, mergeStrategy, null, null);
 
258
                                                                .Id }, mergeStatus, mergeStrategy, null, msg);
213
259
                                                }
214
260
                                                else
215
261
                                                {
336
382
                {
337
383
                        return Include(new ObjectIdRef.Unpeeled(RefStorage.LOOSE, name, commit.Copy()));
338
384
                }
 
385
 
 
386
                /// <summary>
 
387
                /// If <code>true</code>, will prepare the next commit in working tree and
 
388
                /// index as if a real merge happened, but do not make the commit or move the
 
389
                /// HEAD.
 
390
                /// </summary>
 
391
                /// <remarks>
 
392
                /// If <code>true</code>, will prepare the next commit in working tree and
 
393
                /// index as if a real merge happened, but do not make the commit or move the
 
394
                /// HEAD. Otherwise, perform the merge and commit the result.
 
395
                /// <p>
 
396
                /// In case the merge was successful but this flag was set to
 
397
                /// <code>true</code> a
 
398
                /// <see cref="MergeCommandResult">MergeCommandResult</see>
 
399
                /// with status
 
400
                /// <see cref="MergeStatus.MERGED_SQUASHED">MergeStatus.MERGED_SQUASHED</see>
 
401
                /// or
 
402
                /// <see cref="MergeStatus.FAST_FORWARD_SQUASHED">MergeStatus.FAST_FORWARD_SQUASHED</see>
 
403
                /// is returned.
 
404
                /// </remarks>
 
405
                /// <param name="squash">whether to squash commits or not</param>
 
406
                /// <returns>
 
407
                /// 
 
408
                /// <code>this</code>
 
409
                /// </returns>
 
410
                /// <since>2.0</since>
 
411
                public virtual NGit.Api.MergeCommand SetSquash(bool squash)
 
412
                {
 
413
                        CheckCallable();
 
414
                        this.squash = squash;
 
415
                        return this;
 
416
                }
339
417
        }
340
418
}