Skip to content

Commit

Permalink
Merge pull request #4309 from unisonweb/cp/relax-hash-mismatch
Browse files Browse the repository at this point in the history
Relax hash-mismatch errors if the remote head is what we wanted
  • Loading branch information
aryairani authored Sep 6, 2023
2 parents fac59ee + 7c3df64 commit a8e45bb
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions unison-cli/src/Unison/Codebase/Editor/HandleInput/Push.hs
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,24 @@ makeSetHeadAfterUploadAction force pushing localBranchHead remoteBranch = do
branchOldCausalHash = Just remoteBranchHead,
branchNewCausalHash = localBranchHead
}
let onSuccess =
case pushing of
PushingLooseCode -> pure ()
PushingProjectBranch (ProjectAndBranch localProject localBranch) -> do
Cli.runTransaction do
Queries.ensureBranchRemoteMapping
(localProject ^. #projectId)
(localBranch ^. #branchId)
(remoteBranch ^. #projectId)
Share.hardCodedUri
(remoteBranch ^. #branchId)
Share.setProjectBranchHead request >>= \case
Share.SetProjectBranchHeadResponseSuccess -> onSuccess
-- Sometimes a different request gets through in between checking the remote head and
-- executing the check-and-set push, if it managed to set the head to what we wanted
-- then the goal was achieved and we can consider it a success.
Share.SetProjectBranchHeadResponseExpectedCausalHashMismatch _expected actual
| actual == localBranchHead -> onSuccess
Share.SetProjectBranchHeadResponseExpectedCausalHashMismatch _expected _actual ->
Cli.returnEarly (RemoteProjectBranchHeadMismatch Share.hardCodedUri remoteProjectAndBranchNames)
Share.SetProjectBranchHeadResponseNotFound -> do
Expand All @@ -758,17 +775,6 @@ makeSetHeadAfterUploadAction force pushing localBranchHead remoteBranch = do
Cli.returnEarly (Output.RemoteProjectReleaseIsDeprecated Share.hardCodedUri remoteProjectAndBranchNames)
Share.SetProjectBranchHeadResponsePublishedReleaseIsImmutable -> do
Cli.returnEarly (Output.RemoteProjectPublishedReleaseCannotBeChanged Share.hardCodedUri remoteProjectAndBranchNames)
Share.SetProjectBranchHeadResponseSuccess -> do
case pushing of
PushingLooseCode -> pure ()
PushingProjectBranch (ProjectAndBranch localProject localBranch) -> do
Cli.runTransaction do
Queries.ensureBranchRemoteMapping
(localProject ^. #projectId)
(localBranch ^. #branchId)
(remoteBranch ^. #projectId)
Share.hardCodedUri
(remoteBranch ^. #branchId)
where
remoteBranchHead =
Share.API.hashJWTHash (remoteBranch ^. #branchHead)
Expand Down

0 comments on commit a8e45bb

Please sign in to comment.