Skip to content
Christopher Dunn edited this page Jun 14, 2015 · 9 revisions

Example and test for git-sym

See https://github.com/cdunn2001/git-sym.

Testing

git-sym must be in $PATH.

Basic usage

This should explain the idea.

# This example uses a fresh check-out.
git clone https://github.com/cdunn2001/git-sym-test.git
cd git-sym-test

# We have prepared the 'links/' directory for this example.
ls -l links
## lrwxrwxrwx 1 cdunn Group   19 Jun 10 00:35 dirlink -> ../.git-sym/dirlink
## lrwxrwxrwx 1 cdunn Group   15 Jun  9 21:31 foo -> ../.git-sym/foo
## lrwxrwxrwx 1 cdunn Group   15 Jun 10 00:36 foo.alias -> ../.git-sym/foo
## drwxr-xr-x 2 cdunn Group 4096 Jun 10 00:36 sub
## lrwxrwxrwx 1 cdunn Group    4 Jun  9 21:12 unrelated -> /tmp

# The 'show' sub-command lists all symlinks in our repo.
git-sym show
## + links/dirlink .git-sym/dirlink
## + links/foo     .git-sym/foo
## + links/foo.alias     .git-sym/foo
## + links/sub/foo .git-sym/foo
## + links/sub/foo.alias .git-sym/foo
## O links/unrelated       /tmp

# The '+' means that it requires update.
# The 'O' means that git-sym ignores this unrelated symlink.
# Note: 'show' has the point-of-view of the current directory.

# The 'missing' sub-command reports only the symlinks
# that we need to update.
git-sym missing
## links/dirlink
## links/foo
## links/foo.alias
## links/sub/foo
## links/sub/foo.alias

# The 'update' sub-command runs `git-sym.makefile` on each
# missing link and fills in the symlinks.
git-sym update

# After 'update', nothing is missing!
git-sym missing

# The makefile has retrieved the actual files into our cache.
ls .git/git-sym-local/cache/
## dirlink  foo

# 'git-sym' has created a new symlink within our repo.
ls -la .git-sym
## lrwxrwxrwx 1 cdunn Group 61 Jun 10 00:37 .git-sym -> .git/git-sym-local/links

# 'update' has created several symlinks within `.git/git-sym-local/links`
ls -l .git/git-sym-local/links/
## lrwxrwxrwx 1 cdunn Group 43 Jun 10 00:38 dirlink -> ../cache/dirlink
## lrwxrwxrwx 1 cdunn Group 39 Jun 10 00:38 foo -> ../cache/foo

# 'show' now tells a different story.
git-sym show
## / links/dirlink .git-sym/dirlink
## . links/foo     .git-sym/foo
## . links/foo.alias     .git-sym/foo
## . links/sub/foo .git-sym/foo
## . links/sub/foo.alias .git-sym/foo
## O links/unrelated       /tmp

# The '.' means that a symlink now resolves to a file.
# The '/' means that a symlink now resolves to a directory.

# Note that we can symlink directories.
find links/dirlink
## links/dirlink

find links/dirlink/
## links/dirlink/
## links/dirlink/x
## links/dirlink/subdir
## links/dirlink/subdir/a
## links/dirlink/subdir/b

find .git/git-sym-local/cache/dirlink/
## .git/git-sym-local/cache/dirlink
## .git/git-sym-local/cache/dirlink/x
## .git/git-sym-local/cache/dirlink/subdir
## .git/git-sym-local/cache/dirlink/subdir/a
## .git/git-sym-local/cache/dirlink/subdir/b

Adding a big file

git-sym link can be very convenient, if you do not need to choose your own filenames.

cd git-sym-test

# This will create our big-file.
truncate -s 10M output.file || mkfile -n 10m output.file

# The filename can be anything, in any directory of our repo.
ls -l output.file
## -rw-r--r-- 1 cdunn Group 10485760 Jun 10 00:53 output.file

# The 'link' sub-command will
#  1. choose a unique name for the cached file
#  2. mv it to the cache
#  3. create an appropriate symlink
#  4. add the symlink to your repo (if '--add')
git-sym link --add output.file
## . output.file   .git-sym/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file

# You can do all that yourself and choose any unique filename,
# but 'git-sym link' is very helpful.
ls -l output.file
## lrwxrwxrwx 1 cdunn Group 66 Jun 10 00:53 output.file -> .git-sym/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file

ls -l .git-sym/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file
## lrwxrwxrwx 1 cdunn Group 66 Jun 10 00:53 .git-sym/output.file -> .git/git-sym-local/links/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file

ls -l .git/git-sym-local/links/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file
## lrwxrwxrwx 1 cdunn Group 66 Jun 10 00:53 .git/git-sym/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file -> ../cache/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file

# 'ls -lL' follows symlinks.
ls -lL output.file
## -r--r--r-- 1 cdunn Group 10485760 Jun 10 00:53 output.file

# You will need to commit the file manually.
git status --short
## A  output.file

git commit -m 'added output.file w/ name generated by git-sym link'
## [master ???????] output.file
##  1 file changed, 1 insertion(+)
##   create mode 120000 output.file

# 'show' now sees our new, resolved symlink.
 git-sym show
## / links/dirlink .git-sym/dirlink
## . links/foo     .git-sym/foo
## . links/foo.alias     .git-sym/foo
## . links/sub/foo .git-sym/foo
## . links/sub/foo.alias .git-sym/foo
## O links/unrelated       /tmp
## . output.file   .git-sym/sha1.6c5d4031e03408e34ae476c5053ee497a91ac37b.output.file

As you can see, the filename is irrelevant, but including the SHA1 can be helpful for future verification.

Smoke tests

make

Those tests are not complete. (E.g. git-sym fix is missing.) But the symlinks there are useful for debugging.

Clone this wiki locally