예제 #1
0
        private static void UpdateRef(string refToUpdate, string refToUpdateTo)
        {
            Files.AssertInRepo();

            // Get the hash that `refToUpdateTo` points at.
            var hash = Refs.Hash(refToUpdateTo);

            // Abort if `refToUpdateTo` does not point at a hash.
            if (!Objects.Exists(hash))
            {
                throw new Exception(refToUpdateTo + " not a valid SHA1");
            }

            // Abort if `refToUpdate` does not match the syntax of a ref.
            if (!Refs.IsRef(refToUpdate))
            {
                throw new Exception("cannot lock the ref " + refToUpdate);
            }

            // Abort if `hash` points to an object in the `objects` directory
            // that is not a commit.
            if (Objects.Type(Objects.Read(hash)) != "commit")
            {
                var branch = Refs.TerminalRef(refToUpdate);
                throw new Exception(branch + " cannot refer to non-commit object " + hash + "\n");
            }

            // Otherwise, set the contents of the file that the ref represents
            // to `hash`.
            Refs.Write(Refs.TerminalRef(refToUpdate), hash);
        }