-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathGitIgnoreFile.cs
More file actions
36 lines (31 loc) · 1.61 KB
/
Copy pathGitIgnoreFile.cs
File metadata and controls
36 lines (31 loc) · 1.61 KB
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
using System;
using System.Collections.Generic;
namespace SourceGit.Models
{
public record GitIgnoreFile(string DisplayName, string FullPath, string Pattern, bool IsLocalOnly)
{
public static List<GitIgnoreFile> GetSupported(string repo, string gitDir, string pattern)
{
var supported = new List<GitIgnoreFile>();
// .gitignore in repository root.
supported.Add(new(".gitignore", $"{repo}/.gitignore", pattern, false));
// If pattern points to a file/directory that in sub-directory of repository, we should also support .gitignore in that sub-directory.
var normalizedPattern = pattern.Replace('\\', '/').TrimEnd('/');
var lastDirIdx = normalizedPattern.LastIndexOf('/');
if (lastDirIdx > 0)
{
var parentDir = normalizedPattern.Substring(0, lastDirIdx);
var overridedPattern = normalizedPattern.Substring(lastDirIdx + 1);
supported.Add(new($"{parentDir}/.gitignore", $"{repo}/{parentDir}/.gitignore", overridedPattern, false));
}
// .git/info/exclude in git directory.
var normalizedGitDir = gitDir.Replace('\\', '/');
var testGitDir = $"{repo}/.git".Replace('\\', '/');
if (normalizedGitDir.Equals(testGitDir, StringComparison.Ordinal))
supported.Add(new(".git/info/exclude", $"{normalizedGitDir}/info/exclude", pattern, true));
else
supported.Add(new(".git/info/exclude", $"{gitDir}/info/exclude", pattern, true));
return supported;
}
}
}