Push/pull: Fix the handling of the Default URL

On a successful push/pull operation, Fossil allows user to save
the used remote URL, such that the next time it would be used by
default. With Fossil plugin, the user is allowed to choose the
saved Default location, also it's pre-filled in Remote URL field.
A choice is offered to save the newly entered Remote URL,
otherwise the entered URL is used only once without saving.

To use the Default URL, Fossil push/pull command should be called
without specifying any URL explicitly. Otherwise, Fossil client
displays a prompt asking whether to save it, even when it matches
the currently stored one.

Change-Id: I3f517be4b60bef5bf1f5bca19345078ef6d6dda2
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Artur Shepilko
2020-06-15 19:22:59 -05:00
parent 9a64faff10
commit 30b04ca919
2 changed files with 55 additions and 50 deletions

View File

@@ -711,11 +711,15 @@ bool FossilClient::synchronousMove(const QString &workingDir,
bool FossilClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions) bool FossilClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions)
{ {
const QString remoteLocation = (!srcLocation.isEmpty() ? srcLocation : synchronousGetRepositoryURL(workingDir)); QStringList args(vcsCommandString(PullCommand));
if (remoteLocation.isEmpty()) if (srcLocation.isEmpty()) {
return false; const QString defaultURL(synchronousGetRepositoryURL(workingDir));
if (defaultURL.isEmpty())
return false;
} else {
args << srcLocation;
}
QStringList args({vcsCommandString(PullCommand), remoteLocation});
args << extraOptions; args << extraOptions;
// Disable UNIX terminals to suppress SSH prompting // Disable UNIX terminals to suppress SSH prompting
const unsigned flags = const unsigned flags =
@@ -731,11 +735,15 @@ bool FossilClient::synchronousPull(const QString &workingDir, const QString &src
bool FossilClient::synchronousPush(const QString &workingDir, const QString &dstLocation, const QStringList &extraOptions) bool FossilClient::synchronousPush(const QString &workingDir, const QString &dstLocation, const QStringList &extraOptions)
{ {
const QString remoteLocation = (!dstLocation.isEmpty() ? dstLocation : synchronousGetRepositoryURL(workingDir)); QStringList args(vcsCommandString(PushCommand));
if (remoteLocation.isEmpty()) if (dstLocation.isEmpty()) {
return false; const QString defaultURL(synchronousGetRepositoryURL(workingDir));
if (defaultURL.isEmpty())
return false;
} else {
args << dstLocation;
}
QStringList args({vcsCommandString(PushCommand), remoteLocation});
args << extraOptions; args << extraOptions;
// Disable UNIX terminals to suppress SSH prompting // Disable UNIX terminals to suppress SSH prompting
const unsigned flags = const unsigned flags =

View File

@@ -139,6 +139,11 @@ class FossilPluginPrivate final : public VcsBase::VcsBasePluginPrivate
Q_DECLARE_TR_FUNCTIONS(Fossil::Internal::FossilPlugin) Q_DECLARE_TR_FUNCTIONS(Fossil::Internal::FossilPlugin)
public: public:
enum SyncMode {
SyncPull,
SyncPush
};
FossilPluginPrivate(); FossilPluginPrivate();
// IVersionControl // IVersionControl
@@ -184,8 +189,8 @@ public:
void statusMulti(); void statusMulti();
// Repository menu action slots // Repository menu action slots
void pull(); void pull() { pullOrPush(SyncPull); }
void push(); void push() { pullOrPush(SyncPush); }
void update(); void update();
void configureRepository(); void configureRepository();
void commit(); void commit();
@@ -201,6 +206,7 @@ public:
void createRepositoryActions(const Core::Context &context); void createRepositoryActions(const Core::Context &context);
void describe(const QString &source, const QString &id) { m_client.view(source, id); }; void describe(const QString &source, const QString &id) { m_client.view(source, id); };
bool pullOrPush(SyncMode mode);
// Variables // Variables
FossilSettings m_fossilSettings; FossilSettings m_fossilSettings;
@@ -591,60 +597,51 @@ void FossilPluginPrivate::createRepositoryActions(const Core::Context &context)
m_fossilContainer->addAction(command); m_fossilContainer->addAction(command);
} }
void FossilPluginPrivate::pull() bool FossilPluginPrivate::pullOrPush(FossilPluginPrivate::SyncMode mode)
{ {
const VcsBase::VcsBasePluginState state = currentState(); PullOrPushDialog::Mode pullOrPushMode;
QTC_ASSERT(state.hasTopLevel(), return); switch (mode) {
case SyncPull:
pullOrPushMode = PullOrPushDialog::PullMode;
break;
case SyncPush:
pullOrPushMode = PullOrPushDialog::PushMode;
break;
default:
return false;
}
PullOrPushDialog dialog(PullOrPushDialog::PullMode, Core::ICore::dialogParent()); const VcsBase::VcsBasePluginState state = currentState();
QTC_ASSERT(state.hasTopLevel(), return false);
PullOrPushDialog dialog(pullOrPushMode, Core::ICore::dialogParent());
dialog.setLocalBaseDirectory(m_client.settings().stringValue(FossilSettings::defaultRepoPathKey)); dialog.setLocalBaseDirectory(m_client.settings().stringValue(FossilSettings::defaultRepoPathKey));
dialog.setDefaultRemoteLocation(m_client.synchronousGetRepositoryURL(state.topLevel())); const QString defaultURL(m_client.synchronousGetRepositoryURL(state.topLevel()));
dialog.setDefaultRemoteLocation(defaultURL);
if (dialog.exec() != QDialog::Accepted) if (dialog.exec() != QDialog::Accepted)
return; return true;
QString remoteLocation(dialog.remoteLocation()); QString remoteLocation(dialog.remoteLocation());
if (remoteLocation.isEmpty()) if (remoteLocation.isEmpty() && defaultURL.isEmpty()) {
remoteLocation = m_client.synchronousGetRepositoryURL(state.topLevel());
if (remoteLocation.isEmpty()) {
VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined.")); VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined."));
return; return false;
} else if (remoteLocation == defaultURL) {
remoteLocation.clear();
} }
QStringList extraOptions; QStringList extraOptions;
if (!dialog.isRememberOptionEnabled()) if (!remoteLocation.isEmpty() && !dialog.isRememberOptionEnabled())
extraOptions << "--once"; extraOptions << "--once";
if (dialog.isPrivateOptionEnabled()) if (dialog.isPrivateOptionEnabled())
extraOptions << "--private"; extraOptions << "--private";
m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions); switch (mode) {
} case SyncPull:
return m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions);
void FossilPluginPrivate::push() case SyncPush:
{ return m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions);
const VcsBase::VcsBasePluginState state = currentState(); default:
QTC_ASSERT(state.hasTopLevel(), return); return false;
PullOrPushDialog dialog(PullOrPushDialog::PushMode, Core::ICore::dialogParent());
dialog.setLocalBaseDirectory(m_client.settings().stringValue(FossilSettings::defaultRepoPathKey));
dialog.setDefaultRemoteLocation(m_client.synchronousGetRepositoryURL(state.topLevel()));
if (dialog.exec() != QDialog::Accepted)
return;
QString remoteLocation(dialog.remoteLocation());
if (remoteLocation.isEmpty())
remoteLocation = m_client.synchronousGetRepositoryURL(state.topLevel());
if (remoteLocation.isEmpty()) {
VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined."));
return;
} }
QStringList extraOptions;
if (!dialog.isRememberOptionEnabled())
extraOptions << "--once";
if (dialog.isPrivateOptionEnabled())
extraOptions << "--private";
m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions);
} }
void FossilPluginPrivate::update() void FossilPluginPrivate::update()