Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/CLI/RodelCommit/CommitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,9 @@ public static string RemoveMarkdownCodeBlockDelimiters(string input)
return default;
}

var currentDirectory = Environment.CurrentDirectory;
var currentDirectory = Path.GetFullPath(Environment.CurrentDirectory);
(string? name, string? desc) bestMatch = default;
var bestMatchLength = -1;
foreach (var file in files)
{
var lines = await File.ReadAllLinesAsync(file);
Expand All @@ -462,14 +464,22 @@ public static string RemoveMarkdownCodeBlockDelimiters(string input)
continue;
}

if (currentDirectory.Contains(firstLine!) || firstLine!.Contains(currentDirectory))
var descriptorDirectory = Path.GetFullPath(firstLine);
var relativePath = Path.GetRelativePath(descriptorDirectory, currentDirectory);
var isSameOrChildDirectory = relativePath == "."
|| (!Path.IsPathRooted(relativePath)
&& relativePath != ".."
&& !relativePath.StartsWith($"..{Path.DirectorySeparatorChar}", StringComparison.Ordinal)
&& !relativePath.StartsWith($"..{Path.AltDirectorySeparatorChar}", StringComparison.Ordinal));
if (isSameOrChildDirectory && descriptorDirectory.Length > bestMatchLength)
{
var otherContent = string.Join('\n', lines.Skip(1).Where(p => !string.IsNullOrWhiteSpace(p)).ToList());
return (Path.GetFileNameWithoutExtension(file), otherContent.Trim());
bestMatch = (Path.GetFileNameWithoutExtension(file), otherContent.Trim());
bestMatchLength = descriptorDirectory.Length;
}
}

return default;
return bestMatch;
}

private static async Task<string> GetDiffAsync()
Expand Down