Beispiel #1
0
        /// <summary>
        /// Fast forwarding means making the
        /// current branch reflect the commit that `giverHash` points at.  No
        /// new commit is created.
        /// </summary>
        public static void WriteFastForwardMerge(string receiverHash, string giverHash)
        {
            // Point head at `giverHash`.
            Refs.Write(Refs.ToLocalRef(Refs.HeadBranchName()), giverHash);

            // Make the index mirror the content of `giverHash`.
            Index.Write(Index.TocToIndex(Objects.CommitToc(giverHash)));

            // If the repo is bare, it has no working copy, so there is no
            // more work to do.  If the repo is not bare...
            if (!Config.Read().Bare)
            {
                // ...Get an object that maps from file paths in the
                // `receiverHash` commit to hashes of the files' content.  If
                // `recevierHash` is undefined, the repository has no commits,
                // yet, and the mapping object is empty.
                var receiverToc =
                    receiverHash == null
                        ? new Dictionary <string, string>()
                        : Objects.CommitToc(receiverHash);

                // ...and write the content of the files to the working copy.
                WorkingCopy.Write(Diff.TocDiff(receiverToc, Objects.CommitToc(giverHash)));
            }
        }
Beispiel #2
0
        public static void WriteNonFastForwardMerge(string receiverHash, string giverHash, string giverRef)
        {
            // Write `giverHash` to `.gitlet/MERGE_HEAD`.  This file acts as a
            // record of `giverHash` and as the signal that the repository is
            // in the merging state.
            Refs.Write("MERGE_HEAD", giverHash);

            // Write a standard merge commit message that will be used when
            // the merge commit is created.
            Merge.WriteMergeMsg(receiverHash, giverHash, giverRef);

            // Merge the `receiverHash` commit with the `giverHash` commit and
            // write the content to the index.
            Merge.WriteIndex(receiverHash, giverHash);

            // If the repo is bare, it has no working copy, so there is no
            // more work to do.  If the repo is not bare...
            if (!Config.Read().Bare)
            {
                // ...merge the `receiverHash` commit with the `giverHash`
                // commit and write the content to the working copy.
                WorkingCopy.Write(Merge.MergeDiff(receiverHash, giverHash));
            }
        }