forked from Mirrors/flatpak-builder
builder: Allow specifying the git commit if the branch is a tag
If the ref specified in "branch" is actually a tag, we were requiring that the "commit" property must match "git rev-parse $branch", but in the case of a tagname that actually expands to the id of the tag object, not the commit id. We now also try to match against "rev-parse $branch^{commit}" which expands to the actual commit object. We still allow the tag object for backwards compat.tingping/wmclass
parent
3d1b51b5c0
commit
8c78700363
|
@ -71,13 +71,20 @@ git_get_mirror_dir (const char *url_or_path,
|
|||
static char *
|
||||
git_get_current_commit (GFile *repo_dir,
|
||||
const char *branch,
|
||||
gboolean ensure_commit,
|
||||
BuilderContext *context,
|
||||
GError **error)
|
||||
{
|
||||
char *output = NULL;
|
||||
g_autofree char *arg = NULL;
|
||||
|
||||
if (ensure_commit)
|
||||
arg = g_strconcat (branch, "^{commit}", NULL);
|
||||
else
|
||||
arg = g_strdup (branch);
|
||||
|
||||
if (!git (repo_dir, &output, error,
|
||||
"rev-parse", branch, NULL))
|
||||
"rev-parse", arg, NULL))
|
||||
return NULL;
|
||||
|
||||
/* Trim trailing whitespace */
|
||||
|
@ -89,13 +96,14 @@ git_get_current_commit (GFile *repo_dir,
|
|||
char *
|
||||
builder_git_get_current_commit (const char *repo_location,
|
||||
const char *branch,
|
||||
gboolean ensure_commit,
|
||||
BuilderContext *context,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GFile) mirror_dir = NULL;
|
||||
|
||||
mirror_dir = git_get_mirror_dir (repo_location, context);
|
||||
return git_get_current_commit (mirror_dir, branch, context, error);
|
||||
return git_get_current_commit (mirror_dir, branch, ensure_commit, context, error);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -326,7 +334,7 @@ builder_git_mirror_repo (const char *repo_location,
|
|||
|
||||
if (mirror_submodules)
|
||||
{
|
||||
current_commit = git_get_current_commit (mirror_dir, ref, context, error);
|
||||
current_commit = git_get_current_commit (mirror_dir, ref, FALSE, context, error);
|
||||
if (current_commit == NULL)
|
||||
return FALSE;
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ gboolean builder_git_mirror_repo (const char *repo_location,
|
|||
GError **error);
|
||||
char * builder_git_get_current_commit (const char *repo_location,
|
||||
const char *branch,
|
||||
gboolean ensure_commit,
|
||||
BuilderContext *context,
|
||||
GError **error);
|
||||
gboolean builder_git_checkout (const char *repo_location,
|
||||
|
|
|
@ -215,11 +215,13 @@ builder_source_git_download (BuilderSource *source,
|
|||
|
||||
if (self->commit != NULL && self->branch != NULL)
|
||||
{
|
||||
g_autofree char *current_commit = builder_git_get_current_commit (location,get_branch (self), context, error);
|
||||
if (current_commit == NULL)
|
||||
/* We want to support the commit being both a tag object and the real commit object that it points too */
|
||||
g_autofree char *current_commit = builder_git_get_current_commit (location,get_branch (self), FALSE, context, error);
|
||||
g_autofree char *current_commit2 = builder_git_get_current_commit (location,get_branch (self), TRUE, context, error);
|
||||
if (current_commit == NULL || current_commit2 == NULL)
|
||||
return FALSE;
|
||||
if (strcmp (current_commit, self->commit) != 0)
|
||||
return flatpak_fail (error, "Git commit for branch %s is %s, but expected %s\n", self->branch, current_commit, self->commit);
|
||||
if (strcmp (current_commit, self->commit) != 0 && strcmp (current_commit2, self->commit) != 0)
|
||||
return flatpak_fail (error, "Git commit for branch %s is %s, but expected %s\n", self->branch, current_commit2, self->commit);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
@ -299,7 +301,7 @@ builder_source_git_checksum (BuilderSource *source,
|
|||
location = get_url_or_path (self, context, &error);
|
||||
if (location != NULL)
|
||||
{
|
||||
current_commit = builder_git_get_current_commit (location,get_branch (self), context, &error);
|
||||
current_commit = builder_git_get_current_commit (location,get_branch (self), FALSE, context, &error);
|
||||
if (current_commit)
|
||||
builder_cache_checksum_str (cache, current_commit);
|
||||
else if (error)
|
||||
|
@ -324,7 +326,7 @@ builder_source_git_update (BuilderSource *source,
|
|||
if (location == NULL)
|
||||
return FALSE;
|
||||
|
||||
current_commit = builder_git_get_current_commit (location, get_branch (self), context, NULL);
|
||||
current_commit = builder_git_get_current_commit (location, get_branch (self), FALSE, context, NULL);
|
||||
if (current_commit)
|
||||
{
|
||||
g_free (self->branch);
|
||||
|
|
Loading…
Reference in New Issue