@@ -79,7 +79,7 @@ static gboolean sign = FALSE;
7979static gboolean no_appstream = FALSE;
8080gchar * * remaining_args = NULL ;
8181gchar * updateinformation = NULL ;
82- static gboolean guessupdateinformation = FALSE;
82+ static gboolean guess_update_information = FALSE;
8383gchar * bintray_user = NULL ;
8484gchar * bintray_repo = NULL ;
8585gchar * sqfs_comp = "gzip" ;
@@ -464,7 +464,7 @@ static GOptionEntry entries[] =
464464{
465465 { "list" , 'l' , 0 , G_OPTION_ARG_NONE , & list , "List files in SOURCE AppImage" , NULL },
466466 { "updateinformation" , 'u' , 0 , G_OPTION_ARG_STRING , & updateinformation , "Embed update information STRING; if zsyncmake is installed, generate zsync file" , NULL },
467- { "guess" , 'g' , 0 , G_OPTION_ARG_NONE , & guessupdateinformation , "Guess update information based on Travis CI or GitLab environment variables" , NULL },
467+ { "guess" , 'g' , 0 , G_OPTION_ARG_NONE , & guess_update_information , "Guess update information based on Travis CI or GitLab environment variables" , NULL },
468468 { "bintray-user" , 0 , 0 , G_OPTION_ARG_STRING , & bintray_user , "Bintray user name" , NULL },
469469 { "bintray-repo" , 0 , 0 , G_OPTION_ARG_STRING , & bintray_repo , "Bintray repository" , NULL },
470470 { "version" , 0 , 0 , G_OPTION_ARG_NONE , & showVersionOnly , "Show version number" , NULL },
@@ -559,27 +559,31 @@ main (int argc, char *argv[])
559559 * TODO: Might also want to somehow make use of
560560 * git rev-parse --abbrev-ref HEAD
561561 * git log -1 --format=%ci */
562- gchar * version_env ; // In which cases do we need to malloc() here?
563- version_env = getenv ( "VERSION" );
564- if ( guessupdateinformation ){
565- if (g_find_program_in_path ("git" )) {
562+ gchar * version_env = getenv ( "VERSION" );
563+
564+ if ( guess_update_information ){
565+ if (g_find_program_in_path ("git" )) {
566566 if (version_env == NULL ) {
567- GError * error = NULL ;
568- gchar * out = NULL ;
569- GString * command_line = g_string_new ("git" );
570- g_string_append_printf (command_line , " rev-parse --short HEAD" );
571- int ret = g_spawn_command_line_sync (command_line -> str , & out , NULL , NULL , & error );
572- g_assert_no_error (error );
573- if (ret ) {
574- version_env = g_strstrip (out );
567+ GError * error = NULL ;
568+ gchar * out = NULL ;
569+
570+ char command_line [] = "git rev-parse --short HEAD" ;
571+
572+ int exitcode = -1 ;
573+ int ret = g_spawn_command_line_sync (command_line , & out , NULL , & exitcode , & error );
574+
575+ if (ret != 0 || error != NULL ) {
576+ g_printerr ("Failed to run 'git rev-parse --short HEAD': %s\n" , error -> message );
577+ } else if (exitcode != 0 ) {
578+ g_printerr ("Failed to run 'git rev-parse --short HEAD': exited with code %d\n" , exitcode );
575579 } else {
576- g_print ( "Failed to run 'git rev-parse --short HEAD'" );
577- }
578- g_string_free ( command_line , true);
579- if ( version_env != NULL ) {
580- g_print ( "NOTE: Using the output of 'git rev-parse --short HEAD' as the version: \n" );
581- g_print (" %s \n" , version_env );
582- g_print ( " Please set the $VERSION environment variable if this is not intended\n" );
580+ version_env = g_strstrip ( out );
581+
582+ if ( version_env != NULL ) {
583+ g_printerr ( "NOTE: Using the output of 'git rev-parse --short HEAD' as the version:\n" );
584+ g_printerr ( " %s \n", version_env );
585+ g_printerr (" Please set the $VERSION environment variable if this is not intended \n" );
586+ }
583587 }
584588 }
585589 }
@@ -857,7 +861,7 @@ main (int argc, char *argv[])
857861
858862 /* If the user has not provided update information but we know this is a Travis CI build,
859863 * then fill in update information based on TRAVIS_REPO_SLUG */
860- if (guessupdateinformation ){
864+ if (guess_update_information ){
861865 if (travis_repo_slug ){
862866 if (!github_token ) {
863867 printf ("Will not guess update information since $GITHUB_TOKEN is missing,\n" );
0 commit comments