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

Enable changing root path to Git repository #138

Open
wants to merge 5 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
20 changes: 18 additions & 2 deletions Source/GitSourceControl/Private/GitSourceControlOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ bool FGitConnectWorker::Execute(FGitSourceControlCommand& InCommand)
{
// Now update the status of assets in Content/ directory and also Config files
TArray<FString> ProjectDirs;
ProjectDirs.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir()));
ProjectDirs.Add(FPaths::ConvertRelativePathToFull(FPaths::ProjectConfigDir()));
FString ProjContentDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectContentDir());
FString ProjectConfigDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectConfigDir());
if (ProjContentDir.Contains(InCommand.PathToRepositoryRoot))
{
ProjectDirs.Add(ProjContentDir);
}
if (ProjectConfigDir.Contains(InCommand.PathToRepositoryRoot))
{
ProjectDirs.Add(ProjectConfigDir);
}
InCommand.bCommandSuccessful = GitSourceControlUtils::RunUpdateStatus(InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, InCommand.bUsingGitLfsLocking, ProjectDirs, InCommand.ErrorMessages, States);
if(!InCommand.bCommandSuccessful || InCommand.ErrorMessages.Num() > 0)
{
Expand All @@ -60,6 +68,14 @@ bool FGitConnectWorker::Execute(FGitSourceControlCommand& InCommand)
InCommand.bCommandSuccessful = GitSourceControlUtils::RunCommand(TEXT("lfs locks"), InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, TArray<FString>(), TArray<FString>(), InCommand.InfoMessages, InCommand.ErrorMessages);
}
}

GitSourceControlUtils::GetCommitInfo(InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, InCommand.CommitId, InCommand.CommitSummary);

if (InCommand.bUsingGitLfsLocking)
{
// Check server connection by checking lock status (when using Git LFS file Locking worflow)
InCommand.bCommandSuccessful = GitSourceControlUtils::RunCommand(TEXT("lfs locks"), InCommand.PathToGitBinary, InCommand.PathToRepositoryRoot, TArray<FString>(), TArray<FString>(), InCommand.InfoMessages, InCommand.ErrorMessages);
}
}
else
{
Expand Down
56 changes: 52 additions & 4 deletions Source/GitSourceControl/Private/GitSourceControlProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void FGitSourceControlProvider::CheckGitAvailability()
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
FString PathToGitBinary = GitSourceControl.AccessSettings().GetBinaryPath();
FString PathToGitRepo = GitSourceControl.AccessSettings().GetRepoPath();

if(PathToGitBinary.IsEmpty())
{
// Try to find Git binary, and update settings accordingly
Expand All @@ -74,11 +76,57 @@ void FGitSourceControlProvider::CheckGitAvailability()
}
}

bool FGitSourceControlProvider::CheckIfValidRepository(const FString& InPathToGitBinary, const FString& InPathToGitRepo)
{
const FString PathToRepo = FPaths::ConvertRelativePathToFull(InPathToGitRepo);
bGitRepositoryFound = GitSourceControlUtils::FindRootDirectory(PathToRepo, PathToRepositoryRoot);
if (bGitRepositoryFound)
{
GitSourceControlMenu.Register();

// Get branch name
bGitRepositoryFound = GitSourceControlUtils::GetBranchName(InPathToGitBinary, PathToRepositoryRoot, BranchName);
if (bGitRepositoryFound)
{
GitSourceControlUtils::GetRemoteUrl(InPathToGitBinary, PathToRepositoryRoot, RemoteUrl);
}
else
{
UE_LOG(LogSourceControl, Error, TEXT("'%s' is not a valid Git repository"), *PathToRepositoryRoot);
}
}
else
{
UE_LOG(LogSourceControl, Warning, TEXT("'%s' is not part of a Git repository"), *FPaths::ProjectDir());
}

// Get user name & email (of the repository, else from the global Git config)
GitSourceControlUtils::GetUserConfig(InPathToGitBinary, PathToRepositoryRoot, UserName, UserEmail);
return bGitRepositoryFound;
}

void FGitSourceControlProvider::CheckRepositoryStatus(const FString& InPathToGitBinary)
{
// Find the path to the root Git directory (if any, else uses the ProjectDir)
const FString PathToProjectDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
bGitRepositoryFound = GitSourceControlUtils::FindRootDirectory(PathToProjectDir, PathToRepositoryRoot);
// Get the root Git directory from loaded settings
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
FString PathToGitRepo = GitSourceControl.AccessSettings().GetRepoPath();

FString SearchedGitRepo;

if (PathToGitRepo.IsEmpty())
{
// Find the path to the root Git directory (if any, else uses the ProjectDir)
const FString PathToProjectDir = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
bGitRepositoryFound = GitSourceControlUtils::FindRootDirectory(PathToProjectDir, PathToRepositoryRoot);
SearchedGitRepo = PathToProjectDir;
}
else
{
// make sure the saved root Git directory is still valid and copy the path
bGitRepositoryFound = GitSourceControlUtils::FindRootDirectory(PathToGitRepo, PathToRepositoryRoot);
SearchedGitRepo = PathToGitRepo;
}

if(bGitRepositoryFound)
{
GitSourceControlMenu.Register();
Expand All @@ -96,7 +144,7 @@ void FGitSourceControlProvider::CheckRepositoryStatus(const FString& InPathToGit
}
else
{
UE_LOG(LogSourceControl, Warning, TEXT("'%s' is not part of a Git repository"), *FPaths::ProjectDir());
UE_LOG(LogSourceControl, Warning, TEXT("'%s' is not part of a Git repository"), *SearchedGitRepo);
}

// Get user name & email (of the repository, else from the global Git config)
Expand Down
5 changes: 5 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class FGitSourceControlProvider : public ISourceControlProvider
*/
void CheckRepositoryStatus(const FString& InPathToGitBinary);

/**
* Check if a git repository can be found in the given path.
*/
bool CheckIfValidRepository(const FString& InPathToGitBinary, const FString& InPathToGitRepo);

/** Is git binary found and working. */
inline bool IsGitAvailable() const
{
Expand Down
19 changes: 19 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ const FString FGitSourceControlSettings::GetBinaryPath() const
return BinaryPath; // Return a copy to be thread-safe
}

const FString FGitSourceControlSettings::GetRepoPath() const
{
FScopeLock ScopeLock(&CriticalSection);
return RepoPath; // Return a copy to be thread-safe
}

bool FGitSourceControlSettings::SetBinaryPath(const FString& InString)
{
FScopeLock ScopeLock(&CriticalSection);
Expand All @@ -37,6 +43,17 @@ bool FGitSourceControlSettings::SetBinaryPath(const FString& InString)
return bChanged;
}

bool FGitSourceControlSettings::SetRepoPath(const FString& InString)
{
FScopeLock ScopeLock(&CriticalSection);
const bool bChanged = (RepoPath != InString);
if (bChanged)
{
RepoPath = InString;
}
return bChanged;
}

/** Tell if using the Git LFS file Locking workflow */
bool FGitSourceControlSettings::IsUsingGitLfsLocking() const
{
Expand Down Expand Up @@ -76,6 +93,7 @@ void FGitSourceControlSettings::LoadSettings()
FScopeLock ScopeLock(&CriticalSection);
const FString& IniFile = SourceControlHelpers::GetSettingsIni();
GConfig->GetString(*GitSettingsConstants::SettingsSection, TEXT("BinaryPath"), BinaryPath, IniFile);
GConfig->GetString(*GitSettingsConstants::SettingsSection, TEXT("RepoRootPath"), RepoPath, IniFile);
GConfig->GetBool(*GitSettingsConstants::SettingsSection, TEXT("UsingGitLfsLocking"), bUsingGitLfsLocking, IniFile);
GConfig->GetString(*GitSettingsConstants::SettingsSection, TEXT("LfsUserName"), LfsUserName, IniFile);
}
Expand All @@ -85,6 +103,7 @@ void FGitSourceControlSettings::SaveSettings() const
FScopeLock ScopeLock(&CriticalSection);
const FString& IniFile = SourceControlHelpers::GetSettingsIni();
GConfig->SetString(*GitSettingsConstants::SettingsSection, TEXT("BinaryPath"), *BinaryPath, IniFile);
GConfig->SetString(*GitSettingsConstants::SettingsSection, TEXT("RepoRootPath"), *RepoPath, IniFile);
GConfig->SetBool(*GitSettingsConstants::SettingsSection, TEXT("UsingGitLfsLocking"), bUsingGitLfsLocking, IniFile);
GConfig->SetString(*GitSettingsConstants::SettingsSection, TEXT("LfsUserName"), *LfsUserName, IniFile);
}
9 changes: 9 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ class FGitSourceControlSettings
/** Get the Git Binary Path */
const FString GetBinaryPath() const;

/** Get the Git Root Path */
const FString GetRepoPath() const;

/** Set the Git Binary Path */
bool SetBinaryPath(const FString& InString);

/** Set the Git Root Path */
bool SetRepoPath(const FString& InString);

/** Tell if using the Git LFS file Locking workflow */
bool IsUsingGitLfsLocking() const;

Expand All @@ -40,6 +46,9 @@ class FGitSourceControlSettings

/** Git binary path */
FString BinaryPath;

/** Git root path */
FString RepoPath;

/** Tells if using the Git LFS file Locking workflow */
bool bUsingGitLfsLocking;
Expand Down
41 changes: 39 additions & 2 deletions Source/GitSourceControl/Private/SGitSourceControlSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Widgets/Input/SCheckBox.h"
#include "Widgets/Input/SEditableTextBox.h"
#include "Widgets/Input/SFilePathPicker.h"
#include "Widgets/Input/SDirectoryPicker.h"
#include "Widgets/Input/SMultiLineEditableTextBox.h"
#include "Widgets/Layout/SBorder.h"
#include "Widgets/Layout/SSeparator.h"
Expand Down Expand Up @@ -102,11 +103,18 @@ void SGitSourceControlSettings::Construct(const FArguments& InArgs)
]
+SHorizontalBox::Slot()
.FillWidth(2.0f)
[
SNew(SDirectoryPicker)
.Directory(SGitSourceControlSettings::GetPathToRepositoryRoot())
.OnDirectoryChanged(this, &SGitSourceControlSettings::OnRepoPathPicked)
]
/**
[
SNew(STextBlock)
.Text(this, &SGitSourceControlSettings::GetPathToRepositoryRoot)
.Font(Font)
]
*/
]
// User Name
+SVerticalBox::Slot()
Expand Down Expand Up @@ -404,6 +412,13 @@ FString SGitSourceControlSettings::GetBinaryPathString() const
return GitSourceControl.AccessSettings().GetBinaryPath();
}

FString SGitSourceControlSettings::GetRepoPathString() const
{
const FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
return GitSourceControl.AccessSettings().GetRepoPath();
}


void SGitSourceControlSettings::OnBinaryPathPicked( const FString& PickedPath ) const
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
Expand All @@ -420,10 +435,32 @@ void SGitSourceControlSettings::OnBinaryPathPicked( const FString& PickedPath )
}
}

FText SGitSourceControlSettings::GetPathToRepositoryRoot() const
void SGitSourceControlSettings::OnRepoPathPicked(const FString& PickedPath) const
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
FString PickedFullPath = FPaths::ConvertRelativePathToFull(PickedPath);
FString PathToGitBinary = GitSourceControl.AccessSettings().GetBinaryPath();
bool RepoFound = GitSourceControl.GetProvider().CheckIfValidRepository(PathToGitBinary, PickedFullPath);
bool bChanged = false;
if (RepoFound)
{
bChanged = GitSourceControl.AccessSettings().SetRepoPath(PickedFullPath);
}
if (bChanged)
{
// Re-Check provided git binary path for each change
GitSourceControl.GetProvider().CheckGitAvailability();
if (GitSourceControl.GetProvider().IsGitAvailable())
{
GitSourceControl.SaveSettings();
}
}
}

FString SGitSourceControlSettings::GetPathToRepositoryRoot()
{
const FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
return FText::FromString(GitSourceControl.GetProvider().GetPathToRepositoryRoot());
return GitSourceControl.GetProvider().GetPathToRepositoryRoot();
}

FText SGitSourceControlSettings::GetUserName() const
Expand Down
10 changes: 7 additions & 3 deletions Source/GitSourceControl/Private/SGitSourceControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class SGitSourceControlSettings : public SCompoundWidget
/** Delegates to get Git binary path from/to settings */
FString GetBinaryPathString() const;
void OnBinaryPathPicked(const FString & PickedPath) const;

/** Delegate to get repository root, user name and email from provider */
FText GetPathToRepositoryRoot() const;

/** Delegates to get Git root path from/to settings */
FString GetRepoPathString() const;
void OnRepoPathPicked(const FString & PickedPath) const;

/** Delegate to get repository root, user name and email from provider */
FString GetPathToRepositoryRoot();
FText GetUserName() const;
FText GetUserEmail() const;

Expand Down