-
Notifications
You must be signed in to change notification settings - Fork 15
/
git-d8ci
executable file
·69 lines (55 loc) · 2.5 KB
/
git-d8ci
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
#!/bin/bash
# Instructions for set up:
# 1. Put this in a file named git-d8ci in your $PATH
# 2. chmod a+x git-d8ci
# Instructions for use:
# 1. Goto Drupal checkout on a branch you want to commit to.
# 2. Apply the patch you want to commit and review it
# 3. git d8ci OTHER_BRANCHES_TO_COMMIT_TO "commit message"
# 4. Remember to use the push command it prepares for you at the end. Automatic pushes are not done to allow review.
# Example command (whilst on 8.1.x): git d8ci 8.0.x 'Issue #2608072 by ameymudras: "Object of type "@class" cannot be printed." exception message should not be translated'
# Example command (whilst on 8.2.x): git d8ci 8.1.x,8.0.x 'Issue #2608072 by ameymudras: "Object of type "@class" cannot be printed." exception message should not be translated'
# Ensure there is something to commit.
git diff --quiet --exit-code --cached
CHANGES=$?
if [[ "$CHANGES" == "0" ]] ; then
echo "There's nothing to commit" 1>&2 && exit 1
fi
# Ensure we exit as soon as there is an error
set -e
branches=$1
test -z $branches && echo "Other branch to commit to required." 1>&2 && exit 1
branches=$(echo $branches | tr "," "\n")
message=$2
test -z "$message" && echo "Commit message required." 1>&2 && exit 1
if ! [[ "$message" =~ ^Issue ]]; then
echo "Message \"$message\" should start with 'Issue'." 1>&2 && exit 1
fi
for branch in $branches
do
# Check branch exists
if ! git rev-parse --verify $branch >/dev/null 2>&1; then
echo "git branch $branch not found." && exit 1
fi
done
first_branch=`git rev-parse --abbrev-ref HEAD`
# Commit patch to the first branch
git commit -m "$message"
commit_hash=`git log -n 1 --pretty=format:"%H"`
short_commit_hash=`git log -n 1 --pretty=format:"%h"`
push_message="Use the following command to push the changes: git push origin $first_branch"
thanks_message="Committed and pushed <a href=\"https://git.drupalcode.org/project/drupal/commit/$short_commit_hash\">$short_commit_hash</a> to $first_branch"
echo $TEXT | pbcopy
for branch in $branches
do
# Cherry pick to the other branches. The -x option adds an additional line to the commit message linking back to the original commit.
git checkout $branch
git pull --rebase
git cherry-pick -x $commit_hash
branch_hash=`git log -n 1 --pretty=format:"%h"`
thanks_message="$thanks_message and <a href=\"https://git.drupalcode.org/project/drupal/commit/$branch_hash\">$branch_hash</a> to $branch"
push_message="$push_message $branch"
done
git checkout $first_branch
echo "$push_message"
echo "$thanks_message. Thanks!" | pbcopy