akaros/scripts/git/adt
<<
>>
Prefs
   1#!/bin/bash
   2# Gan Shun Lim (ganshun@gmail.com)
   3# Copyright 2016 Google Inc
   4
   5# Use local branch name as the default topic unless overridden
   6GERRIT_TOPIC=`git symbolic-ref -q --short HEAD`
   7
   8GERRIT_REMOTE=gerrit
   9GERRIT_PUSH_COMMAND="git push $GERRIT_REMOTE HEAD:refs/for/master"
  10GERRIT_REVIEWERS_LINE="%"
  11
  12REVIEWERS=""
  13CC=""
  14
  15
  16if [ $# -ne 1 ] && [ $# -ne 3 ] && [ $# -ne 5 ] && [ $# -ne 7 ]
  17then
  18        echo "Usage: adt mail [-m reviewer1,reviewer2...] [-cc cc1,cc2...] [-t topic]"
  19        echo "Other functionalities are not yet supported"
  20        exit -1
  21fi
  22
  23if [ $1 != "mail" ]
  24then
  25        echo "Only mail functionality is supported right now. Please do adt mail."
  26        exit -1
  27fi
  28
  29OLDIFS=$IFS
  30I=2
  31while [ $I -lt $# ]
  32do
  33        if [ ${!I} = "-t" ]
  34        then
  35                # Doesn't support multiple topics. not sure what gerrit will do.
  36                (( I++ ))
  37                GERRIT_TOPIC=${!I}
  38                (( I++ ))
  39        elif [ ${!I} = "-m" ]
  40        then
  41                (( I++ ))
  42                IFS=$IFS","
  43                for R in ${!I}
  44                do
  45                        IFS=$OLDIFS
  46                        if [ $GERRIT_REVIEWERS_LINE = "%" ]
  47                        then
  48                                GERRIT_REVIEWERS_LINE="${GERRIT_REVIEWERS_LINE}r=$R"
  49                        else
  50                                GERRIT_REVIEWERS_LINE="${GERRIT_REVIEWERS_LINE},r=$R"
  51                        fi
  52                done
  53                (( I++ ))
  54        elif [ ${!I} = "-cc" ]
  55        then
  56                (( I++ ))
  57                IFS=$IFS","
  58                for R in ${!I}
  59                do
  60                        IFS=$OLDIFS
  61                        if [ $GERRIT_REVIEWERS_LINE = "%" ]
  62                        then
  63                                GERRIT_REVIEWERS_LINE="${GERRIT_REVIEWERS_LINE}cc=$R"
  64                        else
  65                                GERRIT_REVIEWERS_LINE="${GERRIT_REVIEWERS_LINE},cc=$R"
  66                        fi
  67                done
  68                (( I++ ))
  69        else
  70                echo "Unsupported flag ${!I}."
  71                echo "Usage: adt mail [-m reviewer1,reviewer2...] [-cc cc1,cc2...] [-t topic]"
  72                exit -1
  73        fi
  74done
  75
  76if [ "$GERRIT_TOPIC" != "" ]
  77then
  78        # Append topic
  79        GERRIT_PUSH_COMMAND="$GERRIT_PUSH_COMMAND/$GERRIT_TOPIC"
  80fi
  81
  82if [ $GERRIT_REVIEWERS_LINE != "%" ]
  83then
  84        eval "$GERRIT_PUSH_COMMAND$GERRIT_REVIEWERS_LINE"
  85else
  86        eval $GERRIT_PUSH_COMMAND
  87fi
  88
  89if [ "$?" -ne 0 ]
  90then
  91        echo "Error occurred during git push. Please make sure that your remote for gerrit exists, and that GERRIT_REMOTE in this script is pointing to the correct remote."
  92        exit -1
  93fi
  94