Skip to content

Commit 7f8cfad

Browse files
pcloudsgitster
authored andcommitted
contrib/fast-import: add simple shell example
This example just puts a directory under git control. It is significantly slower than using the git tools directly, but hopefully shows a bit how fast-import works. [jk: added header comments] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5327141 commit 7f8cfad

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

contrib/fast-import/git-import.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/sh
2+
#
3+
# Performs an initial import of a directory. This is the equivalent
4+
# of doing 'git init; git add .; git commit'. It's a lot slower,
5+
# but is meant to be a simple fast-import example.
6+
7+
if [ -z "$1" -o -z "$2" ]; then
8+
echo "Usage: git-import branch import-message"
9+
exit 1
10+
fi
11+
12+
USERNAME="$(git config user.name)"
13+
EMAIL="$(git config user.email)"
14+
15+
if [ -z "$USERNAME" -o -z "$EMAIL" ]; then
16+
echo "You need to set user name and email"
17+
exit 1
18+
fi
19+
20+
git init
21+
22+
(
23+
cat <<EOF
24+
commit refs/heads/$1
25+
committer $USERNAME <$EMAIL> now
26+
data <<MSGEOF
27+
$2
28+
MSGEOF
29+
30+
EOF
31+
find * -type f|while read i;do
32+
echo "M 100644 inline $i"
33+
echo data $(stat -c '%s' "$i")
34+
cat "$i"
35+
echo
36+
done
37+
echo
38+
) | git fast-import --date-format=now

0 commit comments

Comments
 (0)