forked from qt-creator/qt-creator
Git: Simplify cloning of a specific branch
Delete master branch option is removed since the master branch is not created when specifying a branch to clone Change-Id: Ided5e28a40ad459dcfaa3ef91ffa7c24e585d0ca Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
0e91d10878
commit
0c92cb015f
@@ -46,15 +46,12 @@ struct CloneWizardPagePrivate {
|
|||||||
const QString mainLinePostfix;
|
const QString mainLinePostfix;
|
||||||
const QString gitPostFix;
|
const QString gitPostFix;
|
||||||
const QString protocolDelimiter;
|
const QString protocolDelimiter;
|
||||||
QCheckBox *deleteMasterCheckBox;
|
|
||||||
QString headBranch;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CloneWizardPagePrivate::CloneWizardPagePrivate() :
|
CloneWizardPagePrivate::CloneWizardPagePrivate() :
|
||||||
mainLinePostfix(QLatin1String("/mainline.git")),
|
mainLinePostfix(QLatin1String("/mainline.git")),
|
||||||
gitPostFix(QLatin1String(".git")),
|
gitPostFix(QLatin1String(".git")),
|
||||||
protocolDelimiter(QLatin1String("://")),
|
protocolDelimiter(QLatin1String("://"))
|
||||||
deleteMasterCheckBox(0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,10 +71,6 @@ CloneWizardPage::CloneWizardPage(QWidget *parent) :
|
|||||||
setTitle(tr("Location"));
|
setTitle(tr("Location"));
|
||||||
setSubTitle(tr("Specify repository URL, checkout directory and path."));
|
setSubTitle(tr("Specify repository URL, checkout directory and path."));
|
||||||
setRepositoryLabel(tr("Clone URL:"));
|
setRepositoryLabel(tr("Clone URL:"));
|
||||||
d->deleteMasterCheckBox = new QCheckBox(tr("Delete master branch"));
|
|
||||||
d->deleteMasterCheckBox->setToolTip(tr("Delete the master branch after checking out the repository."));
|
|
||||||
addLocalControl(d->deleteMasterCheckBox);
|
|
||||||
setDeleteMasterBranch(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloneWizardPage::~CloneWizardPage()
|
CloneWizardPage::~CloneWizardPage()
|
||||||
@@ -85,16 +78,6 @@ CloneWizardPage::~CloneWizardPage()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CloneWizardPage::deleteMasterBranch() const
|
|
||||||
{
|
|
||||||
return d->deleteMasterCheckBox->isChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CloneWizardPage::setDeleteMasterBranch(bool v)
|
|
||||||
{
|
|
||||||
d->deleteMasterCheckBox->setChecked(v);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CloneWizardPage::directoryFromRepository(const QString &urlIn) const
|
QString CloneWizardPage::directoryFromRepository(const QString &urlIn) const
|
||||||
{
|
{
|
||||||
/* Try to figure out a good directory name from something like:
|
/* Try to figure out a good directory name from something like:
|
||||||
@@ -143,34 +126,13 @@ QSharedPointer<VcsBase::AbstractCheckoutJob> CloneWizardPage::createCheckoutJob(
|
|||||||
|
|
||||||
VcsBase::ProcessCheckoutJob *job = new VcsBase::ProcessCheckoutJob;
|
VcsBase::ProcessCheckoutJob *job = new VcsBase::ProcessCheckoutJob;
|
||||||
const QProcessEnvironment env = client->processEnvironment();
|
const QProcessEnvironment env = client->processEnvironment();
|
||||||
|
|
||||||
// 1) Basic checkout step
|
|
||||||
QStringList args;
|
|
||||||
args << QLatin1String("clone") << repository() << checkoutDir;
|
|
||||||
job->addStep(binary, args, workingDirectory, env);
|
|
||||||
const QString checkoutBranch = branch();
|
const QString checkoutBranch = branch();
|
||||||
|
|
||||||
// 2) Checkout branch, change to checkoutDir
|
QStringList args(QLatin1String("clone"));
|
||||||
if (!checkoutBranch.isEmpty() && checkoutBranch != d->headBranch) {
|
if (!checkoutBranch.isEmpty())
|
||||||
// Create branch
|
args << QLatin1String("--branch") << checkoutBranch;
|
||||||
if (!d->urlIsLocal(repository())) {
|
args << repository() << checkoutDir;
|
||||||
args.clear();
|
job->addStep(binary, args, workingDirectory, env);
|
||||||
args << QLatin1String("branch") << QLatin1String("--track")
|
|
||||||
<< checkoutBranch << (QLatin1String("origin/") + checkoutBranch);
|
|
||||||
job->addStep(binary, args, *checkoutPath, env);
|
|
||||||
}
|
|
||||||
// Checkout branch
|
|
||||||
args.clear();
|
|
||||||
args << QLatin1String("checkout") << checkoutBranch;
|
|
||||||
job->addStep(binary, args, *checkoutPath, env);
|
|
||||||
if (deleteMasterBranch() && d->headBranch != QLatin1String("<detached HEAD>")) {
|
|
||||||
// Make sure we only have the requested branch:
|
|
||||||
args.clear();
|
|
||||||
args << QLatin1String("branch") << QLatin1String("-D") << d->headBranch;
|
|
||||||
}
|
|
||||||
job->addStep(binary, args, *checkoutPath, env);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QSharedPointer<VcsBase::AbstractCheckoutJob>(job);
|
return QSharedPointer<VcsBase::AbstractCheckoutJob>(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,15 +140,12 @@ QStringList CloneWizardPage::branches(const QString &repository, int *current)
|
|||||||
{
|
{
|
||||||
// Run git on remote repository if an URL was specified.
|
// Run git on remote repository if an URL was specified.
|
||||||
*current = -1;
|
*current = -1;
|
||||||
d->headBranch.clear();
|
|
||||||
|
|
||||||
if (repository.isEmpty())
|
if (repository.isEmpty())
|
||||||
return QStringList();
|
return QStringList();
|
||||||
const QStringList branches = Internal::GitPlugin::instance()->gitClient()->synchronousRepositoryBranches(repository);
|
const QStringList branches = Internal::GitPlugin::instance()->gitClient()->synchronousRepositoryBranches(repository);
|
||||||
if (!branches.isEmpty()) {
|
if (!branches.isEmpty())
|
||||||
*current = 0; // default branch is always returned first!
|
*current = 0; // default branch is always returned first!
|
||||||
d->headBranch = branches.at(0);
|
|
||||||
}
|
|
||||||
return branches;
|
return branches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ struct CloneWizardPagePrivate;
|
|||||||
class CloneWizardPage : public VcsBase::BaseCheckoutWizardPage
|
class CloneWizardPage : public VcsBase::BaseCheckoutWizardPage
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool deleteMasterBranch READ deleteMasterBranch WRITE setDeleteMasterBranch)
|
|
||||||
public:
|
public:
|
||||||
explicit CloneWizardPage(QWidget *parent = 0);
|
explicit CloneWizardPage(QWidget *parent = 0);
|
||||||
~CloneWizardPage();
|
~CloneWizardPage();
|
||||||
@@ -57,9 +56,6 @@ protected:
|
|||||||
QString directoryFromRepository(const QString &r) const;
|
QString directoryFromRepository(const QString &r) const;
|
||||||
QStringList branches(const QString &repository, int *current);
|
QStringList branches(const QString &repository, int *current);
|
||||||
|
|
||||||
bool deleteMasterBranch() const;
|
|
||||||
void setDeleteMasterBranch(bool v);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CloneWizardPagePrivate *d;
|
CloneWizardPagePrivate *d;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user