Skip to content

Commit 3aff9fb

Browse files
committed
Revert git/commands
1 parent a408e1d commit 3aff9fb

1 file changed

Lines changed: 116 additions & 6 deletions

File tree

‎plugins/git/commands‎

Lines changed: 116 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,129 @@
22

33
source "$(dirname $0)/../dokku_common"
44

5-
cat
5+
create_pre_receive_hook() {
6+
PRERECEIVE_HOOK="$2/hooks/pre-receive"
7+
cat > "$PRERECEIVE_HOOK" <<EOF
8+
#!/usr/bin/env bash
9+
set -e; set -o pipefail;
10+
cat | DOKKU_ROOT="$DOKKU_ROOT" dokku git-hook "$1"
11+
EOF
12+
chmod +x "$PRERECEIVE_HOOK"
13+
}
14+
15+
create_bare_repository() {
16+
git init --bare "$2" > /dev/null
17+
create_pre_receive_hook "$@"
18+
}
619

720
case "$1" in
821
git-hook)
9-
check_app_name "$2"
10-
echo "deploy"
11-
echo "$APP"
22+
verify_app_name "$2"
23+
24+
# if we got here we have full access
25+
export NAME="dokku"
26+
export FINGERPRINT=""
27+
28+
while read oldrev newrev refname
29+
do
30+
# Only run this script for the master branch. You can remove this
31+
# if block if you wish to run it for others as well.
32+
if [[ $refname = "refs/heads/master" ]] ; then
33+
dokku rebuild "$APP" "$newrev"
34+
else
35+
echo $'\e[1G\e[K'"-----> WARNING: deploy did not complete, you must push to master."
36+
echo $'\e[1G\e[K'"-----> for example, try 'git push <dokku> ${refname/refs\/heads\/}:master'"
37+
fi
38+
done
39+
;;
40+
41+
git-upload-pack)
42+
APP="$(echo $2 | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
43+
pluginhook git-pre-pull $APP
44+
cat | git-upload-pack "$DOKKU_ROOT/$APP"
45+
pluginhook git-post-pull $APP
1246
;;
1347

1448
git-*)
1549
APP="$(echo "$2" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g')"
1650
check_app_name "$APP"
17-
echo "deploy"
18-
echo "$APP"
51+
52+
if [[ $1 == "git-receive-pack" && ! -d "$APP_DIR/refs" ]]; then
53+
[[ "$DOKKU_DISABLE_AUTO_APP_CREATE" == "1" ]] && fail "$APP: application doesn't exit, please create it with: dokku create $APP"
54+
create_bare_repository "$APP" "$APP_DIR"
55+
fi
56+
57+
verify_app_name "$APP"
58+
59+
args=$@
60+
git-shell -c "$args"
61+
;;
62+
63+
create|apps:create)
64+
check_app_name "$2"
65+
verify_max_args 2 "$@"
66+
[[ -d "$APP_DIR/refs" ]] && fail "$APP: already exist"
67+
create_bare_repository "$APP" "$APP_DIR"
68+
info "Application $APP created!"
1969
;;
70+
71+
clone)
72+
cleanup_clone() {
73+
dokku delete "$APP"
74+
}
75+
check_app_name "$2"
76+
verify_max_args 4 "$@"
77+
[[ -d "$APP_DIR/refs" ]] && fail "$APP: already exist"
78+
info "Cloning $APP repository from $3..."
79+
git clone --bare -b "${4:-master}" "$3" "$APP_DIR"
80+
cd "$APP_DIR"
81+
HEAD="$(git rev-parse "${4:-master}")"
82+
trap cleanup_clone EXIT
83+
create_pre_receive_hook "$APP" "$APP_DIR"
84+
dokku rebuild "$APP" "$HEAD"
85+
echo "$HEAD" > "refs/heads/master"
86+
trap - EXIT
87+
;;
88+
89+
import:docker)
90+
cleanup() {
91+
dokku delete "$APP"
92+
[[ -n "$TMP_WORK_DIR" ]] && rm -rf "$TMP_WORK_DIR"
93+
}
94+
check_app_name "$2"
95+
verify_max_args 3 "$@"
96+
dokku create "$2"
97+
trap cleanup EXIT
98+
99+
TMP_WORK_DIR="$(mktemp -d)"
100+
echo "$3"
101+
# clone git repository
102+
chmod 755 "$TMP_WORK_DIR"
103+
unset GIT_DIR GIT_WORK_TREE
104+
pushd "$TMP_WORK_DIR" > /dev/null
105+
git clone "$APP_DIR" "$TMP_WORK_DIR" > /dev/null
106+
git config advice.detachedHead false
107+
git config user.email "$(id -u -n)@$(hostname)"
108+
git config user.name "$(id -u -n)"
109+
cat <<EOF > Dockerfile
110+
FROM $3
111+
EOF
112+
git add Dockerfile
113+
git commit -am "Created application with Docker FROM $3"
114+
git push origin master
115+
trap - EXIT
116+
;;
117+
118+
help | git:help)
119+
cat && cat <<EOF
120+
create <app> Create shallow app
121+
clone <app> <repository> [branch] Create application by cloning git repository
122+
import:docker <app> <docker-image-from> Create application from Docker image
123+
EOF
124+
;;
125+
126+
*)
127+
exit $DOKKU_NOT_IMPLEMENTED_EXIT
128+
;;
129+
20130
esac

0 commit comments

Comments
 (0)