forked from tieto/sipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-snapshot.sh
executable file
·45 lines (42 loc) · 1.22 KB
/
git-snapshot.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
#
# Take a snapshot of the current pidgin-sipe git HEAD from the mob branch.
#
# You can specify the path to a local repository to speed up the cloning
# process. The output will be a bzip2 compressed tarball whose name includes
# the current date and the abbreviated commit object name of HEAD.
#
# Adapted from several examples found on the Internet.
#
# Configuration
PROJECT=pidgin-sipe
REPOSITORY="git+ssh://[email protected]/srv/git/siplcs.git"
BRANCH=mob
# Create clone
set -e
TODAY=$(date +%Y%m%d)
CLONEDIR=${PROJECT}-${TODAY}
echo "Clone directory '$CLONEDIR'."
REFERENCE=${1:+--reference $1}
if [ -n "$1" ]; then
echo "Using local repository under '$1'."
fi
if [ -n "$2" ]; then
REPOSITORY=$2
fi
echo "Cloning from repository URL '$REPOSITORY'."
rm -rf $CLONEDIR
git clone -n $REFERENCE $REPOSITORY $CLONEDIR
cd $CLONEDIR
git checkout -q -b $CLONEDIR origin/$BRANCH
# Create archive
COMMIT=$(git log -n 1 --abbrev-commit --pretty=oneline | cut -d' ' -f1| sed -e 's/\.//g')
PREFIX=${PROJECT}-${TODAY}git${COMMIT}
ARCHIVE=${PREFIX}.tar.bz2
echo "Creating archive '$ARCHIVE'..."
git archive --format=tar --prefix=$PREFIX/ HEAD | bzip2 >../${PREFIX}.tar.bz2
# Cleanup
echo "Cleanup..."
cd ..
rm -rf $CLONEDIR
echo "DONE."