aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorAndrew Robbins <contact@andrewrobbins.info>2019-03-18 16:34:52 -0400
committerAndrew Robbins <contact@andrewrobbins.info>2019-03-18 22:18:26 -0400
commit88a7101827ebd8ce2adb0d3d451254614d80904f (patch)
tree80af8f34eef48e6ac6716a9240eb259a38c70e6d /libs
parent3f3d1c0437fd3dfe1cb11fc622d317daa004ea2a (diff)
downloadlibrebootfr-88a7101827ebd8ce2adb0d3d451254614d80904f.tar.gz
librebootfr-88a7101827ebd8ce2adb0d3d451254614d80904f.zip
libs/git: Add git_apply() and git_apply_check()
Since changes from an applied diff need to be added to the index and committed (vs. mailbox files with the git_patch function) new functions were necessary to account for this difference. This also fixes a bug where diffs were applied but not committed, at minimum dirtying the work tree and potentially causing problems for any later patches.
Diffstat (limited to 'libs')
-rwxr-xr-xlibs/git34
1 files changed, 33 insertions, 1 deletions
diff --git a/libs/git b/libs/git
index 998ceae7..358d5d1f 100755
--- a/libs/git
+++ b/libs/git
@@ -169,6 +169,37 @@ git_commit() {
)
}
+git_apply() {
+ local repository_path=$1
+ local branch=$2
+ local patch=$3
+
+ (
+ export GIT_COMMITTER_NAME=$GIT_NAME
+ export GIT_COMMITTER_EMAIL=$GIT_EMAIL
+
+ 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_check() {
+ local repository_path=$1
+ local branch=$2
+ local patch=$3
+
+ (
+ cd "$repository_path"
+ git checkout "$branch" >/dev/null 2>&1
+
+ git apply --check "$patch"
+ )
+}
+
git_patch() {
local repository_path=$1
local branch=$2
@@ -249,7 +280,8 @@ git_project_patch_recursive() {
if [[ ${patch##*.} == patch ]]; then
git_patch "$repository_path" "$branch" "$patch"
else
- diff_patch "$repository_path" "$patch"
+ git_apply "$repository_path" "$branch" "$patch"
+ git_commit "$repository_path" "Applied ${patch##*/}"
fi
done
}