diff options
author | Artur Shepilko <artur.shepilko@nomadbyte.com> | 2020-06-15 19:22:59 -0500 |
---|---|---|
committer | Artur Shepilko <artur.shepilko@nomadbyte.com> | 2020-06-16 19:29:24 +0000 |
commit | 30b04ca9190f139498f59b7e75eea19933ceec4f (patch) | |
tree | 7222cf172ed2efa0e71fe0b31a95665728d40d8b | |
parent | 9a64faff10162200c31babbccb3a1d9d6acd082d (diff) |
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>
-rw-r--r-- | plugins/fossil/fossilclient.cpp | 24 | ||||
-rw-r--r-- | plugins/fossil/fossilplugin.cpp | 77 |
2 files changed, 53 insertions, 48 deletions
diff --git a/plugins/fossil/fossilclient.cpp b/plugins/fossil/fossilclient.cpp index 16385c5..a2817d0 100644 --- a/plugins/fossil/fossilclient.cpp +++ b/plugins/fossil/fossilclient.cpp @@ -711,11 +711,15 @@ bool FossilClient::synchronousMove(const QString &workingDir, bool FossilClient::synchronousPull(const QString &workingDir, const QString &srcLocation, const QStringList &extraOptions) { - const QString remoteLocation = (!srcLocation.isEmpty() ? srcLocation : synchronousGetRepositoryURL(workingDir)); - if (remoteLocation.isEmpty()) - return false; + QStringList args(vcsCommandString(PullCommand)); + if (srcLocation.isEmpty()) { + const QString defaultURL(synchronousGetRepositoryURL(workingDir)); + if (defaultURL.isEmpty()) + return false; + } else { + args << srcLocation; + } - QStringList args({vcsCommandString(PullCommand), remoteLocation}); args << extraOptions; // Disable UNIX terminals to suppress SSH prompting 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) { - const QString remoteLocation = (!dstLocation.isEmpty() ? dstLocation : synchronousGetRepositoryURL(workingDir)); - if (remoteLocation.isEmpty()) - return false; + QStringList args(vcsCommandString(PushCommand)); + if (dstLocation.isEmpty()) { + const QString defaultURL(synchronousGetRepositoryURL(workingDir)); + if (defaultURL.isEmpty()) + return false; + } else { + args << dstLocation; + } - QStringList args({vcsCommandString(PushCommand), remoteLocation}); args << extraOptions; // Disable UNIX terminals to suppress SSH prompting const unsigned flags = diff --git a/plugins/fossil/fossilplugin.cpp b/plugins/fossil/fossilplugin.cpp index 88d93ca..a83d547 100644 --- a/plugins/fossil/fossilplugin.cpp +++ b/plugins/fossil/fossilplugin.cpp @@ -139,6 +139,11 @@ class FossilPluginPrivate final : public VcsBase::VcsBasePluginPrivate Q_DECLARE_TR_FUNCTIONS(Fossil::Internal::FossilPlugin) public: + enum SyncMode { + SyncPull, + SyncPush + }; + FossilPluginPrivate(); // IVersionControl @@ -184,8 +189,8 @@ public: void statusMulti(); // Repository menu action slots - void pull(); - void push(); + void pull() { pullOrPush(SyncPull); } + void push() { pullOrPush(SyncPush); } void update(); void configureRepository(); void commit(); @@ -201,6 +206,7 @@ public: void createRepositoryActions(const Core::Context &context); void describe(const QString &source, const QString &id) { m_client.view(source, id); }; + bool pullOrPush(SyncMode mode); // Variables FossilSettings m_fossilSettings; @@ -591,60 +597,51 @@ void FossilPluginPrivate::createRepositoryActions(const Core::Context &context) m_fossilContainer->addAction(command); } -void FossilPluginPrivate::pull() +bool FossilPluginPrivate::pullOrPush(FossilPluginPrivate::SyncMode mode) { - const VcsBase::VcsBasePluginState state = currentState(); - QTC_ASSERT(state.hasTopLevel(), return); - - PullOrPushDialog dialog(PullOrPushDialog::PullMode, 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; + PullOrPushDialog::Mode pullOrPushMode; + switch (mode) { + case SyncPull: + pullOrPushMode = PullOrPushDialog::PullMode; + break; + case SyncPush: + pullOrPushMode = PullOrPushDialog::PushMode; + break; + default: + return false; } - QStringList extraOptions; - if (!dialog.isRememberOptionEnabled()) - extraOptions << "--once"; - if (dialog.isPrivateOptionEnabled()) - extraOptions << "--private"; - m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions); -} - -void FossilPluginPrivate::push() -{ const VcsBase::VcsBasePluginState state = currentState(); - QTC_ASSERT(state.hasTopLevel(), return); + QTC_ASSERT(state.hasTopLevel(), return false); - PullOrPushDialog dialog(PullOrPushDialog::PushMode, Core::ICore::dialogParent()); + PullOrPushDialog dialog(pullOrPushMode, Core::ICore::dialogParent()); 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) - return; + return true; QString remoteLocation(dialog.remoteLocation()); - if (remoteLocation.isEmpty()) - remoteLocation = m_client.synchronousGetRepositoryURL(state.topLevel()); - - if (remoteLocation.isEmpty()) { + if (remoteLocation.isEmpty() && defaultURL.isEmpty()) { VcsBase::VcsOutputWindow::appendError(tr("Remote repository is not defined.")); - return; + return false; + } else if (remoteLocation == defaultURL) { + remoteLocation.clear(); } QStringList extraOptions; - if (!dialog.isRememberOptionEnabled()) + if (!remoteLocation.isEmpty() && !dialog.isRememberOptionEnabled()) extraOptions << "--once"; if (dialog.isPrivateOptionEnabled()) extraOptions << "--private"; - m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions); + switch (mode) { + case SyncPull: + return m_client.synchronousPull(state.topLevel(), remoteLocation, extraOptions); + case SyncPush: + return m_client.synchronousPush(state.topLevel(), remoteLocation, extraOptions); + default: + return false; + } } void FossilPluginPrivate::update() |