Skip to content

fix: Do not error out if remote missing #46

New issue

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

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

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
14 changes: 13 additions & 1 deletion Git/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Init(string repository)
if (!Directory.Exists(GitPath)) Directory.CreateDirectory(GitPath);
if (!File.Exists(Path.Join(GitPath, ".git", "config"))) RunCommand($"init");

RunCommand($"config remove-section remote.origin");
RunCommandIgnoreErrors($"config remove-section remote.origin");
RunCommand($"remote add origin --mirror=fetch {repository}");
}

Expand Down Expand Up @@ -137,6 +137,18 @@ public void SetBranchRef(string branch, string reference)
RunCommand($"branch -f {branch} {reference}");
}

void RunCommandIgnoreErrors(string arguments)
{
try
{
RunCommand(arguments);
}
catch (ApplicationException)
{
// We are deliberately ignoring errors; RunCommand will have already printed them
}
}

void RunCommand(string arguments)
{
foreach (var line in GetCommandOutput(arguments, true))
Expand Down
Loading