6

I have my current sublime-text-2 "Packages/User" folder in a git repo (on github)

How do I clone it into an existing folder "Application Support/Sublime Text 2" now that I am on a new computer?

Here is the repo:
http://github.com/andxyz/sublime-text-2-configs

Here is the existing folder on the new computer:

cd /Users/andxyz/Library/Application\ Support/Sublime\ Text\ 2/Packages/User
andxyz
  • 3,848
  • 2
  • 18
  • 18

3 Answers3

6

The following worked for me on an OSX mavericks 1.9.2 machine (after I got my github ssh clone stuff working) I did this:

git clone git@github.com:andxyz/sublime-text-2-configs.git ~/temp-sublime-text-2-configs
mv ~/temp-sublime-text-2-configs/.git ~/Library/Application\ Support/Sublime\ Text\ 2/.git
rm -rf ~/temp-sublime-text-2-configs
cd ~/Library/Application\ Support/Sublime\ Text\ 2/
git checkout --force master

The reasoning being that we can move the hidden .git folder from our temp-repo into the existing folder. Then move to that folder and force a git checkout with --force.

andxyz
  • 3,848
  • 2
  • 18
  • 18
1

From Here: https://stackoverflow.com/a/13738951/1601989

Adjusted to your question:

What you are trying to do is called a sparse checkout, and that feature was added in git 1.7.0 (Feb. 2012). The steps to do a sparse clone are as follows:

cd /Users/andxyz/Library/Application\ Support/Sublime\ Text\ 2/
rm -rf Packages # to delete current files there
git init
git remote add -f origin http://github.com/andxyz/sublime-text-2-configs

This initiates an empty repository with your remote. Then do:

git config core.sparsecheckout true

Now you need to define which files/folders you want to actually check out. This is done by listing them in .git/info/sparse-checkout, eg:

echo "Packages" >> .git/info/sparse-checkout

Last but not least, update your empty repo with the state from the remote:

git pull origin master

You might want to have a look at the extended tutorial and you should probably read the official documentation for sparse checkout.

EDIT: After further pondering of why I don't really use sparse checkout anywhere I realized I use symlinks for this.

Just clone your repository and create a symlink to the dir you want.

Community
  • 1
  • 1
DavidGamba
  • 3,503
  • 2
  • 30
  • 46
  • I don't believe this is a sparse checkout scenario. I want to checkout everything that's contained in the git repo. I painstakingly setup a .gitignore so that I only get the folders I need. see https://github.com/andxyz/sublime-text-2-configs/blob/master/.gitignore notice that I used whitelisting. I think sparsecheckout is used when the git repo has more folders then you would like to checkout. In this case I want to checkout everything in the git repo. But, the directory structure already exists (causing some issues), because I installed a fresh sublimetext2 on a new machine. – andxyz Apr 24 '14 at 14:49
0

Maybe using cURL could be an alternative? Here's a one-liner:

$ cd ~/Library/Application\ Support/Sublime\ Text\ 2/; zip -r Packages-$(date +%Y%m%d%I%M%S).zip ./Packages; rm -rf ./Packages; curl -#L https://github.com/andxyz/sublime-text-2-configs/tarball/master | tar -xzv --strip-components 1 --exclude={.gitignore,README.md}

Line-by-line breakdown:

Move to where your Packages is located:

cd ~/Library/Application\ Support/Sublime\ Text\ 2/;

Create a backup zip of your existing Packages folder (optional):

zip -r Packages-$(date +%Y%m%d%I%M%S).zip ./Packages;

To keep things clean, remove existing Packages folder:

rm -rf ./Packages;

Lastly, cURL your repo's master branch and download latest tarball; ignore boilerplate files (like README) and extract files at current location:

curl -#L https://github.com/andxyz/sublime-text-2-configs/tarball/master | tar -xzv --strip-components 1 --exclude={.gitignore,README.md}

Bonus:

You could create a bash function to make this a simple one line bash function call.

mhulse
  • 4,062
  • 6
  • 28
  • 35
  • that's some excellent bash-fu. However I'm interested in continuing to use git to manage my configurations across machines. I'm not going to down vote or anything, it is just that zips are not what I myself am looking for. Still it's great work around you did there. – andxyz Apr 24 '14 at 14:43
  • No worries. I think I mis-read your original post … I see now that you're only interested in a Git solution. Well, even if you are not interested in a bash solution, maybe someone else would find it helpful. I included the `zip` part just to be safe; cURL could be useful if you are **not** worried about syncing changes **from** child machines (i.e. make changes on master computer, push to GitHub, and have other machines get latest copy). Anyway, sorry to have wasted time. :( – mhulse Apr 24 '14 at 18:41