7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Suppress git remove if not at head

Don't offer to remove the .git directory if we are not looking at the
base of the git repository for safety

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19889
This commit is contained in:
Seth Hillbrand 2025-02-12 14:42:16 -08:00
parent 088a90cf68
commit ba208fd5c9
3 changed files with 28 additions and 4 deletions

View File

@ -81,7 +81,9 @@ wxString KIGIT_COMMON::GetCurrentBranchName() const
std::vector<wxString> KIGIT_COMMON::GetBranchNames() const
{
wxCHECK( m_repo, {} );
if( !m_repo )
return {};
std::vector<wxString> branchNames;
std::map<git_time_t, wxString> branchNamesMap;
wxString firstName;
@ -435,6 +437,17 @@ void KIGIT_COMMON::SetSSHKey( const wxString& aKey )
}
wxString KIGIT_COMMON::GetGitRootDirectory() const
{
if( !m_repo )
return wxEmptyString;
const char *path = git_repository_path( m_repo );
wxString retval = path;
return retval;
}
void KIGIT_COMMON::updatePublicKeys()
{
m_publicKeys.clear();

View File

@ -116,6 +116,8 @@ public:
// Updates the password and remote information for the repository given the current branch
void UpdateCurrentBranchInfo();
wxString GetGitRootDirectory() const;
wxString GetRemotename() const;
void ResetNextKey() { m_nextPublicKey = 0; }

View File

@ -744,6 +744,15 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
m_TreeProject->SelectItem( curr_item );
std::vector<PROJECT_TREE_ITEM*> selection = GetSelectedData();
KIGIT_COMMON* git = m_TreeProject->GitCommon();
wxFileName prj_dir( Prj().GetProjectPath(), wxEmptyString );
wxFileName git_dir( git->GetGitRootDirectory(), wxEmptyString );
prj_dir.Normalize( wxPATH_NORM_ABSOLUTE | wxPATH_NORM_CASE | wxPATH_NORM_DOTS
| wxPATH_NORM_ENV_VARS | wxPATH_NORM_TILDE );
git_dir.Normalize( wxPATH_NORM_ABSOLUTE | wxPATH_NORM_CASE | wxPATH_NORM_DOTS
| wxPATH_NORM_ENV_VARS | wxPATH_NORM_TILDE );
wxString prj_name = prj_dir.GetFullPath();
wxString git_name = git_dir.GetFullPath();
bool can_switch_to_project = true;
bool can_create_new_directory = true;
@ -756,9 +765,9 @@ void PROJECT_TREE_PANE::onRight( wxTreeEvent& Event )
bool vcs_has_repo = m_TreeProject->GetGitRepo() != nullptr;
bool vcs_can_commit = hasChangedFiles();
bool vcs_can_init = !vcs_has_repo;
bool vcs_can_remove = vcs_has_repo;
bool vcs_can_fetch = vcs_has_repo && m_TreeProject->GitCommon()->HasPushAndPullRemote();
bool vcs_can_push = vcs_can_fetch && m_TreeProject->GitCommon()->HasLocalCommits();
bool vcs_can_remove = vcs_has_repo && git_name.StartsWith( prj_name ); // This means the .git is a subdirectory of the project
bool vcs_can_fetch = vcs_has_repo && git->HasPushAndPullRemote();
bool vcs_can_push = vcs_can_fetch && git->HasLocalCommits();
bool vcs_can_pull = vcs_can_fetch;
bool vcs_can_switch = vcs_has_repo;
bool vcs_menu = ADVANCED_CFG::GetCfg().m_EnableGit;