From 227231d06eda9366d10a890cd918d3cca092a75e Mon Sep 17 00:00:00 2001 From: Alastair Poole Date: Mon, 3 Sep 2018 16:11:09 +0100 Subject: [PATCH] examples: update examples if repository exists. This adds a git_update method to the scm lib which we use here to update the existing examples git repository. This ensures the developer is always using an up-to-date copy of EFL examples when creating. --- src/lib/edi_create.c | 3 +-- src/lib/edi_scm.c | 17 +++++++++++++++++ src/lib/edi_scm.h | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/lib/edi_create.c b/src/lib/edi_create.c index 8ac10a1..5f004ef 100644 --- a/src/lib/edi_create.c +++ b/src/lib/edi_create.c @@ -410,8 +410,7 @@ edi_create_example(const char *example_name, const char *parentdir, INF("Extracting example project \"%s\" at path %s\n", example_name, dest); if (ecore_file_exists(examplepath)) - ERR("TODO: UPDATE NOT IMPLEMENTED"); -// status = edi_scm_git_update(examplepath); + status = edi_scm_git_update(examplepath); else status = edi_scm_git_clone(EXAMPLES_GIT_URL, examplepath); diff --git a/src/lib/edi_scm.c b/src/lib/edi_scm.c index fd5c3d6..1553f8b 100644 --- a/src/lib/edi_scm.c +++ b/src/lib/edi_scm.c @@ -85,6 +85,23 @@ edi_scm_git_clone(const char *url, const char *dir) return code; } +EAPI int +edi_scm_git_update(const char *dir) +{ + char *oldpwd; + int code; + + oldpwd = getcwd(NULL, PATH_MAX); + + chdir(dir); + code = edi_exe_wait("git fetch origin && git reset --hard origin/master"); + chdir(oldpwd); + + free(oldpwd); + + return code; +} + static int _edi_scm_git_file_stage(const char *path) { diff --git a/src/lib/edi_scm.h b/src/lib/edi_scm.h index 3ba0c43..ad3858e 100644 --- a/src/lib/edi_scm.h +++ b/src/lib/edi_scm.h @@ -128,14 +128,25 @@ EAPI int edi_scm_git_new(void); /** * Clone an existing git repository from the provided url. * - * @param url the URL to clone from. - * @param dir the new directory that will be created to clone into + * @param url The URL to clone from. + * @param dir The new directory that will be created to clone into. * @return The status code of the clone command. * * @ingroup Scm */ EAPI int edi_scm_git_clone(const char *url, const char *dir); +/** + * Update a local git repository from remote source. + * + * @param dir The directory to update. + * + * @return The status code of the update process. + * + * @ingroup Scm + */ +EAPI int edi_scm_git_update(const char *dir); + /** * Get a pointer to the SCM engine in use. *