1

I use Ubuntu 18.04 with filesystem ext and git 2.26.0. I want to add a macOS Framework to my git repo, which fails with the following error message:

$ git add -f /var/opt/project1/Foo.framework/Headers/Interior.h
fatal: pathspec '/var/opt/project1/Foo.framework/Headers/Interior.h' is beyond a symbolic link

The root of the project is located under /var/opt/project1. This is what ls returns:

Foo.framework $ ls -l
lrwxr-xr-x  Headers -> Versions/Current/Headers
lrwxr-xr-x  Resources -> Versions/Current/Resources
drwxr-xr-x  Versions

The actual command is executed by a system service, so I need to make this work on the Ubuntu machine. Any idea what I am doing wrong?

Daniel Stephens
  • 2,371
  • 8
  • 34
  • 86
  • Some interesting info here, perhaps, not sure. https://stackoverflow.com/questions/954560/how-does-git-handle-symbolic-links – matt Mar 25 '20 at 23:04
  • Thank you! But Git seems to support symlinks, that's why I am wondering it fails on my Ubuntu machine – Daniel Stephens Mar 25 '20 at 23:08
  • I think the problem is that the symlink is to a directory, but that means nothing to git because git doesn't track directories. See https://stackoverflow.com/questions/14783847/git-file-is-beyond-a-symbolic-link for example – matt Mar 25 '20 at 23:13
  • More here https://stackoverflow.com/questions/86402/how-can-i-get-git-to-follow-symlinks It seems that the behavior in the first link I found is outdated. – matt Mar 25 '20 at 23:15
  • I'm totally ignorant, if you figure it out, you can answer your own question. :) – matt Mar 25 '20 at 23:22
  • Ok, I tried a new empty git repo and added a testfile. Then I added a macOS framework and used Visual Studio Code and commited the changes. Then I switched back to my first commit, and then back where I added the framework. The directories are properly resolved as a symlink :-( – Daniel Stephens Mar 25 '20 at 23:25
  • Thanks for your help though! Really odd – Daniel Stephens Mar 25 '20 at 23:25

1 Answers1

2

In general, you want to add files that are relative to the repository root. Git lets you add absolute paths, but only if the absolute path resolves to a file that is inside the repository root and the directory must contain no symbolic links.

You cannot add something by specifying a path that includes a symbolic link. Your directory components must be only directories, not symbolic links to directories.

If you specify a path that's relative to your repository without any symbolic link components, then it should work. If you want to add a symbolic link, you can do so, but the symbolic link itself must live within your repository, although it can point anywhere.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Thanks for your reply! `/var/opt/project1` is the root of the repo, and the symbolic link is relative, so source and destination are within the repo – Daniel Stephens Mar 26 '20 at 00:01
  • 1
    I've updated the answer. It's likely that one of your path components is a symbolic link. The thing you're adding can be a symbolic link, but your path components can't be; they have to point to the real location within your repository. – bk2204 Mar 26 '20 at 00:14