@@ -28,7 +28,7 @@ The beginning of any script in bash
2828** Read variable:**
2929
3030``` bash
31- " $path " или " ${path} "
31+ " $path " or " ${path} "
3232```
3333
3434** Pass arguments to a script:**
@@ -153,7 +153,7 @@ The beginning of any script in bash
153153 echo " Removing dir"
154154 rm -r " $1 "
155155 else
156- echo " Can't remove ${1} "
156+ echo " Cannot remove ${1} "
157157 fi
158158```
159159
@@ -242,33 +242,44 @@ The beginning of any script in bash
242242``` bash
243243 #! /bin/bash
244244
245+ PATH_TO_DIFF_DIR=" ${HOME} /diff/"
246+ FILE_EXTENTION=" .diff"
247+
248+ USER_NAME=" <user_name>"
249+ USER_PASSWORD=" <user_password>"
250+ PROJECT_NAME=" <project_name>"
251+
252+ # if "$1" is empty
245253 if [ -z " $1 " ]
246254 then
247255 echo " Please, specify an issue ID"
248- exit 1
256+ exit 0
249257 fi
250258
251259 issue_id=" $1 "
252260 branch=$( git rev-parse --abbrev-ref HEAD)
253261
254262 # Get the first line of git remote output and cut a path to repository
255263 repository=$( git remote -v | head -n1 | sed " s/^origin.*\/\(.*\)\.git\s(.*)/\1/" )
264+ file_name=" ${branch} -${repository}${FILE_EXTENTION} "
256265
257- path_to_diff=" ${HOME} /<path_to_diff_directory>${branch} -${repository} .diff"
266+ # path to diff directory with <filename>.diff
267+ path_to_diff=" ${PATH_TO_DIFF_DIR}${file_name} "
258268
259- diff_live () {
260- git diff " origin/live.. master/${branch} " > " $path_to_diff "
269+ diffMaster () {
270+ git diff " origin/master origin /${branch} " > " $path_to_diff "
261271 }
262272
263- attach_diff () {
264- curl -D- -u " <ipa_username> " :" <ipa_password> " -X POST -H " X-Atlassian-Token: no-check" -F " file=@${path_to_diff} ;type=text/x-diff" " https://jira.<project_name> .com/rest/api/2/issue/${issue_id} /attachments"
273+ attachDiff () {
274+ curl -D -u " ${USER_NAME} " :" ${USER_PASSWORD} " -X POST -H " X-Atlassian-Token: no-check" -F " file=@${path_to_diff} ;type=text/x-diff" " https://jira.${PROJECT_NAME} .com/rest/api/2/issue/${issue_id} /attachments"
265275 }
266276
267- diff_live && attach_diff
277+ diffMaster && attachDiff
268278
269- # Usage: cd <repo_name> && attach_diff <issue_id>
279+ # Usage: cd <repo_name> && fast_diff_v2.sh <issue_id>
270280 # <issue_id> should include your company prefix (ABC, XYZ, XX, etc.)
271- # At instance, "attach_diff XYZ-135" will try to attach diff to https://jira.<project_name>.com/browse/XYZ-135
281+ # At instance, "./fast_diff_v2.sh XYZ-135" will try to attach diff to
282+ # https://jira.<project_name>.com/browse/XYZ-135
272283```
273284
274285#### Up a large number of repositories
@@ -287,41 +298,56 @@ The beginning of any script in bash
287298 # get list of repositories
288299 findRepo () {
289300 REPO_NAME=" terminalForCoder__WSD"
290- path_to_vendor_repo=" ${HOME} /${REPO_NAME} /bash/core/vendors/"
291- # find all git repositories in $path_to_vendor_repo
301+ PATH_TO_VENDORS_REPO=" ${HOME} /${REPO_NAME} /bash/core/vendors/"
302+
303+ # find all git repositories in $PATH_TO_VENDORS_REPO
292304 # filter by /.git
293- r=$( find ${path_to_vendor_repo} -name .git | xargs | sed " s/\\ /.git//g" )
305+
306+ if [[ -e " $PATH_TO_VENDORS_REPO " ]]
307+ then
308+ r=$( find " $PATH_TO_VENDORS_REPO " -name .git | xargs | sed " s/\\ /.git//g" )
309+ else
310+ echo " Cannot find ${PATH_TO_VENDORS_REPO} "
311+ echo " Try to edit REPO_NAME in ${0} "
312+ exit 0
313+ fi
314+
294315 # do check repositories stuff
295- checkBranch " $r "
316+ checkBranch $r
296317 }
297318
298319 # do check repositories stuff
299320 checkBranch () {
300321 BRANCH=" master"
322+ CHECK_BRANCH=" * master"
301323
302- # $i is item in $r
324+ # $i is an item in $r
303325 for i in " $@ "
304326 do
305327 # get current branch name
306- b=` cd ${i} && git branch | grep \* `
328+ b=$( cd " $i " && git branch | grep \* )
307329 echo " repo: ${i} "
308330 echo " current brunch: ${b} "
309331
310332 # check branch
311- if [[ " $b " != " * master " ]]
333+ if [[ " $b " != " $CHECK_BRANCH " ]]
312334 then
313335 echo " !Error! ${i} is not on ${BRANCH} branch"
314336 echo " Current branch is ${b} "
337+ echo " Checkout to ${BRANCH} and do git pull stuff for ${i} "
315338 cd " $i " && git checkout " $BRANCH " && git branch && git pull origin " $BRANCH "
339+ echo " "
316340 else
317- echo " Do pull stuff"
341+ echo " Do git pull stuff for ${i} "
318342 cd " $i " && git branch && git pull origin " $BRANCH "
343+ echo " "
319344 fi
320345 done
321346 echo " Done. Congratulation, you win!"
322347 }
323348
324349 findRepo " $@ "
350+
325351```
326352
327353#### Helpful aliases
0 commit comments