aboutsummaryrefslogtreecommitdiffstats
path: root/git-repository--after-tarball
blob: 47844d09970d60294ea7777e8dc75f2e6970b584 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh -ex

# usage: git-repository--after-tarball [<tarballs>]
# with optional environment variables:
# - GIT_URL="git://xxx/foo.git [branch]"
# - GIT_REPOSITORY_CACHE=/zzz/foo.git
#
# the GIT_REPOSITORY_CACHE can be used with or without GIT_URL
# - if GIT_URL is given, GIT_REPOSITORY_CACHE will be a "bare" clone of GIT_URL
# - otherwise, GIT_REPOSITORY_CACHE can be created using:
#   % git clone --bare BUILD/foo-1 $GIT_REPOSITORY_CACHE
#   where foo-1 is the previous version


tarballs="$*"


git_clone_in_cwd() {
    URL=$1
    [ -n "$2" ] && BRANCH="origin/$2"

    git clone $URL .git-tmp

    cd .git-tmp
    git checkout $BRANCH
    cd ..

    mv .git-tmp/.git .
    rm -r .git-tmp
}

our_git_clone() {
    URL=$1
    HEAD=$2

    if [ -n "$GIT_REPOSITORY_CACHE" ]; then
      if [ -d "$GIT_REPOSITORY_CACHE" ]; then
        cd "$GIT_REPOSITORY_CACHE"
	git fetch $GIT_URL
        cd -
      else
        git clone --bare $URL "$GIT_REPOSITORY_CACHE"	
      fi
      git_clone_in_cwd "$GIT_REPOSITORY_CACHE" $HEAD
    else
      git_clone_in_cwd $URL $HEAD
    fi
}

set_GIT_AUTHOR_DATE() {
    # taking date of first tarball, sorry for the other tarballs ;)
    tarball=$1
    export GIT_AUTHOR_DATE=`stat -c '%y' "$RPM_SOURCE_DIR/$tarball"`
}

if [ ! -e .git ]; then
  if [ -n "$GIT_URL" ]; then
    our_git_clone $GIT_URL
  elif [ -n "$GIT_REPOSITORY_CACHE" -a -d "$GIT_REPOSITORY_CACHE" ]; then
    git_clone_in_cwd "$GIT_REPOSITORY_CACHE" vanilla
  else
    git init
  fi
fi
git add . 
set_GIT_AUTHOR_DATE $tarballs
git commit -q -a --author="unknown author <cooker@mandrivalinux.org>" -m "imported $tarballs" 
git branch -f vanilla
git branch -f patches-applied
git checkout patches-applied