160 likes | 293 Views
Software Engineering – Introduction. VERSION CONTROL - SVN Good software engineering practice manages the development and change of your source code as well as any other documents (to a point) you use to maintain information about your project.
E N D
Software Engineering – Introduction VERSION CONTROL - SVN Good software engineering practice manages the development and change of your source code as well as any other documents (to a point) you use to maintain information about your project. SVN is one of many version control systems. Others include: SourceSafe, CVS, etc. To implement SVN you can use a UNIX account. Tux will do nicely. From the prompt, type “bash” to get a simpler interface to the kernel. The next step is to create a directory for the repository. mkdir svnroot then create a directory for the project you wish to work on. mkdir svnroot/myproject
Software Engineering – Introduction VERSION CONTROL - SVN Now we need to change the permissions on the directory so that your group (you will need to get a group) will have access to your files and no other people. chgrp –R groupname svnroot //assigns the svnroot to a group chmod –R g+rws svnroot //assigns the correct permissions for group // sharing Note if you have multiple projects, assign the group name to a project directory rather than the svnroot. Create an empty repository at the path we created svnadmin create svnroot/myproject/ SVN repository is now created.
Software Engineering – Introduction VERSION CONTROL - SVN Each group member needs to access the SVN repository. Check out the current revision of the repository to the directory specified, in this case svn. svn co file:///home/UserName/svnroot/myproject/ svn Enter the newly created directory cd svn Observe the information for your local copy of the repository svn info Type svn help at any time to get a list of the possible commands.
Software Engineering – Introduction VERSION CONTROL - SVN Once the repository is checked out, you may begin your development. Make the code directory mkdir source Now create your source file. vi source/fletch.c #include <stdio.h> int main() { printf(“Fletch Lives!\n”); return 0; }
Software Engineering – Introduction VERSION CONTROL - SVN Add the file (directory) to the repository svn add source The file is loaded, but not committed. To commit the file type: svn commit –m “Place a message so that the group understands what you did”
Software Engineering – Introduction VERSION CONTROL - SVN If you wish to see what activity has transpired within the repository, type: svn log source Output similar to the following will appear: jsalvage@tux64-04:~/svn$ svn log source ------------------------------------------------------------------------ r3 | jsalvage | 2007-08-02 11:28:03 -0400 (Thu, 02 Aug 2007) | 1 line removed kyle's crappy work ------------------------------------------------------------------------ r2 | kfu22 | 2007-08-02 11:17:51 -0400 (Thu, 02 Aug 2007) | 1 line forcing conflict ------------------------------------------------------------------------ r1 | jsalvage | 2007-08-02 10:34:18 -0400 (Thu, 02 Aug 2007) | 1 line Initial creation of Fletch ------------------------------------------------------------------------ jsalvage@tux64-04:~/svn$
Software Engineering – Introduction VERSION CONTROL - SVN Now, let’s show the power of SVN and modify the fletch.c file from two different group members. However, before you start making changes to your local code it is a good idea to issue an update command to bring your copy up to date with the latest code in the repository. Type the following: svn update Now let’s will change the output to “Fletch hates the Red Sox” while the other group member will change it to “Hello world”. Once your changes have been saved locally, you now must load them to the repository. To do this type: svn commit –m “New message”
Software Engineering – Introduction VERSION CONTROL - SVN The first person to commit the file will not receive an error, however the second person will receive a conflict as shown below: jsalvage@tux64-04:~/svn$ svn commit -m "update to fletch" Sending source/fletch.c svn: Commit failed (details follow): svn: Out of date: '/source/fletch.c' in transaction '2-1' jsalvage@tux64-04:~/svn$ To fix this situation, issue an svn update command as follows: svn update jsalvage@tux64-04:~/svn$ svn update C source/fletch.c Updated to revision 2. C stands for conflict
Software Engineering – Introduction VERSION CONTROL - SVN Observe the following screen capture which appears after typing svn update
Software Engineering – Introduction VERSION CONTROL - SVN Delete the code you do not wish to keep. Clearly Fletch is not a Red Sox fan!
Software Engineering – Introduction VERSION CONTROL - SVN If you try to commit your code now, you will still fail. jsalvage@tux64-04:~/svn$ svn commit svn: Commit failed (details follow): svn: Aborting commit: '/home/jsalvage/svn/source/fletch.c' remains in conflict You must first resolve the state of conflict. You can do this by typig the following: svn resolved jsalvage@tux64-04:~/svn$ svn resolved source/fletch.c Resolved conflicted state of 'source/fletch.c' Then you can commit your code: svn commit jsalvage@tux64-04:~/svn$ svn commit -m "removed kyle's crappy work" Sending source/fletch.c Transmitting file data . Committed revision 3.
Software Engineering – Introduction VERSION CONTROL - SVN In contrast, if you do an svn update without having made local modifications to the same files. Your update will appear as follows: jsalvage@tux64-04:~/svn$ svn update U source/fletch.c Updated to revision 4.
Software Engineering – Introduction VERSION CONTROL - SVN If both users make changes, but to separate lines of code, SVN will automatically merge the two files when they are both committed. Be careful. This may not do what you expect. Imagine one developer sees that there is an inconstancy in the code. i.e. the use of .h. The other developer may also see this. What happens if each developer implements their changes differently?
Software Engineering – Introduction VERSION CONTROL - SVN
Software Engineering – Introduction VERSION CONTROL - SVN jsalvage@tux64-04:~/svn$ svn update G source/fletch.c Updated to revision 5. Notice the G, it means successful merge, but what does that mean?
Software Engineering – Introduction VERSION CONTROL - SVN At any time you can type svn status and it will show you the state of your local files. For example: jsalvage@tux64-04:~/svn$ svn status M source/fletch.c The M shows the local file fletch.c has been modified locally.