You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2022/01/11 21:00:11 UTC

[GitHub] [solr] janhoy opened a new pull request #514: New dev-tools/scripts/cherrypick.sh

janhoy opened a new pull request #514:
URL: https://github.com/apache/solr/pull/514


   Script that may assist in boring backporting trivial features - especially where you don't expect any merge conflicts. See usage in script.
   
   Tested just a few times, but I hope it will be useful when having to backport many small fixes twice between branches that are almost identical. Take it for a spin..


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782574683



##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'

Review comment:
       Fixed

##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+     -p          Push to remote. Only done if both cherry-pick and tests succeeded
+     WARNING: Never push changes to a remote branch before a thorough local test
+    
+    Simple script for aiding in back-porting one more (trivial) commits to other branches.

Review comment:
       Fixed




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782574879



##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+     -p          Push to remote. Only done if both cherry-pick and tests succeeded
+     WARNING: Never push changes to a remote branch before a thorough local test
+    
+    Simple script for aiding in back-porting one more (trivial) commits to other branches.
+    On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+    for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+    
+    Example:
+      # Backport two commits to both stable and release branch
+      dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111

Review comment:
       It turned out to be not too hard, test it out




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy merged pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy merged pull request #514:
URL: https://github.com/apache/solr/pull/514


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782571957



##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license

Review comment:
       MIT license is more liberal than ours. We might want to add the (c) notice to our main LICENSE.txt perhaps.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782574005



##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license
+# Copyright (c) 2017 Shibin Das - @d34dman
+
+function LOG() {
+  local STATUS=$1
+  local MESSAGE=$2
+  echo "[$(date)] ${STATUS} ${MESSAGE}"
+}
+
+function usage() {
+  cat << EOF
+Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+ -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+ -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+ -t          Run the full test suite during check, not only precommit
+ -n          Skips git pull of target branch. Useful if you are without internet access
+ -a          Enters automated mode. Aborts cherry-pick and exits on error
+ -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+ -p          Push to remote. Only done if both cherry-pick and tests succeeded
+    WARNING: Never push changes to a remote branch before a thorough local test
+
+Simple script for aiding in back-porting one more (trivial) commits to other branches.
+On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+
+Example:
+  # Backport two commits to both stable and release branch
+  dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111
+  dev-tools/scripts/cherrypick.sh -b branch_9_0 deadbeef0000 cafebabe1111
+EOF
+}
+
+function yesno() {
+  question=$1
+  unset answer
+  echo "$question"
+  while [[ "$answer" != "y" ]] && [[ "$answer" != "n" ]]; do
+    read -r answer
+    if [[ "$answer" == "y" ]]; then
+      true
+    else
+      false
+    fi
+  done
+}
+
+GIT_COMMAND=git
+PRECOMMIT="true"
+TESTARG="-x test"
+TEST=
+TESTS_PASSED=
+PUSH=
+REMOTE=origin
+NOPULL=
+AUTO_MODE=
+
+while getopts ":b:phstnar:" opt; do
+  case ${opt} in
+    b)
+      BRANCH=$OPTARG
+      ;;
+    r)
+      REMOTE=$OPTARG
+      ;;
+    p)
+      PUSH=true
+      ;;
+    s)
+      PRECOMMIT=
+      ;;
+    a)
+      AUTO_MODE="true"
+      ;;
+    n)
+      NOPULL="true"
+      ;;
+    t)
+      TEST="true"
+      TESTARG=""
+      ;;
+    h)
+      usage
+      exit 0
+      ;;
+   \?)
+      echo "Unknown option $OPTARG"
+      usage
+      exit 1
+   esac
+done
+shift $((OPTIND -1))
+
+COMMITS=( "$@" )
+
+if [ -z "$BRANCH" ]; then
+  LOG INFO "Lacking -b option, must specify target branch"
+  usage
+  exit
+fi
+
+if [ ${#COMMITS[@]} -eq 0 ]; then
+  LOG ERROR "Please specify one or more commits"
+  usage
+  exit
+fi
+
+LOG INFO "Checking out target branch $BRANCH"
+$GIT_COMMAND checkout "$BRANCH"
+if [[ ! "$NOPULL" ]]; then
+  $GIT_COMMAND pull --ff-only
+else
+  LOG INFO "Skipping git pull"
+fi
+
+## main processing loop
+for i in "${COMMITS[@]}"
+  do
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+    LOG "INFO" "Processing commit          : $i"
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+
+    $GIT_COMMAND cherry-pick "$i" -x
+    if [ $? -eq 0 ]; then
+      LOG "INFO" "Cherry pick of $i completed successfully."
+      continue;
+    fi
+    LOG "ERROR" "Cherry pick encountered an error."
+    if [[ "$AUTO_MODE" ]]; then
+      LOG ERROR "Aborting cherry-pick and exiting. Please handle this manually"
+      $GIT_COMMAND cherry-pick --abort
+      exit 2
+    fi
+    if yesno "Do you want me to open mergetool? (y/n) "; then
+      $GIT_COMMAND mergetool
+    fi
+    if yesno "Have you resolved the merge conflict? (y/n) "; then
+      LOG INFO "Continuing..."
+    else
+      if yesno "Clean up by aborting the cherry-pick? (y/n) "; then
+        $GIT_COMMAND cherry-pick --abort
+      fi
+      LOG INFO "Bye"
+      exit 1
+    fi
+  done
+
+LOG INFO "All cherry-pick succeeded"
+
+if [[ "$PRECOMMIT" ]] || [[ "$TEST" ]]; then
+  LOG "INFO" "Testing the cherry-pick by running 'gradlew check ${TESTARG}'"
+  ./gradlew check -q "${TESTARG}"
+  if [ $? -gt 0 ]; then
+    LOG "WARN" "Tests failed. Please fix and push manually"
+    exit 2
+  fi
+  TESTS_PASSED="true"
+  LOG "INFO" "Tests passed"
+else
+  LOG "INFO" "Skipping tests"
+fi
+
+if [[ "$PUSH" ]]; then
+  if [[ ! $TESTS_PASSED ]]; then
+    LOG "WARN" "Cannot auto push if tests are disabled" 
+    exit 1
+  fi
+  LOG "INFO" "Pushing changes to $REMOTE/$BRANCH"
+  $GIT_COMMAND push "$REMOTE"

Review comment:
       Yep




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] madrob commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
madrob commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782536056



##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+     -p          Push to remote. Only done if both cherry-pick and tests succeeded
+     WARNING: Never push changes to a remote branch before a thorough local test
+    
+    Simple script for aiding in back-porting one more (trivial) commits to other branches.

Review comment:
       "one or more"

##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'

Review comment:
       I think you're missing a word here in the description, not entirely sure what you meant to say.

##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license
+# Copyright (c) 2017 Shibin Das - @d34dman
+
+function LOG() {
+  local STATUS=$1
+  local MESSAGE=$2
+  echo "[$(date)] ${STATUS} ${MESSAGE}"
+}
+
+function usage() {
+  cat << EOF
+Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+ -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+ -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+ -t          Run the full test suite during check, not only precommit
+ -n          Skips git pull of target branch. Useful if you are without internet access
+ -a          Enters automated mode. Aborts cherry-pick and exits on error
+ -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+ -p          Push to remote. Only done if both cherry-pick and tests succeeded
+    WARNING: Never push changes to a remote branch before a thorough local test
+
+Simple script for aiding in back-porting one more (trivial) commits to other branches.
+On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+
+Example:
+  # Backport two commits to both stable and release branch
+  dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111
+  dev-tools/scripts/cherrypick.sh -b branch_9_0 deadbeef0000 cafebabe1111
+EOF
+}
+
+function yesno() {
+  question=$1
+  unset answer
+  echo "$question"
+  while [[ "$answer" != "y" ]] && [[ "$answer" != "n" ]]; do
+    read -r answer
+    if [[ "$answer" == "y" ]]; then
+      true
+    else
+      false
+    fi
+  done
+}
+
+GIT_COMMAND=git
+PRECOMMIT="true"
+TESTARG="-x test"
+TEST=
+TESTS_PASSED=
+PUSH=
+REMOTE=origin
+NOPULL=
+AUTO_MODE=
+
+while getopts ":b:phstnar:" opt; do
+  case ${opt} in
+    b)
+      BRANCH=$OPTARG
+      ;;
+    r)
+      REMOTE=$OPTARG
+      ;;
+    p)
+      PUSH=true
+      ;;
+    s)
+      PRECOMMIT=
+      ;;
+    a)
+      AUTO_MODE="true"
+      ;;
+    n)
+      NOPULL="true"
+      ;;
+    t)
+      TEST="true"
+      TESTARG=""
+      ;;
+    h)
+      usage
+      exit 0
+      ;;
+   \?)
+      echo "Unknown option $OPTARG"
+      usage
+      exit 1
+   esac
+done
+shift $((OPTIND -1))
+
+COMMITS=( "$@" )
+
+if [ -z "$BRANCH" ]; then
+  LOG INFO "Lacking -b option, must specify target branch"
+  usage
+  exit
+fi
+
+if [ ${#COMMITS[@]} -eq 0 ]; then
+  LOG ERROR "Please specify one or more commits"
+  usage
+  exit
+fi
+
+LOG INFO "Checking out target branch $BRANCH"
+$GIT_COMMAND checkout "$BRANCH"
+if [[ ! "$NOPULL" ]]; then
+  $GIT_COMMAND pull --ff-only
+else
+  LOG INFO "Skipping git pull"
+fi
+
+## main processing loop
+for i in "${COMMITS[@]}"
+  do
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+    LOG "INFO" "Processing commit          : $i"
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+
+    $GIT_COMMAND cherry-pick "$i" -x
+    if [ $? -eq 0 ]; then
+      LOG "INFO" "Cherry pick of $i completed successfully."
+      continue;
+    fi
+    LOG "ERROR" "Cherry pick encountered an error."
+    if [[ "$AUTO_MODE" ]]; then
+      LOG ERROR "Aborting cherry-pick and exiting. Please handle this manually"
+      $GIT_COMMAND cherry-pick --abort
+      exit 2
+    fi
+    if yesno "Do you want me to open mergetool? (y/n) "; then
+      $GIT_COMMAND mergetool
+    fi
+    if yesno "Have you resolved the merge conflict? (y/n) "; then

Review comment:
       I think this can read the exit status of merge tool to know if it was resolved or not?

##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+     -p          Push to remote. Only done if both cherry-pick and tests succeeded
+     WARNING: Never push changes to a remote branch before a thorough local test
+    
+    Simple script for aiding in back-porting one more (trivial) commits to other branches.
+    On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+    for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+    
+    Example:
+      # Backport two commits to both stable and release branch
+      dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111

Review comment:
       can we allow specifying multiple `-b` options?

##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license
+# Copyright (c) 2017 Shibin Das - @d34dman
+
+function LOG() {
+  local STATUS=$1
+  local MESSAGE=$2
+  echo "[$(date)] ${STATUS} ${MESSAGE}"
+}
+
+function usage() {
+  cat << EOF
+Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+ -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+ -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+ -t          Run the full test suite during check, not only precommit
+ -n          Skips git pull of target branch. Useful if you are without internet access
+ -a          Enters automated mode. Aborts cherry-pick and exits on error
+ -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+ -p          Push to remote. Only done if both cherry-pick and tests succeeded
+    WARNING: Never push changes to a remote branch before a thorough local test
+
+Simple script for aiding in back-porting one more (trivial) commits to other branches.
+On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+
+Example:
+  # Backport two commits to both stable and release branch
+  dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111
+  dev-tools/scripts/cherrypick.sh -b branch_9_0 deadbeef0000 cafebabe1111
+EOF
+}
+
+function yesno() {
+  question=$1
+  unset answer
+  echo "$question"
+  while [[ "$answer" != "y" ]] && [[ "$answer" != "n" ]]; do
+    read -r answer
+    if [[ "$answer" == "y" ]]; then
+      true
+    else
+      false
+    fi
+  done
+}
+
+GIT_COMMAND=git
+PRECOMMIT="true"
+TESTARG="-x test"
+TEST=
+TESTS_PASSED=
+PUSH=
+REMOTE=origin
+NOPULL=
+AUTO_MODE=
+
+while getopts ":b:phstnar:" opt; do
+  case ${opt} in
+    b)
+      BRANCH=$OPTARG
+      ;;
+    r)
+      REMOTE=$OPTARG
+      ;;
+    p)
+      PUSH=true
+      ;;
+    s)
+      PRECOMMIT=
+      ;;
+    a)
+      AUTO_MODE="true"
+      ;;
+    n)
+      NOPULL="true"
+      ;;
+    t)
+      TEST="true"
+      TESTARG=""
+      ;;
+    h)
+      usage
+      exit 0
+      ;;
+   \?)
+      echo "Unknown option $OPTARG"
+      usage
+      exit 1
+   esac
+done
+shift $((OPTIND -1))
+
+COMMITS=( "$@" )
+
+if [ -z "$BRANCH" ]; then
+  LOG INFO "Lacking -b option, must specify target branch"
+  usage
+  exit
+fi
+
+if [ ${#COMMITS[@]} -eq 0 ]; then
+  LOG ERROR "Please specify one or more commits"
+  usage
+  exit
+fi
+
+LOG INFO "Checking out target branch $BRANCH"
+$GIT_COMMAND checkout "$BRANCH"
+if [[ ! "$NOPULL" ]]; then
+  $GIT_COMMAND pull --ff-only
+else
+  LOG INFO "Skipping git pull"
+fi
+
+## main processing loop
+for i in "${COMMITS[@]}"
+  do
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+    LOG "INFO" "Processing commit          : $i"
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+
+    $GIT_COMMAND cherry-pick "$i" -x
+    if [ $? -eq 0 ]; then
+      LOG "INFO" "Cherry pick of $i completed successfully."
+      continue;
+    fi
+    LOG "ERROR" "Cherry pick encountered an error."
+    if [[ "$AUTO_MODE" ]]; then
+      LOG ERROR "Aborting cherry-pick and exiting. Please handle this manually"
+      $GIT_COMMAND cherry-pick --abort
+      exit 2
+    fi
+    if yesno "Do you want me to open mergetool? (y/n) "; then
+      $GIT_COMMAND mergetool
+    fi
+    if yesno "Have you resolved the merge conflict? (y/n) "; then
+      LOG INFO "Continuing..."
+    else
+      if yesno "Clean up by aborting the cherry-pick? (y/n) "; then
+        $GIT_COMMAND cherry-pick --abort
+      fi
+      LOG INFO "Bye"
+      exit 1
+    fi
+  done
+
+LOG INFO "All cherry-pick succeeded"
+
+if [[ "$PRECOMMIT" ]] || [[ "$TEST" ]]; then
+  LOG "INFO" "Testing the cherry-pick by running 'gradlew check ${TESTARG}'"
+  ./gradlew check -q "${TESTARG}"
+  if [ $? -gt 0 ]; then
+    LOG "WARN" "Tests failed. Please fix and push manually"
+    exit 2
+  fi
+  TESTS_PASSED="true"
+  LOG "INFO" "Tests passed"
+else
+  LOG "INFO" "Skipping tests"
+fi
+
+if [[ "$PUSH" ]]; then
+  if [[ ! $TESTS_PASSED ]]; then
+    LOG "WARN" "Cannot auto push if tests are disabled" 
+    exit 1
+  fi
+  LOG "INFO" "Pushing changes to $REMOTE/$BRANCH"
+  $GIT_COMMAND push "$REMOTE"

Review comment:
       this should include the branch?

##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license

Review comment:
       I don't know the legal implications of this... I think it's fine but will try to find precedent from legal.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782571651



##########
File path: dev-tools/scripts/cherrypick.sh
##########
@@ -0,0 +1,191 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Forked and adapted from https://github.com/factorial-io/cherrypicker - MIT license
+# Copyright (c) 2017 Shibin Das - @d34dman
+
+function LOG() {
+  local STATUS=$1
+  local MESSAGE=$2
+  echo "[$(date)] ${STATUS} ${MESSAGE}"
+}
+
+function usage() {
+  cat << EOF
+Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+ -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+ -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+ -t          Run the full test suite during check, not only precommit
+ -n          Skips git pull of target branch. Useful if you are without internet access
+ -a          Enters automated mode. Aborts cherry-pick and exits on error
+ -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+ -p          Push to remote. Only done if both cherry-pick and tests succeeded
+    WARNING: Never push changes to a remote branch before a thorough local test
+
+Simple script for aiding in back-porting one more (trivial) commits to other branches.
+On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+
+Example:
+  # Backport two commits to both stable and release branch
+  dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111
+  dev-tools/scripts/cherrypick.sh -b branch_9_0 deadbeef0000 cafebabe1111
+EOF
+}
+
+function yesno() {
+  question=$1
+  unset answer
+  echo "$question"
+  while [[ "$answer" != "y" ]] && [[ "$answer" != "n" ]]; do
+    read -r answer
+    if [[ "$answer" == "y" ]]; then
+      true
+    else
+      false
+    fi
+  done
+}
+
+GIT_COMMAND=git
+PRECOMMIT="true"
+TESTARG="-x test"
+TEST=
+TESTS_PASSED=
+PUSH=
+REMOTE=origin
+NOPULL=
+AUTO_MODE=
+
+while getopts ":b:phstnar:" opt; do
+  case ${opt} in
+    b)
+      BRANCH=$OPTARG
+      ;;
+    r)
+      REMOTE=$OPTARG
+      ;;
+    p)
+      PUSH=true
+      ;;
+    s)
+      PRECOMMIT=
+      ;;
+    a)
+      AUTO_MODE="true"
+      ;;
+    n)
+      NOPULL="true"
+      ;;
+    t)
+      TEST="true"
+      TESTARG=""
+      ;;
+    h)
+      usage
+      exit 0
+      ;;
+   \?)
+      echo "Unknown option $OPTARG"
+      usage
+      exit 1
+   esac
+done
+shift $((OPTIND -1))
+
+COMMITS=( "$@" )
+
+if [ -z "$BRANCH" ]; then
+  LOG INFO "Lacking -b option, must specify target branch"
+  usage
+  exit
+fi
+
+if [ ${#COMMITS[@]} -eq 0 ]; then
+  LOG ERROR "Please specify one or more commits"
+  usage
+  exit
+fi
+
+LOG INFO "Checking out target branch $BRANCH"
+$GIT_COMMAND checkout "$BRANCH"
+if [[ ! "$NOPULL" ]]; then
+  $GIT_COMMAND pull --ff-only
+else
+  LOG INFO "Skipping git pull"
+fi
+
+## main processing loop
+for i in "${COMMITS[@]}"
+  do
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+    LOG "INFO" "Processing commit          : $i"
+    LOG "INFO" "::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
+
+    $GIT_COMMAND cherry-pick "$i" -x
+    if [ $? -eq 0 ]; then
+      LOG "INFO" "Cherry pick of $i completed successfully."
+      continue;
+    fi
+    LOG "ERROR" "Cherry pick encountered an error."
+    if [[ "$AUTO_MODE" ]]; then
+      LOG ERROR "Aborting cherry-pick and exiting. Please handle this manually"
+      $GIT_COMMAND cherry-pick --abort
+      exit 2
+    fi
+    if yesno "Do you want me to open mergetool? (y/n) "; then
+      $GIT_COMMAND mergetool
+    fi
+    if yesno "Have you resolved the merge conflict? (y/n) "; then

Review comment:
       Yea, perhaps, but an explicit prompt gives an explicit consent.. Can put it as future improvement




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org


[GitHub] [solr] janhoy commented on a change in pull request #514: New dev-tools/scripts/cherrypick.sh

Posted by GitBox <gi...@apache.org>.
janhoy commented on a change in pull request #514:
URL: https://github.com/apache/solr/pull/514#discussion_r782561028



##########
File path: dev-tools/scripts/README.md
##########
@@ -159,3 +159,24 @@ and prints a regular expression that will match all of them
 
 TBD
 
+
+### cherrypick.sh
+
+    Usage: dev-tools/scripts/cherrypick.sh [<options>] <commit-hash> [<commit-hash>...]
+     -b <branch> Sets the branch to cherry-pick to, typically branch_Nx or branch_x_y
+     -s          Skips precommit test. WARNING: Always run precommit for code- and doc changes
+     -t          Run the full test suite during check, not only precommit
+     -n          Skips git pull of target branch. Useful if you are without internet access
+     -a          Enters automated mode. Aborts cherry-pick and exits on error
+     -r <remote> Specify remote to push to. Defaults to if other than 'origin'
+     -p          Push to remote. Only done if both cherry-pick and tests succeeded
+     WARNING: Never push changes to a remote branch before a thorough local test
+    
+    Simple script for aiding in back-porting one more (trivial) commits to other branches.
+    On merge conflict the script will run 'git mergetool'. See 'git mergetool --help'
+    for help on configuring your favourite merge tool. Check out Sublime Merge (smerge).
+    
+    Example:
+      # Backport two commits to both stable and release branch
+      dev-tools/scripts/cherrypick.sh -b branch_9x  deadbeef0000 cafebabe1111

Review comment:
       Thought of it, guess it would be possible




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org