Пример #1
0
        public IPackageContent GetSourcePackage(string url, string gitHash)
        {
            var sourceName = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(url, string.Empty, "Source", string.Empty));

            if (this.HasSourcePackage(url, gitHash))
            {
                try
                {
                    GitUtils.RunGitAbsolute(sourceName, "fetch origin +refs/heads/*:refs/heads/*");
                }
                catch (InvalidOperationException)
                {
                    // Ignore exceptions here in case the user is offline.
                }

                return(new SourcePackageContent(this)
                {
                    SourcePath = sourceName,
                    GitRef = gitHash,
                    OriginalGitUri = url,
                });
            }

            Directory.CreateDirectory(sourceName);
            GitUtils.RunGit(null, "clone --bare " + url + " " + sourceName);

            return(new SourcePackageContent(this)
            {
                SourcePath = sourceName,
                GitRef = gitHash,
                OriginalGitUri = url,
            });
        }
Пример #2
0
        public void DownloadSourcePackage(string gitUrl, string targetPath)
        {
            if (Directory.Exists(targetPath))
            {
                throw new Exception("Unable to download source package; target path already exists!");
            }

            if (File.Exists(targetPath))
            {
                throw new Exception("Target path already exists (but is not a directory)");
            }

            Directory.CreateDirectory(targetPath);
            GitUtils.RunGit(targetPath, "git clone --bare " + gitUrl + " .");
        }
Пример #3
0
        private void InitializeSubmodulesFromCache(string workingDirectory, string path)
        {
            GitUtils.RunGit(workingDirectory, path, "submodule init");
            var submodules = GitUtils.RunGitAndCapture(workingDirectory, path, "config --local --list");

            foreach (Match match in new Regex(@"submodule\.(?<name>.*)\.url=(?<url>.*)").Matches(submodules))
            {
                var name = match.Groups["name"].Value;
                var url  = match.Groups["url"].Value;

                var submodule = GetSourcePackage(workingDirectory, url);
                GitUtils.RunGit(workingDirectory, path, "config --local submodule." + name + ".url " + submodule);
                GitUtils.RunGit(workingDirectory, path, "submodule update " + name);
                this.InitializeSubmodulesFromCache(workingDirectory, Path.Combine(path ?? "", name));
                GitUtils.RunGit(workingDirectory, path, "config --local submodule." + name + ".url " + url);
            }
        }
Пример #4
0
        private void ExtractGitSourceTo(string workingDirectory, string sourcePath, string gitRef, string path)
        {
            // FIXME: This assumes packages are being extracted underneath the current
            // working directory (i.e. the module root).
            if (GitUtils.IsGitRepository())
            {
                GitUtils.UnmarkIgnored(path);
            }

            GitUtils.RunGit(workingDirectory, null, "clone --progress " + sourcePath + " \"" + path + "\"");
            GitUtils.RunGit(workingDirectory, path, "checkout -f " + gitRef);
            this.InitializeSubmodulesFromCache(workingDirectory, path);

            if (GitUtils.IsGitRepository())
            {
                GitUtils.MarkIgnored(path);
            }
        }
Пример #5
0
        public void ExtractTo(string path)
        {
            // FIXME: This assumes packages are being extracted underneath the current
            // working directory (i.e. the module root).
            if (GitUtils.IsGitRepository())
            {
                GitUtils.UnmarkIgnored(path);
            }

            GitUtils.RunGit(null, "clone " + this.SourcePath + " " + path);
            GitUtils.RunGit(path, "checkout -f " + this.GitRef);
            this.InitializeSubmodulesFromCache(path);

            if (GitUtils.IsGitRepository())
            {
                GitUtils.MarkIgnored(path);
            }
        }
Пример #6
0
        private string GetSourcePackage(string workingDirectory, string url)
        {
            var sourcePath = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(url));

            if (this.HasSourcePackage(url))
            {
                if (Directory.Exists(Path.Combine(sourcePath, "objects")) &&
                    File.Exists(Path.Combine(sourcePath, "config")))
                {
                    try
                    {
                        GitUtils.RunGitAbsolute(sourcePath, "fetch origin +refs/heads/*:refs/heads/*");
                    }
                    catch (InvalidOperationException)
                    {
                        // Ignore exceptions here in case the user is offline.
                    }

                    return(sourcePath);
                }
                else
                {
                    RedirectableConsole.ErrorWriteLine("WARNING: Source package cache is corrupt, removing and cloning again...");
                    try
                    {
                        PathUtils.AggressiveDirectoryDelete(sourcePath);
                    }
                    catch (Exception)
                    {
                        RedirectableConsole.ErrorWriteLine("WARNING: Unable to delete invalid source package from cache!");
                    }
                }
            }

            Directory.CreateDirectory(sourcePath);
            GitUtils.RunGit(workingDirectory, null, "clone --progress --bare " + url + " \"" + sourcePath + "\"");

            return(sourcePath);
        }