Issue with Source Tree not finding sub-directories
Asked by MIke Neill:

Hi, I have an Xcode project where I added the library RestKit as a sub-directory of my project. The issue I'm seeing is that SourceTree will not recongize the new directory at all in my working copy. Do you guys have any thoughts on why this would happen?


Answers:
author: Dan Bishop
body: For what its worth, I just experienced the same issue on my machine. I dragged \& dropped a folder that contained some .h and .m files, plus a Readme.md file into my Xcode project (using Finder), then added the files to my project (within Xcode).

SourceTree was completely unaware of any file inside the sub-folder that I had added. This could have caused a serious issue for me, as I thought all my files were committed to the index and pushed to GitHub. I only discovered the problem after deleting and re-cloning my repo (which I did for an unrelated reason).

I tried the usual CMD+R, changing the UI to Show All, Show Uncommitted, etc, but nothing worked. I verified that my .gitignore had nothing even remotely close to the files/folder that I had added.

The one thing I will say is that the folder I copied in was originally setup as a separate repository in SourceTree. Is it possible that SourceTree thought the files were part of a sub-module/sub-repository, and tried to "helpfully" prevent them from being added to the index?

comments: author: stevestreeting
body: Yes, if you have a .git folder in any subfolder, git will totally ignore it because it considers that whole tree to be a nested repository that looks after its own files. This isn't a SourceTree feature, this is something git always does when you use 'git status' (and hg does the same FWIW).

So if you copy files around that you intend to add to a repo (rather than as a submodule), it's really important not to copy any .git or .hg folders with it. Can be tricky I know, since Finder doesn't show them by default and will implicitly take them if you copy the parent folder.


author: Alexei Akimov
body: This is what solved it for me. I had buried .git files inside folders which I dragged-in. After doing "ls -la" to show all files, and doing "rm -rf .git" on the unneeded git files (those inside the sub-folder, not the main .git file on the repository top level), all the new files and folders are now tracked.


author: Chris Lanning
body: Yep, buried .git folders is what killed me.


author: stevestreeting
body: This should only happen if there are no files inside the folder, or if every file was ignored by either your global ignore file, or the local ignore file.

You can use Cmd-R to force a refresh if you want to make sure that's happened, but if not it'll be that. You can check what ignored files there are in a repository by switching the file filter to 'Show Ignored' (it defaults to 'Show Pending', which includes unknown files so long as they're not ignored).

comments: author: MIke Neill
body: Ok, I have verified you guys have a bug. What I did to resolve my problem was I completely emptied the RestKit folder, then I created a simple TXT file called "readme.txt" and added it into the RestKit folder. When I did that then SourceTree started to see the RestKit directory. I then re-added all of the RestKit files back into that folder, and SourceTree saw those files as it should have done in the first place. I think there may be a logical error in the process that checks directories for files. Purhaps you guys need to take a look at that.

Thanks


author: MIke Neill
body: I tried a cmd-R refresh, and I also looked at the show ignored, but the RestKit folder isn't showing up anywhere. The RestKit folder has several sub-directories and an Xcode project file in it. I did noticed a similar issue earlier this morning when trying to add in a folder that contained two sub-folders. The sub-folders did have files, but nothing ever showed up in SourceTree. I think you guys have a bug.


author: stevestreeting
body: I've just run a test here in both Mercurial and Git:

1. Take a clean repo with no changes
2. Set the view options to 'Show Pending' and clear the Search filter box
3. In a terminal for this repo:  
   mkdir folder1  
   mkdir folder1/folder2  
   echo "Test" \> folder1/folder2/testfile.txt
4. Switch back to SourceTree

The result is an auto-refresh and a new untracked file 'testfile.txt' shows up in the folder 'folder1/folder2'.

I really do think you must have something in your ignore files which is causing this, because I can't replicate your issue here. I also use XCode projects regularly - they just look like regular folders to SourceTree, just like they do to git/hg and the terminal.


author: stevestreeting
body: Sorry, you replied while I had the page open so we overlapped.

Here's the thing - the untracked files are reported by 'git status' or 'hg status', they're not at any time queried manually by SourceTree (if we did it ourselves we have to replicate the ignore behaviour). So there's no filtering or iteration in SourceTree to fix.

I re-ran my test with a copy of RestKit instead of creating folders myself. It worked perfectly when I moved or copied the RestKit folder in, here's the video: <http://www.screencast.com/t/5XPXWCNpm>

So, I can't replicate this behaviour.


author: deelakameegoda
body: There must be a .git folder inside the directory that you've copied. Get rid of that unwanted .git folder and you'll be able to see the unstaged files in the sourcetree.


author: super0
body: Got the same issue, SourceTree didn't saw any of subfolders as "ProjectNameFolder" and "PodsFolder" inside my project folder. After trying to create new folders, move all files into them, removing unseen folders and rename new folders with default names, SourceTree started to track them with all files within. There were no filters or gitignore files or anything that could cause this issue with my preferences. Just strange standard subfolders block.