1 | #include "GitCredentials.h" |
---|---|
2 | |
3 | #include <GitBase.h> |
4 | #include <GitConfig.h> |
5 | |
6 | #include <QProcess> |
7 | #include <QTextStream> |
8 | |
9 | void GitCredentials::configureStorage(const QString &user, const QString &password, |
10 | const QSharedPointer<GitBase> &gitBase) |
11 | { |
12 | const auto dir = gitBase->getGitDir(); |
13 | const auto ret = gitBase->run(QString("git config credential.helper \'store --file %1/.git-credentials\'").arg(dir)); |
14 | |
15 | QProcess storeProcess; |
16 | storeProcess.start("git", { "credential-store", "store", "--file", QString( "%1/.git-credentials").arg(dir) }); |
17 | |
18 | auto started = storeProcess.waitForStarted(); |
19 | |
20 | if (started) |
21 | { |
22 | QScopedPointer<GitConfig> gitConf(new GitConfig(gitBase)); |
23 | |
24 | QTextStream out(&storeProcess); |
25 | out << "protocol=https"<< endl; |
26 | out << "host="<< gitConf->getServerHost().toUtf8() << endl; |
27 | out << "username="<< user.toUtf8() << endl; |
28 | out << "password="<< password.toUtf8() << endl; |
29 | out << endl; |
30 | |
31 | storeProcess.closeWriteChannel(); |
32 | storeProcess.waitForFinished(); |
33 | } |
34 | } |
35 | |
36 | void GitCredentials::configureCache(uint64_t timeout, const QSharedPointer<GitBase> &gitBase) |
37 | { |
38 | gitBase->run("git credential-cache exit"); |
39 | gitBase->run( |
40 | QString("git credential.helper 'cache --timeout %1 --socket %2/socket'").arg(timeout).arg(gitBase->getGitDir())); |
41 | } |
42 |