-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·61 lines (52 loc) · 1.49 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·61 lines (52 loc) · 1.49 KB
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
#!/bin/bash
# Save the DB changes to a SQL file in the project's .db folder
# named after the "deploy" value from the git config
db_folder=.db
example_config=$(cat << EOF
####################################################################
# An example git configuration for saving SQL for a site called "test":
####################################################################
[wp-site]
test = local.example.com
live = example.com
deploy = test
EOF
)
# Create the SQL file for the Wordpress DB
if [ ! -d "$db_folder" ]; then
echo "Could not find DB folder: $(pwd)/$db_folder"
echo "Creating database folder..."
if [ ! mkdir .db ]; then
echo "Could not create DB folder: $(pwd)/$db_folder"
exit 1
fi
fi
# The name of the SQL file helps to identify the site url that will be in it
sitename=$(git config --get wp-site.deploy)
if [ -z "$sitename" ]; then
cat << EOF
Could not find name of site. Make sure there is a [wp-site] section in the
git config that defines a "deploy" key and the available sites.
EOF
echo
echo "$example_config"
exit 1
fi
# Clear out the DB folder
echo "Clearing SQL files from $db_folder"
rm $db_folder/*.sql
savepath="$db_folder"/"$sitename".sql
if ! wp db export "$savepath" $WP_CLI_PATH_OPTION; then
echo "There was an error saving to $savepath"
exit 1
fi
if [ ! -e "$savepath" ]; then
echo "Could not find $savepath"
exit 1
fi
if git add -A "$db_folder"; then
echo "Changes to $db_folder added to index"
else
echo "Could not save $savepath to index"
exit 1
fi