Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/WingetCreateCLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,11 @@ protected async Task<bool> GitHubSubmitManifests(Manifests manifests)
Logger.ErrorLocalized(nameof(Resources.Error_Prefix), e.Message);
return false;
}
else if (e is NonFastForwardException nonFastForwardException)
else if (e is Octokit.NotFoundException)
{
Logger.ErrorLocalized(nameof(Resources.FastForwardUpdateFailed_Message), nonFastForwardException.CommitsAheadBy);
// This exception can occur if the client is unable to create a reference due to being behind by too many commits.
// The user will need to manually update their master branch of their winget-pkgs fork.
Logger.ErrorLocalized(nameof(Resources.SyncForkWithUpstream_Message));
return false;
}
else
Expand Down
18 changes: 9 additions & 9 deletions src/WingetCreateCLI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/WingetCreateCLI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -890,10 +890,6 @@
<data name="UpgradeCode_KeywordDescription" xml:space="preserve">
<value>UpgradeCode used for correlation of packages across sources</value>
</data>
<data name="FastForwardUpdateFailed_Message" xml:space="preserve">
<value>Failed to update fork because the default branch is ahead by {0} commit(s). </value>
<comment>{0} - represents the number of commits the default branch is ahead by</comment>
</data>
<data name="DisplayInstallWarnings_KeywordDescription" xml:space="preserve">
<value>Indicates whether winget should display a warning message if the install or upgrade is known to interfere with running applications</value>
</data>
Expand All @@ -919,4 +915,7 @@
<value>List of winget arguments the installer does not support</value>
<comment>"winget" is the proper name of the tool</comment>
</data>
<data name="SyncForkWithUpstream_Message" xml:space="preserve">
<value>Unable to create a reference to the forked repository. This can be caused when the forked repository is behind by too many commits. Sync your fork and try again.</value>
</data>
</root>
24 changes: 16 additions & 8 deletions src/WingetCreateCore/Common/GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,30 @@ private async Task<PullRequest> SubmitPRAsync(string packageId, string version,
var upstreamMasterSha = upstreamMaster.Object.Sha;

Reference newBranch = null;
bool forkSyncAttempted = false;

try
{
var retryPolicy = Policy.Handle<ApiException>().WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(i));
var retryPolicy = Policy
.Handle<ApiException>()
.Or<NonFastForwardException>()
.WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(i));

await retryPolicy.ExecuteAsync(async () =>
{
try
// Related issue: https://github.com/microsoft/winget-create/issues/282
// There is a known issue where a reference is unable to be created if the fork is behind by too many commits.
// Always attempt to sync fork during first execution in order to mitigate the possibility of this scenario occurring.
// If the fork is behind by too many commits, syncing will also fail with a NotFoundException.
// Updating the fork can fail if it is a non-fast forward update, but this should not be blocking as pull request submission can still proceed.
// If creating a reference fails, that means syncing the fork also failed, therefore the user will need to manually sync their repo regardless.
if (!forkSyncAttempted && submitToFork)
{
await this.github.Git.Reference.Create(repo.Id, new NewReference($"refs/{newBranchNameHeads}", upstreamMasterSha));
}
catch (Octokit.NotFoundException)
{
// Creating a reference can sometimes fail with a NotFoundException if the fork is not up to date with the upstream repository.
forkSyncAttempted = true;
await this.UpdateForkedRepoWithUpstreamCommits(repo);
throw;
}

await this.github.Git.Reference.Create(repo.Id, new NewReference($"refs/{newBranchNameHeads}", upstreamMasterSha));
});

// Update from upstream branch master
Expand Down