Skip to content

Commit

Permalink
Added function in GitSourceControlUtils to get the last revision from…
Browse files Browse the repository at this point in the history
… origin/develop
  • Loading branch information
Michael Delva authored and TheEmidee committed Jan 30, 2023
1 parent f339da5 commit ae2cdc7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
45 changes: 44 additions & 1 deletion Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,13 @@ void GetUserConfig(const FString& InPathToGitBinary, const FString& InRepository

bool GetBranchName(const FString& InPathToGitBinary, const FString& InRepositoryRoot, FString& OutBranchName)
{
const FGitSourceControlProvider& Provider = FGitSourceControlModule::Get().GetProvider();
auto * git_module = FModuleManager::Get().LoadModulePtr< FGitSourceControlModule >( "GitSourceControl" );
if ( git_module == nullptr )
{
return false;
}

const FGitSourceControlProvider & Provider = git_module->GetProvider();
if (!Provider.GetBranchName().IsEmpty())
{
OutBranchName = Provider.GetBranchName();
Expand Down Expand Up @@ -2157,6 +2163,43 @@ bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToReposit
return bSuccess;
}

TSharedPtr<ISourceControlRevision, ESPMode::ThreadSafe> GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray<FString> & OutErrorMessages )
{
TGitSourceControlHistory OutHistory;

TArray< FString > Results;
TArray< FString > Parameters;
Parameters.Add( TEXT( "origin/develop" ) );
Parameters.Add( TEXT( "--date=raw" ) );
Parameters.Add( TEXT( "--pretty=medium" ) ); // make sure format matches expected in ParseLogResults

TArray< FString > Files;
const auto bResults = RunCommand( TEXT( "show" ), InPathToGitBinary, InRepositoryRoot, Parameters, Files, Results, OutErrorMessages );

if ( bResults )
{
ParseLogResults( Results, OutHistory );
}

if ( OutHistory.Num() > 0 )
{
auto AbsoluteFileName = FPaths::ConvertRelativePathToFull( InRelativeFileName );

AbsoluteFileName.RemoveFromStart( InRepositoryRoot );

if ( AbsoluteFileName[ 0 ] == '/' )
{
AbsoluteFileName.RemoveAt( 0 );
}


OutHistory[ 0 ]->Filename = AbsoluteFileName;

return OutHistory[ 0 ];
}

return nullptr;
}
} // namespace GitSourceControlUtils

#undef LOCTEXT_NAMESPACE
3 changes: 3 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,7 @@ bool FetchRemote(const FString& InPathToGitBinary, const FString& InPathToReposi
bool PullOrigin(const FString& InPathToGitBinary, const FString& InPathToRepositoryRoot, const TArray<FString>& InFiles, TArray<FString>& OutFiles,
TArray<FString>& OutResults, TArray<FString>& OutErrorMessages);


TSharedPtr< class ISourceControlRevision, ESPMode::ThreadSafe > GetOriginDevelopRevision( const FString & InPathToGitBinary, const FString & InRepositoryRoot, const FString & InRelativeFileName, TArray< FString > & OutErrorMessages );

}

0 comments on commit ae2cdc7

Please sign in to comment.