Ejemplo n.º 1
0
        public static IEnumerable <Change> GetChanges(this IGit git, params string[] logArguments)
        {
            var r = git.Run(new[] { "log", "--no-merges", "--pretty=raw", "--numstat" }.Concat(logArguments)).Result;

            using (var reader = new StringReader(r.Output))
            {
                return(ReadChanges(reader).ToList());
            }
        }
Ejemplo n.º 2
0
 public Task Pull()
 {
     // itw4yclaa3btvv6psuesw5hn6zntnbw4yysczevrnhampjdseota
     if (nextPull < DateTime.UtcNow)
     {
         nextPull = DateTime.UtcNow + pullInterval;
         return(git.Run(new[] { "pull" }));
     }
     else
     {
         return(Task.CompletedTask);
     }
 }
Ejemplo n.º 3
0
        public async Task <IEnumerable <GrepResult> > Grep(string q)
        {
            var result = await git.Run(new[] { "grep", "-I", "-n", "-i", q });

            return(ParseGitGrepOutput(result.Output));
        }
Ejemplo n.º 4
0
        // GET: /<controller>/
        public async Task <IActionResult> Index(
            [FromServices] IContentProvider contentProvider,
            [FromServices] IMarkdownRenderer renderer,
            [FromServices] IHistory history,
            [FromServices] IGit git,
            [FromQuery] string log,
            [FromQuery] string q,
            string path)
        {
            var contentPath = ContentPath.FromUrlPath(path);

            if (this.HttpContext.WebSockets.IsWebSocketRequest)
            {
                await NotifyContentChanged(this.HttpContext.WebSockets, contentProvider, contentPath);

                return(Ok());
            }

            if (log != null)
            {
                var r = await git.Run(new[] { "log" }.Concat(Utils.SplitArguments(log)).Concat(new[] { "--", git.GetPath(contentPath) }));

                return(await MarkdownView(renderer, contentPath, AsCode(r.Output)));
            }

            if (q != null)
            {
                var pretty  = $"--pretty=format:* [%ar: %s]({git.GetPath(contentPath)}?log=--stat+-p+-1+-U+%H), by %an";
                var grepLog = await git.Run(new[] { "log", pretty, "-100", "-S", q, git.GetPath(contentPath) });

                var grepText = git.GrepOutputToMarkdown((await git.Run(new[] { "grep", "-I", "-n", q })).Output);
                return(await MarkdownView(renderer, contentPath, grepLog.Output + hr + grepText));
            }

            var children = contentProvider.GetChildren(contentPath);

            if (children.Any())
            {
                if (!this.HttpContext.Request.Path.Value.EndsWith("/"))
                {
                    var url        = Microsoft.AspNetCore.Http.Extensions.UriHelper.GetEncodedUrl(this.HttpContext.Request);
                    var redirectTo = url + "/";
                    return(this.Redirect(redirectTo));
                }
                return(await MarkdownView(renderer, contentPath, GetDirectoryMarkdown(contentProvider, history, contentPath, children)));
            }

            if (contentPath.IsExtension(new[] { ".md" }))
            {
                return(await MarkdownView(renderer, contentPath, GetMarkdown(contentProvider, history, contentPath)));
            }

            var mdFile = contentPath.CatName(".md");

            if (mdFile.HasValue && contentProvider.Exists(mdFile.Value))
            {
                return(await MarkdownView(renderer, contentPath, GetText(contentProvider, mdFile.Value)));
            }

            if (IsText(contentProvider, contentPath))
            {
                return(await MarkdownView(renderer, contentPath, GetSourceAsMarkdown(contentProvider, history, contentPath)));
            }

            contentProvider.Pull();

            // raw file
            return(await Raw(contentProvider, path));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Commit([FromServices] IMarkdownRenderer renderer, [FromServices] IGit git, string commit)
        {
            var r = await git.Run(new[] { "show", commit });

            return(await MarkdownView(renderer, ContentPath.Root, AsCode(r.Output)));
        }
Ejemplo n.º 6
0
        public async Task <Option <string> > GetRecentChanges(ContentPath path)
        {
            var r = await git.Run(new[] { "log", "-100", $"--pretty=format:* [%ar: %s]({path.AbsoluteHref}?log=--stat+-p+-1+-U+%H), by %an", "--", git.GetPath(path) });

            return(r.Success ? UrlEncode(r.Output) : Option <string> .None);
        }