How to push shared files (header/source) from outside a Git repository to it? - linux

I've developed two small programs, both of which include my_lcd_lib.h and my_lcd_lib.c.
To prevent code duplication I moved this "lib" from the include folder in each project to /usr/local/include. So far, so good.
How could I tell Git to include those files when pushing the repo?
So the repos from Prog1 and Prog2 would have their own copies of the header/source files.
I can imagine three ways:
When pushing the program repo from dev pc to gitlab server, git could include those outside files by some tricks. Maybe need to edit some .git* files?
I could make a lib-repo for the stuff in /usr/local/include. I could set up my program repo to load the appropriate files from the lib-repo. Is that what the pipe/cli are meant for?
I could copy the header files from /usr/local/include to the program repo just before pushing the program repo. This looks very unsexy.

No, you cannot push files outside the repository. Git does not push individual files, it pushes commits. The files have to part of a commit.
Once you've committed those files in your repository, the rough solution is to symlink them into /usr/local/include/. The better solution is to used a build tool like autoconf and install them in /usr/local/include.
Git is not a substitute for a build tool, nor dependency manager, nor installer.

Related

How can I add a .git directory to a git repository?

I am doing unit tests on a python program who, for QA purposes, gets the repository name and the current commit hash from the .git in the directory
For my unit tests on that program I would like to have a dummy .git directory in the tests directory. That .git repository would have a single initialization commit and a remote that would not be used
When attempting to add a .git to my tool's repository, git seems to ignore it and indicates that there are no differences in the status and commit
How can I add the .git directory to my project repository ? Something like tests/.git
You can't do that. It's inherently forbidden by Git.
You can store a tar or ZIP archive that contains the repository, and then have your test routine extract it to a temporary location. If you go that route, I recommend to use an uncompressed archive format, because it allows Git's own compression algorithms to work more efficient.
I think we would need more details about what you want to achieve to provide like the best answer... but I think you should look at git bundle. You can track a bundle file and then use it to regenerate a git repo.

How to prevent Git from storing copies of LFS files in .git dir?

It seems that Git is storing copies of LFS files in .git/lfs. This is taking twice of the space. I know this is a typical way Git handles the files, but I'm still wondering if there is a way to prevent Git from caching copies of them and just download from cloud when trying to revert the files.
If the files are in the lfs folder, it's that git needed them at a moment to populate your working directory.
So, no, there is no way to prevent git to cache them (except maybe by doing a sparse checkout if you really don't need to have the files handled by git-lfs in your working directory).
But you have an easy way to clean this cache directory (git will keep only the currently used files and delete the others unused) with the command:
git lfs prune

Git clone without including top/parent folder

We have a repo in git where the project is contained in a folder called Project. We'd like to be able to release the code to a production server, by cloning the repo, without including the "Project" folder, but with everything below it. Is this possible? The destination directory name is /var/www, which is unrelated to anything in the project. Unfortunately I can't just do a symbolic link because of the nature of our hosting provider (which we'll change soon).
My answer take the assumption that you have a git repository whose content is the following:
/.gitignore
/Project
/Project/index.php
/ProjectB
/ProjectB/pom.xml
If you don't need history at all in that copy of your repository, there is the git archive command which can do what you want except its output its data in tar or zip format:
git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
[-o <file> | --output=<file>] [--worktree-attributes]
[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
[<path>…]
Like:
git archive --format=zip --remote=git#foobar.git master -- Project | unzip
However, the git clone command does not accept a repository path, and I think it's not really git like to export only a tree view of some branch. You would probably need a submodule making Project an independent git repository, or like the git archive example, get only what you want but without versioning (which can be questionable on a production server).
Instead, you can do that:
Clone your repository to whatever path, say /opt/foobar.
Create a symbolic link of /opt/foobar/Project in /var/www.
Or reference the /opt/foobar/Project in your apache configuration (to avoid the symlink) instead of plain /var/www.

Specify SVN destination folder name in Buildbot

I'm setting up buildbot to build a project. The project's code is stored in SVN and it uses a couple of libs in our SVN repository.
When performing a manul build, what I need to do is (of course) to checkout the main project and the libs. The command used to checkout the libs is something like:
svn co svn://<path_to_lib_repo>/trunk mylib
That way the code of the library is stored in a local folder called "mylib" where the makefiles will look for.
Is there a way to configure the SVN build step to have the code checked-out to a folder with a custom name, as above? I did not found a way so far.
As a (temporarly?) workaround on Linux, I'm using the ShellCommand() step building myself the svn command, but I really don't like such solution.
Use the workdir paraemter to set the directory where you want the files. For example:
f.addStep(SVN(name='pull.src', repourl=svn://<path_to_lib_repo>/trunk,
workdir='mylib',
description='pull.src'))

Exporting files from hook in bare git repository

So, my situation is the following: I want to maintain my website using emacs-muse mode. For transferring the website (and version control), I want to use git. So I would create a hook in the remote (bare) repository that automatically copies the HTML subdir to the web directory. How can I do that from a hook? Also note that the whole directory contains a lot of files, so I can't export the whole directory.
Any help welcome.
You can use git archive, as it takes a path command. So, in your post-update hook you can do something like
git archive $SHA HTML | (cd dir/where/html/should/go && tar x)
this first creates a tarball of the subdir, and pipes that tarball to a tar command to untar it in the specified directory
(just a suggestion, as it may not be applicable in your exact configuration)
You might consider adopting this Web-Focused Git Workflow which, instead of copying, does push your repo directly on the web directory.
(From Joe MALLER)
Less complicated: Using Git to maintain your website (Daniel MIESSLER):
Daniel MIESSLER has an updated version of that same process:
Other suggestions are available at this SO question, like this post-update script mentioned in the Git FAQ.

Resources