Skip to content

Commit 8645236

Browse files
authored
Use git revision as the version when VERSION is not set and when -g is passed
1 parent 617d6e7 commit 8645236

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

src/appimagetool.c

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**************************************************************************
22
*
3-
* Copyright (c) 2004-18 Simon Peter
3+
* Copyright (c) 2004-19 Simon Peter
44
*
55
* All Rights Reserved.
66
*
@@ -483,10 +483,6 @@ static GOptionEntry entries[] =
483483
int
484484
main (int argc, char *argv[])
485485
{
486-
/* Parse VERSION environment variable.
487-
* We cannot use g_environ_getenv (g_get_environ() since it is too new for CentOS 6 */
488-
char* version_env;
489-
version_env = getenv("VERSION");
490486

491487
/* Parse Travis CI environment variables.
492488
* https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables
@@ -556,6 +552,39 @@ main (int argc, char *argv[])
556552
if (showVersionOnly)
557553
exit(0);
558554

555+
/* Parse VERSION environment variable.
556+
* We cannot use g_environ_getenv (g_get_environ() since it is too new for CentOS 6
557+
* Also, if VERSION is not set and -g is called and if git is on the path, use
558+
* git rev-parse --short HEAD
559+
* TODO: Might also want to somehow make use of
560+
* git rev-parse --abbrev-ref HEAD
561+
* 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")) {
566+
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);
575+
} 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");
583+
}
584+
}
585+
}
586+
}
587+
559588
if(!((0 == strcmp(sqfs_comp, "gzip")) || (0 ==strcmp(sqfs_comp, "xz"))))
560589
die("Only gzip (faster execution, larger files) and xz (slower execution, smaller files) compression is supported at the moment. Let us know if there are reasons for more, should be easy to add. You could help the project by doing some systematic size/performance measurements. Watch for size, execution speed, and zsync delta size.");
561590
/* Check for dependencies here. Better fail early if they are not present. */

0 commit comments

Comments
 (0)