PDA

View Full Version : GIT - QProcess



Binary01
11th August 2016, 16:14
Hii Forum,

I'm using QProcess to execute some cmd GIT

I tried :
process.start("git pull origin master");

How do I know if the operation is OK or NOT ??

I can get the response :
if(process.waitForFinished())
{
process.waitForReadyRead(1000);
qDebug() << "read output" << process.readAllStandardOutput();
pullOk = true;
}

I tried to use a boolean pullOK, but I didn't find a methode (QProcess) ...

I have to know the result of the operation ([B] true [/ B] or [B] false [/ B]) for treatment after

Regards,

anda_skoa
11th August 2016, 17:07
See QProcess::exitStatus() and QProcess::exitCode().

Cheers,
_

Binary01
11th August 2016, 19:22
Yes,

When I try to execute
git pull origin master

I have two cases :
1- update ok
2- generate conflicts ( some problems with remote repository)

So in this 2cases ===> exitCode = 0 ===> operation pull OK

is the second case : generate conflicts ===> exitCode = 0 ??

jefftee
12th August 2016, 03:19
What is the git command return code when you execute the same from the command line? i.e. If linux or mac run the command from the command line then echo $? which will show you the return code. You'll have to google how to do the same on Windows if you're using Windows.

If git's return code is indeed zero on a conflict, you'll have to parse the output of the git command to determine success/failure, but I know that git generally sets return code 1 on error, 0 on success, although there may be exceptions to that rule.

scary hallo
12th August 2016, 14:27
Have you tried something like this:


QStringList argumemts;
arguments << "pull" << "origin" << "master";
process.start("git", aguments);

Binary01
16th August 2016, 12:44
Thanks,

some notes :

1- GIT command QProces work well
2- GIT command QProces return the same result = GIT command Line

Code :
process.start("git pull origin master");
if(process.waitForFinished())
{
QString out = process.readAllStandardOutput();
QStringList projects = out.split("\n");

for (int i = 0; i < projects.size()-1; ++i)
{
qDebug() << " --> " << projects[i];
}
}

QProcess::ExitStatus Status = process.exitStatus();

qDebug() << Status;
if (Status == 0)
{
qDebug() << "App executed OK!!";
pullOk = true;
}

Now, I can't test the conflicts because I can't generate conflicts (now) and I have to analyze all cases

>> I wonder if someone has already done the same thing (Testing conflicts)
>> Git's return code is indeed zero on a conflict ??

Any Idea (Test conflict, ...)

Thanks,

jefftee
17th August 2016, 03:10
From my Mac using git version 2.9.2:



mbp02:~/develop/InkjetPlumber[testb2]$ git merge testb1
Auto-merging InkjetPlumber.pro
CONFLICT (content): Merge conflict in InkjetPlumber.pro
Automatic merge failed; fix conflicts and then commit the result.
mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$ echo $?
1
mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$ git --version
git version 2.9.2
mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$

So the git command exits with rc=1 on a merge conflict as shown on line 6 above.

Your example still shows that you're executing the QProcess with "git pull origin master" as the program to execute. Post #5 demonstrated the correct way to do this, the program is "git" and the arguments should be "pull", "origin", "master". Not sure if this is related to your issue, but you should make that change regardless.

Good luck.