Skip to content

Commit

Permalink
Merge pull request #146 from sinbad/no-push-option-lfs
Browse files Browse the repository at this point in the history
Add the option to NOT push after commit on Submit when using LFS
  • Loading branch information
SRombauts authored Apr 4, 2022
2 parents 3d9026a + 6628b99 commit af646aa
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ bool FGitCheckInWorker::Execute(FGitSourceControlCommand& InCommand)
UE_LOG(LogSourceControl, Log, TEXT("commit successful: %s"), *Message);

// git-lfs: push and unlock files
if(InCommand.bUsingGitLfsLocking && InCommand.bCommandSuccessful)
if(InCommand.bUsingGitLfsLocking &&
InCommand.bCommandSuccessful &&
GitSourceControl.AccessSettings().IsPushAfterCommitEnabled())
{
TArray<FString> Parameters2;
// TODO Configure origin
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 @@ -70,6 +70,23 @@ bool FGitSourceControlSettings::SetLfsUserName(const FString& InString)
return bChanged;
}

bool FGitSourceControlSettings::SetIsPushAfterCommitEnabled(bool bInEnabled)
{
FScopeLock ScopeLock(&CriticalSection);
const bool bChanged = (bIsPushAfterCommitEnabled != bInEnabled);
if (bChanged)
{
bIsPushAfterCommitEnabled = bInEnabled;
}
return bChanged;
}

bool FGitSourceControlSettings::IsPushAfterCommitEnabled() const
{
FScopeLock ScopeLock(&CriticalSection);
return bIsPushAfterCommitEnabled;
}

// This is called at startup nearly before anything else in our module: BinaryPath will then be used by the provider
void FGitSourceControlSettings::LoadSettings()
{
Expand All @@ -78,6 +95,7 @@ void FGitSourceControlSettings::LoadSettings()
GConfig->GetString(*GitSettingsConstants::SettingsSection, TEXT("BinaryPath"), BinaryPath, IniFile);
GConfig->GetBool(*GitSettingsConstants::SettingsSection, TEXT("UsingGitLfsLocking"), bUsingGitLfsLocking, IniFile);
GConfig->GetString(*GitSettingsConstants::SettingsSection, TEXT("LfsUserName"), LfsUserName, IniFile);
GConfig->GetBool(*GitSettingsConstants::SettingsSection, TEXT("IsPushAfterCommitEnabled"), bIsPushAfterCommitEnabled, IniFile);
}

void FGitSourceControlSettings::SaveSettings() const
Expand All @@ -87,4 +105,5 @@ void FGitSourceControlSettings::SaveSettings() const
GConfig->SetString(*GitSettingsConstants::SettingsSection, TEXT("BinaryPath"), *BinaryPath, IniFile);
GConfig->SetBool(*GitSettingsConstants::SettingsSection, TEXT("UsingGitLfsLocking"), bUsingGitLfsLocking, IniFile);
GConfig->SetString(*GitSettingsConstants::SettingsSection, TEXT("LfsUserName"), *LfsUserName, IniFile);
GConfig->SetBool(*GitSettingsConstants::SettingsSection, TEXT("IsPushAfterCommitEnabled"), bIsPushAfterCommitEnabled, IniFile);
}
9 changes: 9 additions & 0 deletions Source/GitSourceControl/Private/GitSourceControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class FGitSourceControlSettings
/** Set the username used by the Git LFS 2 File Locks server */
bool SetLfsUserName(const FString& InString);

/** Set whether Submit means Commit AND push (default true) */
bool SetIsPushAfterCommitEnabled(bool bCond);

/** Get whether Submit means Commit AND push (default true) */
bool IsPushAfterCommitEnabled() const;

/** Load settings from ini file */
void LoadSettings();

Expand All @@ -46,4 +52,7 @@ class FGitSourceControlSettings

/** Username used by the Git LFS 2 File Locks server */
FString LfsUserName;

/** Does Submit mean Commit AND push */
bool bIsPushAfterCommitEnabled = true;
};
48 changes: 48 additions & 0 deletions Source/GitSourceControl/Private/SGitSourceControlSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,36 @@ void SGitSourceControlSettings::Construct(const FArguments& InArgs)
.Font(Font)
]
]
// Option that can be disabled to make Submit ONLY commit and not push
// This is useful in these cases:
// - To do a bunch of local commits more quickly and push in one go
// - Working disconnected
// - To combine asset changes with C++ changes in one commit; you can amend the UE commit to add the C++ changes before push
// Push can be used separately and will unlock files if using LFS locking.
+SVerticalBox::Slot()
.AutoHeight()
.Padding(2.0f)
.VAlign(VAlign_Center)
[
SNew(SHorizontalBox)
.ToolTipText(LOCTEXT("GitPushAfterCommit_Tooltip", "Always try to Push (and unlock) after Commit on Submit when using LFS. Turning this off means you have to Push separately; Push will unlock LFS files."))
+SHorizontalBox::Slot()
.FillWidth(0.1f)
[
SNew(SCheckBox)
.IsChecked(SGitSourceControlSettings::IsPushAfterCommitEnabled())
.OnCheckStateChanged(this, &SGitSourceControlSettings::OnIsPushAfterCommitEnabled)
.IsEnabled(this, &SGitSourceControlSettings::GetIsUsingGitLfsLocking)
]
+SHorizontalBox::Slot()
.FillWidth(3.f)
.VAlign(VAlign_Center)
[
SNew(STextBlock)
.Text(LOCTEXT("GitPushAfterCommit", "Submit means Commit AND Push"))
.Font(Font)
]
]
// Option to Make the initial Git commit with custom message
+SVerticalBox::Slot()
.AutoHeight()
Expand Down Expand Up @@ -699,6 +729,24 @@ bool SGitSourceControlSettings::GetIsUsingGitLfsLocking() const
return GitSourceControl.AccessSettings().IsUsingGitLfsLocking();
}

void SGitSourceControlSettings::OnIsPushAfterCommitEnabled(ECheckBoxState NewCheckedState)
{
FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
GitSourceControl.AccessSettings().SetIsPushAfterCommitEnabled(NewCheckedState == ECheckBoxState::Checked);
GitSourceControl.AccessSettings().SaveSettings();
}

bool SGitSourceControlSettings::GetIsPushAfterCommitEnabled() const
{
const FGitSourceControlModule& GitSourceControl = FModuleManager::GetModuleChecked<FGitSourceControlModule>("GitSourceControl");
return GitSourceControl.AccessSettings().IsPushAfterCommitEnabled();
}

ECheckBoxState SGitSourceControlSettings::IsPushAfterCommitEnabled() const
{
return (GetIsPushAfterCommitEnabled() ? ECheckBoxState::Checked : ECheckBoxState::Unchecked);
}

ECheckBoxState SGitSourceControlSettings::IsUsingGitLfsLocking() const
{
return (GetIsUsingGitLfsLocking() ? ECheckBoxState::Checked : ECheckBoxState::Unchecked);
Expand Down
4 changes: 4 additions & 0 deletions Source/GitSourceControl/Private/SGitSourceControlSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class SGitSourceControlSettings : public SCompoundWidget
void OnCheckedUseGitLfsLocking(ECheckBoxState NewCheckedState);
ECheckBoxState IsUsingGitLfsLocking() const;
bool GetIsUsingGitLfsLocking() const;

void OnIsPushAfterCommitEnabled(ECheckBoxState NewCheckedState);
bool GetIsPushAfterCommitEnabled() const;
ECheckBoxState IsPushAfterCommitEnabled() const;

void OnLfsUserNameCommited(const FText& InText, ETextCommit::Type InCommitType);
FText GetLfsUserName() const;
Expand Down

0 comments on commit af646aa

Please sign in to comment.