Results 1 to 7 of 7

Thread: GIT - QProcess

  1. #1
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default GIT - QProcess

    Hii Forum,

    I'm using QProcess to execute some cmd GIT

    I tried :
    Qt Code:
    1. process.start("git pull origin master");
    To copy to clipboard, switch view to plain text mode 

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

    I can get the response :
    Qt Code:
    1. if(process.waitForFinished())
    2. {
    3. process.waitForReadyRead(1000);
    4. qDebug() << "read output" << process.readAllStandardOutput();
    5. pullOk = true;
    6. }
    To copy to clipboard, switch view to plain text mode 

    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,
    Last edited by Binary01; 11th August 2016 at 16:20.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: GIT - QProcess


  3. #3
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: GIT - QProcess

    Yes,

    When I try to execute
    Qt Code:
    1. git pull origin master
    To copy to clipboard, switch view to plain text mode 

    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 ??

  4. #4
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: GIT - QProcess

    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  5. #5
    Join Date
    May 2012
    Location
    Germany
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: GIT - QProcess

    Have you tried something like this:
    Qt Code:
    1. QStringList argumemts;
    2. arguments << "pull" << "origin" << "master";
    3. process.start("git", aguments);
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2016
    Posts
    54
    Thanks
    7
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: GIT - QProcess

    Thanks,

    some notes :

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

    Code :
    Qt Code:
    1. process.start("git pull origin master");
    2. if(process.waitForFinished())
    3. {
    4. QString out = process.readAllStandardOutput();
    5. QStringList projects = out.split("\n");
    6.  
    7. for (int i = 0; i < projects.size()-1; ++i)
    8. {
    9. qDebug() << " --> " << projects[i];
    10. }
    11. }
    12.  
    13. QProcess::ExitStatus Status = process.exitStatus();
    14.  
    15. qDebug() << Status;
    16. if (Status == 0)
    17. {
    18. qDebug() << "App executed OK!!";
    19. pullOk = true;
    20. }
    To copy to clipboard, switch view to plain text mode 

    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,

  7. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: GIT - QProcess

    From my Mac using git version 2.9.2:

    Qt Code:
    1. mbp02:~/develop/InkjetPlumber[testb2]$ git merge testb1
    2. Auto-merging InkjetPlumber.pro
    3. CONFLICT (content): Merge conflict in InkjetPlumber.pro
    4. Automatic merge failed; fix conflicts and then commit the result.
    5. mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$ echo $?
    6. 1
    7. mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$ git --version
    8. git version 2.9.2
    9. mbp02:~/develop/InkjetPlumber[testb2 *+|MERGING]$
    To copy to clipboard, switch view to plain text mode 
    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.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. QProcess crashes second QProcess
    By Ion in forum Newbie
    Replies: 1
    Last Post: 23rd September 2014, 21:00
  2. Replies: 1
    Last Post: 3rd June 2013, 13:11
  3. Replies: 0
    Last Post: 23rd March 2013, 19:23
  4. Replies: 0
    Last Post: 26th August 2010, 10:44
  5. QProcess inside QProcess
    By bunjee in forum Qt Programming
    Replies: 7
    Last Post: 4th December 2008, 00:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.