Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 221e0ec

Browse files
antis81scunz
authored andcommitted
Remotes Module: add (preview) implementation for menu action "fetch -> all remotes"
Also fixes a compile error due to a double closing bracket. Caution: This currently *only* works within a repository context (static cast to RM::Repo)! If used in other contexts, MGV might crash or not behave like expected!
1 parent 9d4c987 commit 221e0ec

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

Modules/Remotes/RemotesModule.cpp

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616

1717
#include <QtPlugin>
1818
#include <QFileDialog>
19+
#include <QMessageBox>
20+
21+
#include "libGitWrap/Operations/RemoteOperations.hpp"
1922

2023
#include "libMacGitverCore/App/MacGitver.hpp"
24+
#include "libMacGitverCore/RepoMan/Repo.hpp"
2125

2226
#include "RemoteCreateEditDlg.h"
2327
#include "RemotesModule.h"
@@ -59,14 +63,69 @@ void RemotesModule::onRemoteCreateEdit()
5963
//TODO: dlg.setContext( ctx );
6064
dlg.exec();
6165
}
66+
67+
void RemotesModule::onRemoteDelete()
68+
{
69+
// TODO: requires the remote context (the remote to delete)
6270
}
6371

6472
/**
6573
* @brief Menu action to fetch all remotes of a repository.
6674
*/
6775
void RemotesModule::onRemotesFetchAll()
6876
{
69-
// TODO: requires a RepositoryContext (the repo to fetch all remotes from)
77+
// TODO: requires a repository context (the repo to fetch all remotes from)
7078
// A sub-context (i.e. a branch) can further restrict, what is fetched
79+
Heaven::Action* action = qobject_cast< Heaven::Action* >( sender() );
80+
Q_ASSERT( action );
81+
RM::Repo* repo = qobject_cast< RM::Repo* >( action->activatedBy() );
82+
if( repo ) {
83+
Git::Result r;
84+
Git::Repository gitRepo = repo->gitRepo();
85+
const QStringList aliases( gitRepo.allRemoteNames(r) );
86+
if ( !r ) {
87+
QMessageBox::warning( 0, tr("Lookup of remotes failed"),
88+
tr("Unable to lookup remotes for repository '%1'."
89+
"\nMessage: %2").arg(repo->displayName())
90+
.arg(r.errorText())
91+
);
92+
return;
93+
}
94+
95+
if ( aliases.isEmpty() ) {
96+
QMessageBox::information( 0, tr("No Remotes found"),
97+
tr("No remotes configured for repository '%1'.")
98+
.arg(repo->displayName())
99+
);
100+
return;
101+
}
102+
103+
foreach (const QString& alias, aliases) {
104+
Git::FetchOperation* op = new Git::FetchOperation( repo->gitRepo() );
105+
op->setRemoteAlias( alias );
106+
op->setBackgroundMode( true );
107+
connect( op, SIGNAL(finished()), this, SLOT(fetchOperationFinished()) );
108+
// TODO: create a central dialog to show progress of parallel operations
109+
op->execute();
110+
}
111+
}
112+
}
113+
114+
/**
115+
* @brief Called, when an non-blocking Git::Operation finished.
116+
*/
117+
void RemotesModule::onOperationFinished()
118+
{
119+
Git::BaseOperation* op = qobject_cast<Git::BaseOperation*>( sender() );
120+
Q_ASSERT( op );
121+
Git::Result r( op->result() );
122+
if ( !r ) {
123+
QMessageBox::warning( 0, tr("Operation failed."),
124+
tr("Operation failed. Message:\n %1").arg(r.errorText())
125+
);
126+
}
127+
128+
// delete the operation
129+
op->deleteLater();
71130
}
72131

Modules/Remotes/RemotesModule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ class RemotesModule : public Module, public RemotesModuleActions
4040
private slots:
4141
// RemotesAC
4242
void onRemoteCreateEdit();
43+
void onRemoteDelete();
4344

4445
private slots:
4546
// RemotesFetchAC
4647
void onRemotesFetchAll();
48+
49+
private slots:
50+
void onOperationFinished();
4751
};
4852

4953
#endif

0 commit comments

Comments
 (0)