3 # Performs an initial import of a directory. This is the equivalent
4 # of doing 'git init; git add .; git commit'. It's a little slower,
5 # but is meant to be a simple fast-import example.
10 my $USAGE = 'usage: git-import branch import-message';
11 my $branch = shift or die "$USAGE\n";
12 my $message = shift or die "$USAGE\n";
14 chomp(my $username = `git config user.name`);
15 chomp(my $email = `git config user.email`);
16 die 'You need to set user name and email'
17 unless $username && $email;
20 open(my $fi, '|-', qw(git fast-import --date-format=now))
21 or die "unable to spawn fast-import: $!";
24 commit refs/heads/$branch
25 committer $username <$email> now
34 if($File::Find::name eq './.git') {
35 $File::Find::prune = 1;
40 my $fn = $File::Find::name;
44 or die "unable to open $fn: $!";
46 or die "unable to stat $fn: $!";
49 print $fi "M 644 inline $fn\n";
50 print $fi "data $len\n";
52 my $r = read($in, my $buf, $len < 4096 ? $len : 4096);
53 defined($r) or die "read error from $fn: $!";
54 $r > 0 or die "premature EOF from $fn: $!";