File indexing completed on 2024-03-24 05:44:49

0001 #!/bin/sh
0002 
0003 # Merges the tree and history of another git repository into the current one.
0004 # Based on code Linux Torvalds wrote in an email.
0005 #
0006 # This must be run from the root of the target repository, and takes
0007 # a single argument: a path to the source repository.
0008 #
0009 # You must make sure the trees are distinct first. Typically, you
0010 # move things around in the source repository to be how you want them
0011 # to appear in the target repository.
0012 
0013 if [ ! -d .git ]; then
0014   echo "This script must be run from the root of a git repository" >&2
0015   exit 1
0016 fi
0017 
0018 if [ -z "$1" ]; then
0019   echo "Usage: $0 <source-repo>" >&2
0020   exit 1
0021 fi
0022 
0023 git fetch $1
0024 if [ $? != 0 ]; then
0025   echo "Could not fetch $1; make sure it is a git repository" >&2
0026   exit 1
0027 fi
0028 GIT_INDEX_FILE=.git/tmp-index git read-tree FETCH_HEAD || exit 1
0029 GIT_INDEX_FILE=.git/tmp-index git checkout-index -a -u
0030 if [ $? != 0 ]; then
0031   echo "Could not checkout fetched tree; make sure it is disjoint from this repository's tree" >&2
0032   exit 1
0033 fi
0034 git update-index --add -- $(GIT_INDEX_FILE=.git/tmp-index git ls-files) || exit 1
0035 cp .git/FETCH_HEAD .git/MERGE_HEAD || exit 1
0036 sed -i -e 's/^\([a-z0-9]*\)\s.*/\1/' .git/MERGE_HEAD
0037 git commit || exit 1