|
#!/bin/bash |
|
## |
|
## (C) Copyright 2014-2015 Nuxeo SA (http://nuxeo.com/) and contributors. |
|
## |
|
## All rights reserved. This program and the accompanying materials |
|
## are made available under the terms of the GNU Lesser General Public License |
|
## (LGPL) version 2.1 which accompanies this distribution, and is available at |
|
## http://www.gnu.org/licenses/lgpl-2.1.html |
|
## |
|
## This library is distributed in the hope that it will be useful, |
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
## Lesser General Public License for more details. |
|
## |
|
## Contributors: |
|
## Julien Carsique |
|
## Thomas Roger |
|
## |
|
## Prepare a Git repository for merge with https://github.com/robinst/git-merge-repos |
|
## Applies a workaround for https://github.com/robinst/git-merge-repos/issues/3 by moving the content into a subdir before |
|
## the call to git-merge-repos/run.sh |
|
## Usage: ./prepare_repo.sh <subdir> <JIRA ref> |
|
|
|
set -e |
|
rm -f /tmp/ref-* |
|
|
|
fmt=' |
|
#set -x |
|
ref=%(refname) |
|
unique=`git rev-parse $ref` |
|
ref=${ref#refs/remotes/origin/} |
|
if [[ $ref != HEAD ]]; then |
|
echo "Working on ref=$ref ($unique)" |
|
git checkout -q $ref |
|
if [ -f /tmp/ref-$unique ]; then |
|
echo "Align on $(cat /tmp/ref-$unique)" |
|
git reset --hard $(cat /tmp/ref-$unique) |
|
else |
|
git clean -fdq |
|
mkdir MERGETMP |
|
mkdir -p $(dirname $SUB_DIR) |
|
git mv $(git ls-tree --name-only HEAD) MERGETMP/ |
|
git mv MERGETMP $SUB_DIR |
|
# repeat as workaround for "error building trees" due to some filesystem latency |
|
git commit -q -m"$JIRA: prepare repositories merge" -a || git commit -q -m"$JIRA: prepare repositories merge" -a |
|
git rev-parse HEAD>/tmp/ref-$unique |
|
fi |
|
fi |
|
' |
|
eval=`git for-each-ref --shell --format="$fmt" refs/remotes` |
|
SUB_DIR=$1 JIRA=$2 eval "$eval" |
|
|
|
#set +x |
|
|
|
fmt=' |
|
#set -x |
|
ref=%(refname) |
|
unique=`git rev-parse $ref` |
|
ref=${ref#refs/tags/} |
|
if [[ $ref != HEAD ]]; then |
|
echo "Working on ref=$ref ($unique)" |
|
git checkout -q $ref |
|
if [ -f /tmp/ref-$unique ]; then |
|
echo "Align on $(cat /tmp/ref-$unique)" |
|
git tag -f $ref $(cat /tmp/ref-$unique) |
|
else |
|
git clean -fdq |
|
mkdir MERGETMP |
|
mkdir -p $(dirname $SUB_DIR) |
|
git mv $(git ls-tree --name-only HEAD) MERGETMP |
|
git mv MERGETMP $SUB_DIR |
|
# repeat as workaround for "error building trees" due to some filesystem latency |
|
git commit -q -m"$JIRA: prepare repositories merge" -a || git commit -q -m"$JIRA: prepare repositories merge" -a |
|
git tag -f $ref |
|
git rev-parse HEAD>/tmp/ref-$unique |
|
fi |
|
fi |
|
' |
|
eval=`git for-each-ref --shell --format="$fmt" refs/tags` |
|
SUB_DIR=$1 JIRA=$2 eval "$eval" |
WARNING: