summaryrefslogtreecommitdiff
path: root/commit-package
blob: 65ad5b2d8d5f1580bc2483daa9ca83bcea51b963 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash

set -e

pdiff () {
  local one="$1";
  local two="$2";
  local pipe="$3";
  shift 3;
  diff "$@" <(
    cat "$one" \
    | bash -c "$pipe"
  ) <(
    cat "$two" \
    | bash -c "$pipe"
  )
}

unset commit_message
if [ $# -eq 1 ]; then
  commit_message="$1"
elif [ $# -ne 0 ]; then
  >&2 'usage: commit-package [commit-message]'
  >&2 '  without a commit message, it will only be added for commit'
  exit 1
fi

if [ -d '.git' ] || [ -f '.git' ]; then
  if ! git remote \
    | grep -qxF aur \
    || ! git remote \
    | grep -qxF ecknernet; then
    >&2 echo 'I cannot find the necessary remotes: aur and ecknernet'
    exit 1
  fi
  if ! git branch --format='%(refname:lstrip=-1)' \
    | grep -qxF master \
    || ! git branch --format='%(refname:lstrip=-1)' \
    | grep -qxF archlinuxewe; then
    >&2 echo 'I cannot find the necessary branches: master and archlinuxewe'
    exit 1
  fi
  if ! git merge-base --is-ancestor master archlinuxewe; then
    >&2 echo 'master is not an ancestor of archlinuxewe'
    exit 1
  fi
  git checkout archlinuxewe
  git pull ecknernet --ff-only
  makepkg --printsrcinfo > .SRCINFO
  git commit 'PKGBUILD' '.SRCINFO' -m "${commit_message:-rebuild}"
  git checkout master
  diff=$(
    git diff archlinuxewe{^,} --name-status \
    | cut -f2 \
    | grep -vxF .SRCINFO \
    | grep -vxF PKGBUILD \
    | xargs -r git diff archlinuxewe{^,} --
  )
  if [ -n "${diff}" ]; then
    printf '%s\n' "${diff}" \
    | git apply
  fi
  pdiff <(
    git archive archlinuxewe^ -- PKGBUILD
  ) <(
    git archive archlinuxewe -- PKGBUILD
  ) '
    tar -Ox \
    | sed "
      /^_pinned_dependencies=(/,/)/d
    "
  ' -u \
  | sed '
    s@^\(---\|+++\) /dev/fd/\S\+\s\+@\1 a/PKGBUILD @
  ' \
  | git apply
  makepkg --printsrcinfo > .SRCINFO
  git commit 'PKGBUILD' '.SRCINFO' -m "${commit_message:-rebuild}"
  git push aur
  git checkout archlinuxewe
  git rebase master
  git push ecknernet --force
  cd ..
  if [ -n "${commit_message}" ]; then
    git commit "${paket}" -m "${commit_message}"
  else
    git add "${paket}"
  fi
else
  if [ -n "${commit_message}" ]; then
    git commit 'PKGBUILD' -m "${commit_message}"
  else
    git add 'PKGBUILD'
  fi
fi