How can I cd outside my git hook directory - ruby

I'm writing my own git post-receive hook in ruby, and it resembles something like this:
if !File.exists?(rep_dir+repo)
puts "Cloning repository #{repo} into #{rep_dir}."
`cd #{rep_dir}; sudo git clone file:////home/git/repositories/#{repo}.git`
exit
end
This hook is setup in gitolite common hooks, so when I push configurations for a new repository, I clone it right away to a new location.
I also loop for each project in gitolite config to check if the repository exists for each project, but that's not where I'm having problems.
My issue is, whenever this script runs I get:
remote: cd: 1: can't cd to /home/<somedir>/repositories/
remote: Cloning repository gitolite-admin into /home/<somedir>/repositories/.
The repository was not cloned to the target directory after the hook ran. I read about unsetting the GIT_DIR environment variable, but I had no success.

You don't have to cd anywhere when you are cloning.
You can simply add the destination path as a parameter to clone command.
git clone file:///xxx /path/where/to/clone
(Make sure the destination path doesn't exist, or the git will refuse to clone there)

Related

I want to clone a git rep. into my neovim config but it gives me a fatal

I want to run the following command:
git clone https://github.com/ChristianChiarulli/nvim.git ~/.config/nvim
Which gives me fatal: destination path '/Users/Me/.config/nvim' already exists and is not an empty directory
How can I fix this?
Your command aims to replace your ~/.config/nvim completely. So either delete your nvim config directory, or clone into another dir e.g. ~/.config/nvim/ and it will be cloned into ~/.config/nvim/nvim.

How to include files from another repo in Jekyll build?

When I run this, files changes from the copied /first-repo are being ignored by bundle exec. How can I make sure that the files from /first-repo are included?
#!/bin/bash
cd /first-repo;
git pull;
cd /second-repo;
git pull;
# copy folder from first repo to second repo
cp -rf /first-repo /second-repo/destination_folder;
git add -A;
git commit -m "update destination folder from first repo";
git push;
# build
bundle exec rake build_site;
Sounds like you could use a Git Submodule.
Continuing the example, in second-repo you can instantiate a git submodule of first-repo to get the whole first-repo repository as a directory inside second-repo. You can also use the Jekyll config include variable to specify what files from first-repo to use in second-repo.

Git giving warning: unable to rmdir

I am using git bash on windows 10 which was recently updated to creators update.
whenever i am trying to switch between branches i get following thing
$ git fetch && git checkout master
warning: unable to rmdir Ionic_Developemnt: Directory not empty
Checking out files: 100% (6312/6312), done.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
I don't know why this is happening also there is a .git hidden folder in the Ionic_Development folder
Can anyone help with this why so error _/_
warning: unable to rmdir on git checkout means that you're switching to a branch where this directory doesn't exist; git tries to remove it but there are some temporary files that git cannot remove; the directory is not empty so git cannot remove it also, hence the warning.
This happens mostly when your files are still in use. I personally experienced this sometimes with atom editor. Try to close your editor, and maybe any running compilers that are watching for changes too, and try to checkout again.
Found the answer, instead of git checkout, use git checkout --recurse-submodules.
Use git config submodule.recurse true to tell git always use --recurse-submodules (only in git versions 2.14+), add --local if you want that only in local project level.
Reason:
This issue happens on (Git < 2.13) when git checkout could not take care of those submodules correctly.
Reference: https://github.com/gitextensions/gitextensions/issues/2966#issuecomment-622666568
Original Answer
Actually I think this answer is partially right :O
If a folder is tracked by local .git within that folder, it would be changed according to .git when you switch branches (e.g. deleted from our point of view, if the other branch does not have this folder).
If a folder is ignored by .gitignore, the folder would be left unchanged when you switch branches.
However, if the folder is a submodule, which is tracked by submodule .git, local .git would try use rmdir when switching branches, which caused the problem.
I know this is old, but in case anyone stumbles on this, as I did, it can also be that you're switching to a different branch and you have a Git submodule. Look for the .git hidden folder in the directory, you can delete it if you don't need it to be a submodule--just be sure to commit the folder to the parent repo in the current branch before switching.
rm -r .git

Cannot PUSH recent commits to Github that have been pushed to Bitbucket

I have two remote repositories. One is private (Bitbucket) and the other public (Github). I had been pushing changes to Bitbucket using Github app and then pushing the same commit to Github repo using Xcode. However, recently I have been unable to PUSH the commits to Github and using SourceTree I get this error message:
This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.
This is how it looks from within SourceTree:
How can I get my Github repo to accept the most recent commits?
You have a pre-push hook which is telling you that you have git-lfs (large file support) enabled for this repository, but that it can't find the git-lfs program on your computer. The solution is to either remove the hook (which is located in .git/hooks/pre-push, as the error message says), or to fix your PATH so that it can find the git-lfs program.
It would have been enough to say that the .git directory is in the original local directory of your repository and you probably need a program like TextWrangler or similar, that shows the hidden files starting with a dot, to be able to see it and delete it by moving it to the trash (right click mouse). It took me one hour to figure out this. I hope no one else have to waste that time.
Here is the instructions for removing the pre-push file using Mac Terminal:
First: cd to the directory that is your local repository for your project. (The main folder that holds .xcodeproj and other files) The .git file is hidden but you can still access it by typing cd .git/hooks in terminal. If you type ls in terminal to view all files within the current directory, you'll notice the pre-push file. Type rm pre-push to remove the file. You should now be able to push to your remote repository. Just be sure to cd .. back a few times to your local directory for your project. Simple as that.

Is it possible to add a git submodule with recursive flag?

I am adding a submodule to my project which contains another git repo.
To get the module I ran:
git submodule add git://github.com/biakaveron/debug-toolbar.git modules/debug-toolbar
Then ran:
git submodule update --init --recursive
Which generated this error:
fatal: Not a git repository: ../../../../../../..//d/websites/project/.git/modules/modules/debug-toolbar/modules/vendor/firephp
Failed to recurse into submodule path 'modules/debug-toolbar'
I have run into similar problems before. Previously I just added the submodule and then re-cloned the project with the recursive flag (git clone --recursive project.git) which works. However it would be easier if I could get the submodule to pull in recursively in the first place. Is there a way to do this?
One possible cause could be the fact that github.com/cadorn/firephp-libs mentions:
THIS PROJECT HAS MOVED TO THE FOLLOWING REPOSITORIES:
https://github.com/firephp/firephp
https://github.com/firephp/firephp-core
So you might want to update the .gitmodules file of debug-toolbar first (after a git submodule update --init, without the --recursive part), and then, try again the git submodule update --init --recursive)
The OP did:
committing, then a recursive clone - which worked.
Original answer:
It seems that the path definition for one of the submodules (in the .gitmodules file) is not correct:
Being a relative path, it won't resolve successfully when cloned/updated by a git submodule --recursive command done from a parent repo for which said relative path is invalid.

Resources