From 2b351b2fc33cf6e5642fbd1f47984189374fe0e4 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Wed, 27 Mar 2019 22:06:38 -0400 Subject: libs/git: Fail if patching fails The recursive call in git_project_patch_recursive() is now performed last so that if a patching attempt fails, the calling functions won't attempt to apply more patches. The consequence of this change is that patches are applied in (nearly) opposite order from before. git_project_prepare_patch() is now called after git_project_prepare_blobs() so that if patching fails and the user chooses to perform additional project actions anyway, such as building, the project is already deblobbed and not a risk to their freedom. I had mistakenly reordered these function calls in a prior commit. --- libs/git | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libs/git') diff --git a/libs/git b/libs/git index fa4434f7..a83f2246 100755 --- a/libs/git +++ b/libs/git @@ -271,16 +271,16 @@ git_project_patch_recursive() { local patches_path=$project_path/$PATCHES/$path if ! [[ -d $project_path/$PATCHES ]]; then - return + return 0 fi + for patch in "$patches_path"/[!.]*.@(patch|diff); do + git_patch "$repository_path" "$branch" "$patch" || return 1 + done + if [[ $path != . ]]; then git_project_patch_recursive "$project" "$repository" "$branch" "$(dirname "$path")" fi - - for patch in "$patches_path"/[!.]*.@(patch|diff); do - git_patch "$repository_path" "$branch" "$patch" - done } git_project_clone() { @@ -316,8 +316,8 @@ git_project_prepare() { shift git_project_prepare_revision "$project" "$repository" "$@" - git_project_prepare_patch "$project" "$repository" "$@" git_project_prepare_blobs "$project" "$repository" "$@" + git_project_prepare_patch "$project" "$repository" "$@" } git_project_prepare_blobs() { -- cgit v1.2.3-70-g09d2 From e681d7cd9679244fe7f43ce9e66b8cf83f706d8a Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Mon, 25 Mar 2019 01:35:45 -0400 Subject: libs/git: Commit only if any blobs were removed git_diff_check() was added for future use since it's complementary to git_diff_staged_check(). It could be used to check for a dirty worktree, for example. --- libs/git | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'libs/git') diff --git a/libs/git b/libs/git index a83f2246..6fbd2302 100755 --- a/libs/git +++ b/libs/git @@ -141,6 +141,26 @@ git_remove() { ) } +git_diff_staged_check() { + local repository_path=$1 + + ( + cd "$repository_path" + + git diff --staged --quiet + ) +} + +git_diff_check() { + local repository_path=$1 + + ( + cd "$repository_path" + + git diff --quiet + ) +} + git_commit() { local repository_path=$1 local message=$2 @@ -340,7 +360,10 @@ git_project_prepare_blobs() { git_remove "$repository_path" "$blob" done < "$blobs_path" - git_commit "$repository_path" "Removed blobs" + if ! git_diff_staged_check "$repository_path" + then + git_commit "$repository_path" "Removed blobs" + fi } git_project_prepare_patch() { -- cgit v1.2.3-70-g09d2 From ac462c0df361e067698f04111bad078fa7d1e1b8 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Thu, 28 Mar 2019 11:00:28 -0400 Subject: libs/git: Remove check from git_am() and git_apply() Having a specific function for checking whether a patch would apply isn't that useful if git_am and git_apply call it internally anyway. --- libs/git | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'libs/git') diff --git a/libs/git b/libs/git index 6fbd2302..4e62873d 100755 --- a/libs/git +++ b/libs/git @@ -186,8 +186,10 @@ git_am() { cd "$repository_path" git checkout "$branch" >/dev/null 2>&1 - if git_apply_check "$repository_path" "$branch" "$patch"; then - git am "$patch" || git am --abort + if ! git am "$patch"; then + git am --abort + + exit 1 fi ) } @@ -201,9 +203,7 @@ git_apply() { cd "$repository_path" git checkout "$branch" >/dev/null 2>&1 - if git_apply_check "$repository_path" "$branch" "$patch"; then - git apply --index "$patch" - fi + git apply --index "$patch" ) } @@ -225,12 +225,14 @@ git_patch() { local branch=$2 local patch=$3 + git_apply_check "$repository_path" "$branch" "$patch" || return 1 + case $patch in *.patch) git_am "$repository_path" "$branch" "$patch" ;; *.diff) - git_apply "$repository_path" "$branch" "$patch" && + git_apply "$repository_path" "$branch" "$patch" git_commit "$repository_path" "Applied ${patch##*/}" ;; *) -- cgit v1.2.3-70-g09d2 From 89176737ad54ddbdef55e0c207ccd5dba7ade2b4 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Tue, 26 Mar 2019 20:34:35 -0400 Subject: libs/git: Exit subshell upon "cd" failure If cd fails, nothing else should be done. This is to prevent a potentially destructive action from being performed on the Libreboot repository (if the script is executed from the same directory). --- libs/git | 54 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 21 deletions(-) (limited to 'libs/git') diff --git a/libs/git b/libs/git index 4e62873d..b5b2ffdb 100755 --- a/libs/git +++ b/libs/git @@ -41,7 +41,8 @@ git_submodule_update() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git submodule update --init ) } @@ -51,7 +52,8 @@ git_merge() { local revision=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git merge "$revision" ) } @@ -62,7 +64,8 @@ git_branch_create() { local revision=$3 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout -B "$branch" if [[ -n "$revision" ]] @@ -77,7 +80,8 @@ git_branch_delete() { local branch=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git branch -D "$branch" ) } @@ -87,7 +91,8 @@ git_branch_checkout() { local branch=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" > /dev/null ) } @@ -97,7 +102,7 @@ git_branch_check() { local branch=$2 ( - cd "$repository_path" >/dev/null 2>&1 || return 1 + cd "$repository_path" 2>/dev/null || exit 1 git rev-parse --verify "$branch" >/dev/null 2>&1 ) @@ -107,7 +112,8 @@ git_fetch() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git fetch origin ) } @@ -116,7 +122,7 @@ git_fetch_check() { local repository_path=$1 ( - cd "$repository_path" >/dev/null 2>&1 || return 1 + cd "$repository_path" 2>/dev/null || exit 1 git fetch --dry-run origin >/dev/null 2>&1 ) @@ -126,7 +132,8 @@ git_clean() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git clean -df ) } @@ -136,7 +143,8 @@ git_remove() { local path=$2 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git rm -rf "$path" ) } @@ -145,7 +153,7 @@ git_diff_staged_check() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git diff --staged --quiet ) @@ -155,7 +163,7 @@ git_diff_check() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git diff --quiet ) @@ -169,7 +177,8 @@ git_commit() { export GIT_COMMITTER_NAME=$GIT_NAME export GIT_COMMITTER_EMAIL=$GIT_EMAIL - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git commit --author="$GIT_NAME <$GIT_EMAIL>" -m "$message" ) } @@ -183,7 +192,8 @@ git_am() { export GIT_COMMITTER_NAME=$GIT_NAME export GIT_COMMITTER_EMAIL=$GIT_EMAIL - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 if ! git am "$patch"; then @@ -200,9 +210,9 @@ git_apply() { local patch=$3 ( - cd "$repository_path" - git checkout "$branch" >/dev/null 2>&1 + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 git apply --index "$patch" ) } @@ -213,9 +223,9 @@ git_apply_check() { local patch=$3 ( - cd "$repository_path" - git checkout "$branch" >/dev/null 2>&1 + cd "$repository_path" 2>/dev/null || exit 1 + git checkout "$branch" >/dev/null 2>&1 git apply --check "$patch" ) } @@ -244,7 +254,8 @@ git_revision() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git rev-parse "$HEAD" ) } @@ -253,7 +264,8 @@ git_describe() { local repository_path=$1 ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 + git describe --tags ) } @@ -262,7 +274,7 @@ git_files() { local repository_path="$1" ( - cd "$repository_path" + cd "$repository_path" 2>/dev/null || exit 1 git ls-files -z | sort -z ) -- cgit v1.2.3-70-g09d2