How to set up Mercurial on Snow Leopard with Eclipse - eclipse

I'm using Eclipse with C++ plugins on my macbook, trying some practice projects to improve my skills. I'd also like to test out Mercurial and get a taste of DVCS. Unfortunately, Eclipse + Mercurial + OSX seems to be a rare enough combination that there isn't a lot of helpful documentation out there.
What I've done so far:
Installed Mercurial SCM
Installed the HgEclipse plugin
Installed GnuPG
Set path to GnuPG and hg executables in Eclipse preferences > Team > Mercurial
I know I can turn a directory into an hg repository by navigating to that directory in terminal and using
hg init
and then I can add files with
hg add
hg commit
This should give me an hg repo with my files in it. So far, so good...but now I begin to falter.
How do I get HgEclipse pointed to my repo? My synchronize view has a Mercurial option, but when I select it, the Next button is grayed out, and the Finish button doesn't do anything...
Ideally, I would like to set up two local repositories, one personal and one "team" repo, so I can really evaluate Hg as this seems to be the popular configuration. Does HgEclipse only support commits to a single repo, or can it commit to the local repo and push to the "team" repo?
Any other suggestions from DVCS vets on how best to set up my environment?

To point eclipse at your local repo there are two main ways.
File -> Import -> Mercurial -> Clone (Starting a new Project from a repo)
(right click Project) -> Team -> Share Project -> Mercurial
(see How to turn on Mercurial in existing Eclipse project ?)
When you are up and running you can Push/Pull to another repository via the Team push/pull menu item.
(right click Project) -> Team -> Pull ...
(right click Project) -> Team -> Push ...

Ran through the setup steps again, following this excellent guide and everything is now working. I had a little trouble getting my brain around the fact that the eclipse workspace is itself a repository. With that set up, I was able to commit changes and push to another repository very easily.

Related

How to synchronize Eclipse project workspace with Git-BitBucket?

I am new to Eclipse as well as Git world. Following question may sound like really dumb thing to ask, but I have spent hours finding how to do it and found no way.
We have a Git remote repository that I have cloned using Eclipse's Git perspective. My team makes some changes to code and pushes them to remote repository. I am stuck with "getting latest" code in my local workspace.
Here is what I tried:
Open Java EE perspective. Right click on my project -> Team -> Synchronize Workspace. This opens "Team Synchronizing" perspective. It shows me that there are some "incoming" files, but there is no option to "get" them. Only options I see are Merge, Overwrite, Commit. Well, none of them make sense to me.
In TFS world, I just select "get latest" and new versions replace old versions in local workspace. What am I missing?
The Synchronize View will only allow you to inspect the differences between the resources in the local workspace and a local or remote tracking branch.
It won't get the last commits.
For that, you need to pull new changes from the upstream branch
Right-click on a project in the Package Explorer and select Team > Pull or right-click on a repository in the Git Repositories view and select Pull to pull new changes from the upstream branch your local branch is tracking.
This also works if resources are selected from more than one repository.
See for instance "EGit Auto-Merge and Conflict Resolution "
To understand more about that workflow, look at GIT Illustrated Cheatsheet -- Working with remote repositories

Changing the git branch on eclipse

This is the first time I do this.
I imported a git project in eclipse.
Then I used the shell to create another branch and checkout to the new branch.
Is refreshing the imported project in Eclipse enough to tell Eclipse that we are working on the new created branch?
thanks
Right-click your project and select Team → Branch to create new branches or to switch between existing branches. You can also switch branches in the History view.
Actually, I don't think you even need to refresh the project. That is, assuming you have 'eGit' installed and your projects are already configure as git projects (they should be, because in most cases, egit does that automatically).
Whenever you run git commands on the shell (outside eclipse) egit will automatically refresh projects for you and update their status when you switch back to Eclipse.
If you are not using egit then yes, you have to refresh the projects manually, but that is all you'd have to do since running the 'git checkout my-branch' command in the shell already changed the files on disk to be those from 'my-branch'.
Actually when you are working with eclipse, eGit is a very cool tool integrated inside eclipse, which lets you do all git stuff, like
git checkout to a new branch
git create new branch
git stash
even view your unstaged changes(select files and avoid complexities caused by git add .)
and finally commit.
Read here to know more. Eclipse Egit user guide
So you get to do all version repository stuff at one place as you code.
So to answer your question, yes as you checkout a new branch even in a shell/command prompt your changes will be reflected in eclipse.

Use CVS and GIT together in Eclipse

I already have a CVS and that cvs is used to share the source among other developers. But I need to keep a track of my source code changes separately. Moving the project from cvs to git is not practicable here.. and you may think that why 2 versioning controls. Any way I need to have a separate repository. I have tried git with eclipse. It is ok. I want to know how I can use both my personal git repository and cvs together in eclipse. (For example, when I commit my changes in eclipse, Team -> commit .. How can I separately commit to both cvs and git..and whenever I need to see the history in eclipse, separately git and cvs.. .Also when CVS server is not supporting, I can work with my local git repo as well. ) I need to handle all in eclipse IDE. Any one give any tutorial or links for my solution, it is highly appreciated.
You can have a git repo directly within your sources, but Eclipse would still be set on using CVS (and cannot show you both git and cvs commands at the same time).
That means you go on committing with CVS and Eclipse, but would need to commit (locally) in Git with an external tool (either a simple command-line session, or any GUI you want, like GitHub for Windows or SourceTree)
It actually is possible, if you create a dummy Eclipse project and designate the git repository at the workspace root (.git directory at same level as all projects in the workspace). This way when you make commits from this project, all projects in the workspace are its members and you can keep the members themselves connected to cvs.
You can create such repository by first creating the dummy project, and (Team->Share) sharing it via git using the Configure Git Repository dialog. Select “Use or create repository in parent folder” and explicitly remove the project folder from the "Create Repository" line after checking (checkbox) the project from the list of available projects.
After pressing "Create Repository" the project directory suffix will reappear, but remove it again before pressing Finish. In my version of Eclipse pressing Finish will hang, and I must terminate Eclipse to restart it.
After restarting the dummy project can be used to Commit files in all the other projects while the other projects remain connected to cvs.
Screenshot of “Use or create repository in parent folder” view when pathname has been entered by pressing "Create Repository" and then (corrected again before pressing) Finish.

How do I configure Eclipse to use an existing git repository with existing source code?

I have Eclipse Juno with EGit and a project that I've been working on for a while. I've decided to move it to Git, so I created a Github account and downloaded and installed the program. The repository is at C:\Users\username\GitHub\project_name\, but all it has is the README.md file.
How can I configure Eclipse to use my existing source code (in a workspace separate from the git folder) to work well with git? I've tried using Window → Show View → Other and selecting "Git Repositories," but other than adding a repository (which I have done) I can't figure out how to sync the code.
I've read this question but I get the impression that those answers will perform a one-time commit, instead of a sync.
To clarify: The repository does not have any code. I would like my existing code (in the Eclipse workspace) to be synced to the new repository.
If you already have a git repository in place, first copy all your files to that directory (yes, manually) and do a git commit -a to commit all the files into the repository. I'm assuming here that you've already initialized the repository at C:\Users\username\GitHub\project_name\ with git init.
In eclipse, go to File → Switch Workspace → Other... and point it to a workspace of your choice that can be completely different than the location of your code, or your earlier workspace. In fact, don't point it to the directory which contains your git repository.
Once you have a clean workspace, go to File → New → Other..., select Git → Git Repository and enter the path of your git repository (C:\Users\username\GitHub\project_name\). Enter a name for the repository, and click Finish.
I would really recommend you read at least the first few chapters of the git book to understand how git works, and to help you push and pull code to and from remote repositories.
If your existing repository is not git, you're going to have a hard time keeping the directories in sync. You might want to setup rsync to sync the directories. There is no way AFAIK for eclipse to automagically keep the two repositories in sync.

Git, SVN and Eclipse workflow

I am trying to adopt the following workflow:
git svn clone a svn repository through command line (egit doesn't support git-svn)
Open the project in eclipse with egit since I rather use egit to branch, merge, commit etc...
When i'm ready commit the changes back, I use use git svn dcommit to commit back to svn
I am having trouble with step number 2, don't understand how to import a git project, eclipse tells me i can't import it to use the same directory it's currently in because another project with the same name is already there. this is confusing.
Anyone knows how to do this ?
Also would like to hear other workflow examples that uses egit and git svn. I am aware that it is better to do it all through command line, however, I am trying to ease the move to git for fellow developers in my team, who are not used to command line interface etc...
I've worked briefly with the egit plugin (I actually recently stopped using it and just use msysgit as my Git guiclient and run it separately from Eclipse). I find Eclipse very busy as is and adding this plugin slows it down (for me at least).
What I did when setting up an already cloned project in Eclipse:
In Eclipse. File -> Import -> Existing Project into Workspace
Select root directory of project. Do NOT check copy projects into workspace. Click finish.
After project has been imported. Right click on project, go to Team -> Share Project
Select Git as a repo type, click next
Check use or create repo in parent folder of project. Since you already cloned the project it will be tracked with git. When you check this option it will show the project, the path, and the repo (.git).
Click finish and you will be all set.
I think you'd better use SubGit instead of git-svn.
SubGit works on a server side. It synchronizes all the modification between Subversion and Git repositories automatically on every incoming modification from either side.
From the client perspective SubGit enabled repository is a usual Git repository, so you may pull from and push to it. Please refer to SubGit documentation or SubGit vs. git-svn comparison for more details.