Esempio n. 1
0
        private IList <RefSpec> CalculateRefSpecs(string dst)
        {
            RefSpec wcrs = new RefSpec();

            wcrs = wcrs.SetForceUpdate(true);
            wcrs = wcrs.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*");
            //$NON-NLS-1$ //$NON-NLS-2$
            IList <RefSpec> specs = new AList <RefSpec>();

            if (cloneAllBranches)
            {
                specs.AddItem(wcrs);
            }
            else
            {
                if (branchesToClone != null && branchesToClone.Count > 0)
                {
                    foreach (string selectedRef in branchesToClone)
                    {
                        if (wcrs.MatchSource(selectedRef))
                        {
                            specs.AddItem(wcrs.ExpandFromSource(selectedRef));
                        }
                    }
                }
            }
            return(specs);
        }
Esempio n. 2
0
        public static LocalGitRepository Init(string targetLocalPath, string url)
        {
            InitCommand ci = new InitCommand();

            ci.SetDirectory(targetLocalPath);
            ci.Call();
            LocalGitRepository repo = new LocalGitRepository(Path.Combine(targetLocalPath, Constants.DOT_GIT));

            string branch = Constants.R_HEADS + "master";

            RefUpdate head = repo.UpdateRef(Constants.HEAD);

            head.DisableRefLog();
            head.Link(branch);

            if (url != null)
            {
                RemoteConfig remoteConfig = new RemoteConfig(repo.GetConfig(), "origin");
                remoteConfig.AddURI(new URIish(url));

                string  dst  = Constants.R_REMOTES + remoteConfig.Name;
                RefSpec wcrs = new RefSpec();
                wcrs = wcrs.SetForceUpdate(true);
                wcrs = wcrs.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*");

                remoteConfig.AddFetchRefSpec(wcrs);
                remoteConfig.Update(repo.GetConfig());
            }

            // we're setting up for a clone with a checkout
            repo.GetConfig().SetBoolean("core", null, "bare", false);

            repo.GetConfig().Save();
            return(repo);
        }
Esempio n. 3
0
        /// <exception cref="Sharpen.URISyntaxException"></exception>
        /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
        /// <exception cref="NGit.Api.Errors.InvalidRemoteException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private FetchResult Fetch(Repository repo, URIish u)
        {
            // create the remote config and save it
            RemoteConfig config = new RemoteConfig(repo.GetConfig(), remote);

            config.AddURI(u);
            string  dst     = bare ? Constants.R_HEADS : Constants.R_REMOTES + config.Name;
            RefSpec refSpec = new RefSpec();

            refSpec = refSpec.SetForceUpdate(true);
            refSpec = refSpec.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*");
            //$NON-NLS-1$ //$NON-NLS-2$
            config.AddFetchRefSpec(refSpec);
            config.Update(repo.GetConfig());
            repo.GetConfig().Save();
            // run the fetch command
            FetchCommand command = new FetchCommand(repo);

            command.SetRemote(remote);
            command.SetProgressMonitor(monitor);
            command.SetTagOpt(TagOpt.FETCH_TAGS);
            command.SetTimeout(timeout);
            if (credentialsProvider != null)
            {
                command.SetCredentialsProvider(credentialsProvider);
            }
            IList <RefSpec> specs = CalculateRefSpecs(dst);

            command.SetRefSpecs(specs);
            return(command.Call());
        }
Esempio n. 4
0
        /// <exception cref="Sharpen.URISyntaxException"></exception>
        /// <exception cref="NGit.Api.Errors.JGitInternalException"></exception>
        /// <exception cref="NGit.Api.Errors.InvalidRemoteException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private FetchResult Fetch(Repository repo, URIish u)
        {
            // create the remote config and save it
            RemoteConfig config = new RemoteConfig(repo.GetConfig(), remote);

            config.AddURI(u);
            string  dst     = Constants.R_REMOTES + config.Name;
            RefSpec refSpec = new RefSpec();

            refSpec = refSpec.SetForceUpdate(true);
            refSpec = refSpec.SetSourceDestination(Constants.R_HEADS + "*", dst + "/*");
            //$NON-NLS-1$ //$NON-NLS-2$
            config.AddFetchRefSpec(refSpec);
            config.Update(repo.GetConfig());
            repo.GetConfig().SetString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants
                                       .CONFIG_KEY_REMOTE, remote);
            repo.GetConfig().SetString(ConfigConstants.CONFIG_BRANCH_SECTION, branch, ConfigConstants
                                       .CONFIG_KEY_MERGE, branch);
            repo.GetConfig().Save();
            // run the fetch command
            FetchCommand command = new FetchCommand(repo);

            command.SetRemote(remote);
            command.SetProgressMonitor(monitor);
            command.SetTagOpt(TagOpt.FETCH_TAGS);
            if (credentialsProvider != null)
            {
                command.SetCredentialsProvider(credentialsProvider);
            }
            return(command.Call());
        }