#!/usr/bin/perl

use CM_util;

#########################################
# Hauptprogramm
#########################################

# open files
open (FIN, "$ARGV[0]") || die "file not found: $ARGV[0]\n";
open (FOUT, ">$ARGV[1]") || die "file not found: $ARGV[1]\n";

# define command tables
@UpdateDirs       = ();
@CheckinDirs      = ();
@DeleteFiles      = ();
@IgnoreFiles      = ();
@DeleteRepository = ();
@AddFiles         = ();
@BinFiles         = ();

analyseCmStatus();

# now build git specific commands
foreach $Item ( @UpdateDirs )
{
    print FOUT "echo git checkout -- $Item\n";
    print FOUT "git checkout -- $Item\n\n";
}

foreach $Item ( @DeleteFiles )
{
    print FOUT "rm -r $Item\n\n";
}

foreach $Item ( @IgnoreFiles )
{
    print FOUT "echo \"$Item\" >> .cm.ignore\n\n";
}

foreach $Item ( @DeleteRepository )
{
    print FOUT "echo git rm $Item\n";
    print FOUT "git rm $Item\n\n";
}

foreach $Item ( @AddFiles )
{
   print FOUT "echo git add $Item\n";
   if (-d $Item && ! -l $Item) {
		print FOUT "touch $Item.dummy\n\n";
		print FOUT "git add $Item.dummy\n\n";
	}
	else {
		print FOUT "git add $Item\n\n";
	}
}

foreach $Item ( @BinFiles )
{
    print FOUT "echo git add $Item\n";
    print FOUT "git add $Item\n\n";
}

$hostname = $ENV{'M_HOST'};

if (@CheckinDirs)
{
    print FOUT "echo Check in\n";
    print FOUT "git commit -a -m $hostname\n";
	print FOUT "echo \"Don't forget to backup your git repository!\"\n\n";
}

print FOUT "git_up | true\n";

