diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-01-29 20:05:10 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-01-29 20:05:10 +0100 |
commit | cfafcaa25575e00106b68c6c3c1bc7392108a593 (patch) | |
tree | addd91607d6db4573e792553003235fbaf877e5b | |
parent | Add script to merge remote patches (diff) | |
download | gitmirror-cfafcaa25575e00106b68c6c3c1bc7392108a593.tar.gz gitmirror-cfafcaa25575e00106b68c6c3c1bc7392108a593.tar.zst gitmirror-cfafcaa25575e00106b68c6c3c1bc7392108a593.zip |
Remove merge script
Jenkins already provides a setting for merging a branch into upstream.
-rwxr-xr-x | gitmirror-merge.sh | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/gitmirror-merge.sh b/gitmirror-merge.sh deleted file mode 100755 index d346602..0000000 --- a/gitmirror-merge.sh +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | set -Eeuo pipefail | ||
3 | |||
4 | MIRROR_REMOTE="gitmirror_remote" | ||
5 | CLONE_URL_PATTERN="file://${PWD}/%s" | ||
6 | |||
7 | msg() { | ||
8 | echo "==> $1" | ||
9 | } | ||
10 | |||
11 | msg2() { | ||
12 | echo "--> $1" | ||
13 | } | ||
14 | |||
15 | deepened_fetch() { | ||
16 | local fetch_spec="$1" | ||
17 | local exclude="$2" | ||
18 | if git fetch "${MIRROR_REMOTE}" "${fetch_spec}" \ | ||
19 | --shallow-exclude="${exclude}"; then | ||
20 | msg2 "Deepen fetch by 1" | ||
21 | git fetch "${MIRROR_REMOTE}" "${fetch_spec}" --deepen=1 | ||
22 | else | ||
23 | msg2 "Shallow request possibly empty, retry with depth=1" | ||
24 | git fetch "${MIRROR_REMOTE}" "${fetch_spec}" --depth=1 | ||
25 | fi | ||
26 | } | ||
27 | |||
28 | merge_patches() { | ||
29 | if (( $# != 3 )); then | ||
30 | echo "Usage: $0 REPOSITORY REMOTE BRANCH" >&2 | ||
31 | exit 1 | ||
32 | fi | ||
33 | |||
34 | local repository="$1" | ||
35 | local remote="$2" | ||
36 | local branch="$3" | ||
37 | |||
38 | if [[ "${remote}" == "${MIRROR_REMOTE}" ]]; then | ||
39 | msg "REMOTE must not be ${MIRROR_REMOTE}" >&2 | ||
40 | exit 1 | ||
41 | fi | ||
42 | |||
43 | local copy_name="${repository}-patch-${remote}-${branch}" | ||
44 | msg "Create working copy ${copy_name}" | ||
45 | rm -rf "${copy_name}" | ||
46 | mkdir "${copy_name}" | ||
47 | pushd "${copy_name}" > /dev/null | ||
48 | git init | ||
49 | local clone_url | ||
50 | # shellcheck disable=2059 | ||
51 | clone_url="$(printf "${CLONE_URL_PATTERN}" "${repository}")" | ||
52 | git remote add "${MIRROR_REMOTE}" "${clone_url}" | ||
53 | |||
54 | local patch_branch="patch-for/${branch}" | ||
55 | msg "Fetch patch at ${patch_branch}" | ||
56 | local upstream_branch="${remote}/${branch}" | ||
57 | local remote_upstream_ref="refs/remotes/${upstream_branch}" | ||
58 | deepened_fetch "${patch_branch}" "${remote_upstream_ref}" | ||
59 | |||
60 | msg "Fetch upstream at ${upstream_branch}" | ||
61 | local local_upstream_ref="refs/remotes/${MIRROR_REMOTE}/${upstream_branch}" | ||
62 | deepened_fetch "${remote_upstream_ref}:${local_upstream_ref}" \ | ||
63 | "refs/heads/${patch_branch}" | ||
64 | |||
65 | msg "Merge ${patch_branch} into ${upstream_branch}" | ||
66 | git checkout -b "${branch}" --no-track "${local_upstream_ref}" | ||
67 | git merge "${MIRROR_REMOTE}/${patch_branch}" --no-ff \ | ||
68 | -m "Merge branch '${patch_branch}' into ${upstream_branch}" | ||
69 | |||
70 | msg "Push ${branch} to ${MIRROR_REMOTE}" | ||
71 | git push --force "${MIRROR_REMOTE}" "${branch}:${branch}" | ||
72 | |||
73 | popd > /dev/null | ||
74 | rm -rf "${copy_name}" | ||
75 | } | ||
76 | |||
77 | if [[ "$0" == "${BASH_SOURCE[0]}" ]]; then | ||
78 | merge_patches "$@" | ||
79 | fi | ||