25 Latest Articles

Blog

Managing Multiple Apps in a Single Git Repository with Titanium Studio
I was very excited to hear about the recent beta release of Titanium Studio (formerly Aptana Studio), as it now gives us the ability for real live debugging!  An added bonus was integrated git support, allowing us to do stuff like view diffs, blames, commit, push and pull, right from the IDE. 

One thing I ran across, however, is if the Titanium project is not in the root directory of the git repository, then Studio won't see the app project, and not be able to run from within the IDE.

This can occur, if like me, you have a git repository that contains multiple Titanium projects, each in their own sub directories within the repository.  For example, if you have a directory structure like this:
GitRespository/
GitRespository/AppProject1/
GitRespository/AppProject2/
If we clone this repository locally using Titanium Studio, then the Run and Debug Configurations won't see the project files located in AppProject1 and 2. 

This is a reported issue (login may be required), and hopefully there will be a fix soon, as this git repository setup is not unique, and is even used in git repositories such as Appcelerator's popular Tweetanium project.

In the meantime, here's a simple workaround.  We'll even use the Tweetanium project mentioned above for our example.

Workaround

I'm assuming you have the following stuff:


Step One: Clone the git repository somewhere outside of the Titanium Studio Workspace

To do this, we will need to use git terminal commands.  Again, use the links above for general help with git setup and use.

1) In a terminal window, navigate to where you want the repository located.  Important: Do not place the repository inside of the Titanium Studio Workspace directory.  Stuff will break if that happens.

So, I do:
cd dev/gitrepositories
2) Issue the git command to clone the remote repository. We are using the Tweetanium project for the example.
git clone git://github.com/appcelerator/tweetanium.git
You should get some stuff that looks like:
Cloning into tweetanium...
remote: Counting objects: 298, done.
remote: Compressing objects: 100% (199/199), done.
remote: Total 298 (delta 88), reused 272 (delta 76)
Receiving objects: 100% (298/298), 1.20 MiB | 341 KiB/s, done.
Resolving deltas: 100% (88/88), done.
You can now see the tweetanium respository located in your directory, such as /dev/gitrespositories/tweetanium. 

Step Two: Import the Individual App projects into Titanium Studio

Now we have our respository cloned, we need to fire up Titanium Studio and import the individual app projects so we can run them.  First, we'll need to check the git settings in Studio.

1) In Studio, open Preferences from the Toolbar, and navigate to Team > Git.  Make sure there is a check next to: "Automatically attach our git support to projects added that have git repositories".  Click Apply to save and close Preferences window.

2) Next, go to File > Import...

3) Select Titanium > Import Existing Titanium Project  (note: we are not selecting Git Repository here.  We'd use that if we are using a repository that doesn't have multiple app projects in it.)  Click Next.

4) Now, we need to browse to the app project directory.  I am going to:

/Dev/gitrepositories/tweetanium/mobile/Tweetanium

Wow, did you notice that the app project was not one, but two subdirectories deep?  That wouldn't work for us.

5) When we click Finish, the project gets imported (it actually stays in the same place on our filesystem, but now Studio knows where it is and has associated a project for it).

In App Explorer, we see the Tweetanium project loaded up, and the git options are available to us, such as the branch dropdown [master * ].




We will also be able to use the other context menu options, such as pull, push, diff, etc.

Conclusion

In addition to having git source management functionality tracking our project from inside Studio, we can now set up and use the Debug and Run Configurations to build and test our app as normal.  You've got that figured out, so no need to go over it here.

Also, if you have multiple projects, you should now be able to repeat the steps above to load those projects as well*, and Studio / git will take care of the rest.

Issues

*You may have noticed one thing that has come up in this very example: if you have a project setup like Tweetanium, with multiple app projects housed under a couple of subdirectories with the last level of directories named the same, such as mobile/Tweetanium, ipad/Tweetanium, etc., then when you try to import the second project, Studio will balk, saying that there is already a project named 'Tweetanium'. 

I haven't found a way to specify or change the project name, so if your directories are named like this, I guess we are out of luck for now.

Comments

Mark L. Smith
Mark L. Smith
Thank you for this important post, Adam. NUB questions to clarify the distinction between Titanium projects, Git projects and Git repositories.

The Tweetanium Appcelerator project builds three applications (desktop, mobile & iPad). You seem to see these as three Appcelerator projects (each with its own .project dir, separate import into Appcelerator, and rename, since the bug prevents all three from having the same name). One Git repo is cloned, and three projects imported, right?

I see one Git repo, one Tweetanium Appcelerator project (and .project dir), and three ways to build/deploy the one app. Am I just being naive?

When I start a completely different Appcelerator project for triple application deployment, am I creating another Git repository and importing it to create Appcelerator .project(s)? Or can I add the new Git project to the existing Git repo?

Hope I've been clear and appreciate the adGUIDANCEvance.
~mark->
Mark L. Smith
Mark L. Smith
Ahh. Just answered one question myself: Can't make the top-level tweetanium dir a project because it lacks a tiapp.xml. So you MUST have three projects (with the same name).

Having trouble getting a big picture view of multiple apps (with multiple deployment version and therefore projects), and multiple Git repos.

What does this many-to-many relationship look like?
~mark->
Adam Paxton
Hey Mark,

Thanks for the comments. A couple of things to note:

- Mobile and iPad can now be the same project along with iPhone, Android, Blackberry (beta), etc. This wasn't the case when Tweetanium was released.

- If you are just starting your project and are putting together the repository for the first time, I recommend avoiding this whole problem and keep your mobile and desktop projects in separate repositories. I know it kind of sucks if you are using an online repository site that charges by repository, but it does let you get around this issue completely. This wasn't an option for me as I was already in the middle of a large project with the repo structured this way, which is why I had to figure out a workaround.

If that doesn't work for you, then your top level directory in the repo should contain 2 folders with different names, like MyMobileProject and MyDesktopProject, and the respective project files should be directly within. This avoids the problem I pointed out in the footnote about having the last level of directories with the same name.

- You can mostly ignore the .project file, as it isn't used by the actual Titanium project. Instead, it is auto-generated by Titanium Studio (which is based on Aptana, which, in turn, is based on Eclipse). I usually add .project to .gitignore file to keep it out of the repo.
Adam Paxton
Update to my previous comment: yes, you probably do need to leave the .project file in the repo. I recently ran into an issue with Ti Studio where it wasn't letting me run or debug a project, and it turns out, the generated .project file was missing some stuff.

Post Comment

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above: