Skip to content
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

Add support for Unreal 5 "soft revert" to undockeckout without reverting the file content #70

Merged
merged 5 commits into from
Mar 8, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -594,51 +594,101 @@ bool FPlasticRevertWorker::Execute(FPlasticSourceControlCommand& InCommand)

check(InCommand.Operation->GetName() == GetName());
TSharedRef<FRevert, ESPMode::ThreadSafe> Operation = StaticCastSharedRef<FRevert>(InCommand.Operation);
#if ENGINE_MAJOR_VERSION == 5
const bool bIsSoftRevert = Operation->IsSoftRevert();
#else
const bool bIsSoftRevert = false;
#endif
if (bIsSoftRevert && GetProvider().GetPlasticScmVersion() < PlasticSourceControlVersions::UndoCheckoutKeepChanges)
{
// If a soft revert is requested but not supported by the version of Plastic SCM, warn the user and stop
FText FailureText = FText::FormatOrdered(
LOCTEXT("Plastic version Error", "Plastic SCM {0} cannot keep changes when undoing the checkout of the selected files. Update to version {1} or above."),
FText::FromString(*GetProvider().GetPlasticScmVersion().String),
FText::FromString(*PlasticSourceControlVersions::UndoCheckoutKeepChanges.String));

TArray<FString> Files = GetFilesFromCommand(GetProvider(), InCommand);
AsyncTask(ENamedThreads::GameThread, [FailureText]
{
FMessageLog LocalizationServiceMessageLog("SourceControl");
LocalizationServiceMessageLog.Error(FailureText);
LocalizationServiceMessageLog.Notify(FailureText, EMessageSeverity::Error, true);
});

return false;
}

for (int i = 0; i < Files.Num(); i++) // Required for loop on index since we are adding to the Files array as we go
{
const FString& File = Files[i];
const TArray<FString> Files = GetFilesFromCommand(GetProvider(), InCommand);

TArray<FString> LocallyChangedFiles;
TArray<FString> CheckedOutFiles;

for (const FString& File : Files)
{
const TSharedRef<const FPlasticSourceControlState, ESPMode::ThreadSafe> State = GetProvider().GetStateInternal(File);

if (State->WorkspaceState == EWorkspaceState::Moved)
if (State->WorkspaceState == EWorkspaceState::Changed)
{
const FString& MovedFrom = State->MovedFrom;

// In case of a file Moved/Renamed, consider the rename Origin (where there is now a Redirector file Added)
// and add it to the list of files to revert (only if it is not already in) to revert both at once
if (!Files.FindByPredicate([&MovedFrom](const FString& File) { return File.Equals(MovedFrom, ESearchCase::IgnoreCase); }))
LocallyChangedFiles.Add(State->LocalFilename);
}
else
{
CheckedOutFiles.Add(State->LocalFilename);
// in case of a Moved/Renamed, find the rename origin to revert both at once
if (State->WorkspaceState == EWorkspaceState::Moved)
{
Files.Add(MovedFrom);
}
const FString& MovedFrom = State->MovedFrom;

// and delete the Redirector (else the reverted file will collide with it and create a *.private.0 file)
IFileManager::Get().Delete(*MovedFrom);
}
// In case of a file Moved/Renamed, consider the rename Origin (where there is now a Redirector file Added)
// and add it to the list of files to revert (only if it is not already in) to revert both at once
if (!CheckedOutFiles.FindByPredicate([&MovedFrom](const FString& File) { return File.Equals(MovedFrom, ESearchCase::IgnoreCase); }))
{
CheckedOutFiles.Add(MovedFrom);
}

// and delete the Redirector (else the reverted file will collide with it and create a *.private.0 file)
IFileManager::Get().Delete(*MovedFrom);
}
#if ENGINE_MAJOR_VERSION == 5
if (State->WorkspaceState == EWorkspaceState::Added && Operation->ShouldDeleteNewFiles())
{
IFileManager::Get().Delete(*File);
}
else if (State->WorkspaceState == EWorkspaceState::Added && Operation->ShouldDeleteNewFiles())
{
IFileManager::Get().Delete(*File);
}
#endif
}
}

InCommand.bCommandSuccessful = true;

if (Files.Num() > 0)
if (LocallyChangedFiles.Num() > 0)
{
if (-1 != InCommand.ChangesetNumber)
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undochange"), TArray<FString>(), LocallyChangedFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
}
else
{
// partial undochange doesn't exist in partial mode
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("partial undo"), TArray<FString>(), LocallyChangedFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
}
}

if (CheckedOutFiles.Num() > 0)
{
TArray<FString> Parameters;
if (bIsSoftRevert)
{
Parameters.Add(TEXT("--keepchanges"));
}

// revert the checkout and any changes of the given file in workspace
// Detect special case for a partial checkout (CS:-1 in Gluon mode)!
if (-1 != InCommand.ChangesetNumber)
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undo"), TArray<FString>(), Files, InCommand.InfoMessages, InCommand.ErrorMessages);
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("undocheckout"), Parameters, CheckedOutFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
}
else
{
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("partial undo"), TArray<FString>(), Files, InCommand.InfoMessages, InCommand.ErrorMessages);
InCommand.bCommandSuccessful &= PlasticSourceControlUtils::RunCommand(TEXT("partial undocheckout"), Parameters, CheckedOutFiles, InCommand.InfoMessages, InCommand.ErrorMessages);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace EWorkspaceState
Unknown,
Ignored,
Controlled, // called "Pristine" in Perforce, "Unchanged" in Git, "Clean" in SVN
CheckedOut,
CheckedOut, // Checked-out, without telling if Changed or not
Added,
Moved, // Renamed
Copied,
Replaced, // Replaced / Merged
Deleted,
LocallyDeleted, // Missing
Changed, // Modified but not CheckedOut
Changed, // Locally Changed but not CheckedOut
Conflicted,
Private, // "Not Controlled"/"Not In Depot"/"Untracked"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ namespace PlasticSourceControlVersions
// https://www.plasticscm.com/download/releasenotes/11.0.16.7608
static const FSoftwareVersion NewHistoryLimit(TEXT("11.0.16.7608"));

// 11.0.16.7608 add support for undocheckout --keepchanges. It allows undo checkout and preserve all local changes.
// https://www.plasticscm.com/download/releasenotes/11.0.16.7665
static const FSoftwareVersion UndoCheckoutKeepChanges(TEXT("11.0.16.7665"));

} // namespace PlasticSourceControlVersions