-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathIgnoreFileParser.cs
56 lines (46 loc) · 1.67 KB
/
IgnoreFileParser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//-----------------------------------------------------------------------
// <copyright file="IgnoreFileParser.cs" company="(none)">
// Copyright © 2013 John Gietzen and the WebGit .NET Authors. All rights reserved.
// </copyright>
// <author>John Gietzen</author>
//-----------------------------------------------------------------------
namespace WebGitNet
{
using System.Collections.Generic;
using System.Linq;
public static class IgnoreFileParser
{
public static List<IgnoreEntry> Parse(string[] lines)
{
var entries = new List<IgnoreEntry>();
foreach (var line in lines)
{
if (string.IsNullOrWhiteSpace(line) || line.TrimStart().StartsWith("#"))
{
continue;
}
var lineParts = line.Split(":".ToArray(), 2);
var commitHash = lineParts[0];
var pathGlobs = lineParts[1];
var negated = false;
var rooted = false;
if (pathGlobs.StartsWith("!"))
{
negated = true;
pathGlobs = pathGlobs.Substring(1);
}
if (pathGlobs.StartsWith("/"))
{
rooted = true;
pathGlobs = pathGlobs.Substring(1);
}
if (pathGlobs.EndsWith("/"))
{
pathGlobs += "*";
}
entries.Add(new IgnoreEntry { CommitHash = commitHash, PathGlobs = pathGlobs, Negated = negated, Rooted = rooted });
}
return entries;
}
}
}