Commit 2231d3da authored by Niko Sams's avatar Niko Sams
Browse files

fix deleting an empty folder in a git versioned project

parent b8ab040c
......@@ -42,6 +42,7 @@
#include <vcs/vcsannotation.h>
#include <vcs/widgets/standardvcslocationwidget.h>
#include <KIO/CopyJob>
#include <KIO/NetAccess>
#include "gitclonejob.h"
#include <interfaces/contextmenuextension.h>
#include <QMenu>
......@@ -415,17 +416,38 @@ VcsJob* GitPlugin::remove(const KUrl::List& files)
{
if (files.isEmpty())
return errorsFound(i18n("No files to remove"));
QDir dir = dotGitDirectory(files.front());
QDir dotGitDir = dotGitDirectory(files.front());
KUrl::List files_(files);
//removing empty folders manually, git doesn't do that
QMutableListIterator<KUrl> i(files_);
while (i.hasNext()) {
KUrl file = i.next();
QFileInfo fileInfo(file.toLocalFile());
if (fileInfo.isDir()) {
QDir dir(file.toLocalFile());
if (dir.entryList(QDir::NoDotAndDotDot).isEmpty()) {
kDebug() << "empty folder, removing manually" << file;
KIO::NetAccess::synchronousRun(KIO::trash(file), 0);
i.remove();
}
}
}
if (files_.isEmpty()) return 0;
QStringList otherStr = getLsFiles(dir, QStringList() << "--others" << "--" << files.front().toLocalFile(), KDevelop::OutputJob::Silent);
QStringList otherStr = getLsFiles(dotGitDir, QStringList() << "--others" << "--" << files_.front().toLocalFile(), KDevelop::OutputJob::Silent);
if(otherStr.isEmpty()) {
DVcsJob* job = new GitJob(dir, this);
DVcsJob* job = new GitJob(dotGitDir, this);
job->setType(VcsJob::Remove);
*job << "git" << "rm" << "-r";
*job << "--" << files;
*job << "--" << files_;
return job;
} else {
return new StandardJob(this, KIO::trash(files), KDevelop::OutputJob::Silent);
kDebug() << "non versioned file, removing manually";
return new StandardJob(this, KIO::trash(files_), KDevelop::OutputJob::Silent);
}
}
......
......@@ -37,7 +37,7 @@
#include "../gitplugin.h"
#define VERIFYJOB(j) \
QVERIFY(j); QVERIFY(j->exec()); QVERIFY((j)->status() == KDevelop::VcsJob::JobSucceeded)
do { QVERIFY(j); QVERIFY(j->exec()); QVERIFY((j)->status() == KDevelop::VcsJob::JobSucceeded); } while(0)
const QString tempDir = QDir::tempPath();
const QString gitTest_BaseDir(tempDir + "/kdevGit_testdir/");
......@@ -367,6 +367,70 @@ void GitInitTest::testAnnotation()
QCOMPARE(annotation.commitMessage(), QString("KDevelop's Test commit3"));
}
void GitInitTest::testRemoveEmptyFolder()
{
repoInit();
QDir d(gitTest_BaseDir);
d.mkdir("emptydir");
VcsJob* j = m_plugin->remove(KUrl::List(KUrl::fromLocalFile(gitTest_BaseDir+"emptydir/")));
if (j) VERIFYJOB(j);
QVERIFY(!d.exists("emptydir"));
}
void GitInitTest::testRemoveUnindexedFile()
{
repoInit();
QFile f(gitTest_BaseDir + gitTest_FileName);
QVERIFY(f.open(QIODevice::Append));
QTextStream input(&f);
input << "An appended line";
f.close();
VcsJob* j = m_plugin->remove(KUrl::List(KUrl::fromLocalFile(gitTest_BaseDir + gitTest_FileName)));
if (j) VERIFYJOB(j);
QVERIFY(!QFile::exists(gitTest_BaseDir + gitTest_FileName));
}
void GitInitTest::testRemoveFolderContainingUnversionedFiles()
{
repoInit();
QDir d(gitTest_BaseDir);
d.mkdir("dir");
{
QFile f(gitTest_BaseDir + "dir/foo");
QVERIFY(f.open(QIODevice::Append));
QTextStream input(&f);
input << "An appended line";
f.close();
}
VcsJob* j = m_plugin->add(KUrl::List(KUrl::fromLocalFile(gitTest_BaseDir+"dir")));
VERIFYJOB(j);
j = m_plugin->commit("initial commit", KUrl::List(KUrl::fromLocalFile(gitTest_BaseDir)));
VERIFYJOB(j);
{
QFile f(gitTest_BaseDir + "dir/bar");
QVERIFY(f.open(QIODevice::Append));
QTextStream input(&f);
input << "An appended line";
f.close();
}
j = m_plugin->remove(KUrl::List(KUrl::fromLocalFile(gitTest_BaseDir + "dir")));
if (j) VERIFYJOB(j);
QVERIFY(!QFile::exists(gitTest_BaseDir + "dir"));
}
void GitInitTest::removeTempDirs()
{
if (QFileInfo(gitTest_BaseDir).exists())
......
......@@ -55,6 +55,9 @@ private slots:
void testBranching();
void revHistory();
void testAnnotation();
void testRemoveEmptyFolder();
void testRemoveUnindexedFile();
void testRemoveFolderContainingUnversionedFiles();
private:
GitPlugin* m_plugin;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment