1

I'm very new to git, and still trying to wrap my head around some of the ways it does certain things as opposed to svn, and I'm wondering whether or not what I'm attempting to do is even possible. I'm trying to create a repository for an Arduino project that will include several Arduino "sketches", as well as multiple libraries. Some of these libraries I will be writing, and some come from other, existing repositories belonging to other people, which are dependencies for the code I'll be writing. The local folder structure for Arduino projects works like this:

~/Arduino
 +libraries
   +MyLib1/[lib files]
   +MyLib2/[..]
 +MySketch1/MySketch1.ino
 +MySketch2/MySketch2.ino

(SketchName.ino is just the Arduino naming convention for what is basically main.cpp)

Now, the repositories I've looked at vary in their structure. Some contain the Arduino folder within their top level, some map their top level to the Arduino folder, and some only contain libraries, and map their top level to Arduino/libraries. Is there any way to combine these multiple repositories into my own, keeping the links to the original repositories? I've looked into submodules, but it appears that those only work within their own subdirectories, which wouldn't work for me, because I need the local folder structure to contain all sketches in the same ~/Arduino folder, and all libraries within the ~/Arduino/libraries folder.

So I want to have the above folder structure coexist with another repo containing:

libraries
 +YourLib1/[..]
 +YourLib2/[..]
YourSketch/YourSketch.ino

And a third repo containing:

AnotherRandomLib/[..]

such that the end result is a single repo that looks like this;

~/Arduino
 +libraries
   +AnotherRandomLib/[..]
   +MyLib1/[..]
   +MyLib2/[lib files]
   +YourLib1/[..]
   +YourLib2/[..]
 +MySketch1/MySketch1.ino
 +MySketch2/MySketch2.ino
 +YourSketch/YourSketch.ino

Can this be done, or if not, what would be considered "best practices" for referencing other people's code from within your repo? Just add the files to the repo (simple, bulletproof, but breaks linking to the original repo, losing the ability to pull in updates, and also causes loss of attribution)? Leave them out of the repo and leave it to the user to find and download those other libraries separately (not at all a good solution)? Any ideas?

qwertymodo
  • 435
  • 7
  • 16
  • yep, submodules will give you this functionality, but they can be a hassle to manage. if the arduino ecosystem has some sort of package management, I'd go that direction instead. If not, and you will not be editing the code inside the other sketches, yah, submodules will work – Jed Schneider Dec 06 '13 at 00:51
  • But can I check out 2 submodules into the same directory? I got the impression that a submodule needs to be checked out into its own subdirectory, which wouldn't work here. The Arduino ecosystem doesn't have any nice features like package management, it just has a single folder within your user directory that is treated like it's in the same folder as the Arduino install directory (i.e. user libraries in ~/Arduino/libraries/MyLib are treated the same as if they were in $(ARDUINOPATH)/libraries), but you are limited to that one directory ~/Arduino or else your libs aren't found. – qwertymodo Dec 06 '13 at 00:59
  • ah, yah. that wouldn't work. they need to be separate subdirectories. sorry, sounds like you're stuck in the same word as JavaScript was for the last couple decades: copy and paste :/ Guess you could always write a package management system for arduino. – Jed Schneider Dec 06 '13 at 01:02
  • It's too bad Windows doesn't support real symbolic linking. Otherwise, I could check out submodules into their own directory and symlink them in the main source tree. Edit: actually, I'm finding references to Windows Vista/7 actually supporting symlinks... I'll have to look into it. – qwertymodo Dec 06 '13 at 01:13
  • virtual box ... :trollface: – Jed Schneider Dec 06 '13 at 01:17

1 Answers1

0

Considering that submodules always exist in their own folder, your structure would work if each of the directories you want in "libraries" was a git repo (that could then be referenced as a submodule in a parent repo).

Otherwise, you have to deal with symlinks, which do exist in Windows: read "Git Symlinks in Windows".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250