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

make files read only at the end of checkin command. This will allow u… #108

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "GitSourceControlModule.h"
#include "GitSourceControlCommand.h"
#include "GitSourceControlUtils.h"
#include "IPlatformFileProfilerWrapper.h"
#include "PlatformFilemanager.h"

#define LOCTEXT_NAMESPACE "GitSourceControl"

Expand Down Expand Up @@ -184,6 +186,11 @@ bool FGitCheckInWorker::Execute(FGitSourceControlCommand& InCommand)
const FString Message = (InCommand.InfoMessages.Num() > 0) ? InCommand.InfoMessages[0] : TEXT("");
UE_LOG(LogSourceControl, Log, TEXT("commit successful: %s"), *Message);

for (const FString& File : InCommand.Files)
{
FPlatformFileManager::Get().GetPlatformFile().SetReadOnly(*File, true);
}

// git-lfs: push and unlock files
if(InCommand.bUsingGitLfsLocking && InCommand.bCommandSuccessful)
{
Expand All @@ -193,14 +200,15 @@ bool FGitCheckInWorker::Execute(FGitSourceControlCommand& InCommand)
// unlock files: execute the LFS command on relative filenames
// (unlock only locked files, that is, not Added files)
const TArray<FString> LockedFiles = GetLockedFiles(InCommand.Files);

if(LockedFiles.Num() > 0)
{
const TArray<FString> RelativeFiles = GitSourceControlUtils::RelativeFilenames(LockedFiles, InCommand.PathToRepositoryRoot);
for(const auto& RelativeFile : RelativeFiles)
{
TArray<FString> OneFile;
OneFile.Add(RelativeFile);
GitSourceControlUtils::RunCommand(TEXT("lfs unlock"), InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, TArray<FString>(), OneFile, InCommand.InfoMessages, InCommand.ErrorMessages);
GitSourceControlUtils::RunCommand(TEXT("lfs unlock"), InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, TArray<FString>(), OneFile, InCommand.InfoMessages, InCommand.ErrorMessages);
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,11 @@ bool RunUpdateStatus(const FString& InPathToGitBinary, const FString& InReposito
LockedFiles.Add(MoveTemp(LockFile.LocalFilename), MoveTemp(LockFile.LockUser));
}
}
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");



const FString LfsUserName = GitSourceControl.AccessSettings().GetLfsUserName();
// Git status does not show any "untracked files" when called with files from different subdirectories! (issue #3)
// 1) So here we group files by path (ie. by subdirectory)
TMap<FString, TArray<FString>> GroupOfFiles;
Expand All @@ -1033,6 +1037,23 @@ bool RunUpdateStatus(const FString& InPathToGitBinary, const FString& InReposito
NewGroup.Add(File);
GroupOfFiles.Add(Path, NewGroup);
}

if (LockedFiles.Contains(File))
{
TSharedRef<FGitSourceControlState, ESPMode::ThreadSafe> State= GitSourceControl.GetProvider().GetStateInternal(File, true);

State->LockUser = LockedFiles[File];
if (LfsUserName == State->LockUser)
{
State->LockState = ELockState::Locked;
}
else
{
State->LockState = ELockState::LockedOther;
}
// TODO LFS Debug log
//UE_LOG(LogSourceControl, Log, TEXT("Status(%s) Locked by '%s'"), *File, *FileState.LockUser);
}
}

// Get the current branch name, since we need origin of current branch
Expand Down