blob: 3c13067d5a4ef1521869659a118506cbe950c8b2 [file] [log] [blame]
Fabio Ponciroli380e3912019-09-03 14:11:56 -07001# Copyright (C) 2019 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#!/usr/bin/env bash
15
16set -e
17
18if [[ "$#" -lt "2" ]] ; then
19 cat <<EOF
20Usage: run "$0 /path/to/git/dir [project...]" or "$0 /path/to/git/dir ALL"
21
22This util script can be used in case of rollback to ReviewDB during an unsuccessful
23migration to NoteDB or simply while testing the migration process.
24
25It will remove all the refs used by NoteDB added during the migration (i.e.: change meta refs and sequence ref).
26EOF
27 exit 1
28fi
29
30GERRIT_GIT_DIR=$1
31shift
32
33ALL_PROJECTS=$@
34if [[ "$2" -eq "ALL" ]] ; then
35 ALL_PROJECTS=`find "${GERRIT_GIT_DIR}" -type d -name "*.git"`
36fi
37
38ALL_PROJECTS_ARRAY=(${ALL_PROJECTS// / })
39
40for project in "${ALL_PROJECTS_ARRAY[@]}"
41do
42 if [[ "$project" =~ /All-Users\.git$ ]]; then
43 echo "Skipping $project ..."
44 else
45 echo "Removing meta ref for $project ..."
46 cd "$project"
47 if `git show-ref meta | grep -q "/meta$"`; then
48 git show-ref meta | grep "/meta$" | cut -d' ' -f2 | xargs -L1 git update-ref -d
49 fi
50 fi
51done
52
53echo "Remove sequence ref"
54allProjectDir="$GERRIT_GIT_DIR/All-Projects.git"
55cd $allProjectDir
56git update-ref -d refs/sequences/changes