For some time i have been creating some applescipts scripts to make it simple to work on multiple SVN projects. There are two scripts the first adds the data on the server and exports to the working folder. The other loops through all the projects in the working folder and commits those with changed commit message. This makes it easy to work on several projects and use one action to commit everything.
These scripts use the local setting on SVN, and in each of them the directory is inserted for local folder and external folder on SVN server.
The first script is to create a svn project on the server:
-- 1. Find the folder of the project
tell application "Finder"
activate
set svnFolder to folder (choose folder with prompt "Find the folder containing the project you want to add to svn.")
set als to svnFolder as alias
set svnFolderPOSIXPath to quoted form of POSIX path of als
end tell
tell application "Terminal"
activate
set window_1 to id of first window whose frontmost is true
set moveToFolder to "cd " & svnFolderPOSIXPath
do script moveToFolder in tab 1 of window id window_1 of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
-- ASK FOR USER INFORMATION ABOUT NEW PROJECT
set svnDirectoryLocal to "/Users/SVNFOLDER/"
set svnDirectoryServer to "http://svn.xdomain.com/"
set displayString to "Enter Project Project dir(no spaces)"
set defaultAnswer to 0
repeat
set response to display dialog displayString default answer defaultAnswer
try
set responceString to (text returned of response) as string
exit repeat
on error errstr
set displayString to errstr & return & "Please try again."
set defaultAnswer to text returned of response
end try
end repeat
-- 2. EXPORT ON SERVER
set ts to "svn import "
set te to " -m 'new project ("
set teend to ")'"
set createONServer to ts & svnDirectoryServer & responceString & te & responceString & teend
do script createONServer in tab 1 of window id window_1 of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
-- 3. CHECKOUT
set commandCD to "cd "
set commandCDComplete to commandCD & svnDirectoryLocal
do script commandCDComplete in tab 1 of window id window_1 of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
set ts to "svn checkout "
set checkoutOnServer to ts & svnDirectoryServer & responceString
do script checkoutOnServer in tab 1 of window id window_1 of application "Terminal"
end tell
The other script lets you specify commit messages for all projects in the current active folder, and only those changed (commit message) will get committed:
set svnDirectoryLocal to "/Users/SVNFOLDER/"
set svnDirectoryServer to "http://svn.xdomain.com/"
set stringCommitMessage to "-CommitMessage"
set ASCIICharacter to (ASCII character 13) -- change this dependent on keyboard (can be 10)
-- 1. FIND ALL THE FOLDERS THAT CAN BE COMMITTED
tell application "Finder"
activate
set svnFileList to name of every folder of (svnDirectoryLocal as POSIX file as alias)
end tell
-- 2. ASK FOR COMMIT MESSAGES (ONLY COMMIT IF CHANGED)
-- 2.1 Find the folders and display them
set svnItemString to ""
set numCount to 0
set numItems to count svnFileList
repeat with svnItem in svnFileList
set numCount to numCount + 1
set svnItemString to svnItemString & svnItem & stringCommitMessage
if numCount is not equal to numItems then
set svnItemString to svnItemString & ASCIICharacter
end if
end repeat
set returnCommitMessages to text returned of (display dialog "Write in commit messages to the projects you would like to update. (Only changed projects will be committed)" default answer svnItemString)
-- 2.2 check what is changed, and create the set of svn folders to update
set AppleScript's text item delimiters to ASCIICharacter
set returnCommitSet to every text item of returnCommitMessages
-- 2.3 Loop through the changed list and see where changes have been made
set finalCommitMessages to {}
set finalDirectories to {}
set numCount to 0
repeat with itemFolderCommitInitMessage in svnFileList
set numCount to numCount + 1
set itemCommit to item numCount of returnCommitSet
set itemFolderCommitInitMessageWithString to itemFolderCommitInitMessage & stringCommitMessage
if (itemCommit as string) is not equal to (itemFolderCommitInitMessageWithString as string) then
set end of finalCommitMessages to itemCommit
set end of finalDirectories to itemFolderCommitInitMessage
end if
end repeat
-- 3. INFORMATION
set numItems to count finalCommitMessages
if numItems = 0 then
display dialog "No commit messages written, nothing will get updated." buttons {"RETURN"}
else
set infoString to "UPDATING CURRENT SVN DIRECTORIES:" & ASCIICharacter & ASCIICharacter
set numCount to 0
set numItems to count finalCommitMessages
repeat with finalCommitMessageItem in finalCommitMessages
set numCount to numCount + 1
set infoString to infoString & item numCount in finalDirectories & ASCIICharacter & "- Commit message: " & finalCommitMessageItem
if numCount is not equal to numItems then
set infoString to infoString & ASCIICharacter & ASCIICharacter
end if
end repeat
display dialog infoString buttons {"CANCEL", "COMMIT"}
end if
-- 4. COMMIT ALL THE CHANGED FOLDERS
tell application "Terminal"
activate
set window_id to id of first window whose frontmost is true
-- 4.1 Loop through all the folders to commit
set numCount to 0
set numItems to count finalCommitMessages
repeat with finalCommitMessageItem in finalCommitMessages
set numCount to numCount + 1
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
-- 4.2 Goto the correct folder
set cdAction to "cd " & svnDirectoryLocal & item numCount in finalDirectories
do script cdAction in tab 1 of window id window_id of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
-- 4.3 Find the files to add
do script "svn stat | grep '^?' | awk '{print $2}' | xargs svn add" in tab 1 of window id window_id of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
do script "svn status | grep '^?' | awk '{print $2}' | xargs -I {} svn add {}@" in tab 1 of window id window_id of application "Terminal"
set a to 0
repeat until (a = 1)
if (window 1 is not busy) then
set a to 1
end if
end repeat
-- 4.4 Commit action
set ts to "svn commit -m '"
set te to "'"
set commitAction to ts & finalCommitMessageItem & te
do script commitAction in tab 1 of window id window_id of application "Terminal"
end repeat
end tell
Possible things that i would like to get suggestions on:
- Focus problems, how do i make the script work if terminal is not open?
- Is there a better way to check if terminal is working than “window 1 is busy”?
- Other places i should optimize?