public static string Hash(string refOrHash) { /*if (objects.exists(refOrHash)) { * return refOrHash; * } else { * var terminalRef = refs.terminalRef(refOrHash); * if (terminalRef === "FETCH_HEAD") { * return refs.fetchHeadBranchToMerge(refs.headBranchName()); * } else if (refs.exists(terminalRef)) { * return files.read(files.gitletPath(terminalRef)); * } * }*/ if (Objects.Exists(refOrHash)) { return(refOrHash); } var terminalRef = Refs.TerminalRef(refOrHash); if (terminalRef == "FETCH_HEAD") { return(Refs.FetchHeadBranchToMerge(Refs.HeadBranchName())); } if (Refs.Exists(terminalRef)) { return(Files.Read(Path.Combine(Files.GitletPath(), terminalRef))); } return(null); }
/// <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))); } }
public static string Get() { var lines = new[] { "On branch " + Refs.HeadBranchName() } .Concat(Listing("Untracked files: ", Untracked())) .Concat(Listing("Unmerged paths: ", Index.ConflictedPaths())) .Concat(Listing("Changes to be committed: ", ToBeCommitted())) .Concat(Listing("Changes not staged for commit: ", NotStagedForCommit())); return(string.Join("\n", lines)); }
/// <summary> /// creates a message for the merge commit that /// will potentially be created when the `giverHash` commit is merged /// into the `receiverHash` commit. It writes this message to /// `.gitlet/MERGE_MSG`. /// </summary> private static void WriteMergeMsg(string receiverHash, string giverHash, string @ref) { var msg = "Merge " + @ref + " into " + Refs.HeadBranchName(); var mergeDiff = Merge.MergeDiff(receiverHash, giverHash); var conflicts = mergeDiff.Where(item => item.Value.Status == Diff.FileStatus.CONFLICT).ToList(); if (conflicts.Any()) { msg += "\nConflicts:\n" + string.Join("\n", conflicts); } Files.Write(Path.Combine(Files.GitletPath(), "MERGE_MSG"), msg); }