hg-fast-export.sh should fail if git-fast-import fails
[fast-export/benizi.git] / hg-fast-export.sh
blob334f2862a9244b1e3f00ccce377fab49e060f972
1 #!/bin/sh
3 # Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
4 # License: MIT <http://www.opensource.org/licenses/mit-license.php>
6 ROOT="`dirname $0`"
7 REPO=""
8 PFX="hg2git"
9 SFX_MAPPING="mapping"
10 SFX_MARKS="marks"
11 SFX_HEADS="heads"
12 SFX_STATE="state"
13 GFI_OPTS=""
14 PYTHON=${PYTHON:-python}
16 USAGE="[--quiet] [-r <repo>] [--force] [-m <max>] [-s] [-A <file>] [-M <name>] [-o <name>]"
17 LONG_USAGE="Import hg repository <repo> up to either tip or <max>
18 If <repo> is omitted, use last hg repository as obtained from state file,
19 GIT_DIR/$PFX-$SFX_STATE by default.
21 Note: The argument order matters.
23 Options:
24 -m Maximum revision to import
25 --quiet Passed to git-fast-import(1)
26 -s Enable parsing Signed-off-by lines
27 -A Read author map from file
28 (Same as in git-svnimport(1) and git-cvsimport(1))
29 -r Mercurial repository to import
30 -M Set the default branch name (default to 'master')
31 -o Use <name> as branch namespace to track upstream (eg 'origin')
34 . "$(git --exec-path)/git-sh-setup"
35 cd_to_toplevel
37 while case "$#" in 0) break ;; esac
39 case "$1" in
40 -r|--r|--re|--rep|--repo)
41 shift
42 REPO="$1"
44 --q|--qu|--qui|--quie|--quiet)
45 GFI_OPTS="$GFI_OPTS --quiet"
47 --force)
48 # pass --force to git-fast-import and hg-fast-export.py
49 GFI_OPTS="$GFI_OPTS --force"
50 break
52 -*)
53 # pass any other options down to hg2git.py
54 break
57 break
59 esac
60 shift
61 done
63 # for convenience: get default repo from state file
64 if [ x"$REPO" = x -a -f "$GIT_DIR/$PFX-$SFX_STATE" ] ; then
65 REPO="`egrep '^:repo ' "$GIT_DIR/$PFX-$SFX_STATE" | cut -d ' ' -f 2`"
66 echo "Using last hg repository \"$REPO\""
69 # make sure we have a marks cache
70 if [ ! -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
71 touch "$GIT_DIR/$PFX-$SFX_MARKS"
74 # cleanup on exit
75 trap 'rm -f "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp"' 0
77 GIT_DIR="$GIT_DIR" $PYTHON "$ROOT/hg-fast-export.py" \
78 --repo "$REPO" \
79 --marks "$GIT_DIR/$PFX-$SFX_MARKS" \
80 --mapping "$GIT_DIR/$PFX-$SFX_MAPPING" \
81 --heads "$GIT_DIR/$PFX-$SFX_HEADS" \
82 --status "$GIT_DIR/$PFX-$SFX_STATE" \
83 "$@" \
84 | git fast-import $GFI_OPTS --export-marks="$GIT_DIR/$PFX-$SFX_MARKS.tmp" || exit 1
86 # move recent marks cache out of the way...
87 if [ -f "$GIT_DIR/$PFX-$SFX_MARKS" ] ; then
88 mv "$GIT_DIR/$PFX-$SFX_MARKS" "$GIT_DIR/$PFX-$SFX_MARKS.old"
89 else
90 touch "$GIT_DIR/$PFX-$SFX_MARKS.old"
93 # ...to create a new merged one
94 cat "$GIT_DIR/$PFX-$SFX_MARKS.old" "$GIT_DIR/$PFX-$SFX_MARKS.tmp" \
95 | uniq > "$GIT_DIR/$PFX-$SFX_MARKS"
97 # save SHA1s of current heads for incremental imports
98 # and connectivity (plus sanity checking)
99 for head in `git branch | sed 's#^..##'` ; do
100 id="`git rev-parse $head`"
101 echo ":$head $id"
102 done > "$GIT_DIR/$PFX-$SFX_HEADS"
104 # check diff with color:
105 # ( for i in `find . -type f | grep -v '\.git'` ; do diff -u $i $REPO/$i ; done | cdiff ) | less -r