Skip to content
Snippets Groups Projects
Commit 0c92cb01 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

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: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 0e91d108
No related branches found
No related tags found
No related merge requests found
......@@ -46,15 +46,12 @@ struct CloneWizardPagePrivate {
const QString mainLinePostfix;
const QString gitPostFix;
const QString protocolDelimiter;
QCheckBox *deleteMasterCheckBox;
QString headBranch;
};
CloneWizardPagePrivate::CloneWizardPagePrivate() :
mainLinePostfix(QLatin1String("/mainline.git")),
gitPostFix(QLatin1String(".git")),
protocolDelimiter(QLatin1String("://")),
deleteMasterCheckBox(0)
protocolDelimiter(QLatin1String("://"))
{
}
......@@ -74,10 +71,6 @@ CloneWizardPage::CloneWizardPage(QWidget *parent) :
setTitle(tr("Location"));
setSubTitle(tr("Specify repository URL, checkout directory and path."));
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()
......@@ -85,16 +78,6 @@ CloneWizardPage::~CloneWizardPage()
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
{
/* 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;
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();
// 2) Checkout branch, change to checkoutDir
if (!checkoutBranch.isEmpty() && checkoutBranch != d->headBranch) {
// Create branch
if (!d->urlIsLocal(repository())) {
args.clear();
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);
}
QStringList args(QLatin1String("clone"));
if (!checkoutBranch.isEmpty())
args << QLatin1String("--branch") << checkoutBranch;
args << repository() << checkoutDir;
job->addStep(binary, args, workingDirectory, env);
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.
*current = -1;
d->headBranch.clear();
if (repository.isEmpty())
return QStringList();
const QStringList branches = Internal::GitPlugin::instance()->gitClient()->synchronousRepositoryBranches(repository);
if (!branches.isEmpty()) {
if (!branches.isEmpty())
*current = 0; // default branch is always returned first!
d->headBranch = branches.at(0);
}
return branches;
}
......
......@@ -46,7 +46,6 @@ struct CloneWizardPagePrivate;
class CloneWizardPage : public VcsBase::BaseCheckoutWizardPage
{
Q_OBJECT
Q_PROPERTY(bool deleteMasterBranch READ deleteMasterBranch WRITE setDeleteMasterBranch)
public:
explicit CloneWizardPage(QWidget *parent = 0);
~CloneWizardPage();
......@@ -57,9 +56,6 @@ protected:
QString directoryFromRepository(const QString &r) const;
QStringList branches(const QString &repository, int *current);
bool deleteMasterBranch() const;
void setDeleteMasterBranch(bool v);
private:
CloneWizardPagePrivate *d;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment