Пример #1
0
        public static bool LinkModule(SvnClient client, string installUrl, string moduleName, string releaseUrl)
        {
            // check if a link for given module exists at all
            SvnExternalItem[] extItems;
            if (!Exter.ReadExternals(client, installUrl, out extItems))
            {
                return(false);
            }

            // if not, do not do anything
            // (adding a new module to an installation is too responsible operation to be done automatically)
            int foundAt = -1;

            for (int i = 0; i < extItems.Length; i++)
            {
                if (extItems[i].Target == moduleName)
                {
                    foundAt = i;
                    break;
                }
            }

            if (foundAt < 0)              // module not linked yet
            {
                return(true);
            }

            SvnInfoEventArgs info;

            if (!client.GetInfo(new SvnUriTarget(installUrl), out info))
            {
                return(false);
            }

            // replace the link with a new one
            var    ei = extItems[foundAt];
            string relativizedUrl;

            Exter.TryMakeRelativeReference(client, releaseUrl, info.RepositoryRoot.AbsoluteUri, out relativizedUrl);
            var newEI = new SvnExternalItem(ei.Target, relativizedUrl);

            extItems[foundAt] = newEI;


            if (!Exter.WriteExternals(client, installUrl, extItems, info.Revision))
            {
                return(false);
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Creates a release by copying an existing one and changing the externals type
        /// Only the root externals are changed. All in repository, no WC involved.
        /// </summary>
        /// <param name="srcUrl">
        ///    svn://server/releases/head
        ///    svn://server/releases/candidate/2.0.1
        ///    svn://server/releases/final/2.0.1
        /// </param>
        /// <param name="destUrl">new url
        ///    svn://server/releases/head
        ///    svn://server/releases/candidate/2.0.1
        ///    svn://server/releases/final/2.0.1
        /// </param>
        /// <param name="pinType">the resulting type of externals</param>
        /// <param name="releaseName">name of the release Can contain sub-folders like 'sub1/sub2/version'</param>
        /// <returns></returns>
        public static bool Copy(SvnClient client, string srcUrl, string destUrl, Exter.EPinType pinType, string releaseName = null)
        {
            /*
             * - udělá svn copy (to zkopíruje externalsy jak jsou)
             * - pozmění kořenové externalsy tak, že každý z nich napinuje (pokud ještě není) na konkrétní revizi
             */

            // args check
            if (pinType == Exter.EPinType.Branch || pinType == Exter.EPinType.Tag)
            {
                if (String.IsNullOrEmpty(releaseName))
                {
                    throw new ArgumentException("release Name can't be empty", "releaseName");
                }
            }

            // read externals from the root directory and parse them
            string externalsHostUrl = srcUrl;

            SvnExternalItem[] extItems;
            if (!Exter.ReadExternals(client, externalsHostUrl, out extItems))
            {
                return(false);
            }

            // modify each of them (will create new tags if needed on referenced shared resources!)
            {
                for (int i = 0; i < extItems.Length; i++)
                {
                    if (!ModifyExternal(client, ref extItems[i], pinType, externalsHostUrl, releaseName))
                    {
                        return(false);
                    }
                }
            }

            long dstRevision;

            if (srcUrl != destUrl)
            {
                // make svn copy Head Candidate/2.0.1 (copies the externals as they are)
                try
                {
                    SvnCommitResult copyResult;
                    var             args = new SvnCopyArgs();
                    args.LogMessage    = "";
                    args.CreateParents = true;
                    if (!client.RemoteCopy(new SvnUriTarget(srcUrl, SvnRevision.Head), new Uri(destUrl), args, out copyResult))
                    {
                        return(false);
                    }

                    dstRevision = copyResult.Revision;
                }
                catch (SvnException ex)
                {
                    Logger.Error(ex, $"Failed creating '{destUrl}'");
                    return(false);
                }
            }
            else
            {
                SvnInfoEventArgs info;
                if (!client.GetInfo(new Uri(srcUrl), out info))
                {
                    return(false);
                }
                dstRevision = info.Revision;
            }


            // update its root externals
            if (!Exter.WriteExternals(client, destUrl, extItems, dstRevision))
            {
                return(false);
            }

            return(true);
        }