diff --git a/CMakeLists.txt b/CMakeLists.txt index 9dd19718eb..005fdfadc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,28 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=9525) add_subdirectory(tests) ########### next target ############### set(kdevgit_PART_SRCS gitplugin.cpp - gitexecutor.cpp ) kde4_add_plugin(kdevgit ${kdevgit_PART_SRCS}) target_link_libraries(kdevgit ${KDE4_KDEUI_LIBS} kdevplatformutil kdevplatforminterfaces kdevplatformvcs + kdevplatformshell kdevplatformproject ) install(TARGETS kdevgit DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### install files ############### install( FILES kdevgit.desktop DESTINATION ${SERVICES_INSTALL_DIR} ) install( FILES kdevgit.rc DESTINATION ${DATA_INSTALL_DIR}/kdevgit ) diff --git a/gitexecutor.cpp b/gitexecutor.cpp deleted file mode 100644 index f785e8abc0..0000000000 --- a/gitexecutor.cpp +++ /dev/null @@ -1,781 +0,0 @@ -/*************************************************************************** - * This file was partly taken from KDevelop's cvs plugin * - * Copyright 2007 Robert Gruber * - * * - * Adapted for Git * - * Copyright 2008 Evgeniy Ivanov * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 2 of * - * the License or (at your option) version 3 or any later version * - * accepted by the membership of KDE e.V. (or its successor approved * - * by the membership of KDE e.V.), which shall act as a proxy * - * defined in Section 14 of version 3 of the license. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -//TODO: add jobTypes for every DVCSjob! - -#include "gitexecutor.h" - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -using KDevelop::VcsStatusInfo; - -GitExecutor::GitExecutor(KDevelop::IPlugin* parent) - : QObject(parent), vcsplugin(parent) -{ -} - -GitExecutor::~GitExecutor() -{ -} - -QString GitExecutor::name() const -{ - return QLatin1String("Git"); -} - -bool GitExecutor::isValidDirectory(const KUrl & dirPath) -{ - DVCSjob* job = gitRevParse(dirPath.path(), QStringList(QString("--is-inside-work-tree"))); - if (job) - { - job->exec(); - if (job->status() == KDevelop::VcsJob::JobSucceeded) - { - kDebug() << "Dir:" << dirPath << " is inside work tree of git" ; - return true; - } - } - kDebug() << "Dir:" << dirPath.path() << " is not inside work tree of git" ; - return false; -} - -bool GitExecutor::isInRepo(const KUrl &path) -{ - QString workDir = path.path(); - QString filename; - QFileInfo fsObject(workDir); - if (fsObject.isFile()) - { - workDir = fsObject.path(); - filename = fsObject.fileName(); - } - else - return isValidDirectory(path); - - QStringList otherFiles = getLsFiles(workDir); - return otherFiles.contains(filename); -} - -DVCSjob* GitExecutor::init(const KUrl &directory) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, directory.toLocalFile(), GitExecutor::Init) ) { - *job << "git"; - *job << "init"; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::clone(const KUrl &repository, const KUrl directory) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, directory.toLocalFile(), GitExecutor::Init) ) { - *job << "git"; - *job << "clone"; - *job << repository.path(); -// addFileList(job, repository.path(), directory); //TODO it's temp, should work only with local repos - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::add(const QString& repository, const KUrl::List &files) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "add"; - addFileList(job, files); - - return job; - } - if (job) delete job; - return NULL; -} - -//TODO: git doesn't like empty messages, but "KDevelop didn't provide any message, it may be a bug" looks ugly... -//If no files specified then commit already added files -DVCSjob* GitExecutor::commit(const QString& repository, - const QString &message, /*= "KDevelop didn't provide any message, it may be a bug"*/ - const KUrl::List &args /*= QStringList("")*/) -{ - Q_UNUSED(args) - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "commit"; - *job << "-m"; - //Note: the message is quoted somewhere else, so if we quote here then we have quotes in the commit log - *job << message; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::remove(const QString& repository, const KUrl::List &files) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "rm"; - addFileList(job, files); - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::status(const QString & repository, const KUrl::List & files, bool recursive, bool taginfo) -{ - Q_UNUSED(files) - Q_UNUSED(recursive) - Q_UNUSED(taginfo) - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "status"; - connect(job, SIGNAL(readyForParsing(DVCSjob*)), - this, SLOT(status_slot(DVCSjob*)), Qt::DirectConnection); - return job; - } - if (job) delete job; - return NULL; -} - -void GitExecutor::status_slot(DVCSjob *statusJob) -{ - //everything is ok - if (statusJob->status() == KDevelop::VcsJob::JobSucceeded) - return; - //we have problems, if we are in git-repo then git-status just returned 1, - //because something was changed (see git-status), then we should set exitStatus to 0. - if (isValidDirectory(KUrl(statusJob->getDirectory()) ) ) - statusJob->setExitStatus(0); -} - -DVCSjob* GitExecutor::log(const KUrl& url) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, url.path()) ) { - *job << "git"; - *job << "log"; - addFileList(job, url); - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::var(const QString & repository) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "var"; - *job << "-l"; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::empty_cmd() const -{ - ///TODO: maybe just "" command? - DVCSjob* job = new DVCSjob(vcsplugin); - *job << "echo"; - *job << "-n"; - return job; -} - -DVCSjob* GitExecutor::checkout(const QString &repository, const QString &branch) -{ - ///TODO Check if the branch exists. or send only existed branch names here! - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "checkout"; - *job << branch; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::branch(const QString &repository, const QString &basebranch, const QString &branch, - const QStringList &args) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "branch"; - //Empty branch has 'something' so it breaks the command - if (!args.isEmpty()) - *job << args; - if (!branch.isEmpty()) - *job << branch; - if (!basebranch.isEmpty()) - *job << basebranch; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::reset(const QString &repository, const QStringList &args, const KUrl::List& files) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "reset"; - //Empty branch has 'something' so it breaks the command - if (!args.isEmpty()) - *job << args; - addFileList(job, files); - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::lsFiles(const QString &repository, const QStringList &args) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "ls-files"; - //Empty branch has 'something' so it breaks the command - if (!args.isEmpty()) - *job << args; - return job; - } - if (job) delete job; - return NULL; -} - -QString GitExecutor::curBranch(const QString &repository) -{ - DVCSjob* job = branch(repository); - if (job) - { - kDebug() << "Getting branch list"; - job->exec(); - } - QString branch; - if (job->status() == KDevelop::VcsJob::JobSucceeded) - branch = job->output(); - - branch = branch.prepend('\n').section("\n*", 1); - branch = branch.section('\n', 0, 0).trimmed(); - kDebug() << "Current branch is: " << branch; - return branch; -} - -QStringList GitExecutor::branches(const QString &repository) -{ - DVCSjob* job = branch(repository); - if (job) - { - kDebug() << "Getting branch list"; - job->exec(); - } - QStringList branchListDirty; - if (job->status() == KDevelop::VcsJob::JobSucceeded) - branchListDirty = job->output().split('\n', QString::SkipEmptyParts); - else - return QStringList(); - - QStringList branchList; - foreach(QString branch, branchListDirty) - { - if (branch.contains('*')) - { - branch = branch.prepend('\n').section("\n*", 1); - branch = branch.trimmed(); - } - else - { - branch = branch.prepend('\n').section('\n', 1); - branch = branch.trimmed(); - } - branchList< GitExecutor::getOtherFiles(const QString &directory) -{ - QStringList otherFiles = getLsFiles(directory, QStringList(QString("--others")) ); - - QList others; - foreach(const QString &file, otherFiles) - { - VcsStatusInfo status; - status.setUrl(stripPathToDir(directory) + '/' + file); - status.setState(VcsStatusInfo::ItemUnknown); - others.append(qVariantFromValue(status)); - } - return others; -} - -QList GitExecutor::getModifiedFiles(const QString &directory) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, directory) ) - *job << "git"; - *job << "diff-files"; - if (job) - job->exec(); - QStringList output; - if (job->status() == KDevelop::VcsJob::JobSucceeded) - output = job->output().split('\n', QString::SkipEmptyParts); - else - return QList(); - - QList modifiedFiles; - foreach(const QString &line, output) - { - QChar stCh = line[97]; - - KUrl file(stripPathToDir(directory) + '/' + line.section('\t', 1).section('/', 1).trimmed()); - - VcsStatusInfo status; - status.setUrl(file); - status.setState(charToState(stCh.toAscii() ) ); - - kDebug() << line[97] << " " << file.path(); - - modifiedFiles.append(qVariantFromValue(status)); - } - - return modifiedFiles; -} - -QList GitExecutor::getCachedFiles(const QString &directory) -{ - DVCSjob* job = gitRevParse(directory, QStringList(QString("--branches"))); - job->exec(); - QStringList shaArg; - if (job->output().isEmpty()) - { - //there is no branches, which means there is no commit yet - //let's create an empty tree to use with git-diff-index - //TODO: in newer version of git (AFAIK 1.5.5) we can do: - //"git diff-index $(git rev-parse -q --verify HEAD  || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)" - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, directory) ) - { - *job << "git"; - *job << "mktree"; - job->setStandardInputFile("/dev/null"); - } - if (job && job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded) - shaArg<output().split('\n', QString::SkipEmptyParts); - } - else - shaArg<<"HEAD"; - job = new DVCSjob(vcsplugin); - if (prepareJob(job, directory) ) - *job << "git" << "diff-index" << "--cached" << shaArg; - if (job) - job->exec(); - QStringList output; - if (job->status() == KDevelop::VcsJob::JobSucceeded) - output = job->output().split('\n', QString::SkipEmptyParts); - else - return QList(); - - QList cachedFiles; - - foreach(const QString &line, output) - { - QChar stCh = line[97]; - - KUrl file(stripPathToDir(directory) + '/' + line.section('\t', 1).section('/', 1).trimmed()); - - VcsStatusInfo status; - status.setUrl(file); - //TODO: use abother charToState or anything else! If order of constants is changed... dangerous!!! - status.setState(VcsStatusInfo::State(charToState(stCh.toAscii() ) + - VcsStatusInfo::ItemAddedIndex - VcsStatusInfo::ItemAdded) ); - - kDebug() << line[97] << " " << file.path(); - - cachedFiles.append(qVariantFromValue(status)); - } - - return cachedFiles; -} - -/* Few words about how this hardcore works: -1. get all commits (with --paretns) -2. select master (root) branch and get all unicial commits for branches (git-rev-list br2 ^master ^br3) -3. parse allCommits. While parsing set mask (columns state for every row) for BRANCH, INITIAL, CROSS, - MERGE and INITIAL are also set in DVCScommit::setParents (depending on parents count) - another setType(INITIAL) is used for "bottom/root/first" commits of branches -4. find and set merges, HEADS. It's an ittaration through all commits. - - first we check if parent is from the same branch, if no then we go through all commits searching parent's index - and set CROSS/HCROSS for rows (in 3 rows are set EMPTY after commit with parent from another tree met) - - then we check branchesShas[i][0] to mark heads - -4 can be a seporate function. TODO: All this porn require refactoring (rewriting is better)! - -It's a very dirty implementation. -FIXME: -1. HEAD which is head has extra line to connect it with further commit -2. If you menrge branch2 to master, only new commits of branch2 will be visible (it's fine, but there will be -extra merge rectangle in master. If there are no extra commits in branch2, but there are another branches, then the place for branch2 will be empty (instead of be used for branch3). -3. Commits that have additional commit-data (not only history merging, but changes to fix conflicts) are shown incorrectly -*/ - -QList GitExecutor::getAllCommits(const QString &repo) -{ - static bool hasHash = false; - if (!hasHash) - { - initBranchHash(repo); - hasHash = true; - } - QStringList args; - args << "--all" << "--pretty" << "--parents"; - DVCSjob* job = gitRevList(repo, args); - if (job) - job->exec(); - QStringList commits = job->output().split('\n', QString::SkipEmptyParts); - - static QRegExp rx_com("commit \\w{40,40}"); - - QListcommitList; - DVCScommit item; - - //used to keep where we have empty/cross/branch entry - //true if it's an active branch (then cross or branch) and false if not - QVector additionalFlags(branchesShas.count()); - foreach(int flag, additionalFlags) - flag = false; - - //parse output - for(int i = 0; i < commits.count(); ++i) - { - if (commits[i].contains(rx_com)) - { - kDebug() << "commit found in " << commits[i]; - item.setCommit(commits[i].section(' ', 1, 1).trimmed()); -// kDebug() << "commit is: " << commits[i].section(' ', 1); - - QStringList parents; - QString parent = commits[i].section(' ', 2); - int section = 2; - while (!parent.isEmpty()) - { - /* kDebug() << "Parent is: " << parent;*/ - parents.append(parent.trimmed()); - section++; - parent = commits[i].section(' ', section); - } - item.setParents(parents); - - //Avoid Merge string - while (!commits[i].contains("Author: ")) - ++i; - - item.setAuthor(commits[i].section("Author: ", 1).trimmed()); -// kDebug() << "author is: " << commits[i].section("Author: ", 1); - - item.setDate(commits[++i].section("Date: ", 1).trimmed()); -// kDebug() << "date is: " << commits[i].section("Date: ", 1); - - QString log; - i++; //next line! - while (i < commits.count() && !commits[i].contains(rx_com)) - log += commits[i++]; - --i; //while took commit line - item.setLog(log.trimmed()); -// kDebug() << "log is: " << log; - - //mask is used in CommitViewDelegate to understand what we should draw for each branch - QList mask; - - //set mask (properties for each graph column in row) - for(int i = 0; i < branchesShas.count(); ++i) - { - kDebug()<<"commit: " << item.getCommit(); - if (branchesShas[i].contains(item.getCommit())) - { - mask.append(item.getType()); //we set type in setParents - - //check if parent from the same branch, if not then we have found a root of the branch - //and will use empty column for all futher (from top to bottom) revisions - //FIXME: we should set CROSS between parent and child (and do it when find merge point) - additionalFlags[i] = false; - foreach(const QString &sha, item.getParents()) - { - if (branchesShas[i].contains(sha)) - additionalFlags[i] = true; - } - if (additionalFlags[i] == false) - item.setType(DVCScommit::INITIAL); //hasn't parents from the same branch, used in drawing - } - else - { - if (additionalFlags[i] == false) - mask.append(DVCScommit::EMPTY); - else - mask.append(DVCScommit::CROSS); - } - kDebug() << "mask " << i << "is " << mask[i]; - } - item.setProperties(mask); - commitList.append(item); - } - } - - //find and set merges, HEADS, require refactoring! - for(QList::iterator iter = commitList.begin(); - iter != commitList.end(); ++iter) - { - QStringList parents = iter->getParents(); - //we need only only child branches - if (parents.count() != 1) - break; - - QString parent = parents[0]; - QString commit = iter->getCommit(); - bool parent_checked = false; - int heads_checked = 0; - - for(int i = 0; i < branchesShas.count(); ++i) - { - //check parent - if (branchesShas[i].contains(commit)) - { - if (!branchesShas[i].contains(parent)) - { - //parent and child are not in same branch - //since it is list, than parent has i+1 index - //set CROSS and HCROSS - for(QList::iterator f_iter = iter; - f_iter != commitList.end(); ++f_iter) - { - if (parent == f_iter->getCommit()) - { - for(int j = 0; j < i; ++j) - { - if(branchesShas[j].contains(parent)) - f_iter->setPropetry(j, DVCScommit::MERGE); - else - f_iter->setPropetry(j, DVCScommit::HCROSS); - } - f_iter->setType(DVCScommit::MERGE); - f_iter->setPropetry(i, DVCScommit::MERGE_RIGHT); - kDebug() << parent << " is parent of " << commit; - kDebug() << f_iter->getCommit() << " is merge"; - parent_checked = true; - break; - } - else - f_iter->setPropetry(i, DVCScommit::CROSS); - } - } - } - //mark HEADs - if (commit == branchesShas[i][0]) - { - iter->setType(DVCScommit::HEAD); - iter->setPropetry(i, DVCScommit::HEAD); - heads_checked++; - kDebug() << "HEAD found"; - } - //some optimization - if (heads_checked == branchesShas.count() && parent_checked) - break; - } - } - - return commitList; -} - -void GitExecutor::initBranchHash(const QString &repo) -{ - QStringList branches = GitExecutor::branches(repo); - kDebug() << "BRANCHES: " << branches; - //Now root branch is the current branch. In future it should be the longest branch - //other commitLists are got with git-rev-lits branch ^br1 ^ br2 - QString root = GitExecutor::curBranch(repo); - DVCSjob* job = gitRevList(repo, QStringList(root)); - if (job) - job->exec(); - QStringList commits = job->output().split('\n', QString::SkipEmptyParts); -// kDebug() << "\n\n\n commits" << commits << "\n\n\n"; - branchesShas.append(commits); - foreach(const QString &branch, branches) - { - if (branch == root) - continue; - QStringList args(branch); - foreach(const QString &branch_arg, branches) - { - if (branch_arg != branch) - //man gitRevList for '^' - args<<'^' + branch_arg; - } - DVCSjob* job = gitRevList(repo, args); - if (job) - job->exec(); - QStringList commits = job->output().split('\n', QString::SkipEmptyParts); -// kDebug() << "\n\n\n commits" << commits << "\n\n\n"; - branchesShas.append(commits); - } -} - -//Actually we can just copy the output without parsing. So it's a kind of draft for future -void GitExecutor::parseOutput(const QString& jobOutput, QList& commits) const -{ -// static QRegExp rx_sep( "[-=]+" ); -// static QRegExp rx_date( "date:\\s+([^;]*);\\s+author:\\s+([^;]*).*" ); - - static QRegExp rx_com( "commit \\w{1,40}" ); - - QStringList lines = jobOutput.split('\n', QString::SkipEmptyParts); - - DVCScommit item; - QString commitLog; - - for (int i=0; iexec(); - if (job->status() == KDevelop::VcsJob::JobSucceeded) - return job->output().split('\n', QString::SkipEmptyParts); - else - return QStringList(); - } - return QStringList(); -} - -DVCSjob* GitExecutor::gitRevParse(const QString &repository, const QStringList &args) -{ - //Use prepareJob() here only if you like "dead" recursion and KDevelop crashes - DVCSjob* job = new DVCSjob(vcsplugin); - if (job) - { - QString workDir = repository; - QFileInfo fsObject(workDir); - if (fsObject.isFile()) - workDir = fsObject.path(); - - job->clear(); - job->setDirectory(workDir); - *job << "git"; - *job << "rev-parse"; - foreach(const QString &arg, args) - *job << arg; - return job; - } - if (job) delete job; - return NULL; -} - -DVCSjob* GitExecutor::gitRevList(const QString &repository, const QStringList &args) -{ - DVCSjob* job = new DVCSjob(vcsplugin); - if (prepareJob(job, repository) ) { - *job << "git"; - *job << "rev-list"; - foreach(const QString &arg, args) - *job << arg; - return job; - } - if (job) delete job; - return NULL; -} - -KDevelop::VcsStatusInfo::State GitExecutor::charToState(const char ch) -{ - switch (ch) - { - case 'M': - { - return VcsStatusInfo::ItemModified; - break; - } - case 'A': - { - return VcsStatusInfo::ItemAdded; - break; - } - case 'D': - { - return VcsStatusInfo::ItemDeleted; - break; - } - //ToDo: hasConflicts - default: - { - return VcsStatusInfo::ItemUnknown; - break; - } - } - return VcsStatusInfo::ItemUnknown; -} - -// #include "gitexetor.moc" diff --git a/gitexecutor.h b/gitexecutor.h deleted file mode 100644 index e901f985fb..0000000000 --- a/gitexecutor.h +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * This file was partly taken from KDevelop's cvs plugin * - * Copyright 2007 Robert Gruber * - * * - * Adapted for Git * - * Copyright 2008 Evgeniy Ivanov * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License as * - * published by the Free Software Foundation; either version 2 of * - * the License or (at your option) version 3 or any later version * - * accepted by the membership of KDE e.V. (or its successor approved * - * by the membership of KDE e.V.), which shall act as a proxy * - * defined in Section 14 of version 3 of the license. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -#ifndef GIT_EXECUTOR_H -#define GIT_EXECUTOR_H - -#include -#include -#include - -#include -#include - -class DVCSjob; - -namespace KDevelop -{ - class IPlugin; - class VcsStatusInfo; -} - -/** - * This proxy acts as a single point of entry for most of the common git commands. - * It is very easy to use, as the caller does not have to deal which the DVCSjob class directly. - * All the command line generation and job handling is done internally. The caller gets a DVCSjob - * object returned from the proxy and can then call it's start() method. - * - * Here is and example of how to user the proxy: - * @code - * DVCSjob* job = proxy->editors( repo, urls ); - * if ( job ) { - * connect(job, SIGNAL( result(KJob*) ), - * this, SIGNAL( jobFinished(KJob*) )); - * job->start(); - * } - * @endcode - * - * @note All actions that take a KUrl::List also need an url to the repository which - * must be a common base directory to all files from the KUrl::List. - * Actions that just take a single KUrl don't need a repository, the git command will be - * called directly in the directory of the given file - * - * @author Robert Gruber - * @author Evgeniy Ivanov - */ -class GitExecutor : public QObject, public KDevelop::IDVCSexecutor -{ - Q_OBJECT -public: - explicit GitExecutor(KDevelop::IPlugin* parent = 0); - ~GitExecutor(); - - bool isValidDirectory(const KUrl &dirPath); - bool isInRepo(const KUrl &path); - QString name() const; - - DVCSjob* init(const KUrl & directory); - DVCSjob* clone(const KUrl &directory, const KUrl repository); - DVCSjob* add(const QString& repository, const KUrl::List &files); - DVCSjob* commit(const QString& repository, - const QString& message = "KDevelop did not provide any message, it may be a bug", - const KUrl::List& args = QStringList()); - DVCSjob* remove(const QString& repository, const KUrl::List& files); - DVCSjob* status(const QString & repo, const KUrl::List & files, - bool recursive=false, bool taginfo=false); - DVCSjob* log(const KUrl& url); - DVCSjob* var(const QString &directory); - DVCSjob* empty_cmd() const; - - DVCSjob* checkout(const QString &repository, const QString &branch); - DVCSjob* branch(const QString &repository, const QString &basebranch = QString(), const QString &branch = QString(), - const QStringList &args = QStringList()); - DVCSjob* reset(const QString &repository, const QStringList &args, const KUrl::List &files); - - - DVCSjob* lsFiles(const QString &repository, const QStringList &args); - DVCSjob* gitRevParse(const QString &repository, const QStringList &args); - DVCSjob* gitRevList(const QString &repository, const QStringList &args); -public: - //parsers for branch: - QString curBranch(const QString &repository); - QStringList branches(const QString &repository); - - //commit dialog helpers, send to main helper the arg for git-ls-files: - QList getModifiedFiles(const QString &directory); - QList getCachedFiles(const QString &directory); - QList getOtherFiles(const QString &directory); - - //graph helpers - QList getAllCommits(const QString &repo); - - //used in log - void parseOutput(const QString& jobOutput, QList& commits) const; - -private slots: - void status_slot(DVCSjob *statusJob); - -private: - //commit dialog "main" helper - QStringList getLsFiles(const QString &directory, const QStringList &args = QStringList()); - - void initBranchHash(const QString &repo); - KDevelop::VcsStatusInfo::State charToState(const char ch); - - QList branchesShas; - KDevelop::IPlugin* vcsplugin; - -}; - -#endif diff --git a/gitplugin.cpp b/gitplugin.cpp index 90b4ec3b0e..75fd411ae1 100644 --- a/gitplugin.cpp +++ b/gitplugin.cpp @@ -1,84 +1,800 @@ /*************************************************************************** * Copyright 2008 Evgeniy Ivanov * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #include "gitplugin.h" #include #include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include #include #include #include - -#include "gitexecutor.h" +#include K_PLUGIN_FACTORY(KDevGitFactory, registerPlugin(); ) K_EXPORT_PLUGIN(KDevGitFactory(KAboutData("kdevgit","kdevgit",ki18n("Git"),"0.1",ki18n("A plugin to support git version control systems"), KAboutData::License_GPL))) +using namespace KDevelop; + GitPlugin::GitPlugin( QObject *parent, const QVariantList & ) : DistributedVersionControlPlugin(parent, KDevGitFactory::componentData()) { KDEV_USE_EXTENSION_INTERFACE( KDevelop::IBasicVersionControl ) KDEV_USE_EXTENSION_INTERFACE( KDevelop::IDistributedVersionControl ) - core()->uiController()->addToolView(i18n("Git"), DistributedVersionControlPlugin::d->m_factory); - QString EasterEgg = i18n("Thanks for the translation! Have a nice day, mr. translator!"); Q_UNUSED(EasterEgg) - setXMLFile("kdevgit.rc"); - - DistributedVersionControlPlugin::d->m_exec = new GitExecutor(this); + core()->uiController()->addToolView(i18n("Git"), dvcsViewFactory()); + if (!(KDevelop::Core::self()->setupFlags() & KDevelop::Core::NoUi)) + setXMLFile("kdevgit.rc"); } GitPlugin::~GitPlugin() { - delete DistributedVersionControlPlugin::d; } -KDevelop::VcsJob* - GitPlugin::log(const KUrl& localLocation, - const KDevelop::VcsRevision& rev, - unsigned long limit) + +QString GitPlugin::name() const { - Q_UNUSED(limit) - Q_UNUSED(rev) + return QLatin1String("Git"); +} + +bool GitPlugin::isValidDirectory(const KUrl & dirPath) +{ + KDevelop::VcsJob* job = gitRevParse(dirPath.path(), QStringList(QString("--is-inside-work-tree"))); + if (job) + { + job->exec(); + if (job->status() == KDevelop::VcsJob::JobSucceeded) + { + kDebug() << "Dir:" << dirPath << " is inside work tree of git" ; + return true; + } + } + kDebug() << "Dir:" << dirPath.path() << " is not inside work tree of git" ; + return false; +} + +bool GitPlugin::isVersionControlled(const KUrl &path) +{ + QString workDir = path.path(); + QString filename; + QFileInfo fsObject(workDir); + if (fsObject.isFile()) + { + workDir = fsObject.path(); + filename = fsObject.fileName(); + } + else + return isValidDirectory(path); + + QStringList otherFiles = getLsFiles(workDir); + return otherFiles.contains(filename); +} + +VcsJob* GitPlugin::init(const KUrl &directory) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, directory.toLocalFile(), GitPlugin::Init) ) { + *job << "git"; + *job << "init"; + return job; + } + if (job) delete job; + return NULL; +} + +VcsJob* GitPlugin::clone(const KDevelop::VcsLocation & localOrRepoLocationSrc, const KUrl& localRepositoryRoot) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, localRepositoryRoot.toLocalFile(), GitPlugin::Init) ) { + *job << "git"; + *job << "clone"; + *job << localOrRepoLocationSrc.localUrl().pathOrUrl(); + return job; + } + if (job) delete job; + return NULL; +} + +VcsJob* GitPlugin::add(const KUrl::List& localLocations, KDevelop::IBasicVersionControl::RecursionMode recursion) +{ + Q_UNUSED(recursion) + if (localLocations.empty()) + return NULL; + + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, localLocations.front().path()) ) { + *job << "git"; + *job << "add"; + addFileList(job, localLocations); + + return job; + } + if (job) delete job; + return NULL; +} + +KDevelop::VcsJob* GitPlugin::status(const KUrl::List& localLocations, + KDevelop::IBasicVersionControl::RecursionMode recursion) +{ + Q_UNUSED(recursion) + //it's a hack!!! See VcsCommitDialog::setCommitCandidates and the usage of DVcsJob/IDVCSexecutor + //We need results just in status, so we set them here before execution in VcsCommitDialog::setCommitCandidates + QString repo = localLocations[0].toLocalFile(); + QList statuses; + qDebug("GitPlugin::status"); + statuses << getCachedFiles(repo) + << getModifiedFiles(repo) + << getOtherFiles(repo); + DVcsJob * noOp = empty_cmd(); + noOp->setResults(QVariant(statuses)); + return noOp; +} + +//TODO: git doesn't like empty messages, but "KDevelop didn't provide any message, it may be a bug" looks ugly... +//If no files specified then commit already added files +VcsJob* GitPlugin::commit(const QString& message, + const KUrl::List& localLocations, + KDevelop::IBasicVersionControl::RecursionMode recursion) +{ + Q_UNUSED(recursion) + + if (localLocations.empty()) + return NULL; + + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, localLocations.front().path()) ) { + *job << "git"; + *job << "commit"; + *job << "-m"; + //Note: the message is quoted somewhere else, so if we quote here then we have quotes in the commit log + *job << message; + return job; + } + if (job) delete job; + return NULL; +} - DVCSjob* job = d->m_exec->log(localLocation); - return job; +VcsJob* GitPlugin::remove(const KUrl::List& files) +{ + if (files.empty()) + return NULL; + + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, files.front().path()) ) { + *job << "git"; + *job << "rm"; + addFileList(job, files); + return job; + } + if (job) delete job; + return NULL; } -KDevelop::VcsJob* - GitPlugin::log(const KUrl& localLocation, - const KDevelop::VcsRevision& rev, - const KDevelop::VcsRevision& limit) + +VcsJob* GitPlugin::log(const KUrl& localLocation, + const KDevelop::VcsRevision& rev, + unsigned long limit) +{ + Q_UNUSED(rev) + Q_UNUSED(limit) + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, localLocation.path()) ) { + *job << "git"; + *job << "log"; + addFileList(job, localLocation); + return job; + } + if (job) delete job; + return NULL; +} + +VcsJob* GitPlugin::log(const KUrl& localLocation, + const KDevelop::VcsRevision& rev, + const KDevelop::VcsRevision& limit) { Q_UNUSED(limit) return log(localLocation, rev, 0); } + +DVcsJob* GitPlugin::var(const QString & repository) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository) ) { + *job << "git"; + *job << "var"; + *job << "-l"; + return job; + } + if (job) delete job; + return NULL; +} + +DVcsJob* GitPlugin::switchBranch(const QString &repository, const QString &branch) +{ + ///TODO Check if the branch exists. or send only existed branch names here! + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository) ) { + *job << "git"; + *job << "checkout"; + *job << branch; + return job; + } + if (job) delete job; + return NULL; +} + +DVcsJob* GitPlugin::branch(const QString &repository, const QString &basebranch, const QString &branch, + const QStringList &args) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository) ) { + *job << "git"; + *job << "branch"; + //Empty branch has 'something' so it breaks the command + if (!args.isEmpty()) + *job << args; + if (!branch.isEmpty()) + *job << branch; + if (!basebranch.isEmpty()) + *job << basebranch; + return job; + } + if (job) delete job; + return NULL; +} + +VcsJob* GitPlugin::reset(const KUrl& repository, const QStringList &args, const KUrl::List& files) +{ + if (files.empty()) + return NULL; + + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository.path()) ) { + *job << "git"; + *job << "reset"; + //Empty branch has 'something' so it breaks the command + if (!args.isEmpty()) + *job << args; + addFileList(job, files); + return job; + } + if (job) delete job; + return NULL; +} + +DVcsJob* GitPlugin::lsFiles(const QString &repository, const QStringList &args) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository) ) { + *job << "git"; + *job << "ls-files"; + //Empty branch has 'something' so it breaks the command + if (!args.isEmpty()) + *job << args; + return job; + } + if (job) delete job; + return NULL; +} + +QString GitPlugin::curBranch(const QString &repository) +{ + DVcsJob* job = branch(repository); + if (job) + { + kDebug() << "Getting branch list"; + job->exec(); + } + QString branch; + if (job->status() == KDevelop::VcsJob::JobSucceeded) + branch = job->output(); + + branch = branch.prepend('\n').section("\n*", 1); + branch = branch.section('\n', 0, 0).trimmed(); + kDebug() << "Current branch is: " << branch; + return branch; +} + +QStringList GitPlugin::branches(const QString &repository) +{ + DVcsJob* job = branch(repository); + if (job) + { + kDebug() << "Getting branch list"; + job->exec(); + } + QStringList branchListDirty; + if (job->status() == KDevelop::VcsJob::JobSucceeded) + branchListDirty = job->output().split('\n', QString::SkipEmptyParts); + else + return QStringList(); + + QStringList branchList; + foreach(QString branch, branchListDirty) + { + if (branch.contains('*')) + { + branch = branch.prepend('\n').section("\n*", 1); + branch = branch.trimmed(); + } + else + { + branch = branch.prepend('\n').section('\n', 1); + branch = branch.trimmed(); + } + branchList< GitPlugin::getOtherFiles(const QString &directory) +{ + QStringList otherFiles = getLsFiles(directory, QStringList(QString("--others")) ); + + QList others; + foreach(const QString &file, otherFiles) + { + VcsStatusInfo status; + status.setUrl(stripPathToDir(directory) + file); + status.setState(VcsStatusInfo::ItemUnknown); + others.append(qVariantFromValue(status)); + } + return others; +} + +QList GitPlugin::getModifiedFiles(const QString &directory) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, directory) ) + *job << "git"; + *job << "diff-files"; + if (job) + job->exec(); + QStringList output; + if (job->status() == KDevelop::VcsJob::JobSucceeded) + output = job->output().split('\n', QString::SkipEmptyParts); + else + return QList(); + + QList modifiedFiles; + foreach(const QString &line, output) + { + QChar stCh = line[97]; + + KUrl file(stripPathToDir(directory) + line.section('\t', 1).trimmed()); + + VcsStatusInfo status; + status.setUrl(file); + status.setState(charToState(stCh.toAscii() ) ); + kDebug() << line[97] << " " << file.path(); + + modifiedFiles.append(qVariantFromValue(status)); + } + + return modifiedFiles; +} + +QList GitPlugin::getCachedFiles(const QString &directory) +{ + DVcsJob* job = gitRevParse(directory, QStringList(QString("--branches"))); + job->exec(); + QStringList shaArg; + if (job->output().isEmpty()) + { + //there is no branches, which means there is no commit yet + //let's create an empty tree to use with git-diff-index + //TODO: in newer version of git (AFAIK 1.5.5) we can do: + //"git diff-index $(git rev-parse -q --verify HEAD  || echo 4b825dc642cb6eb9a060e54bf8d69288fbee4904)" + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, directory) ) + { + *job << "git"; + *job << "mktree"; + job->setStandardInputFile("/dev/null"); + } + if (job && job->exec() && job->status() == KDevelop::VcsJob::JobSucceeded) + shaArg<output().split('\n', QString::SkipEmptyParts); + } + else + shaArg<<"HEAD"; + job = new DVcsJob(this); + if (prepareJob(job, directory) ) + *job << "git" << "diff-index" << "--cached" << shaArg; + if (job) + job->exec(); + QStringList output; + if (job->status() == KDevelop::VcsJob::JobSucceeded) + output = job->output().split('\n', QString::SkipEmptyParts); + else + return QList(); + + QList cachedFiles; + + foreach(const QString &line, output) + { + QChar stCh = line[97]; + + KUrl file(stripPathToDir(directory) + line.section('\t', 1).trimmed()); + + VcsStatusInfo status; + status.setUrl(file); + //TODO: use abother charToState or anything else! If order of constants is changed... dangerous!!! + status.setState(VcsStatusInfo::State(charToState(stCh.toAscii() ) + + VcsStatusInfo::ItemAddedIndex - VcsStatusInfo::ItemAdded) ); + + kDebug() << line[97] << " " << file.path(); + + cachedFiles.append(qVariantFromValue(status)); + } + + return cachedFiles; +} + +/* Few words about how this hardcore works: +1. get all commits (with --paretns) +2. select master (root) branch and get all unicial commits for branches (git-rev-list br2 ^master ^br3) +3. parse allCommits. While parsing set mask (columns state for every row) for BRANCH, INITIAL, CROSS, + MERGE and INITIAL are also set in DVCScommit::setParents (depending on parents count) + another setType(INITIAL) is used for "bottom/root/first" commits of branches +4. find and set merges, HEADS. It's an ittaration through all commits. + - first we check if parent is from the same branch, if no then we go through all commits searching parent's index + and set CROSS/HCROSS for rows (in 3 rows are set EMPTY after commit with parent from another tree met) + - then we check branchesShas[i][0] to mark heads + +4 can be a seporate function. TODO: All this porn require refactoring (rewriting is better)! + +It's a very dirty implementation. +FIXME: +1. HEAD which is head has extra line to connect it with further commit +2. If you menrge branch2 to master, only new commits of branch2 will be visible (it's fine, but there will be +extra merge rectangle in master. If there are no extra commits in branch2, but there are another branches, then the place for branch2 will be empty (instead of be used for branch3). +3. Commits that have additional commit-data (not only history merging, but changes to fix conflicts) are shown incorrectly +*/ + +QList GitPlugin::getAllCommits(const QString &repo) +{ + static bool hasHash = false; + if (!hasHash) + { + initBranchHash(repo); + hasHash = true; + } + QStringList args; + args << "--all" << "--pretty" << "--parents"; + DVcsJob* job = gitRevList(repo, args); + if (job) + job->exec(); + QStringList commits = job->output().split('\n', QString::SkipEmptyParts); + + static QRegExp rx_com("commit \\w{40,40}"); + + QListcommitList; + DVcsEvent item; + + //used to keep where we have empty/cross/branch entry + //true if it's an active branch (then cross or branch) and false if not + QVector additionalFlags(branchesShas.count()); + foreach(int flag, additionalFlags) + flag = false; + + //parse output + for(int i = 0; i < commits.count(); ++i) + { + if (commits[i].contains(rx_com)) + { + kDebug() << "commit found in " << commits[i]; + item.setCommit(commits[i].section(' ', 1, 1).trimmed()); +// kDebug() << "commit is: " << commits[i].section(' ', 1); + + QStringList parents; + QString parent = commits[i].section(' ', 2); + int section = 2; + while (!parent.isEmpty()) + { + /* kDebug() << "Parent is: " << parent;*/ + parents.append(parent.trimmed()); + section++; + parent = commits[i].section(' ', section); + } + item.setParents(parents); + + //Avoid Merge string + while (!commits[i].contains("Author: ")) + ++i; + + item.setAuthor(commits[i].section("Author: ", 1).trimmed()); +// kDebug() << "author is: " << commits[i].section("Author: ", 1); + + item.setDate(commits[++i].section("Date: ", 1).trimmed()); +// kDebug() << "date is: " << commits[i].section("Date: ", 1); + + QString log; + i++; //next line! + while (i < commits.count() && !commits[i].contains(rx_com)) + log += commits[i++]; + --i; //while took commit line + item.setLog(log.trimmed()); +// kDebug() << "log is: " << log; + + //mask is used in CommitViewDelegate to understand what we should draw for each branch + QList mask; + + //set mask (properties for each graph column in row) + for(int i = 0; i < branchesShas.count(); ++i) + { + kDebug()<<"commit: " << item.getCommit(); + if (branchesShas[i].contains(item.getCommit())) + { + mask.append(item.getType()); //we set type in setParents + + //check if parent from the same branch, if not then we have found a root of the branch + //and will use empty column for all futher (from top to bottom) revisions + //FIXME: we should set CROSS between parent and child (and do it when find merge point) + additionalFlags[i] = false; + foreach(const QString &sha, item.getParents()) + { + if (branchesShas[i].contains(sha)) + additionalFlags[i] = true; + } + if (additionalFlags[i] == false) + item.setType(DVcsEvent::INITIAL); //hasn't parents from the same branch, used in drawing + } + else + { + if (additionalFlags[i] == false) + mask.append(DVcsEvent::EMPTY); + else + mask.append(DVcsEvent::CROSS); + } + kDebug() << "mask " << i << "is " << mask[i]; + } + item.setProperties(mask); + commitList.append(item); + } + } + + //find and set merges, HEADS, require refactoring! + for(QList::iterator iter = commitList.begin(); + iter != commitList.end(); ++iter) + { + QStringList parents = iter->getParents(); + //we need only only child branches + if (parents.count() != 1) + break; + + QString parent = parents[0]; + QString commit = iter->getCommit(); + bool parent_checked = false; + int heads_checked = 0; + + for(int i = 0; i < branchesShas.count(); ++i) + { + //check parent + if (branchesShas[i].contains(commit)) + { + if (!branchesShas[i].contains(parent)) + { + //parent and child are not in same branch + //since it is list, than parent has i+1 index + //set CROSS and HCROSS + for(QList::iterator f_iter = iter; + f_iter != commitList.end(); ++f_iter) + { + if (parent == f_iter->getCommit()) + { + for(int j = 0; j < i; ++j) + { + if(branchesShas[j].contains(parent)) + f_iter->setPropetry(j, DVcsEvent::MERGE); + else + f_iter->setPropetry(j, DVcsEvent::HCROSS); + } + f_iter->setType(DVcsEvent::MERGE); + f_iter->setPropetry(i, DVcsEvent::MERGE_RIGHT); + kDebug() << parent << " is parent of " << commit; + kDebug() << f_iter->getCommit() << " is merge"; + parent_checked = true; + break; + } + else + f_iter->setPropetry(i, DVcsEvent::CROSS); + } + } + } + //mark HEADs + + if (!branchesShas[i].empty() && commit == branchesShas[i][0]) + { + iter->setType(DVcsEvent::HEAD); + iter->setPropetry(i, DVcsEvent::HEAD); + heads_checked++; + kDebug() << "HEAD found"; + } + //some optimization + if (heads_checked == branchesShas.count() && parent_checked) + break; + } + } + + return commitList; +} + +void GitPlugin::initBranchHash(const QString &repo) +{ + QStringList branches = GitPlugin::branches(repo); + kDebug() << "BRANCHES: " << branches; + //Now root branch is the current branch. In future it should be the longest branch + //other commitLists are got with git-rev-lits branch ^br1 ^ br2 + QString root = GitPlugin::curBranch(repo); + DVcsJob* job = gitRevList(repo, QStringList(root)); + if (job) + job->exec(); + QStringList commits = job->output().split('\n', QString::SkipEmptyParts); +// kDebug() << "\n\n\n commits" << commits << "\n\n\n"; + branchesShas.append(commits); + foreach(const QString &branch, branches) + { + if (branch == root) + continue; + QStringList args(branch); + foreach(const QString &branch_arg, branches) + { + if (branch_arg != branch) + //man gitRevList for '^' + args<<'^' + branch_arg; + } + DVcsJob* job = gitRevList(repo, args); + if (job) + job->exec(); + QStringList commits = job->output().split('\n', QString::SkipEmptyParts); +// kDebug() << "\n\n\n commits" << commits << "\n\n\n"; + branchesShas.append(commits); + } +} + +//Actually we can just copy the output without parsing. So it's a kind of draft for future +void GitPlugin::parseLogOutput(const DVcsJob * job, QList& commits) const +{ +// static QRegExp rx_sep( "[-=]+" ); +// static QRegExp rx_date( "date:\\s+([^;]*);\\s+author:\\s+([^;]*).*" ); + + static QRegExp rx_com( "commit \\w{1,40}" ); + + QStringList lines = job->output().split('\n', QString::SkipEmptyParts); + + DVcsEvent item; + QString commitLog; + + for (int i=0; iexec(); + if (job->status() == KDevelop::VcsJob::JobSucceeded) + return job->output().split('\n', QString::SkipEmptyParts); + else + return QStringList(); + } + return QStringList(); +} + +DVcsJob* GitPlugin::gitRevParse(const QString &repository, const QStringList &args) +{ + //Use prepareJob() here only if you like "dead" recursion and KDevelop crashes + DVcsJob* job = new DVcsJob(this); + if (job) + { + QString workDir = repository; + QFileInfo fsObject(workDir); + if (fsObject.isFile()) + workDir = fsObject.path(); + + job->clear(); + job->setDirectory(workDir); + *job << "git"; + *job << "rev-parse"; + foreach(const QString &arg, args) + *job << arg; + return job; + } + if (job) delete job; + return NULL; +} + +DVcsJob* GitPlugin::gitRevList(const QString &repository, const QStringList &args) +{ + DVcsJob* job = new DVcsJob(this); + if (prepareJob(job, repository) ) { + *job << "git"; + *job << "rev-list"; + foreach(const QString &arg, args) + *job << arg; + return job; + } + if (job) delete job; + return NULL; +} + +KDevelop::VcsStatusInfo::State GitPlugin::charToState(const char ch) +{ + switch (ch) + { + case 'M': + { + return VcsStatusInfo::ItemModified; + break; + } + case 'A': + { + return VcsStatusInfo::ItemAdded; + break; + } + case 'D': + { + return VcsStatusInfo::ItemDeleted; + break; + } + //ToDo: hasConflicts + default: + { + return VcsStatusInfo::ItemUnknown; + break; + } + } + return VcsStatusInfo::ItemUnknown; +} + // #include "gitplugin.moc" diff --git a/gitplugin.h b/gitplugin.h index 2bbc661d36..c3e5bc6a97 100644 --- a/gitplugin.h +++ b/gitplugin.h @@ -1,62 +1,128 @@ /*************************************************************************** * Copyright 2008 Evgeniy Ivanov * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #ifndef GIT_PLUGIN_H #define GIT_PLUGIN_H #include #include -#include +#include +#include + namespace KDevelop { class VcsJob; class VcsRevision; } -class GitExecutor; - /** * This is the main class of KDevelop's Git plugin. * * It implements the DVCS dependent things not implemented in KDevelop::DistributedVersionControlPlugin * @author Evgeniy Ivanov */ class GitPlugin: public KDevelop::DistributedVersionControlPlugin { Q_OBJECT Q_INTERFACES(KDevelop::IBasicVersionControl KDevelop::IDistributedVersionControl) - -friend class GitExecutor; - + friend class GitInitTest; public: GitPlugin(QObject *parent, const QVariantList & args = QVariantList() ); ~GitPlugin(); - //TODO:Things to be moved to DVCSplugin, but not moved because require executor changes in all implemented DVCS + QString name() const; + + bool isVersionControlled(const KUrl &path); + + KDevelop::VcsJob* add(const KUrl::List& localLocations, + KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive); + KDevelop::VcsJob* remove(const KUrl::List& files); + KDevelop::VcsJob* status(const KUrl::List& localLocations, + KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive); + KDevelop::VcsJob* commit(const QString& message, + const KUrl::List& localLocations, + KDevelop::IBasicVersionControl::RecursionMode recursion = KDevelop::IBasicVersionControl::Recursive); KDevelop::VcsJob* log(const KUrl& localLocation, const KDevelop::VcsRevision& rev, unsigned long limit); KDevelop::VcsJob* log(const KUrl& localLocation, const KDevelop::VcsRevision& rev, const KDevelop::VcsRevision& limit); + + // Begin: KDevelop::IDistributedVersionControl + KDevelop::VcsJob* init(const KUrl & directory); + KDevelop::VcsJob* clone(const KDevelop::VcsLocation & localOrRepoLocationSrc, + const KUrl& localRepositoryRoot); + + KDevelop::VcsJob* reset(const KUrl& repository, + const QStringList &args, + const KUrl::List& files); + // End: KDevelop::IDistributedVersionControl + + DVcsJob* var(const QString &directory); + + // Branch management + + DVcsJob* switchBranch(const QString &repository, + const QString &branch); + DVcsJob* branch(const QString &repository, + const QString &basebranch = QString(), + const QString &branch = QString(), + const QStringList &args = QStringList()); + + QString curBranch(const QString &repository); + QStringList branches(const QString &repository); + + //commit dialog helpers, send to main helper the arg for git-ls-files: + QList getModifiedFiles(const QString &directory); + QList getCachedFiles(const QString &directory); + QList getOtherFiles(const QString &directory); + + //graph helpers + QList getAllCommits(const QString &repo); + + //used in log + void parseLogOutput(const DVcsJob * job, + QList& commits) const; + +protected: + bool isValidDirectory(const KUrl &dirPath); + + DVcsJob* lsFiles(const QString &repository, + const QStringList &args); + DVcsJob* gitRevList(const QString &repository, + const QStringList &args); + DVcsJob* gitRevParse(const QString &repository, + const QStringList &args); + +private: + //commit dialog "main" helper + QStringList getLsFiles(const QString &directory, const QStringList &args = QStringList()); + + void initBranchHash(const QString &repo); + + static KDevelop::VcsStatusInfo::State charToState(const char ch); + static KDevelop::VcsStatusInfo::State lsTagToState(const char ch); + + QList branchesShas; }; #endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 35c5a5c20f..6296ccd321 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,31 +1,32 @@ # Due to the use of system() and some unix-style paths this test will only run # under Linux. (Maybe this can be fixed later) # # Moreover, I'm not sure if there is a cvs commandline client for windows # (need to check this out ...) if (UNIX) # Running the test only makes sense if the git command line client # is present. So check for it before adding the test... FIND_PROGRAM(GIT NAMES git PATHS /bin /usr/bin /usr/local/bin ) if (GIT) set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) - set(gitInitTest_SRCS initTest.cpp ../gitexecutor.cpp) + set(gitInitTest_SRCS initTest.cpp ../gitplugin.cpp) kde4_add_unit_test(kdevgit-test ${gitInitTest_SRCS}) target_link_libraries(kdevgit-test ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} kdevplatformutil kdevplatformvcs + kdevplatformtestshell ) endif (GIT) endif (UNIX) diff --git a/tests/initTest.cpp b/tests/initTest.cpp index 2ba05e8b75..8773bd2036 100644 --- a/tests/initTest.cpp +++ b/tests/initTest.cpp @@ -1,373 +1,401 @@ /*************************************************************************** * This file was partly taken from KDevelop's cvs plugin * * Copyright 2007 Robert Gruber * * * * Adapted for Git * * Copyright 2008 Evgeniy Ivanov * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #include "initTest.h" #include #include - +#include +#include #include #include #include #include -#include "../gitexecutor.h" +#include "../gitplugin.h" const QString tempDir = QDir::tempPath(); -const QString GitTestDir1("kdevGit_testdir"); const QString gitTest_BaseDir(tempDir + "/kdevGit_testdir/"); -const QString gitTest_BaseDirNoTrSlash(tempDir + "/kdevGit_testdir"); const QString gitTest_BaseDir2(tempDir + "/kdevGit_testdir2/"); const QString gitRepo(gitTest_BaseDir + ".git"); const QString gitSrcDir(gitTest_BaseDir + "src/"); const QString gitTest_FileName("testfile"); const QString gitTest_FileName2("foo"); const QString gitTest_FileName3("bar"); +using namespace KDevelop; void GitInitTest::initTestCase() { - m_proxy = new GitExecutor; + AutoTestShell::init(); + m_testCore = new KDevelop::TestCore(); + m_testCore->initialize(KDevelop::Core::NoUi); + m_plugin = new GitPlugin(m_testCore); removeTempDirs(); // Now create the basic directory structure QDir tmpdir(tempDir); tmpdir.mkdir(gitTest_BaseDir); tmpdir.mkdir(gitSrcDir); tmpdir.mkdir(gitTest_BaseDir2); } void GitInitTest::cleanupTestCase() { - delete m_proxy; - - if ( QFileInfo(gitTest_BaseDir).exists() ) - KIO::NetAccess::del(KUrl(gitTest_BaseDir), 0); - if ( QFileInfo(gitTest_BaseDir2).exists() ) - KIO::NetAccess::del(KUrl(gitTest_BaseDir2), 0); + delete m_plugin; + m_testCore->cleanup(); + delete m_testCore; + if (QFileInfo(gitTest_BaseDir).exists()) + KIO::NetAccess::del(KUrl(gitTest_BaseDir), 0); + + if (QFileInfo(gitTest_BaseDir2).exists()) + KIO::NetAccess::del(KUrl(gitTest_BaseDir2), 0); } void GitInitTest::repoInit() { kDebug() << "Trying to init repo"; // make job that creates the local repository - DVCSjob* j = m_proxy->init(KUrl(gitTest_BaseDir)); - QVERIFY( j ); + VcsJob* j = m_plugin->init(KUrl(gitTest_BaseDir)); + QVERIFY(j); // try to start the job - QVERIFY( j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //check if the CVSROOT directory in the new local repository exists now - QVERIFY( QFileInfo(gitRepo).exists() ); + QVERIFY(QFileInfo(gitRepo).exists()); //check if isValidDirectory works - QVERIFY(m_proxy->isValidDirectory(KUrl(gitTest_BaseDir))); + QVERIFY(m_plugin->isValidDirectory(KUrl(gitTest_BaseDir))); //and for non-git dir, I hope nobody has /tmp under git - QVERIFY(!m_proxy->isValidDirectory(KUrl("/tmp"))); + QVERIFY(!m_plugin->isValidDirectory(KUrl("/tmp"))); //we have nothing, so ouput should be empty - j = m_proxy->gitRevParse(gitRepo, QStringList(QString("--branches"))); - QVERIFY(j->exec()); - QString out = j->output(); - QVERIFY(j->output().isEmpty()); + DVcsJob * j2 = m_plugin->gitRevParse(gitRepo, QStringList(QString("--branches"))); + QVERIFY(j2); + QVERIFY(j2->exec()); + QString out = j2->output(); + QVERIFY(j2->output().isEmpty()); } void GitInitTest::addFiles() { kDebug() << "Adding files to the repo"; //we start it after repoInit, so we still have empty git repo QFile f(gitTest_BaseDir + gitTest_FileName); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "HELLO WORLD"; } + f.flush(); + f.close(); f.setFileName(gitTest_BaseDir + gitTest_FileName2); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "No, bar()!"; } + f.flush(); - f.close(); - //test git-status exitCode (see DVCSjob::setExitCode). It will be 1, but job should be marked as Succeeded - DVCSjob* j = m_proxy->status(gitTest_BaseDir, KUrl::List(), 0, 0); - QVERIFY( j ); - QVERIFY(!j->exec() ); - QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); + f.close(); - // /tmp/kdevGit_testdir/ and kdevGit_testdir - //add always should use relative path to the any directory of the repository, let's check: - j = m_proxy->add(gitTest_BaseDir, KUrl::List(QStringList(GitTestDir1))); - QVERIFY( j ); - QVERIFY(j->exec() ); + //test git-status exitCode (see DVcsJob::setExitCode). + VcsJob* j = m_plugin->status(KUrl::List(gitTest_BaseDir)); + QVERIFY(j); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); // /tmp/kdevGit_testdir/ and testfile - j = m_proxy->add(gitTest_BaseDir, KUrl::List(QStringList(gitTest_FileName))); - QVERIFY( j ); - QVERIFY(j->exec() ); - QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - - //repository path without trailing slash - j = m_proxy->add(gitTest_BaseDirNoTrSlash, KUrl::List(QStringList(gitTest_FileName))); - QVERIFY( j ); - QVERIFY(j->exec() ); + j = m_plugin->add(KUrl::List(gitTest_BaseDir + gitTest_FileName)); + QVERIFY(j); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); f.setFileName(gitSrcDir + gitTest_FileName3); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "No, foo()! It's bar()!"; } + f.flush(); + f.close(); //test git-status exitCode again - j = m_proxy->status(gitTest_BaseDir, KUrl::List(), 0, 0); - QVERIFY( j ); - QVERIFY(j->exec() ); + j = m_plugin->status(KUrl::List(gitTest_BaseDir)); + QVERIFY(j); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //repository path without trailing slash and a file in a parent directory // /tmp/repo and /tmp/repo/src/bar - j = m_proxy->add(gitTest_BaseDirNoTrSlash, KUrl::List(QStringList(gitSrcDir + gitTest_FileName3))); - QVERIFY( j ); - QVERIFY(j->exec() ); + j = m_plugin->add(KUrl::List(QStringList(gitSrcDir + gitTest_FileName3))); + QVERIFY(j); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //let's use absolute path, because it's used in ContextMenus - j = m_proxy->add(gitTest_BaseDir, KUrl::List(QStringList(gitTest_BaseDir + gitTest_FileName2))); + j = m_plugin->add(KUrl::List(QStringList(gitTest_BaseDir + gitTest_FileName2))); QVERIFY(j); - QVERIFY(j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //Now let's create several files and try "git add file1 file2 file3" f.setFileName(gitTest_BaseDir + "file1"); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "file1"; } + f.flush(); + f.close(); f.setFileName(gitTest_BaseDir + "file2"); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "file2"; } + f.flush(); + f.close(); QStringList multipleFiles; - multipleFiles<<"file1"; - multipleFiles<<"file2"; - j = m_proxy->add(gitTest_BaseDir, KUrl::List(multipleFiles)); + multipleFiles << (gitTest_BaseDir + "file1"); + multipleFiles << (gitTest_BaseDir + "file2"); + j = m_plugin->add(KUrl::List(multipleFiles)); QVERIFY(j); - QVERIFY(j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); } void GitInitTest::commitFiles() { kDebug() << "\nListing variables with KProcess\n"; - DVCSjob* j_var = m_proxy->var(gitTest_BaseDir); - QVERIFY(j_var->exec() ); + DVcsJob* j_var = m_plugin->var(gitTest_BaseDir); + QVERIFY(j_var->exec()); QVERIFY(j_var->status() == KDevelop::VcsJob::JobSucceeded); kDebug() << "Committing..."; //we start it after addFiles, so we just have to commit ///TODO: if "" is ok? - DVCSjob* j = m_proxy->commit(gitTest_BaseDir, QString("Test commit")); - QVERIFY( j ); + VcsJob* j = m_plugin->commit(QString("Test commit"), KUrl::List(gitTest_BaseDir)); + QVERIFY(j); // try to start the job - QVERIFY( j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //test git-status exitCode one more time. - j = m_proxy->status(gitTest_BaseDir, KUrl::List(), 0, 0); - QVERIFY( j ); - QVERIFY(!j->exec() ); + j = m_plugin->status(KUrl::List(gitTest_BaseDir)); + QVERIFY(j); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); //since we commited the file to the "pure" repository, .git/refs/heads/master should exist //TODO: maybe other method should be used QString headRefName(gitRepo + "/refs/heads/master"); - QVERIFY( QFileInfo(headRefName).exists() ); + QVERIFY(QFileInfo(headRefName).exists()); //Test the results of the "git add" - DVCSjob* jobLs = new DVCSjob(0); + DVcsJob* jobLs = new DVcsJob(0); jobLs->clear(); jobLs->setDirectory(gitTest_BaseDir); - *jobLs<<"git"<<"ls-tree"<<"--name-only"<<"-r"<<"HEAD"; + *jobLs << "git" << "ls-tree" << "--name-only" << "-r" << "HEAD"; + if (jobLs) { - QVERIFY(jobLs->exec() ); + QVERIFY(jobLs->exec()); QVERIFY(jobLs->status() == KDevelop::VcsJob::JobSucceeded); QStringList files = jobLs->output().split("\n"); QVERIFY(files.contains(gitTest_FileName)); QVERIFY(files.contains(gitTest_FileName2)); QVERIFY(files.contains("src/" + gitTest_FileName3)); } QString firstCommit; + QFile headRef(headRefName); - if(headRef.open(QIODevice::ReadOnly)) { - QTextStream output( &headRef ); - output>>firstCommit; + + if (headRef.open(QIODevice::ReadOnly)) { + QTextStream output(&headRef); + output >> firstCommit; } + headRef.flush(); + headRef.close(); - QVERIFY(firstCommit!=""); + QVERIFY(firstCommit != ""); kDebug() << "Committing one more time"; //let's try to change the file and test "git commit -a" QFile f(gitTest_BaseDir + gitTest_FileName); - if(f.open(QIODevice::WriteOnly)) { - QTextStream input( &f ); + + if (f.open(QIODevice::WriteOnly)) { + QTextStream input(&f); input << "Just another HELLO WORLD"; } + f.flush(); //add changes - j = m_proxy->add(gitTest_BaseDir, KUrl::List(QStringList(gitTest_FileName))); - QVERIFY( j ); + j = m_plugin->add(KUrl::List(QStringList(gitTest_BaseDir + gitTest_FileName))); + QVERIFY(j); // try to start the job - QVERIFY( j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - j = m_proxy->commit(gitTest_BaseDir, QString("KDevelop's Test commit2")); - QVERIFY( j ); + j = m_plugin->commit(QString("KDevelop's Test commit2"), KUrl::List(gitTest_BaseDir)); + QVERIFY(j); // try to start the job - QVERIFY( j->exec() ); + QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); QString secondCommit; - if(headRef.open(QIODevice::ReadOnly)) { - QTextStream output( &headRef ); - output>>secondCommit; + + if (headRef.open(QIODevice::ReadOnly)) { + QTextStream output(&headRef); + output >> secondCommit; } + headRef.flush(); + headRef.close(); - QVERIFY(secondCommit!=""); + QVERIFY(secondCommit != ""); QVERIFY(firstCommit != secondCommit); } // void GitInitTest::cloneRepository() // { // kDebug() << "Do not clone people, clone Git repos!"; // // make job that clones the local repository, created in the previous test -// DVCSjob* j = m_proxy->clone(KUrl(gitTest_BaseDir), KUrl(gitTest_BaseDir2)); +// DVcsJob* j = m_proxy->clone(KUrl(gitTest_BaseDir), KUrl(gitTest_BaseDir2)); // QVERIFY( j ); -// +// // // try to start the job // QVERIFY( j->exec() ); -// +// // //check if the .git directory in the new local repository exists now // QVERIFY( QFileInfo(QString(gitTest_BaseDir2"kdevGit_testdir/.git/")).exists() ); // } void GitInitTest::testInit() { repoInit(); } void GitInitTest::testAdd() { addFiles(); } void GitInitTest::testCommit() { commitFiles(); } void GitInitTest::testBranching() { - DVCSjob* j = m_proxy->branch(gitTest_BaseDir); + DVcsJob* j = m_plugin->branch(gitTest_BaseDir); QVERIFY(j); QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - QString curBranch = m_proxy->curBranch(gitTest_BaseDir); + QString curBranch = m_plugin->curBranch(gitTest_BaseDir); QCOMPARE(curBranch, QString("master")); QString newBranch("new"); - j = m_proxy->branch(gitTest_BaseDir, QString("master"), newBranch); + j = m_plugin->branch(gitTest_BaseDir, QString("master"), newBranch); QVERIFY(j); QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - QVERIFY(m_proxy->branches(gitTest_BaseDir).contains(newBranch)); + QVERIFY(m_plugin->branches(gitTest_BaseDir).contains(newBranch)); - j = m_proxy->checkout(gitTest_BaseDir, newBranch); + j = m_plugin->switchBranch(gitTest_BaseDir, newBranch); QVERIFY(j); QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - QCOMPARE(m_proxy->curBranch(gitTest_BaseDir), newBranch); + QCOMPARE(m_plugin->curBranch(gitTest_BaseDir), newBranch); - j = m_proxy->branch(gitTest_BaseDir, QString("master"), QString(), QStringList("-D")); + j = m_plugin->branch(gitTest_BaseDir, QString("master"), QString(), QStringList("-D")); QVERIFY(j); QVERIFY(j->exec()); QVERIFY(j->status() == KDevelop::VcsJob::JobSucceeded); - QVERIFY(!m_proxy->branches(gitTest_BaseDir).contains(QString("master"))); + QVERIFY(!m_plugin->branches(gitTest_BaseDir).contains(QString("master"))); } void GitInitTest::revHistory() { - QList commits = m_proxy->getAllCommits(gitTest_BaseDir); + QList commits = m_plugin->getAllCommits(gitTest_BaseDir); QVERIFY(!commits.isEmpty()); QStringList logMessages; - for(int i = 0; i < commits.count(); ++i) + + for (int i = 0; i < commits.count(); ++i) logMessages << commits[i].getLog(); + QCOMPARE(commits.count(), 2); - QCOMPARE(logMessages[0], QString("KDevelop's Test commit2") ); //0 is later than 1! + + QCOMPARE(logMessages[0], QString("KDevelop's Test commit2")); //0 is later than 1! + QCOMPARE(logMessages[1], QString("Test commit")); + QVERIFY(commits[1].getParents().isEmpty()); //0 is later than 1! + QVERIFY(!commits[0].getParents().isEmpty()); //initial commit is on the top + QVERIFY(commits[1].getCommit().contains(QRegExp("^\\w{,40}$"))); + QVERIFY(commits[0].getCommit().contains(QRegExp("^\\w{,40}$"))); + QVERIFY(commits[0].getParents()[0].contains(QRegExp("^\\w{,40}$"))); } void GitInitTest::removeTempDirs() { - if (QFileInfo(gitTest_BaseDir).exists() ) - if (!KIO::NetAccess::del(KUrl(gitTest_BaseDir), 0) ) + if (QFileInfo(gitTest_BaseDir).exists()) + if (!KIO::NetAccess::del(KUrl(gitTest_BaseDir), 0)) qDebug() << "KIO::NetAccess::del(" << gitTest_BaseDir << ") returned false"; - if (QFileInfo(gitTest_BaseDir2).exists() ) - if (!KIO::NetAccess::del(KUrl(gitTest_BaseDir2), 0) ) + + if (QFileInfo(gitTest_BaseDir2).exists()) + if (!KIO::NetAccess::del(KUrl(gitTest_BaseDir2), 0)) qDebug() << "KIO::NetAccess::del(" << gitTest_BaseDir2 << ") returned false"; } QTEST_KDEMAIN(GitInitTest, GUI) // #include "gittest.moc" diff --git a/tests/initTest.h b/tests/initTest.h index 2b302358b5..25e0ef13f8 100644 --- a/tests/initTest.h +++ b/tests/initTest.h @@ -1,58 +1,64 @@ /*************************************************************************** * This file was partly taken from KDevelop's cvs plugin * * Copyright 2007 Robert Gruber * * * * Adapted for Git * * Copyright 2008 Evgeniy Ivanov * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * * published by the Free Software Foundation; either version 2 of * * the License or (at your option) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * ***************************************************************************/ #ifndef GIT_INIT_H #define GIT_INIT_H #include -class GitExecutor; +class GitPlugin; + +namespace KDevelop +{ + class TestCore; +} class GitInitTest: public QObject { Q_OBJECT - private: - void repoInit(); - void addFiles(); - void commitFiles(); -// void cloneRepository(); -// void importTestData(); -// void checkoutTestData(); - - private slots: - void initTestCase(); - void testInit(); - void testAdd(); - void testCommit(); - void testBranching(); - void revHistory(); - void cleanupTestCase(); - - private: - GitExecutor* m_proxy; - void removeTempDirs(); +private: + void repoInit(); + void addFiles(); + void commitFiles(); +// void cloneRepository(); +// void importTestData(); +// void checkoutTestData(); + +private slots: + void initTestCase(); + void testInit(); + void testAdd(); + void testCommit(); + void testBranching(); + void revHistory(); + void cleanupTestCase(); + +private: + KDevelop::TestCore* m_testCore; + GitPlugin* m_plugin; + void removeTempDirs(); }; #endif