Xcode 4: Source Control options grayed out (Git local repository) - xcode

When I set up a new project in Xcode 4, and select "Create local git repository for this project," all seems well enough. I'm able to commit files from the Organizer (it would appear.) However, in the Project Manager, the "Source Control" menu options (commit, etc.) are all grayed out, except for "Repositories" which of course just takes me to the organizer.
Furthermore, in the Project Manager window, I don't see any icons by file names indicating if they're changed, committed etc. like I see in the screenshots in the Xcode 4 documentation.
I've tried this with both a project that's connected to Github, and one that's just using a local repository, and I've still yet to see those options not be grayed out. Any suggestions?

I discovered the cause of this problem is that I was saving projects in /Developer.
Turns out, that's a big no-no. Not only does it break git integration in the way described in the original question, as well as breaking other features such as Xcode 4's refactoring functionality, it also runs the risk of deleting all of your work when you install an update. Once I started saving projects outside of /Developer, all the git functions in Xcode 4 started working as expected.
Bottom line: Don't keep projects in /Developer.

This can be a bit confusing. Apples documentation here:
http://developer.apple.com/library/mac/#documentation/ToolsLanguages/Conceptual/Xcode4UserGuide/SCM/SCM.html
Has a great way to activate the source control via the command line:
To set up a Git repository from the command line . . .
Use the cd command to switch to your project folder, making it the current working directory.
Enter git init to create an empty repository.
Enter git add . to copy your project files into the repository.
Enter git commit -m "Initial commit." to commit all the files.

Related

Xcode's "branches" master is an incorrect project

I want to put my current project on GitHub, but within my Source Control Navigator, it shows Branches. After double clicking the Initial Commit within master, it's showing a different project than what is currently open on Xcode.
Eventually I want to put the Xcode project on GitHub, but even if I try, it puts whatever is in master, which is incorrect. How do I fix this?
Edit:
It took a few Terminal commands, and then I was able to go to the Source Control menu >> Commit without errors.
xcrun git config --global user.email you#whatever.com
xcrun git config --global user.name "Your Name"
This put the correct version of the project on GitHub after I created a remove. Unfortunately, my master(current) is still incorrect and it includes that on GitHub for some reason.
Here are some screenshots of my Source Control Navigator. I only want first master displayed in the root folder or remote >> origin. Within the Branches folder, the only master shown is incorrect.
I moved a hidden ".git" (system) folder outside my main project folder. I then could create a new repository within the Source Control Navigator, create a new remote and the appropriate projects are visible in GitHub.

Xcode crashes when working with repository

I have an Xcode project one local and one remote repository. Firstly, there was a problem in current version and I decided to change local repository's head using terminal. Xcode fetched everything and I continued working on the project. When I decided to commit changes, Xcode gave me an error like this: "error: src refspec (detached from ) does not match any.error: failed to push some refs to [repository address]". After, I decided to create a new remote repository and try to make initial commit of this project. I added remote to Xcode and now it crashes even if I open "remotes" tab. I use bitbucket as my remote repo.
Question: is it possible to fix this, or it is easier to copy all the contents of the project to another one and commit new one? Thanks for replies.
I had the same problem: the local git repo was created from command line (from terminal app) and not from within Xcode, Xcode would crash every time even when clicking on the remote tab. I have a different solution that may be easier:
1)Commit and Push all changes with your current project from your local Xcode-non-compatible repo
2) Re-open Xcode (close it if it's open) and select "Check out an existing project" from Xcode
*If you don't see this Xcode startup screen, go to Source Control->Check Out...
3)Select the remote repo then
4)Select a NEW directory for the checkout destination
Now you will have a project set up and compatible with Xcode!
Solved:
Create new empty project, then copy all the files from previous one. Create new repository, absolutely clean. Push there.
It seems that Xcode had a conflict when local repository's head was changed using command line and git. So, this is as warning for users who got the same situation.

Remove a file form SVN repository in XCode

I have erroneously added a file to a project in Xcode and I have pushed it to the server.
Now I want to remove it.
Does removing the file from the local project will results in removing it from the remote repository too at the first commit?
Removing the file from the Xcode project isn't going to remove the file from the repository. You have to use the Organizer if you want to remove the file from the repository in Xcode.
Open the Organizer and click the Repositories button at the top of the Organizer. Select the repository's Trunk folder from the repository list on the left side of the Organizer. Select the file you want to delete. Click the Delete button at the bottom of the Organizer to remove the file from the repository.
Subversion is like one of those Roach Motels: Files check in, but they never check out.
Once you add a file to Subversion, it's there forever. You can remove it from the current revision of the repository (via the svn rm command), but you can never remove it completely. Someone will always be able to see it in a log, and someone can access it by checking out the revision of that directory right before you removed the file.
There has been a lot of debate about this feature. Most version control systems have an obliterate command of some sort that allows you to remove a version of a file or completely remove the file from the repository. The problem is that Subversion doesn't revision files -- it revisions the entire repository.
I don't know Xcode, so I can't help you with the exact steps. However, there must be a Repository view in Xcode like there is in Eclipse or a series of subcommands that deal with the repository (much like Eclipse's Team commands). You should be able to delete the file from there, then commit your change.
That will remove the file from the latest version of the code (and future versions). However, it will still be there in the repository, so someone can find it via the history log, and then checkout the version of the repository right before you deleted the file. If this file contains your Swiss bank account number, you're in trouble.
NOTE: There is a way to remove a file completely from Subversion, but you have to shutdown the repository, dump it out, filter out the file, then load the repository dump into a new repository. It is usually not worth the effort.
You can do it from command line using svn rm filename
http://svnbook.red-bean.com/en/1.6/svn.ref.svn.c.delete.html
Deleting a file from Xcode WILL delete it from your remote repo when you commit (tested with svn).
Using Xcode 4.6.3 I deleted a file from my project. Committed, and it was in turn deleted from my remote repository. When you delete from Xcode, you must select "move to trash" when prompted what to do. If you select "delete reference" then that file will remain in your remote repository, just as it remains part of your projects files but just not referenced in the actual Xcode project.
When you commit your files, count the files that have checkmarks on them, and look at the count that Xcode reports in the bottom right corner, Xcode reports one extra file! Thats the deleted file, which means its committing that change.
Once again, before committing, go to terminal and 'cd' to the directory where you had the file that you deleted. Enter this:
svn info ./yourFilesName.txt
You will see a result that says:
Schedule: delete
which means that when you do a commit, the file will be deleted from your remote repo.
When you delete from Xcode, you must select "move to trash",and then commit the ".xcodeproj" file

Xcode thinks a remote svn repos is git

I'm running Xcode 4.1 at work and home. I've successfully checked out a project from a remote svn repository (work) on my home setup. The repos was updated, so when I got home, I did an update on the local checkout.
The status of the updated files got flagged "U" (good) and a page appeared showing changes to accept, but when I hit accept, I get a popup that says:
The working copy "ABRA-D" failed to pull. fatal: Not a git repository
(or any of the parent directories): .git
Well, yes... the repo is svn, not git! Closing Xcode and restarting removes the "U" tags and I'm back where I started. Sounds like Xcode is confused about the repo type, though it knew enough to query the svn repo and find out what had been updated. Anyone know a cure?
That issue, already mentioned in "Error : Fatal: Not a git repository (or any of the parent directories): .git", has a somewhat curious solution described here:
Recently I created a new project and at some point I uploaded it to SVN. I am not quite sure how to reproduce this situation but somehow the versioning support of Xcode 4 decided to interpret the project as a git repository.
Each time I tried to copy a file per drag and drop into my project I got following error:
fatal: Not a git repository (or any of the parent directories): .git
The result was that the file got copied into the project folder, but the reference didn't get set in the project. I had to go into the folder and drag and drop the file again and uncheck the copy option this time, so that the reference gets set.
The Solution
Open Xcode and go to Window > Organizer
Find under repositories your project. It might be two entries if you use something like SVN.
Make sure it says "Type Git"
Mark the repository entry and hit backspace or delete (on mac)
Done
In my case, when i created my project it was using git. But later i removed all git files from my SVN repository. Then took an update.
Now, when i tried to add files, it gives me same error.
Solution: I removed all repositories against my project in XCode Organizer. Now when i added new files, it works fine.
I had a git and svn against the same project and tried removing the git and got this error
In the end went and manually edited xcshareddata found at and removed all the entries which had anything to do with the git repositoy.
myproject.xcodeproj/project.xcworkspace/xcshareddata

How would you avoid "Xcode, Subversion Error: 155007 (Path is not a working copy directory)"?

I am not able to see the commit option after I make changes to my working copy, but I ensured that my settings for svn were correct.
What exactly is the problem with this error message?
Xcode is showing:
Your path is not a working copy
What should I do to resolve this?
The blog post "Xcode, Subversion Error: 155007 (Path is not a working copy directory)" and its comment are pretty much the reference on this kind of error.
Simple Workaround:
Delete your local copy (cd myxcodeproject; rm -rf .)
Delete the “build” folder from the server
svn co https://svnserver/path/trunk/project .
Now you should see .svn folders in every directory of your local project (you don’t see them if you use the “Export” function of the SCM panel from Xcode).
At this point, you should be able to edit and commit your changes directly from Xcode.
Now you need to initialize correctly the project.
The following sections illustrate that part:
How to do it right (general principle)
To place the project under Xcode, you need to first import it.
The SCM->commit entire project… gives error 155007 if you don’t first do this:
Under the SCM menu in Xcode select Repositories, then click the IMPORT icon at the top of that dialog that appears.
Select the project from the list and then click the import button.
Of course you need to first configure at least one repository before doing the steps above.
Right Initialization steps (detailed process)
Create the project in XCODE.
Setup subversion in XCODE and select the subversion repository for this project.
Use Xcode SCM > Repository and click on the IMPORT icon. This will move the local copy to the subversion repository.
Now delete your local copy (or move it to another location just in case).
Finally CHECKOUT the project from subversion (this will create the subversion .svn folders, …).
Reselect the subversion repository for this project.
Commit the entire project.

Resources