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

Implemented support for "Not at Head Revision" in UE4 Git #95

Merged
merged 4 commits into from
Apr 11, 2019
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
37 changes: 35 additions & 2 deletions Source/GitSourceControl/Private/GitSourceControlState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ TSharedPtr<class ISourceControlRevision, ESPMode::ThreadSafe> FGitSourceControlS
// @todo add Slate icons for git specific states (NotAtHead vs Conflicted...)
FName FGitSourceControlState::GetIconName() const
{
// Icon for not being up-to-date.
if (!IsCurrent())
{
return FName("Subversion.NotAtHeadRevision");
}


if(LockState == ELockState::Locked)
{
return FName("Subversion.CheckedOut");
Expand Down Expand Up @@ -106,6 +113,12 @@ FName FGitSourceControlState::GetIconName() const

FName FGitSourceControlState::GetSmallIconName() const
{
// Icon for not being up-to-date.
if (!IsCurrent())
{
return FName("Subversion.NotAtHeadRevision_Small");
}

if(LockState == ELockState::Locked)
{
return FName("Subversion.CheckedOut_Small");
Expand Down Expand Up @@ -150,6 +163,13 @@ FName FGitSourceControlState::GetSmallIconName() const

FText FGitSourceControlState::GetDisplayName() const
{
// Let the user know that a newer version is available
if (!IsCurrent())
{
return LOCTEXT("NotCurrent", "Not current");
}


if(LockState == ELockState::Locked)
{
return LOCTEXT("Locked", "Locked For Editing");
Expand Down Expand Up @@ -190,6 +210,13 @@ FText FGitSourceControlState::GetDisplayName() const

FText FGitSourceControlState::GetDisplayTooltip() const
{
// Let the user know that a newer version is available
if (!IsCurrent())
{
return LOCTEXT("NotCurrent_Tooltip", "The file(s) are not at the head revision");
}


if(LockState == ELockState::Locked)
{
return LOCTEXT("Locked_Tooltip", "Locked for editing by current user");
Expand Down Expand Up @@ -259,7 +286,12 @@ bool FGitSourceControlState::CanCheckout() const
{
if(bUsingGitLfsLocking)
{
return (WorkingCopyState == EWorkingCopyState::Unchanged || WorkingCopyState == EWorkingCopyState::Modified) && LockState == ELockState::NotLocked;
return (WorkingCopyState == EWorkingCopyState::Unchanged || WorkingCopyState == EWorkingCopyState::Modified)
&& LockState == ELockState::NotLocked
// We don't want to allow checkout if the file is out-of-date, as modifying an out-of-date binary file will most likely result in a merge conflict
&& IsCurrent()

;
}
else
{
Expand Down Expand Up @@ -290,7 +322,8 @@ bool FGitSourceControlState::IsCheckedOutOther(FString* Who) const

bool FGitSourceControlState::IsCurrent() const
{
return true; // @todo check the state of the HEAD versus the state of tracked branch on remote
return !bIsOutdated;

}

bool FGitSourceControlState::IsSourceControlled() const
Expand Down
6 changes: 6 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlState.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class FGitSourceControlState : public ISourceControlState, public TSharedFromThi
, LockState(ELockState::Unknown)
, bUsingGitLfsLocking(InUsingLfsLocking)
, TimeStamp(0)
, bIsOutdated(false)

{
}

Expand Down Expand Up @@ -110,4 +112,8 @@ class FGitSourceControlState : public ISourceControlState, public TSharedFromThi

/** The timestamp of the last update */
FDateTime TimeStamp;

// For use with FGitSourceControlState::IsCurrent
bool bIsOutdated;

};
43 changes: 43 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,49 @@ bool RunUpdateStatus(const FString& InPathToGitBinary, const FString& InReposito
{
ParseStatusResults(InPathToGitBinary, InRepositoryRoot, InUsingLfsLocking, Files.Value, LockedFiles, Results, OutStates);
}

// Using git diff, we can obtain a list of files that were modified between our current origin and HEAD. Assumes that fetch has been run to get accurate info.

// First we get the current branch name, since we need origin of current branch
Parameters.Empty();
FString BranchName;
if (GitSourceControlUtils::GetBranchName(InPathToGitBinary, InRepositoryRoot, BranchName))
{
FString GitCommand = FString::Printf(TEXT("diff --name-only origin/%s HEAD"), *BranchName);

const bool bResultDiff = RunCommand(GitCommand, InPathToGitBinary, InRepositoryRoot, Parameters, OnePath, Results, ErrorMessages);
OutErrorMessages.Append(ErrorMessages);
if (bResultDiff)
{
const FDateTime Now = FDateTime::Now();
for (const auto& FileName : Results)
{
const FString AbsoluteFilePath = FPaths::ConvertRelativePathToFull(InRepositoryRoot, FileName);

// Check if already exists, and if so, update
bool FoundMatch = false;
for (INT i = 0; i < OutStates.Num(); i++)
{
FGitSourceControlState& FileState = OutStates[i];

if (FileState.LocalFilename != AbsoluteFilePath) continue;

FileState.bIsOutdated = true;

FoundMatch = true;
break;
}
if (FoundMatch) continue;

// If no match, add entry

FGitSourceControlState FileState(FileName, InUsingLfsLocking);
FileState.TimeStamp = Now;
FileState.bIsOutdated = true;
}
}
}

}

return bResults;
Expand Down