예제 #1
0
        /// <summary>
        ///   Create a new local branch with the specified name
        /// </summary>
        /// <param name = "name">The name of the branch.</param>
        /// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
        /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
        /// <returns></returns>
        public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
        {
            Ensure.ArgumentNotNullOrEmptyString(name, "name");

            ObjectId commitId = repo.LookupCommit(shaOrReferenceName).Id;

            using (var osw = new ObjectSafeWrapper(commitId, repo))
            {
                GitOid oid;
                Ensure.Success(NativeMethods.git_branch_create(out oid, repo.Handle, name, osw.ObjectPtr, allowOverwrite));
            }

            return(this[ShortToLocalName(name)]);
        }