Skip to content

Users/merlynop/skip local packages #20987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
67 changes: 67 additions & 0 deletions BuildConfigGen/GitUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,5 +211,72 @@ public static string FixupPath(string s)

return s;
}

internal static bool HasUncommitedChanges(string filePath)
{
// this function generated by Co-pilot

if (!File.Exists(filePath))
{
throw new FileNotFoundException($"The file '{filePath}' does not exist.");
}

string directory = Path.GetDirectoryName(filePath) ?? throw new Exception("Unable to determine the directory of the file.");
string relativePath = FixupPath(filePath);

string[] output;
int exitCode = ProcessUtil.RunCommandWithExitCode("git", $"status --porcelain \"{relativePath}\"", directory, out output);

if (exitCode != 0)
{
throw new Exception("Failed to check git status. Non-zero exit code.");
}

// If the output contains any lines, it means there are uncommitted changes
return output.Length > 0;
}

internal static string GetUnchangedContent(string filePath)
{
// this function generated by Co-pilot

if (!File.Exists(filePath))
{
throw new FileNotFoundException($"The file '{filePath}' does not exist.");
}

string directory = Path.GetDirectoryName(filePath) ?? throw new Exception("Unable to determine the directory of the file.");
string relativePath = GetGitPath(filePath);

string[] output;
int exitCode = ProcessUtil.RunCommandWithExitCode("git", $"show HEAD:\"{relativePath}\"", directory, out output);

if (exitCode != 0)
{
throw new Exception("Failed to retrieve unchanged content. Non-zero exit code.");
}

return string.Join(Environment.NewLine, output);
}

private static string GetGitPath(string filePath)
{
// this function generated by Co-pilot

if (!File.Exists(filePath))
{
throw new FileNotFoundException($"The file '{filePath}' does not exist.");
}

string directory = Path.GetDirectoryName(filePath) ?? throw new Exception("Unable to determine the directory of the file.");
string gitRoot = RunGitCommandScalar(directory, "rev-parse --show-toplevel");

if (!filePath.StartsWith(FixupPath(gitRoot)))
{
throw new Exception($"The file '{filePath}' is not within the Git repository root '{gitRoot}'.");
}

return filePath.Substring(gitRoot.Length + 1).Replace(Path.DirectorySeparatorChar, '/');
}
}
}
Loading