How to include files from another repo in Jekyll build? - bash

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.

Related

Make: Run a target based on a directory status

How can I check if a directory doesn't exists or empty then run a target?
Example:
.PHONY: all
all: build
build: install
# ...
# ...
install:
git submodule update --recursive --remote
bash install.sh
basically, I need to check for the lib/ directory. If it exists and not empty, do nothing. If it doesn't exists or empty, run the install target.
I'd go for something like this (untested):
# if lib is empty, run install
ifeq ($(wildcard lib/*),)
git submodule update --recursive --remote
bash install.sh
endif
It's not technically running a target, but I reckon it's what you ask for.
For running an actual target you'd setup prerequisites accordingly:
# some program using something in lib/
program: lib/libhello.a
# "making" the lib
lib/libhello.a:
git submodule update --recursive --remote
bash install.sh
Not sure I understand the role of the build target. Let's assume it is another intermediate phony target. Let's also assume that your default goal is all, and you want all to fire build, that itself fires install if and only if lib does not exist or is empty. Finally, let's assume that it is:
git submodule update --recursive --remote
bash install.sh
that creates lib and populates it. You could use a dummy empty file to mark that the lib directory exists and is not empty. Example:
.PHONY: all build install
all: build
build: install
# ...
# ...
install: lib/.exists
lib/.exists:
git submodule update --recursive --remote
bash install.sh
touch "$#"

Pushed node_modules but cant figure out how to remove

I push the node modules up to GitHub, then realized I did not have a .gitignore.
I added the gitignore but it did not fix the problem.
I found answers on here that said to remove it from the cached with git rm -r --cached node_modules, but this wont work because it says it cannot find that file, and I can still see it in my repo as well.
My file structure is the repo, then a dev folder with node_modules inside it, along with all the other code I have written.
The .gitignore is outside of the dev folder, next to the README file.
Do I need to give the .gitignore a path to find the modules like a ./node_modules or something?
the gitignore is outside of the dev folder next to the readme file
Then, it should include:
dev/node_modules/
That would ignore the dev/node_modules folder, and its content.
Check that (after a git rm --cached dev/node_modules done from the root folder of your repo) with:
git check-ignore -v -- dev/node_modules/afile
(test it on one existing file inside that dev/node_modules/ folder)
If you've added just node_modules in the .gitignore file, then it ignores all the node_modules directories within the repo. So you are just fine with .gitignore configuration.
The issue is that you should use the correct path when removing the cached copy of the node_modules. It should be as follows from the root of your repository.
git rm -r --cached ./dev/node_modules
Add this in .gitignore
dev/node_modules/
Now reset cache.
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

Xcode git can't ignore all *.xcodeproj/xcuserdata/ folders

I followed cant-ignore-userinterfacestate-xcuserstate and ignore-files-that-have-already-been-committed-to-a-git-repository. But these never works.
My Step Reproduction:
Quit Xcode
project directory: git rm -r --cached .
project directory: git add . && git commit -m "remove junk files"
Open Xcode project
Then these files appear again.
Most troubled me was that each time I rebase code will automatic appear these files so I will rebase fail of unstage files. Each time I need to stash these file.
This is my .gitignore file code section:
### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
*.xcodeproj/xcuserdata/
I just realized that these want to ignored files was buried in deep folder.
And git don't support this kind of pattern *.xcodeproj/xcuserdata/.
Want to ignore other son son (recursive) folder need add this to .gitignore:
ios/**/*.xcodeproj/xcuserdata/
or a clean way:
**/xcuserdata/
This **/*.xcodeproj was git version 1.8.2's feature.
$ git --version
git version 2.16.1
So most of us can use it.
I learnt from how-to-gitignore-files-recursively.

How can I cd outside my git hook directory

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)

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