make_patch.sh
Go to the documentation of this file.
1 #!/bin/bash
2 
3 # Implement the suggestion here:
4 # http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/
5 # Note that if the file was moved, you only get history since the move.
6 
7 usage()
8 {
9  echo "USAGE: `basename ${0}` <repository> <file or directory>"
10 }
11 
12 get_this_dir()
13 {
14  ( cd / ; /bin/pwd -P ) >/dev/null 2>&1
15  if (( $? == 0 )); then
16  pwd_P_arg="-P"
17  fi
18  reldir=`dirname ${0}`
19  thisdir=`cd ${reldir} && /bin/pwd ${pwd_P_arg}`
20 }
21 
22 repo=${1}
23 myfile=${2}
24 
25 if [ -z ${repo} ]; then
26  usage
27  exit 1
28 fi
29 if [ -z ${myfile} ]; then
30  usage
31  exit 1
32 fi
33 
34 currentdir=`pwd`
35 get_this_dir
36 echo " script directory: ${thisdir}"
37 echo " current directory: ${currentdir}"
38 
39 patchdir=${currentdir}/${repo}patch
40 mkdir -p ${patchdir}
41 cd ${currentdir}/${repo}
42 reposrc=${myfile}
43 git format-patch -o ${patchdir} $(git log ${reposrc}|grep ^commit|tail -1|awk '{print $2}')^..HEAD ${reposrc}
44 
45 echo
46 echo "Patch files have been created in ${patchdir}"
47 echo "cd <destination repository>"
48 echo "git am ${patchdir}/*.patch"
49 echo
50 
51 exit 0
52