-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-fake-git-patch-gz
More file actions
executable file
·83 lines (62 loc) · 2.71 KB
/
git-fake-git-patch-gz
File metadata and controls
executable file
·83 lines (62 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
#Copyright 2025 Johannes Zink <opensource@johannes-zink.de>
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
set -euo pipefail
function printUsage {
echo "git fake-git-patch-gz - in-place prepend git header to a gz compressed patch"
echo ""
echo "This is particularly useful for using yocto devtool on a non-git patch,"
echo "e.g. the default rt-Kernel patch, since devtool requires patches to have the git patch format"
echo ""
echo "Usage:"
echo ""
echo "git fake-patch-gz <patch.gz>"
echo ""
}
# --- Configuration ---
header_text="From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Dummy Author <dummy@example.com>
Date: Mon, 1 Jan 2025 00:00:00 +0000
Subject: [PATCH] Dummy commit message
A dummy commit message faking a git-format-patch formatted patch from a raw patch file
---
"
if [ "$#" -lt 1 ]; then
printUsage
exit 1
fi
if [ "$1" == "-h" ]; then
printUsage
exit 0
fi
if [ -z "$1" ]; then
printUsage
exit 1
fi
input_file="$1"
if [[ ! "$input_file" =~ \.gz$ ]]; then
echo "Error: Input file must end with '.gz'"
exit 1
fi
#create temporary working dir
temp_file=$(mktemp)
temp_uncompressed=$(mktemp)
trap cleanup EXIT # Ensure cleanup even if script exits early
cleanup() {
rm -f "$temp_file" "$temp_uncompressed"
}
#Decompress the gzip file to a temporary uncompressed file
gzip -cd "$input_file" > "$temp_uncompressed"
#Prepend the header text to the uncompressed file and write to another temporary file
{
echo -e "$header_text"
cat "$temp_uncompressed"
} > "$temp_file"
# 3. Compress the modified content and overwrite the original file
gzip < "$temp_file" > "$input_file"
echo "Successfully prepended header to '$input_file'"
# Cleanup is handled by the trap command on EXIT