patternbashgitMinor
Bash script for Git & VSS interop
Viewed 0 times
scriptinteropgitforbashvss
Problem
I have been slowly evolving some code for Git and VSS interop based on a quest I started a while ago
And the code is now working, some parts have been updated without test (such as the init) and I am not 100% sure everything is doing what it should/is the best way and some parts seem really round the houses!
Its certainly past the point where it needs some input.
The basic concept is
-
-
-
-
-
The code is currently used in the context of git, vss, beyondcompare and trackgear
I am keeping an up to date version here:
Code at time of question:
`#--useful aliases
alias gitremove="git ls-files --deleted -z | xargs -0 git rm"
alias bcompare="START / \"C:\Program Files (x86)\Beyond Compare 3\BCompare.exe\""
alias initgitss=InitGitAndSourceSafeProject
alias ssclone="ss get "$CURRENT_SOURCE_SAFE_PROJECT" -W -R -Q -Y$SSNAME -I-N"
alias ssdiff="ss Diff -Y$SSNAME"
#----These Need Setting:
##Your source safe project
CURRENT_SOURCE_SAFE_PROJECT=
##You Working directory
CURRENT_PROJ_DIR=
#--For Source Safe Comments
ACTIVE_TRACK_REF=
PROJECT_NAME=
##Your BeyondCompare Session
#its better to create a beyond compare session so you can set it up how you like
BEYOND_COMPARE_SESSION=
#----SysVars
REF_APPEND="_REF"
#--variable set up helper
sset()
{
if [ $# -eq 0 ]
then
echo "No arguments supplied, please supply the SS project name"
fi
CURRENT_SOURCE_SAFE_PROJECT=$1
CURRENT_PROJ_DIR=$(pwd)
}
#--cr
And the code is now working, some parts have been updated without test (such as the init) and I am not 100% sure everything is doing what it should/is the best way and some parts seem really round the houses!
Its certainly past the point where it needs some input.
The basic concept is
- "Pulling" from source safe is achieved by keeping a separate "vss_branch"
-
- vss_branch is kept up to kept up to date with source safe via a full source safe get
-
- master treats vss_branch as its "upstream/origin" so master pulls from vss_branch
- "Pushing" to source safe
-
- is achieved by figuring out what is different between master and vss_branch
-
- saving and then pushing to vss_branch
-
- then I go through all the modified/deleted/added files, and applying the appropriate operation e.g. checking them out and checking them in
The code is currently used in the context of git, vss, beyondcompare and trackgear
I am keeping an up to date version here:
Code at time of question:
`#--useful aliases
alias gitremove="git ls-files --deleted -z | xargs -0 git rm"
alias bcompare="START / \"C:\Program Files (x86)\Beyond Compare 3\BCompare.exe\""
alias initgitss=InitGitAndSourceSafeProject
alias ssclone="ss get "$CURRENT_SOURCE_SAFE_PROJECT" -W -R -Q -Y$SSNAME -I-N"
alias ssdiff="ss Diff -Y$SSNAME"
#----These Need Setting:
##Your source safe project
CURRENT_SOURCE_SAFE_PROJECT=
##You Working directory
CURRENT_PROJ_DIR=
#--For Source Safe Comments
ACTIVE_TRACK_REF=
PROJECT_NAME=
##Your BeyondCompare Session
#its better to create a beyond compare session so you can set it up how you like
BEYOND_COMPARE_SESSION=
#----SysVars
REF_APPEND="_REF"
#--variable set up helper
sset()
{
if [ $# -eq 0 ]
then
echo "No arguments supplied, please supply the SS project name"
fi
CURRENT_SOURCE_SAFE_PROJECT=$1
CURRENT_PROJ_DIR=$(pwd)
}
#--cr
Solution
A couple of minor issues, from top to bottom.
When you need to embed double-quotes in a string,
and you don't need to embed variables inside,
then it's easier to use single-quotes.
So instead of this:
This is easier:
No need to break out of the double-quotes here:
You could embed the variable simply:
Regarding this piece:
...What the heck is
I'd appreciate if you could explain in comments :-)
Especially a keyword would be nice that I can search for in
I'd be really interested to know.
As it stands, it seem to me the expression will always evaluate to the letter "x",
which is not empty, so the
Unnecessary
Remove those.
In some
I suggest to be consistent and stick with the same style everywhere.
The
This is better:
The same goes for these:
In
In the same method you also have an
I suggest to fix these, as they hurt readability and can easily lead to bugs.
No need to quote
This is the same and simpler:
The rest of the code has similar issues to the ones I already pointed out:
Review the entire code, and follow the suggestions above.
When done, copy-paste your code on http://www.shellcheck.net/#,
and correct the remaining warnings it tells you.
When you need to embed double-quotes in a string,
and you don't need to embed variables inside,
then it's easier to use single-quotes.
So instead of this:
alias bcompare="START / \"C:\Program Files (x86)\Beyond Compare 3\BCompare.exe\""This is easier:
alias bcompare='START / "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe"'No need to break out of the double-quotes here:
alias ssclone="ss get "$CURRENT_SOURCE_SAFE_PROJECT" -W -R -Q -Y$SSNAME -I-N"You could embed the variable simply:
alias ssclone="ss get $CURRENT_SOURCE_SAFE_PROJECT -W -R -Q -Y$SSNAME -I-N"Regarding this piece:
if [ -z ${CURRENT_SOURCE_SAFE_PROJECT+x} ];...What the heck is
${CURRENT_SOURCE_SAFE_PROJECT+x} ???I'd appreciate if you could explain in comments :-)
Especially a keyword would be nice that I can search for in
man bash.I'd be really interested to know.
As it stands, it seem to me the expression will always evaluate to the letter "x",
which is not empty, so the
if will always be false.Unnecessary
; at the end of some lines:then echo "CURRENT_SOURCE_SAFE_PROJECT is unset";
exit;Remove those.
In some
ss commands you use cp, in others you use CP.I suggest to be consistent and stick with the same style everywhere.
The
echo in a subshell here is unnecessary:DIR=$(echo ${FULLPATH%/*})This is better:
DIR=${FULLPATH%/*}The same goes for these:
new_file=$(echo ${file##*/})
directory=$(echo ${file%/*})In
AddEachNewFile you have a for-loop with the body not well-indented:for file in $1; do
printf "\n--Resetting Dir---\n"
quietsresetIn the same method you also have an
if block not well-indented.I suggest to fix these, as they hurt readability and can easily lead to bugs.
No need to quote
exist here:test=$(ss CP $directory 2>&1 | grep -c 'exist' 2>&1)This is the same and simpler:
test=$(ss CP $directory 2>&1 | grep -c exist 2>&1)The rest of the code has similar issues to the ones I already pointed out:
- bad indents
- unnecessary trailing
;
- unnecessary quotes
- unnecessary
echosubshells
Review the entire code, and follow the suggestions above.
When done, copy-paste your code on http://www.shellcheck.net/#,
and correct the remaining warnings it tells you.
Code Snippets
alias bcompare="START / \"C:\Program Files (x86)\Beyond Compare 3\BCompare.exe\""alias bcompare='START / "C:\Program Files (x86)\Beyond Compare 3\BCompare.exe"'alias ssclone="ss get "$CURRENT_SOURCE_SAFE_PROJECT" -W -R -Q -Y$SSNAME -I-N"alias ssclone="ss get $CURRENT_SOURCE_SAFE_PROJECT -W -R -Q -Y$SSNAME -I-N"if [ -z ${CURRENT_SOURCE_SAFE_PROJECT+x} ];Context
StackExchange Code Review Q#70718, answer score: 3
Revisions (0)
No revisions yet.