Ejemplo n.º 1
0
        private GitObject RetrieveTreeEntryTarget()
        {
            if (!Type.HasAny(new[] { GitObjectType.Tree, GitObjectType.Blob }))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "TreeEntry target of type '{0}' are not supported.", Type));
            }

            return(GitObject.BuildFrom(repo, targetOid, Type, Path));
        }
Ejemplo n.º 2
0
        private GitObject RetrieveTreeEntryTarget()
        {
            switch (TargetType)
            {
            case TreeEntryTargetType.GitLink:
                return(new GitLink(repo, targetOid));

            case TreeEntryTargetType.Blob:
            case TreeEntryTargetType.Tree:
                return(GitObject.BuildFrom(repo, targetOid, TargetType.ToGitObjectType(), Path));

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture,
                                                                  "TreeEntry target of type '{0}' is not supported.",
                                                                  TargetType));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checkout the specified <see cref="Branch"/>, reference or SHA.
        /// <para>
        ///   If the committishOrBranchSpec parameter resolves to a branch name, then the checked out HEAD will
        ///   will point to the branch. Otherwise, the HEAD will be detached, pointing at the commit sha.
        /// </para>
        /// </summary>
        /// <param name="committishOrBranchSpec">A revparse spec for the commit or branch to checkout.</param>
        /// <param name="checkoutModifiers"><see cref="CheckoutModifiers"/> controlling checkout behavior.</param>
        /// <param name="onCheckoutProgress"><see cref="CheckoutProgressHandler"/> that checkout progress is reported through.</param>
        /// <param name="checkoutNotifications"><see cref="CheckoutNotificationOptions"/> to manage checkout notifications.</param>
        /// <returns>The <see cref="Branch"/> that was checked out.</returns>
        public Branch Checkout(string committishOrBranchSpec, CheckoutModifiers checkoutModifiers, CheckoutProgressHandler onCheckoutProgress, CheckoutNotificationOptions checkoutNotifications)
        {
            Ensure.ArgumentNotNullOrEmptyString(committishOrBranchSpec, "committishOrBranchSpec");

            var handles = Proxy.git_revparse_ext(Handle, committishOrBranchSpec);

            if (handles == null)
            {
                Ensure.GitObjectIsNotNull(null, committishOrBranchSpec);
            }

            var       objH = handles.Item1;
            var       refH = handles.Item2;
            GitObject obj;

            try
            {
                if (!refH.IsInvalid)
                {
                    var reference = Reference.BuildFromPtr <Reference>(refH, this);
                    if (reference.IsLocalBranch())
                    {
                        Branch branch = Branches[reference.CanonicalName];
                        return(Checkout(branch, checkoutModifiers, onCheckoutProgress, checkoutNotifications));
                    }
                }

                obj = GitObject.BuildFrom(this, Proxy.git_object_id(objH), Proxy.git_object_type(objH),
                                          PathFromRevparseSpec(committishOrBranchSpec));
            }
            finally
            {
                objH.Dispose();
                refH.Dispose();
            }

            Commit commit = obj.DereferenceToCommit(true);

            Checkout(commit.Tree, checkoutModifiers, onCheckoutProgress, checkoutNotifications, commit.Id.Sha, committishOrBranchSpec,
                     committishOrBranchSpec != "HEAD");

            return(Head);
        }
Ejemplo n.º 4
0
        internal GitObject LookupInternal(ObjectId id, GitObjectType type, FilePath knownPath)
        {
            Ensure.ArgumentNotNull(id, "id");

            GitObjectSafeHandle obj = null;

            try
            {
                obj = Proxy.git_object_lookup(handle, id, type);

                if (obj == null)
                {
                    return(null);
                }

                return(GitObject.BuildFrom(this, id, Proxy.git_object_type(obj), knownPath));
            }
            finally
            {
                obj.SafeDispose();
            }
        }
Ejemplo n.º 5
0
        internal GitObject Lookup(string objectish, GitObjectType type, LookUpOptions lookUpOptions)
        {
            Ensure.ArgumentNotNullOrEmptyString(objectish, "commitOrBranchSpec");

            GitObject obj;

            using (GitObjectSafeHandle sh = Proxy.git_revparse_single(handle, objectish))
            {
                if (sh == null)
                {
                    if (lookUpOptions.HasFlag(LookUpOptions.ThrowWhenNoGitObjectHasBeenFound))
                    {
                        Ensure.GitObjectIsNotNull(null, objectish);
                    }

                    return(null);
                }

                GitObjectType objType = Proxy.git_object_type(sh);

                if (type != GitObjectType.Any && objType != type)
                {
                    return(null);
                }

                obj = GitObject.BuildFrom(this, Proxy.git_object_id(sh), objType, PathFromRevparseSpec(objectish));
            }

            if (lookUpOptions.HasFlag(LookUpOptions.DereferenceResultToCommit))
            {
                return(obj.DereferenceToCommit(
                           lookUpOptions.HasFlag(LookUpOptions.ThrowWhenCanNotBeDereferencedToACommit)));
            }

            return(obj);
        }