Skip to content

Commit 6b5c5a5

Browse files
authored
Merge pull request #63 from PlasticSCM/1002863-fix-shelve-loosing-files
Fix shelving files could lead to losing some changes previously shelved
2 parents bdec2f1 + fed42a3 commit 6b5c5a5

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

Source/PlasticSourceControl/Private/PlasticSourceControlOperations.cpp

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,8 @@ bool FPlasticShelveWorker::Execute(FPlasticSourceControlCommand& InCommand)
17161716

17171717
int32 PreviousShelveId = ISourceControlState::INVALID_REVISION;
17181718

1719+
InCommand.bCommandSuccessful = true;
1720+
17191721
if (InCommand.Changelist.IsInitialized())
17201722
{
17211723
TSharedRef<FPlasticSourceControlChangelistState, ESPMode::ThreadSafe> ChangelistState = GetProvider().GetStateInternal(InCommand.Changelist);
@@ -1727,37 +1729,48 @@ bool FPlasticShelveWorker::Execute(FPlasticSourceControlCommand& InCommand)
17271729
{
17281730
FilesToShelve = FileNamesFromFileStates(ChangelistState->Files);
17291731
}
1730-
// If the command has specified some files but not all, and if there was already a shelve with,
1732+
// If the command has specified some files, and if there was already a shelve,
17311733
// ensure that the previous shelved files are also put back into the new one.
17321734
// This is to mimic Perforce behavior, where we can add files to a shelve after we made more changes.
17331735
// NOTE: this is a workaround for the fact that we cannot edit an existing shelve.
1734-
else if ((FilesToShelve.Num() < ChangelistState->Files.Num()) && (ChangelistState->ShelvedFiles.Num() > 0))
1736+
else if (ChangelistState->ShelvedFiles.Num() > 0)
17351737
{
17361738
for (const FSourceControlStateRef& ShelveFile : ChangelistState->ShelvedFiles)
17371739
{
17381740
FilesToShelve.AddUnique(ShelveFile->GetFilename());
17391741
}
17401742
}
1741-
}
17421743

1743-
// If the command is issued on the default changelist, then we need to create a new changelist,
1744-
// move the files to the new changelist, then shelve the files
1745-
if (InCommand.Changelist.IsDefault())
1746-
{
1747-
// Create a new numbered persistent changelist ala Perforce
1748-
Changelist = CreatePendingChangelist(GetProvider(), Operation->GetDescription().ToString(), InCommand.InfoMessages, InCommand.ErrorMessages);
1749-
if (Changelist.IsInitialized())
1744+
// Ensure that all the files to shelve are indeed in the changelist, so that we can actually shelve them
1745+
// NOTE: this is because of the workaround that requires to create a new shelve and delete the old one
1746+
for (FString& FileToShelve : FilesToShelve)
17501747
{
1751-
InCommand.bCommandSuccessful = MoveFilesToChangelist(GetProvider(), Changelist, FilesToShelve, InCommand.InfoMessages, InCommand.ErrorMessages);
1752-
if (InCommand.bCommandSuccessful)
1748+
if (!ChangelistState->Files.ContainsByPredicate([&FileToShelve](const FSourceControlStateRef& FileState) { return FileToShelve == FileState->GetFilename(); }))
17531749
{
1754-
MovedFiles = FilesToShelve;
1750+
FPaths::MakePathRelativeTo(FileToShelve, *FPaths::ProjectDir());
1751+
UE_LOG(LogSourceControl, Error, TEXT("The file /%s is not in the changelist anymore, so the shelve cannot be updated. Unshelve the corresponding change and retry."), *FileToShelve);
1752+
InCommand.bCommandSuccessful = false;
17551753
}
17561754
}
17571755
}
1758-
else
1756+
1757+
if (InCommand.bCommandSuccessful)
17591758
{
1760-
InCommand.bCommandSuccessful = true;
1759+
// If the command is issued on the default changelist, then we need to create a new changelist,
1760+
// move the files to the new changelist, then shelve the files
1761+
if (InCommand.Changelist.IsDefault())
1762+
{
1763+
// Create a new numbered persistent changelist ala Perforce
1764+
Changelist = CreatePendingChangelist(GetProvider(), Operation->GetDescription().ToString(), InCommand.InfoMessages, InCommand.ErrorMessages);
1765+
if (Changelist.IsInitialized())
1766+
{
1767+
InCommand.bCommandSuccessful = MoveFilesToChangelist(GetProvider(), Changelist, FilesToShelve, InCommand.InfoMessages, InCommand.ErrorMessages);
1768+
if (InCommand.bCommandSuccessful)
1769+
{
1770+
MovedFiles = FilesToShelve;
1771+
}
1772+
}
1773+
}
17611774
}
17621775

17631776
if (InCommand.bCommandSuccessful)

0 commit comments

Comments
 (0)