-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeagit
executable file
·158 lines (145 loc) · 3.58 KB
/
aeagit
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
AEASRC=git@bitbucket.org:aeaverification
AEAHSRC=bitbucket.org/aeaverification
call=$0
os=$(uname)
codeeditor="$(which code)"
silent=""
DEPTH=50
function code {
case $os in
Linux|Darwin|MING*)
"$codeeditor" "$1"
;;
*)
echo "Open $1 with editor of your choice"
;;
esac
}
if [[ -z $1 ]]
then
cat << EOF
$0 (number) [(method)]
will check out the repo from the AEA repository at
$AEASRC
into the local directory, enter the directory, and open
an editor with the REPLICATION.md file.
Arguments:
(number): the numerical part of the AEAREP-nnnn *repository*
(not ticket)
(method): (optional) method of connecting (ssh or https,
can be abbreviated)
The connection method should default to the right thing according
to the environment. For ssh, you need to have set up the SSH key.
For https, it will use other authentication methods on your
machine (e.g., Github Desktop) if available. In the cloud,
set the variables P_BITBUCKET_PAT and P_BITBUCKET_USERNAME, see README.
EOF
else
manuscript=$1
repo=aearep-$manuscript
_method=$2
case $_method in
silent)
silent="echo"
;;
*)
silent=""
esac
case $_method in
s*|S*)
method=ssh
;;
h*|H*)
method=https
;;
*)
# this sets it to HTTPS for CodeSpace
[[ -z $CODESPACE_NAME ]] && method=ssh || method=https
# This defaults to HTTPS when running on Git Bash
case $os in
MING*)
method=https
;;
esac
;;
esac
authinfo=$3
# construct URL and query other parameters if necessary
case $method in
ssh)
GITURL="$AEASRC/$repo.git"
;;
https)
# we need username and PAT
# try git credentials first
if [[ -f $HOME/.git-credentials ]]
then
authinfo=$(grep bitbucket $HOME/.git-credentials)
authinfo=${authinfo##*/}
authinfo=${authinfo%@*}
fi
# Check to see if that's good, if not use environment variables
if [[ -z $authinfo ]]
then
if [[ ! -z $P_BITBUCKET_PAT && ! -z $P_BITBUCKET_USERNAME ]]
then
authinfo=${P_BITBUCKET_USERNAME}:${P_BITBUCKET_PAT}
fi
fi
# now lets see where we are at.
if [[ -z $authinfo ]]
then
echo "We will use pre-configured credentials for git."
echo "If this does not work, run "
echo " git config --global credential.helper store "
echo "and try again, using the following syntax:"
echo " $0 $manuscript https USERNAME:PAT"
echo "where "
echo " USERNAME is your Bitbucket username"
echo " PAT is your Bitbucket personal access token (note the colon)"
echo "If running on Codespaces:"
echo " - see configuration notes about P_BITBUCKET_PAT"
echo " - candidate PAT: $P_BITBUCKET_PAT (if configured)"
echo " --- "
GITURL="https://$AEAHSRC/$repo.git"
else
GITURL="https://${authinfo}@$AEAHSRC/$repo.git"
fi
;;
esac
if [[ -d $repo ]]
then
echo "Repo $repo already exists - updating only"
else
git clone $GITURL
fi
# directory should exist now
if [[ -d $repo ]]
then
cd $repo && git pull --depth $DEPTH
if [[ -f REPLICATION.md ]]
then
case $os in
Linux|MING*)
$silent code . REPLICATION.md
;;
Darwin)
$silent open -a "Visual Studio Code" . REPLICATION.md
;;
esac
fi
else
echo "Git clone failed"
fi
echo "Done"
echo "Type cd $repo or code $repo and start your work."
case $os in
Linux)
[[ -z $(which xclip) ]] || echo "cd $repo" | xclip -selection c
;;
Darwin)
echo "cd $repo" | pbcopy
;;
esac
fi