bool GitRunner::isValidDirectory()
{
    const QString initialPath(m_lastRepoRoot->toLocalFile(KUrl::RemoveTrailingSlash));
    setDirectory(*m_lastRepoRoot);

    // A possible git repo has a .git subdicerctory
    const QString gitDir(".git");

    // Also, git rev-parse --is-inside-work-tree returns "true" if we are
    // inside any subdirectory of the git tree.
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "rev-parse";
    *job << "--is-inside-work-tree";
    startJob(*job);

    QFileInfo finfo(initialPath);
    QDir dir;
    if (finfo.isFile()) {
        dir = finfo.absoluteDir();
    } else {
        dir = QDir(initialPath);
        dir.makeAbsolute();
    }

    return (dir.exists(gitDir) && m_result.compare("true")) ? true : false;
}
Exemplo n.º 2
0
void writeJob::setJobFileName(const QString fileName)
{
    /// 传递过来文件名要比创建控件来的还要晚
//    qDebug()<<"writeJob::setJobFileName::"<<fileName;
    jobFileName=fileName;
    isFileNameSet=true;
    initJob();  // 设置之后直接初始化
}
DvcsJob::JobStatus GitRunner::branches()
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "branch";

    startJob(*job);
    return m_jobStatus;
}
Exemplo n.º 4
0
void GitRunner::init()
{
    QStringList command;
    command << "init";
    KJob *job = initJob(command);

    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleInit(KJob*)));
    job->start();
}
DvcsJob::JobStatus GitRunner::log()
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "log";

    startJob(*job);
    return m_jobStatus;
}
Exemplo n.º 6
0
void GitRunner::deleteCommit(const QString &sha1hash)
{
    QStringList command;
    command << "reset" << "--hard" << sha1hash;
    KJob *job = initJob(command);

    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleDeleteCommit(KJob*)));

    job->start();
}
DvcsJob::JobStatus GitRunner::newBranch(const QString &newBranch)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "branch";
    *job << newBranch;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::setAuthor(const QString &username)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "config";
    *job << "user.name";
    *job << username;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::setEmail(const QString &email)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "config";
    *job << "user.email";
    *job << email;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::init(const KUrl &directory)
{
    // We need to tell the runner to change dir!
    m_lastRepoRoot->setDirectory(directory.pathOrUrl());
    DvcsJob *job = new DvcsJob();
    initJob(*job);

    *job << "init";
    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::deleteCommit(const QString &sha1hash)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "reset";
    *job << "--hard";
    *job << sha1hash;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::moveToCommit(const QString &sha1hash,
                                           const QString &newBranch)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "checkout";
    *job << sha1hash;

    startJob(*job);
    if (m_jobStatus != DvcsJob::JobSucceeded)
        return m_jobStatus;

    job = new DvcsJob();
    initJob(*job);
    *job << "checkout";
    *job << "-b";
    *job << newBranch;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::mergeBranch(const QString &branchName,
                                          const QString &message)
{
    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "merge";
    *job << "--no-ff";
    *job << "-m";
    *job << message;
    *job << branchName;

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::createWorkingCopy(const KUrl &repoOrigin,
                                                const KUrl &repoDestination)
{
    // TODO: now supports only cloning a local repo(not very useful, I know =P),
    // so extend the method to be used over the Internet.
    m_lastRepoRoot->setDirectory(repoDestination.pathOrUrl());
    DvcsJob *job = new DvcsJob();
    initJob(*job);

    *job << "clone";
    *job << repoOrigin.pathOrUrl();
    startJob(*job);
    return m_jobStatus;
}
Exemplo n.º 15
0
void GitRunner::createWorkingCopy(const KUrl &repoOrigin,
                                                const KUrl &repoDestination)
{
    // TODO: now supports only cloning a local repo(not very useful, I know =P),
    // so extend the method to be used over the Internet.
    m_lastRepoRoot->setDirectory(repoDestination.pathOrUrl());

    QStringList command;
    command << "clone " + repoOrigin.pathOrUrl();
    KJob *job = initJob(command);

    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleCreateWorkingCopy(KJob*)));

    job->start();
}
Exemplo n.º 16
0
void GitRunner::moveToCommit(const QString &sha1hash,
                                           const QString &newBranch)
{
    QStringList command;
    command << "branch" << newBranch << sha1hash;
    execSynchronously(command);

    command.clear();
    command << "checkout" << newBranch;
    KJob *job = initJob(command);

    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleMoveToCommit(KJob*)));

    job->start();
}
DvcsJob::JobStatus GitRunner::remove(const KUrl::List &files)
{
    if (files.empty())
        return m_jobStatus = DvcsJob::JobCancelled;

    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "rm";
    QStringList stringFiles = files.toStringList();
    while (!stringFiles.isEmpty()) {
        *job <<  m_lastRepoRoot->pathOrUrl() + '/' + stringFiles.takeAt(0);
    }

    startJob(*job);
    return m_jobStatus;
}
DvcsJob::JobStatus GitRunner::commit(const QString &message)
{
    // NOTE: git doesn't allow empty commit !
    if (message.isEmpty())
        return m_jobStatus = DvcsJob::JobCancelled;

    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "commit";
    *job << "-m";
    //Note: the message is quoted somewhere else
    *job << message;

    startJob(*job);
    return m_jobStatus;
}
Exemplo n.º 19
0
QString GitRunner::execSynchronously(const QStringList& command)
{
    KJob *job = initJob(command);

    QString result;

    if (!job->exec()) {
        handleError(job);
        return QString();
    } else {
        DvcsJob *j = qobject_cast<DvcsJob*>(job);
        if (!j) {
            return QString();
        }
        result = j->output();
    }
    return result;
}
Exemplo n.º 20
0
void GitRunner::remove(const KUrl::List &files)
{
    if (files.empty()) {
        return;
    }

    QStringList command;
    command << "rm ";
    QStringList stringFiles = files.toStringList();
    while (!stringFiles.isEmpty()) {
        command.append(m_lastRepoRoot->pathOrUrl() + '/' + stringFiles.takeAt(0));
    }

    KJob *job = initJob(command);
    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleRemove(KJob*)));

    job->start();
}
DvcsJob::JobStatus GitRunner::add(const KUrl::List &localLocations)
{
    if (localLocations.empty())
        return m_jobStatus = DvcsJob::JobCancelled;

    DvcsJob *job = new DvcsJob();
    initJob(*job);
    *job << "add";

    // Adding files to the runner.
    QStringList stringFiles = localLocations.toStringList();
    while (!stringFiles.isEmpty()) {
        *job <<  m_lastRepoRoot->pathOrUrl() + '/' + stringFiles.takeAt(0);
    }

    startJob(*job);
    return m_jobStatus;
}
Exemplo n.º 22
0
void GitRunner::commit(const QString &message)
{
    // NOTE: git doesn't allow empty commit !
    if (message.isEmpty()) {
        return;
    }

    QStringList command;
    command << "commit";
    command << "-m";
    //Note: the message is quoted somewhere else
    command << message;

    KJob *job = initJob(command);

    connect(job, SIGNAL(result(KJob*)), this, SLOT(handleCommit(KJob*)));

    job->start();
}
Exemplo n.º 23
0
void initShell() {
        shellTerminal = STDIN_FILENO;
        shellIsInteractive = isatty(shellTerminal);
	jobs = initJob();
     
        jobs->commandLine = NULL;
	if(shellIsInteractive) {
		struct sigaction act, oact;
		sigset_t new_mask, old_mask;		
		if(memset(&act, 0, sizeof(struct sigaction)) == NULL)
			printf("Error in signal handler creation!\n");
		              
		/* Loop until we are in the foreground. */
                while( tcgetpgrp(shellTerminal) != (shellPgid = getpgrp()))
                        kill (-shellPgid, SIGTTIN);     // Send signal to stop all process in the shell group
                
		// Put ourselves in our own process group
                shellPgid = getpid();
                if(setpgid(shellPgid, shellPgid) < 0) {
                        printf("Error: Couldn't put the shell in its own process group");
                        exit(EXIT_FAILURE);                     
                }

                // Grab control of the terminal
                tcsetpgrp(shellTerminal, shellPgid);
        
                // Save default terminal attributes for shell.
                tcgetattr(shellTerminal, &shellTmodes);
	
		// Ignore interactive and job-control signals.
		act.sa_handler = stopJob;
		sigaction(SIGTSTP, &act, &oact); /* SIGTSTP is ^Z */

		sigfillset (&new_mask);
  		sigdelset (&new_mask, SIGTSTP);
  		sigprocmask (SIG_BLOCK, &new_mask, &old_mask);
        }       
}