Snippets

RuWeb.net Initial repo upload keeping file timestamps

Created by Andrey Chesnakov last modified
#!/bin/sh
### Initial repo upload keeping file timestamps

if [ ! -n "$1" ]; then
    echo "usage $0 <https://user@bitbucket.org/user/repo.git>"
    exit 1
fi

if [ "$(uname -s)" == "FreeBSD" ]; then
    stat_args="-f%m:%N"
    date_args="-r "
else
    stat_args="-c%Y:%n"
    date_args="-d @"
fi
git init
git remote add origin $1
time=0
for str in $(find -P ./ ! -type d ! -path '*/\.git/*' -exec stat $stat_args {} ';' | sort); do
    mtime=${str%%:*}
    file=${str##*:}
    let newtime=1+$mtime/60\*60 >/dev/null
    if [ $time -ne $newtime ]; then
        if [ $time -ne 0 ]; then
            git commit -m 'Initial commit'
        fi
        time=$newtime
        export GIT_AUTHOR_DATE=$(date $date_args$time)
        export GIT_COMMITTER_DATE=$GIT_AUTHOR_DATE
    fi
    git add $file
done
git commit -m 'Initial commit'
git push -u origin master

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.