add some utility scripts to create new workdir

based on kohei blog on the subject, adapted for the 'bootstrap' build
This commit is contained in:
Norbert Thiebaud 2010-11-20 23:06:14 -06:00 committed by Norbert Thiebaud
parent 22ce993077
commit f61644158e
4 changed files with 243 additions and 0 deletions

82
bin/git-new-workdir Executable file
View file

@ -0,0 +1,82 @@
#!/bin/sh
usage () {
echo "usage:" $@
exit 127
}
die () {
echo $@
exit 128
}
if test $# -lt 2 || test $# -gt 3
then
usage "$0 <repository> <new_workdir> [<branch>]"
fi
orig_git=$1
new_workdir=$2
branch=$3
# want to make sure that what is pointed to has a .git directory ...
git_dir=$(cd "$orig_git" 2>/dev/null &&
git rev-parse --git-dir 2>/dev/null) ||
die "Not a git repository: \"$orig_git\""
case "$git_dir" in
.git)
git_dir="$orig_git/.git"
;;
.)
git_dir=$orig_git
;;
esac
# don't link to a configured bare repository
isbare=$(git --git-dir="$git_dir" config --bool --get core.bare)
if test ztrue = z$isbare
then
die "\"$git_dir\" has core.bare set to true," \
" remove from \"$git_dir/config\" to use $0"
fi
# don't link to a workdir
if test -L "$git_dir/config"
then
die "\"$orig_git\" is a working directory only, please specify" \
"a complete repository."
fi
# don't recreate a workdir over an existing repository
if test -e "$new_workdir"
then
die "destination directory '$new_workdir' already exists."
fi
# make sure the links use full paths
git_dir=$(cd "$git_dir"; pwd)
# create the workdir
mkdir -p "$new_workdir/.git" || die "unable to create \"$new_workdir\"!"
# create the links to the original repo. explicitly exclude index, HEAD and
# logs/HEAD from the list since they are purely related to the current working
# directory, and should not be shared.
for x in config refs logs/refs objects info hooks packed-refs remotes rr-cache svn
do
case $x in
*/*)
mkdir -p "$(dirname "$new_workdir/.git/$x")"
;;
esac
ln -s "$git_dir/$x" "$new_workdir/.git/$x"
done
# now setup the workdir
cd "$new_workdir"
# copy the HEAD from the original repository as a default branch
cp "$git_dir/HEAD" .git/HEAD
# checkout the branch (either the same as HEAD from the original repository, or
# the one that was asked for)
git checkout -f $branch

52
bin/git-ps1 Executable file
View file

@ -0,0 +1,52 @@
#!/usr/bin/env bash
r=
b=
g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
if [ -d "$g/../.dotest" ]
then
if test -f "$g/../.dotest/rebasing"
then
r="|REBASE"
elif test -f "$g/../.dotest/applying"
then
r="|AM"
else
r="|AM/REBASE"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)"
elif [ -f "$g/.dotest-merge/interactive" ]
then
r="|REBASE-i"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -d "$g/.dotest-merge" ]
then
r="|REBASE-m"
b="$(cat "$g/.dotest-merge/head-name")"
elif [ -f "$g/MERGE_HEAD" ]
then
r="|MERGING"
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
if [ -f "$g/BISECT_LOG" ]
then
r="|BISECTING"
fi
if ! b="$(git symbolic-ref HEAD 2>/dev/null)"
then
if ! b="$(git describe --exact-match HEAD 2>/dev/null)"
then
b="$(cut -c1-7 "$g/HEAD")..."
fi
fi
fi
if [ -n "$1" ]; then
printf "$1" "${b##refs/heads/}$r"
else
printf "%s" "${b##refs/heads/}$r"
fi
else
printf "not-in-git"
fi

108
bin/mkworkdir Executable file
View file

@ -0,0 +1,108 @@
#!/usr/bin/env bash
BASEDIR=$(dirname $0)
GIT_NEW_WORKDIR=`which git-new-workdir 2>/dev/null`
if [ -z $GIT_NEW_WORKDIR ] ; then
GIT_NEW_WORKDIR="$BASEDIR/git-new-workdir"
fi
print_help() {
echo "Usage: $1 [-s | --source bootstrap_reference_repo_path] [ -d | --workdir-base-path path] [ --as alias_name] [branch name]"
echo "--source is optional if you are currently in a bootstrap git repository, in which case that repository is used as source"
echo "--workdir-base-path is optional if you have defined LO_BASE_WORKDIR in your environement"
echo "--as is the name of the directory that will be the bootstrap of your new workdir ensemble. the default is the branch name used to create the workdir"
echo "the branch name is optional, the default is 'master'"
}
die() {
echo $1
exit 1
}
BOOTSTRAP_DIR=
DEST_DIR=${LO_BASE_WORKDIR:-}
BRANCH="master"
while [ "${1:-}" != "" ] ; do
case $1 in
-s | --source )
shift
BOOTSTRAP_DIR="$1"
;;
-d | --workdir-base-path )
shift
DEST_DIR="$1"
;;
--as )
shift
WKDIR_NAME="$1"
;;
-h | --help )
print_help $0
exit 0
;;
-* )
die "invalid option $1"
;;
*)
if [ -z "$BRANCH" ] ; then
BRANCH="$1"
else
die "Too many arguments"
fi
;;
esac
shift
done
if [ -z "$BOOTSTRAP_DIR" ]; then
BOOTSTRAP_DIR=$(git rev-parse --git-dir 2>/dev/null) || die "Cannot use the current working directory as implicit source: Not a git repository"
case "$BOOTSTRAP_DIR" in
.git)
BOOTSTRAP_DIR="$(pwd)"
;;
.)
cd .. && BOOTSTRAP_DIR=$(pwd)
;;
esac
fi
if [ -z "$DEST_DIR" ]; then
echo "destination directory is missing."
print_help $0
exit 1
fi
if [ -z "$WKDIR_NAME" ]; then
WKDIR_NAME="$BRANCH"
fi
if [ -e "$DEST_DIR/$WKDIR_NAME" ]; then
die "$DEST_DIR/$WKDIR_NAME already exists."
fi
echo "===== bootstrap ====="
$GIT_NEW_WORKDIR $BOOTSTRAP_DIR "$DEST_DIR/$WKDIR_NAME" $BRANCH
echo "creating directory $DEST_DIR/$WKDIR_NAME/clone"
mkdir -p "$DEST_DIR/$WKDIR_NAME/clone" || die "failed to create $DEST_DIR/$WKDIR_NAME/clone"
REPOS=$(cat ${BASEDIR}/repo-list)
cd "$DEST_DIR/$WKDIR_NAME"
for repo in $REPOS; do
repo_path="${BOOTSTRAP_DIR}/clone/$repo"
echo "===== $repo ====="
$GIT_NEW_WORKDIR $repo_path "$DEST_DIR/$WKDIR_NAME/clone/$repo" $BRANCH
for link in $(ls ./clone/$repo) ; do
if [ ! -e "$link" ] ; then
echo "Creating link $link"
ln -s "./clone/$repo/$link" "$link"
fi
done
done

1
bin/repo-list Normal file
View file

@ -0,0 +1 @@
artwork base calc components extensions extras filters help impress libs-core libs-extern libs-extern-sys libs-gui postprocess sdk testing ure writer