Managing web project over multiple hosts with revision control - eclipse

Greetings! :-)
I would like to describe a workflow strategy with some gaps in it, and I would be glad if you could fill in the gaps and otherwise give comments. If admins think that this does not validate as a question, then please delete away.
I am working on a webproject having files with PHP, Javascript (jQuery), HTML, CSS and postgresql code for in-database functions, table creation and configuration. All files are changed frequently. I use Apache.
This is what I want:
Introduce revision control.
Use build files for managing compilation and revision control.
Start using a proper IDE.
Be able to hack on my stationary and laptop with little time wasted on keeping code and IDE project configurations synchronized.
Have a setup for the project so some friends (approx 4-5) may join the project in the future.
This is what I am planning to start to use:
Bazaar for revision control and "project distribution".
Ant for build files.
Eclipse setup with proper plugins for managing Bazaar and Ant.
With Bazaar I intend to put code files, build files and even Eclipse project configuration files (configuration files of the project that I create in Eclipse to work with the webproject) under revision control. That way I can pull all that stuff from my stationary to my laptop via Bazaar.
Since I also put Eclipse's project conf files under revision control, I expect that I can without hazzle immediately open the Eclipse project directly on my laptop. So even if I make modifications to the project settings in Eclipse this should also be synchronized over laptop and host.
But I do have a few questions. Do you know how I should use bazaar so that I am notified or stopped when I try to modify the code on my stationary but have forgotten to push/check-in modifications from my laptop?
Also how should I setup Bazaar so that others can easily join the project in the future? I dont like using a service like launchpad, and would like my stationary to be the server. Is it not a bit risky to do it through ssh because I would have to create a new user account on my stationary each time a new user wants to join in?
Thoughts? Comments? It would be appreciated.

On the first question, you should consider using "checkouts", also called bound branches. That makes bzr behave more like svn in that every commit automatically goes to the "server" and you can't forget to push. Of course, bzr can't really detect if you forget to commit something.
On the second question, you can set up a bzr server that runs over HTTP/DAV and uses the web server's authentication methods. However, if you don't really like other people using your machine as a server, you might want to consider using a totally distributed approach, where your codevelopers publish their own branches and you pull in the things you want.
The Bazaar documentation is quite good and has the details on these topics.

Related

GitHub + Eclipse Workflows

I am sure this is a RTFM thing, but after a few days of research I still cannot determine the correct (or best) workflow for this.
I have an Eclipse Workspace with a number of Java Projects in it and a number of C++/Arduino projects.
I want to start using GitHub as an online repository (easily reachable from outside my private LAN dev environment) for my projects
I was thinking I would like a separate C++/Arduino and Java GitHub repos. More could come for Python, PowerShell, etc. (But I will happily entertain other recommendations for repo structures).
Outside of the actual mechanics of using Egit, I cannot figure out the most appropriate workflow/folder structure for accomplishing this. Should I create local Git repos and push to GitHub as a remote? Should I use GitHub's web interface to import the entire Eclipse Workspace? Should I work directly with the Eclipse Workspace or have separate Git folders?
I guess the crux of my problem is that after reading a few related posts on this site I get conflicting advice about creating a local repo from the Eclipse workspace vs. a separate local repo. I think I need to understand this distinction first before I ultimately determine the best overall workflow.
I apologize for the broad nature of this question, but I hope that the community can help me narrow the workflow process design (or the question itself).
Two things up front:
Never put your entire workspace in source control; projects: yes, workspace: no. The .metadata folder contains data specific to that location and your machine, and that's ignoring any potential security risks with making it public.
eGit works with your git clones' own metadata, so if you're more comfortable doing certain things from the command line, go for it. I know I am, but I still appreciate the UI and decorations that eGit provides. Just make sure any automatic refresh/update preferences on the Workspace or Git preference pages are turned on.
You probably want the repository to contain multiple projects, rather than having a separate repository for each one. That way histories and changes that belong together are together. Nest the layout however you like, but remember that you're not constrained to a single repository for everything, either.
I don't know that there's a best practice for this, especially with projects that already exist, but projects should themselves be relocatable. My recommendation, after backing it all up:
Make the Github projects, clone their repos locally. I do it this way, from the command line, to save me any headaches with the history, remotes, and refs. I don't think you can modify the repository metadata in this method, though.
Move the workspace projects into the local clone. You can delete them from the workspace (be sure not to delete the underlying files), physically move the directories while outside of Eclipse, and then import them as projects back in from the Git Repositories View--unless they're Maven projects, in which case it's better to use M2E's import wizard.
Stage, commit, and push the projects up to the remote origin. For Java projects, don't forget to set the JRE System Library in the Java Build Path to use an Execution Environment. It's a simple bit of indirection that makes them more portable across machines.

Struggling with managing my eclipse workspace and what to do about syncing it between two machines

I'm trying to sync my workspace with PC<---->Laptop. PC is windows, the laptop is ubuntu Linux. Both have 5.1 Mars eclipse version.
So far I've been using dropbox to sync in between but problems started occurring but managed to solve them. I was compiling classes with a newer version of java and the other eclipse didn't know what to do. Syncing with dropbox is really not an elegant way of doing this.
So now I'm trying out git, but so far I've been confused by it and how it works. I have managed to set the git plugin in the eclipse but not sure what to do next. The plugin is called EGit.
As far as I understand so far, it works like this? workspace--->local repo---->git repo? Then I would have to manually sync the code back on my laptop by entering the commands in terminal?
I already did push some stuff to my private repository, but that was on my laptop.
Is it possible to setup an easy way to sync the code? I know git is a good versioning system and a good way to keep the code updated? I'm a first year CS student and so far I don't have any complicated or large projects to manage with. I'm just looking for a nice way to sync the code. I guess having git setup is an ok way to go about it, but I'm overwhelmed by the features of git and not really grasping it.
Thanks for reading.
It would be a good idea to learn how to do it right. It's a better investment of your time than working on workarounds which only work in a certain situation or which are of limited use. Yes, you could use git for that. You do not really need the EGit plugin, just use the git command line, in my opinion that is easier. There are a bunch of great git tutorials out there. For the beginning the basic commands like git init, clone, pull, status, diff, add, commit, push are sufficient. You would need a central git repository, get a free GitHub account for that purpose.
Compiled classes should not be commited into your source repository. Add folders with any generated files to your .gitignore file.

Version Control for School Project

we will be doing a project for our Object Oriented Software Eng. class, and our team consists 4 people, including myself. Our groups were made random, so I do not know their level of skills. Maybe they have never heard of version control. I am looking for a system that will allow us to work together. I have used SVN and Git for a very little time. However, I am not very confident with them. Can you suggest a nice and easy to use system that is compatible with Eclipse or NetBeans IDE? Simplicity is the most important thing and I do not know how to use Git or SVN for a project more than one people. (I have only used them individually)
You need to have some kind of Source control.
If you have used SVN/GIT in your own projects using it in a team is just as easy. SVN is easiest, however even though it is a little harder I would go for mercurial with tortoiseHG, hosted for free at bitbucket.
It will Integrate into the windows UI
Its distributed which will make things smoother and reduce merge issues
You get free private hosting
You can use tortoise SVN or VSS (Visual source safe) to maintain project among multiple peoples. In both tool, you can maintain local copy of project in your PC and commit your changes on server when it completes.
Version control tools comparision : http://en.wikipedia.org/wiki/Comparison_of_revision_control_software
Have a look at Mercurial. It is easy to use and portable (it's written in Python). If you use Windows, you will probably find TortoiseHG useful too, as it provides Explorer extensions for mostly all functions Mercurial supports. There are also many sites that provide free project hosting for this VCS, such as BitBucket. And here is a nice tutorial about Mercurial.
EDIT: I once found a Mercurial plug-in for Eclipse. You can find it by searching in Help > Install Software in Eclipse.
I have used Dropbox as source control in a project once, it worked ok you can also revert to old version of your files which is great, we didn`t have to work in the same files so there was no conflict.
But now that I have gotten used to svn and mercurial I would never use something else. I too would recommend using mercurial with tortoiseHg and a bitbucket acount. I have started using it for smaller project as well, I simply did a repository with all of them in it so I have at least a backup and I am able to revert to an old version if need be.
My recommandation is to avoid sharing a folder using tools like dropbox and use a real source control like mercurial hosted on bitbucket (free for project with less than 4 users).
I'd say using SVN or GIT is a bit over kill for a school project which is likely to not last that long.
Another option would be to use something like DropBox.

How can I (externally) automate or script the creation and duplication of projects in Eclipse?

I work on several different projects which use feature branches; that is to say, each feature is implemented on an independent branch. I frequently need to switch between branches rapidly, or test different branches against each other (to see if a branch introduces test failures, or to use a client program in one branch against a server program in a different branch).
Practically speaking, in Eclipse, this means that I need to have a project in my workspace for each different branch.
I already have a little external Python script that creates the .project and .pydevproject files, but I still have to click on "File", "Import", "Existing Projects Into Workspace", "Browse", then select the file, then "Finish". Finally I have to wait for Eclipse to re-scan all of the "new" source code, even though it's the same as every other copy of this project that I have in my workspace.
I would like to automate any of these steps that I can. Is there a way to connect to Eclipse from a script and tell it to invoke this functionality?
If I understand correctly, IMHO your best option is to keep separate workspaces with the different branches and to skip between them. There are tools that can assist in syncing preferences between the workspaces.
Scripting in Eclipse is still a challenge. There are some plugins that provide some basic functionality, but nothing official or commonly used.
Another option is to control Eclipse form a Script in the operating system level. It depends on which platform you use.
If you are really into getting your hands dirty, those actions can be performed by a plugin. You can write one yourself, but there's some major coding effort involved here.

How to actually use a source control system?

So I get that most of you are frowning at me for not currently using any source control. I want to, I really do, now that I've spent some time reading the questions / answers here. I am a hobby programmer and really don't do much more than tinker, but I've been bitten a couple of times now not having the 'time machine' handy...
I still have to decide which product I'll go with, but that's not relevant to this question.
I'm really struggling with the flow of files under source control, so much so I'm not even sure how to pose the question sensibly.
Currently I have a directory hierarchy where all my PHP files live in a Linux Environment. I edit them there and can hit refresh on my browser to see what happens.
As I understand it, my files now live in a different place. When I want to edit, I check it out and edit away. But what is my substitute for F5? How do I test it? Do I have to check it back in, then hit F5? I admit to a good bit of trial and error in my work. I suspect I'm going to get tired of checking in and out real quick for the frequent small changes I tend to make. I have to be missing something, right?
Can anyone step me through where everything lives and how I test along the way, while keeping true to the goal of having a 'time machine' handy?
Eric Sink has a great series of posts on source control basics. His company (Sourcegear) makes a source control tool called Vault, but the how-to is generally pretty system agnostic.
Don't edit your code on production.
Create a development environment, with the appropriate services (apache w/mod_php).
The application directory within your dev environment is where you do your work.
Put your current production app in there.
Commit this directory to the source control tool. (now you have populated source control with your application)
Make changes in your new development environment, hitting F5 when you want to see/test what you've changed.
Merge/Commit your changes to source control.
Actually, your files, while stored in a source repository (big word for another place on your hard drive, or a hard drive somewhere else), can also exist on your local machine, too, just where they exist now.
So, all files that aren't checked out would be marked as "read only", if you are using VSS (not sure about SVN, CVS, etc). So, you could still run your website by hitting "F5" and it will reload the files where they currently are. If you check one out and are editing it, it becomes NOT read only, and you can change it.
Regardless, the web server that you are running will load readonly/writable files with the same effect.
You still have all the files on your hard drive, ready for F5!
The difference is that you can "checkpoint" your files into the repository. Your daily life doesn't have to change at all.
You can do a "checkout" to the same directory where you currently work so that doesn't have to change. Basically your working directory doesn't need to change.
This is a wildly open ended question because how you use a SCM depends heavily on which SCM you choose. A distributed SCM like git works very differently from a centralized one like Subversion.
svn is way easier to digest for the "new user", but git can be a little more powerful and improve your workflow. Subversion also has really great docs and tool support (like trac), and an online book that you should read:
http://svnbook.red-bean.com/
It will cover the basics of source control management which will help you in some way no matter which SCM you ultimately choose, so I recommend skimming the first few chapters.
edit: Let me point out why people are frowning on you, by the way: SCM is more than simply a "backup of your code". Having "timemachine" is nothing like an SCM. With an SCM you can go back in your change history and see what you actually changed and when which is something you'll never get with blobs of code. I'm sure you've asked yourself on more than one occasion: "how did this code get here?" or "I thought I fixed that bug"-- if you did, thats why you need SCM.
You don't "have" to change your workflow in a drastic way. You could, and in some cases you should, but that's not something version control dictates.
You just use the files as you would normally. Only under version control, once you reach a certain state of "finished" or at least "working" (solved an issue in your issue tracker, finished a certain method, tweaked something, etc), you check it in.
If you have more than one developer working on your codebase, be sure to update regularly, so you're always working against a recent (merged) version of the code.
Here is the general workflow that you'd use with a non-centralized source control system like CVS or Subversion: At first you import your current project into the so-called repository, a versioned storage of all your files. Take care only to import hand-generated files (source, data files, makefiles, project files). Generated files (object files, executables, generated documentation) should not be put into the repository.
Then you have to check out your working copy. As the name implies, this is where you will do all your local edits, where you will compile and where you will point your test server at. It's basically the replacement to where you worked at before. You only need to do these steps once per project (although you could check out multiple working copies, of course.)
This is the basic work cycle: At first you check out all changes made in the repository into your local working copy. When working in a team, this would bring in any changes other team members made since your last check out. Then you do your work. When you've finished with a set of work, you should check out the current version again and resolve possible conflicts due to changes by other team members. (In a disciplined team, this is usually not a problem.) Test, and when everything works as expected you commit (check in) your changes. Then you can continue working, and once you've finished again, check out, resolve conflicts, and check in again. Please note that you should only commit changes that were tested and work. How often you check in is a matter of taste, but a general rule says that you should commit your changes at least once at the end of your day. Personally, I commit my changes much more often than that, basically whenever I made a set of related changes that pass all tests.
Great question. With source control you can still do your "F5" refresh process. But after each edit (or a few minor edits) you want to check your code in so you have a copy backed up.
Depending on the source control system, you don't have to explicitly check out the file each time. Just editing the file will check it out. I've written a visual guide to source control that many people have found useful when grokking the basics.
I would recommend a distributed version control system (mercurial, git, bazaar, darcs) rather than a centralized version control system (cvs, svn). They're much easier to setup and work with.
Try mercurial (which is the VCS that I used to understand how version control works) and then if you like you can even move to git.
There's a really nice introductory tutorial on Mercurial's homepage: Understanding Mercurial. That will introduce you to the basic concepts on VCS and how things work. It's really great. After that I suggest you move on to the Mercurial tutorials: Mercurial tutorial page, which will teach you how to actually use Mercurial. Finally, you have a free ebook that is a really great reference on how to use Mercurial: Distributed Revision Control with Mercurial
If you're feeling more adventurous and want to start off with Git straight away, then this free ebook is a great place to start: Git Magic (Very easy read)
In the end, no matter what VCS tool you choose, what you'll end up doing is the following:
Have a repository that you don't manually edit, it only for the VCS
Have a working directory, where you make your changes as usual.
Change what you like, press F5 as many times as you wish. When you like what you've done and think you would like to save the project the way it is at that very moment (much like you would do when you're, for example, writing something in Word) you can then commit your changes to the repository.
If you ever need to go back to a certain state in your project you now have the power to do so.
And that's pretty much it.
If you are using Subversion, you check out your files once . Then, whenever you have made big changes (or are going to lunch or whatever), you commit them to the server. That way you can keep your old work flow by pressing F5, but every time you commit you save a copy of all the files in their current state in your SVN-repository.
Depends on the source control system you use. For example, for subversion and cvs your files can reside in a remote location, but you always check out your own copy of them locally. This local copy (often referred to as the working copy) are just regular files on the filesystem with some meta-data to let you upload your changes back to the server.
If you are using Subversion here's a good tutorial.
Depending on the source control system, 'checkout' may mean different things. In the SVN world, it just means retrieving (could be an update, could be a new file) the latest copy from the repository. In the source-safe world, that generally means updating the existing file and locking it. The text below uses the SVN meaning:
Using PHP, what you want to do is checkout your entire project/site to a working folder on a test apache site. You should have the repository set up so this can happen with a single checkout, including any necessary sub folders. You checkout your project to set this up one time.
Now you can make your changes and hit F5 to refresh as normal. When you're happy with a set of changes to support a particular fix or feature, you can commit in as a unit (with appropriate comments, of course). This puts the latest version in the repository.
Checking out/committing one file at a time would be a hassle.
A source control system is generally a storage place for your files and their history and usually separate from the files you're currently working on. It depends a bit on the type of version control system but suppose you're using something CVS-like (like subversion), then all your files will live in two (or more) places. You have the files in your local directory, the so called "working copy" and one in the repository, which can be located in another local folder, or on another machine, usually accessed over the network. Usually, after the first import of your files into the repository you check them out under a working folder where you continue working on them. I assume that would be the folder where your PHP files now live.
Now what happens when you've checked out a copy and you made some non-trivial changes that you want to "save"? You simply commit those changes in your working copy to the version control system. Now you have a history of your changes. Should you at any point wish to go back to the version at which you committed those changes, then you can simply revert your working copy to an older revision (the name given to the set of changes that you commit at once).
Note that this is all very CVS/SVN-specific, as GIT would work slightly different. I'd recommend starting with subversion and reading the first few chapters of the very excellent SVN Book to get you started.
This is all very subjective depending on the the source control solution that you decide to use. One that you will definitely want to look into is Subversion.
You mentioned that you're doing PHP, but are you doing it in a Linux environment or Windows? It's not really important, but what I typically did when I worked in a PHP environment was to have a production branch and a development branch. This allowed me to configure a cron job (a scheduled task in Windows) for automatically pulling from the production-ready branch for the production server, while pulling from the development branch for my dev server.
Once you decide on a tool, you should really spend some time learning how it works. The concepts of checking in and checking out don't apply to all source control solutions, for example. Either way, I'd highly recommend that you pick one that permits branching. This article goes over a great (in my opinion) source control model to follow in a production environment.
Of course, I state all this having not "tinkered" in years. I've been doing professional development for some time and my techniques might be overkill for somebody in your position. Not to say that there's anything wrong with that, however.
I just want to add that the system that I think was easiest to set up and work with was Mercurial. If you work alone and not in a team you just initialize it in your normal work folder and then go on from there. The normal flow is to edit any file using your favourite editor and then to a checkin (commit).
I havn't tried GIT but I assume it is very similar. Monotone was a little bit harder to get started with. These are all distributed source control systems.
It sounds like you're asking about how to use source control to manage releases.
Here's some general guidance that's not specific to websites:
Use a local copy for developing changes
Compile (if applicable) and test your changes before checking in
Run automated builds and tests as often as possible (at least daily)
Version your daily builds (have some way of specifying the exact bits of code corresponding to a particular build and test run)
If possible, use separate branches for major releases (or have a development and a release branch)
When necessary, stabilize your code base (define a set of tests such that passing all of those tests means you are confident enough in the quality of your product to release it, then drive toward 0 test failures, i.e. ban any checkins to the release branch other than fixes for the outstanding issues)
When you have a build which has the features you want and has passed all of the necessary tests, deploy it.
If you have a small team, a stable product, a fast build, and efficient, high-quality tests then this entire process might be 100% automated and could take place in minutes.
I recommend Subversion. Setting up a repository and using it is actually fairly trivial, even from the command line. Here's how it would go:
if you haven't setup your repo (repository)
1) Make sure you've got Subversion installed on your server
$ which svn
/usr/bin/svn
which is a tool that tells you the path to another tool. if it returns nothing that tool is not installed on your system
1b) If not, get it
$ apt-get install subversion
apt-get is a tool that installs other tools onto your system
If that's not the right name for subversion in apt, try this
$ apt-cache search subversion
or this
$ apt-cache search svn
Find the right package name and install it using apt-get install packagename
2) Create a new repository on your server
$ cd /path/to/directory/of/repositories
$ svnadmin create my_repository
svnadmin create reponame creates a new repository in the present working directory (pwd) with the name reponame
You are officially done creating your repository
if you have an existing repo, or have finished setting it up
1) Make sure you've got Subversion installed on your local machine per the instructions above
2) Check out the repository to your local machine
$ cd /repos/on/your/local/machine
$ svn co svn+ssh://www.myserver.com/path/to/directory/of/repositories/my_repository
svn co is the command you use to check out a repository
3) Create your initial directory structure (optional)
$ cd /repos/on/your/local/machine
$ cd my_repository
$ svn mkdir branches
$ svn mkdir tags
$ svn mkdir trunk
$ svn commit -m "Initial structure"
svn mkdir runs a regular mkdir and creates a directory in the present working directory with the name you supply after typing svn mkdir and then adds it to the repository.
svn commit -m "" sends your changes to the repository and updates it. Whatever you place in the quotes after -m is the comment for this commit (make it count!).
The "working copy" of your code would go in the trunk directory. branches is used for working on individual projects outside of trunk; each directory in branches is a copy of trunk for a different sub project. tags is used more releases. I suggest just focusing on trunk for a while and getting used to Subversion.
working with your repo
1) Add code to your repository
$ cd /repos/on/your/local/machine
$ svn add my_new_file.ext
$ svn add some/new/directory
$ svn add some/directory/*
$ svn add some/directory/*.ext
The second to last line adds every file in that directory. The last line adds every file with the extension .ext.
2) Check the status of your repository
$ cd /repos/on/your/local/machine
$ svn status
That will tell you if there are any new files, and updated files, and files with conflicts (differences between your local version and the version on the server), etc.
3) Update your local copy of your repository
$ cd /repos/on/your/local/machine
$ svn up
Updating pulls any new changes from the server you don't already have
svn up does care what directory you're in. If you want to update your entire repository, makre sure you're in the root directory of the repository (above trunk)
That's all you really need to know to get started. For more information I recommend you check out the Subversion Book.