File: git-merge-repo

package info (click to toggle)
kde-dev-scripts 4%3A25.04.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,612 kB
  • sloc: perl: 15,615; lisp: 5,627; sh: 4,560; python: 3,892; ruby: 1,386; makefile: 13; sed: 9
file content (37 lines) | stat: -rwxr-xr-x 1,184 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/sh

# Merges the tree and history of another git repository into the current one.
# Based on code Linux Torvalds wrote in an email.
#
# This must be run from the root of the target repository, and takes
# a single argument: a path to the source repository.
#
# You must make sure the trees are distinct first. Typically, you
# move things around in the source repository to be how you want them
# to appear in the target repository.

if [ ! -d .git ]; then
  echo "This script must be run from the root of a git repository" >&2
  exit 1
fi

if [ -z "$1" ]; then
  echo "Usage: $0 <source-repo>" >&2
  exit 1
fi

git fetch $1
if [ $? != 0 ]; then
  echo "Could not fetch $1; make sure it is a git repository" >&2
  exit 1
fi
GIT_INDEX_FILE=.git/tmp-index git read-tree FETCH_HEAD || exit 1
GIT_INDEX_FILE=.git/tmp-index git checkout-index -a -u
if [ $? != 0 ]; then
  echo "Could not checkout fetched tree; make sure it is disjoint from this repository's tree" >&2
  exit 1
fi
git update-index --add -- $(GIT_INDEX_FILE=.git/tmp-index git ls-files) || exit 1
cp .git/FETCH_HEAD .git/MERGE_HEAD || exit 1
sed -i -e 's/^\([a-z0-9]*\)\s.*/\1/' .git/MERGE_HEAD
git commit || exit 1