Skip to content

Properly evaluate gitignore and skip ignored files #186

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

Open
wants to merge 2 commits into
base: dev
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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ FGitSourceControlCommand::FGitSourceControlCommand(const TSharedRef<class ISourc

void FGitSourceControlCommand::UpdateRepositoryRootIfSubmodule(TArray<FString>& AbsoluteFilePaths)
{
PathToRepositoryRoot = GitSourceControlUtils::ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot);
PathToRepositoryRoot = GitSourceControlUtils::ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToGitBinary, PathToRepositoryRoot);
}

bool FGitSourceControlCommand::DoWork()
Expand Down
8 changes: 8 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,15 @@ ECommandResult::Type FGitSourceControlProvider::Execute( const FSourceControlOpe
}

FGitSourceControlCommand* Command = new FGitSourceControlCommand(InOperation, Worker.ToSharedRef());
const bool bCancelCommand = AbsoluteFiles.Num() > 0;
Command->UpdateRepositoryRootIfSubmodule(AbsoluteFiles);
if (bCancelCommand &&
AbsoluteFiles.Num() == 0)
{
delete Command;
return ECommandResult::Succeeded;
}

Command->Files = AbsoluteFiles;
Command->OperationCompleteDelegate = InOperationCompleteDelegate;

Expand Down
31 changes: 28 additions & 3 deletions Source/GitSourceControl/Private/GitSourceControlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void FGitLockedFilesCache::OnFileLockChanged(const FString& filePath, const FStr

namespace GitSourceControlUtils
{
FString ChangeRepositoryRootIfSubmodule(TArray<FString>& AbsoluteFilePaths, const FString& PathToRepositoryRoot)
FString ChangeRepositoryRootIfSubmodule(TArray<FString>& AbsoluteFilePaths, const FString& PathToGitBinary, const FString& PathToRepositoryRoot)
{
FString Ret = PathToRepositoryRoot;
// note this is not going to support operations where selected files are in different repositories
Expand Down Expand Up @@ -166,6 +166,7 @@ namespace GitSourceControlUtils
}
}
}

if (!PackageNotIncludedInGit.IsEmpty())
{
for (const FString& ToRemoveFile : PackageNotIncludedInGit)
Expand All @@ -174,13 +175,37 @@ namespace GitSourceControlUtils
}
}

if (AbsoluteFilePaths.Num() > 0)
{
PackageNotIncludedInGit = {};
PackageNotIncludedInGit.Reserve(AbsoluteFilePaths.Num());

TArray<FString> ErrorMessages;
RunCommand(
TEXT("check-ignore"),
PathToGitBinary,
PathToRepositoryRoot,
FGitSourceControlModule::GetEmptyStringArray(),
AbsoluteFilePaths,
PackageNotIncludedInGit,
ErrorMessages);

if (!PackageNotIncludedInGit.IsEmpty())
{
for (const FString& ToRemoveFile : PackageNotIncludedInGit)
{
AbsoluteFilePaths.Remove(ToRemoveFile);
}
}
}

return Ret;
}

FString ChangeRepositoryRootIfSubmodule(FString & AbsoluteFilePath, const FString& PathToRepositoryRoot)
FString ChangeRepositoryRootIfSubmodule(FString & AbsoluteFilePath, const FString& PathToGitBinary, const FString& PathToRepositoryRoot)
{
TArray<FString> AbsoluteFilePaths = { AbsoluteFilePath };
return ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToRepositoryRoot);
return ChangeRepositoryRootIfSubmodule(AbsoluteFilePaths, PathToGitBinary, PathToRepositoryRoot);
}

// Launch the Git command line process and extract its results & errors
Expand Down
6 changes: 4 additions & 2 deletions Source/GitSourceControl/Public/GitSourceControlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ namespace GitSourceControlUtils
* This supports the case where each plugin is a sub module
*
* @param AbsoluteFilePaths The list of files in the SC operation
* @param PathToGitBinary The path to the Git binary
* @param PathToRepositoryRoot The original path to the repository root (used by default)
*/
FString ChangeRepositoryRootIfSubmodule(TArray<FString>& AbsoluteFilePaths, const FString& PathToRepositoryRoot);
FString ChangeRepositoryRootIfSubmodule(TArray<FString>& AbsoluteFilePaths, const FString& PathToGitBinary, const FString& PathToRepositoryRoot);

/**
* Returns an updated repo root if all selected file is in a plugin subfolder, and the plugin subfolder is a git repo
* This supports the case where each plugin is a sub module
*
* @param AbsoluteFilePath The file in the SC operation
* @param PathToGitBinary The path to the Git binary
* @param PathToRepositoryRoot The original path to the repository root (used by default)
*/
FString ChangeRepositoryRootIfSubmodule(FString & AbsoluteFilePath, const FString& PathToRepositoryRoot);
FString ChangeRepositoryRootIfSubmodule(FString & AbsoluteFilePath, const FString& PathToGitBinary, const FString& PathToRepositoryRoot);

/**
* Find the path to the Git binary, looking into a few places (standalone Git install, and other common tools embedding Git)
Expand Down