-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_and_apply_patch.sh
More file actions
65 lines (52 loc) · 1.67 KB
/
generate_and_apply_patch.sh
File metadata and controls
65 lines (52 loc) · 1.67 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
#!/bin/bash
# --- Configuration --
#TODO: This has to be moved to the MQSS github
FORK_URL="git@gitlab-ce.lrz.de:lrz-qct-qis/cuda-quantum.git"
UPSTREAM_URL="https://github.com/NVIDIA/cuda-quantum.git"
UPSTREAM_COMMIT="1d62d8d"
FORK_BRANCH="MQSS-v1"
BASE_BRANCH="main" # or master, depending on upstream
FOLDER_PATH="runtime"
PATCH_FILE="feature_patch.diff"
SUBMODULE_PATH="./extern/cuda-quantum"
# --- Temporary clone directory ---
TEMP_DIR=$(mktemp -d)
echo "Cloning fork..."
git clone "$FORK_URL" "$TEMP_DIR"
cd "$TEMP_DIR" || exit 1
echo "Checking out fork branch '$FORK_BRANCH'..."
git checkout "$FORK_BRANCH"
echo "Adding upstream..."
git remote add upstream "$UPSTREAM_URL"
git fetch upstream
if [ -n "$UPSTREAM_COMMIT" ]; then
echo "Checking out specific upstream commit '$UPSTREAM_COMMIT'..."
git checkout -b upstream-commit "$UPSTREAM_COMMIT"
BASE_REF="upstream-commit"
else
BASE_REF="upstream/$BASE_BRANCH"
fi
echo "Generating patch for folder '$FOLDER_PATH'..."
#git diff "upstream/$BASE_BRANCH".."$FORK_BRANCH" -- "$FOLDER_PATH" > "$PATCH_FILE"
git diff "$BASE_REF".."$FORK_BRANCH" -- "$FOLDER_PATH" > "$PATCH_FILE"
echo "Patch saved to: $TEMP_DIR/$PATCH_FILE"
# --- Apply patch to submodule ---
cd - > /dev/null || exit 1
if [ ! -d "$SUBMODULE_PATH" ]; then
echo "Error: Submodule path '$SUBMODULE_PATH' does not exist."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Applying patch to submodule at '$SUBMODULE_PATH'..."
cd "$SUBMODULE_PATH" || exit 1
git apply "$TEMP_DIR/$PATCH_FILE"
if [ $? -ne 0 ]; then
echo "Error: Failed to apply patch."
rm -rf "$TEMP_DIR"
exit 1
fi
echo "Patch successfully applied to $SUBMODULE_PATH."
# Clean up
cd ..
rm -rf "$TEMP_DIR"
echo "Done."