SourceSafe add files into specific project directories via command line

290 views Asked by At

I have a list of files I want to add

Take for example one is:

  project_dir/nextdir/moredir/test.txt

I then want to add this into VSS, originally I tried

   ss Add "project_dir/nextdir/moredir/test.txt" 

The problem with this is this adds the file "test.txt" to whatever directory I have set as my "working directory" when actually I want my working directory and file directory to mirror. So whereas I have

   $/SS_Project/test.txt

I want

   $/SS_Project/project_dir/nextdir/moredir/test.txt 

Is there anyway of doing this without first using "ss cp /SS_Project/project_dir/nextdir/moredir/test.txt"

Thank you for any help

1

There are 1 answers

0
chrispepper1989 On BEST ANSWER

I ended up using a bash script in what seems like a VERY round the houses method. I am sure someone can provide a better answer but as a work around.

The following function takes a list of files that need to be added and adds them to their corresponding directory in Source Safe. If the file exists in a directory that does not yet exist in sourcesafe, that directory is automatically added recursively.

Example usage (while in root of project):

SSAddEachNewFile file1.txt file2.txt folder1/file3.txt folder1/morefolder/file4.txt

Would add file1.txt file2.txt folder1/file3.txt folder1/morefolder/file4.txt to

$/project/current/myproject/file1.txt
$/project/current/myproject/file2.txt
$/project/current/myproject/folder1/file3.txt
$/project/current/myproject/folder1/morefolder/file4.txt

Bash functions:

SSAddEachNewFile()
{
printf "\n\nAdding files requires us to loop, so we can add to the correct directory"

for file in $1; do

printf "\n--Resetting Dir---\n"
cd %CURRENT_PROJECT_WORKING_DIR
quietsset
printf " ----\n\n"
new_file=$(echo ${file##*/})
directory=$(echo ${file%/*})


#cp to folder
echo "Directory is: $directory"
quietsset
test=$(ss CP $directory 2>&1 | grep -c 'exist' 2>&1)


if (( "1"== $test )); 
then
echo "Did not to find directory! It does not exist!....yet :)";

new_directory=$directory;
last_directory=$directory;
while (( "1"== $test )); 
do
    echo "->This parent directory does not exist, try going up";
    echo "---trying to cp to $new_directory"
    last_directory=$(echo ${new_directory})
    new_directory=$(echo ${new_directory%/*})

    quietsset
    test=$(ss CP $new_directory 2>&1 | grep -c 'exist' 2>&1)

    echo "[+]"
done

echo "Directory does not exit, need to add $last_directory";
ss Add $last_directory -R -C"$SS_COMMENT" -Y$SSNAME 

else
echo "Directory already exists, need to add file: ${file}";
ss Add $file -C"$SS_COMMENT" -Y$SSNAME 
fi 



done

}

It requires one additional function and 2 enviroment variables

quietsset()
{
    ss CP $CURRENT_SOURCE_SAFE_PROJECT -O-
}

Where $CURRENT_SOURCE_SAFE_PROJECT is your SS root and $%CURRENT_PROJECT_WORKING_DIR is your working directory root.

e.g. if you have project/current/myproject and you checkout the "myproject" folder structure. Then your

CURRENT_SOURCE_SAFE_PROJECT = $/project/current/myproject and CURRENT_PROJECT_WORKING_DIR = c/where/you/put/myproject