How to write an update hook for git submodules? - ruby-on-rails

I would like to copy some files in the submodules in my "vendor/assets" directory to another directory -- "public/assets." I heard about update hooks but I am not sure if they work for submodules. I wrote a simple hook and ran update from commandline, but it didn't work.
My update hook looks like this:
#.git/gooks/update.rb
#!/usr/bin/env ruby
puts "Copying files..."
So is this even possible?
btw, I'm using Braid to manage my submodules.

The update hook is only run when someone has pushed into the current repository, which doesn't sound like what you want. You could use the post-commit hook, if you want to copy these files into place every time you create a commit in your repository. (That should be sufficient, because you'd need to commit the new version of any submodule in the main project when you change the commit that the submodule is meant to be at. This would be a natural point to update the files in public/assets.)
You say that your test hook isn't being run - that may be simply because you have the name wrong. The update hook must be an executable file called .git/hooks/update (n.b. without a .rb suffix). Similarly, a post-commit hook must be .git/hooks/post-commit.
You shouldn't create hooks in any particular submodule for this task, since the action the hook will be taking is specific to the main project. Because of that, it doesn't really matter whether the change you're worried about it due to committing a new version of the submodules or just updating any random file.
For writing hooks, you'll find the official githooks documentation useful, and possibly these additional tips.

Related

Update files created by generator in Rails application

I have a generator that creates some view files.
I'm wondering about the extensibility of the generator - if there is a change in the generator template file, do I need to modify the existing files which were created by the generator manually?
I know that I can overwrite the existing files by running the generator command. But if I have edited the file after the file generation, overwriting can remove some necessary parts.
What is the best method to apply the latest generator template in the existing file?
Run the generator and then use git to determine which parts of the change to the generated views you want to keep.
You can do this through the command line using git add -p to stage certain parts of files before you commit (From Git Tools - Interactive Staging).
Any decent git GUI would also allow you to stage changes in this way too.

Is it possible to run Gerrit's commit-msg script standalone, not as hook?

I have no Gerrit hook installed
I have simple commit
I would like to check the Change-id of the commit
Is it possible to get the change id by running some command, for example
./commit-msg xyz
?
I don't want to use Eclipse. I don't want to configure hook.
You don't need to manually install the commit-msg hook in every repository you clone. You can configure Git to do this job for you automatically. When you execute the clone command Git copies a repository template located at:
Linux = /usr/share/git-core/templates
Windows = C:/Program Files (x86)/Git/share/git-core/templates
If you add the commit-msg hook to the template it will be installed automatically for every cloned repository.
However, the best thing to do is the following:
Create a personal template (e.g. $HOME/.git-templates)
Install the commit-msg in $HOME/.git-templates/hooks
Configure Git to use your personal template:
git config --global init.templatedir $HOME/.git-templates
The commit-msg script assumes to be run as Git hook (see example file). Therefore, it makes couple of assumptions.
Executing it stand-alone (you just could have tried that, right?) fails with
sed: : No such file or directory
Thus, no, you cannot run this standalone.
You might be able to fix it to work when called manually, but I'm unsure about your motivation. You sound like you don't want to install anything, but git-review is a nice helper.

how can I change a software of openwrt and rebuild it in Bin file

... $make menuconfig
select some package
... $make
...
there are many bin files in the bin folder.:
My question is , I want to change some software source code of openwrt and rebuild again.
I have try to edit some source code of build_dir. But want I rebuild openwrt My code with be refresh with the newest code of svn.
Does any one how to do that?
Writing your code and synchronizing it:
1) Clone the official linino repository from Arduino on your machine using git (install it using sudo apt-get install git):
git clone https://github.com/linino/linino_distro.git
2) Do your own changes in the relevant code files, Makefiles or whatever that you need to change.
3) Whenever you want to synchronize your work with the latest changes from the remote master branch in the linino repository, you need to first fetch the changes, meaning retrieving them without yet merging them, then in a 2nd time merge them and then resolve conflicts if any:
Preliminary: if you created a local branch with your own changes make sur you get back to the master branch, you need to check out the master:
git checkout master
a) fetching the latest changes:
git fetch master
b) Merging them with your changes on your local repository (normally called origin):
git merge origin/master
Note: alternatively you can do it in one command:
git pull
It essentially does a fetch and a merge at the same time but it's important to understand the process using fetch first. From experience it can be confusing for beginners, plus it can cause automerge if not explicitely specified otherwise, causing more work to undo them.
4) Now you're ready to resolve conflicts if any, for that you can use:
git mergetool
This will allow you to resolve conflicts using a graphical tool such as tkdiff (2 way merge tool), or meld (3 way merge tool, diff your changes, the changes from the remote master, and the original file).
Compiling your code:
5) Open a terminal in your linino buildroot directory, make sure you get to update the config if you added any new packages, then recompile the image i.e.
cd ~/myLininoBuildRoot/trunk
make menuconfig
#now select your new package, that you added in trunk/package
# Make sure you save the configuration before exiting
make
Note: Alternatively you can recompile packages one by one. Instead of doing a simple make do:
Preliminary step:
Make sure to have compiled the linino toolchain that allows you to compile packages separately:
cd trunk/
make tools/install
make toolchain/install
make target/compile
Then compile your package:
make package/myPackage
Or Alternatively, you can be more specific by selecting the any target from your package Makefile say for instance install or compile or build targets:
make package/myPackage/install
make package/myPackage/compile
make package/myPackage/build
Finally, recompile the index target common to all packages that will allow you to have an bin directory trunk/bin/yourArchitecture/packages that contains an up to date index of packages including your freshly compiled one:
make package/index
More info at: http://wiki.openwrt.org/doc/howto/build.a.package
Checking that everything is alright:
Now go have a look at trunk/bin/yourArchitecture/packages/Packages, do a grep to make sure it is listed in Packages (the actual packages index file) and is up to date:
grep Packages | myPackage
You probably want to:
Get the latest version of the source code.
Make whatever changes you want.
Use diff to make a patch recording your changes.
Update the source code (in the future)
Use patch to apply the patch
Manually perform any changes that could not be patched.
This is example build motion to newer version.
edit:
../package/feeds/packages/motion
Original Makefile
PKG_NAME:=motion
PKG_VERSION:=20110826-051001
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lavrsen.dk/sources/motion-daily \
#SF/motion
PKG_MD5SUM:=e703fce57ae2215cb05f25e3027f5818
Edited Makefile
PKG_NAME:=motion
PKG_VERSION:=20120605-224837
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://www.lavrsen.dk/sources/motion-daily \
#SF/motion
PKG_MD5SUM:=145fffcb99aed311a9c1d93b838db66f
You can also change Package Source URL (PKG_SOURCE_URL) if necessary
Rebuild newer motion application with:
make package/feeds/packages/motion/compile

Excluding files from being deployed with Capistrano while still under version control with Git

I want to start testing the JavaScript in my Rails apps with qUnit and I'm wondering how to keep the test JavaScript and test runner HTML page under version control (I'm using Git, of course) but keep them off the production server when I deploy the app with Capistrano. My first thought is to let Capistrano send all the code over as usual including the test files, and write a task to delete them at the end of the deployment process. This seems like sort of a hack, though. Is there a cleaner way to tell Capistrano to ignore certain parts of the repository when deploying?
There are many ways to accomplish this, you can keep your tests in a test branch of the app like VonC suggested, but that would mean that you would make all your changes in your main branch and then sync it to your test branch. (Not without its merits, but sometimes a pain)
You can use the .gitignore file to your directory.
Any file that you add to this will not be added to your repository. Since capistrano just pulls and posts from your repository, not having the files included will keep them off your production server.
Last but not least, if you want the test files in your main repository for version control, you can add a recipe to your config/deploy.rb file.. something like:
desc "Remove Test Files"
task :remove_test_files , :roles => :web do
sudo %{rm -f #{current_path}/public/javascripts/testfile.js}
sudo %{rm -f #{current_path}/public/javascripts/anothertestfile.js}
end
after 'deploy:remove_test_files'
And specify the files you want to remove, this will remove any files you want when you deploy. :)
Any of the above will work. Pick the method that works for you.
As of August 30th, 2013, you can simply create a .gitattributes file and export-ignore the files/folders of your choice.
features/ export-ignore
spec/ export-ignore
Reference: https://github.com/capistrano/capistrano/pull/626
You could have those tests in a test branch (on which you merge your main branch before any test)
That way, when you ask Capistrano to deploy what is on your main branch, no test of any sort is ever included.

Exclude specific files when pushing to a specific Git repository

Is it possible to exclude specific files (*.ai, *.psd) when pushing to certain repositories with Git?
My need comes from trying to use Git for both version control and deployment to Heroku. If I include my graphic assets in the deploy, the slug size is larger than desired. However, I do need to include all project files in my main github repository.
The easy way to solve your actual problem is to create a .slugignore file in the root of the repository that lists files that shouldn't be packaged in the slug.
Heroku documentation on Slugignore
You can maintain a second branch for deployment to Heroku, which contains none of those files, but still merges from master. (Of course, you'll have to work out a system for resolving the merge conflicts you get when you modify the .ai and .psd files in master).
The specific thing you ask is impossible, for the simple reason that when you push, you transfer the exact commits from one repository to another, and two commits which don't have the same tree are by definition different commits.
Tip: The most recent versions of git have a --porcelain option for git status which will give easy to parse information like "M file1" "DU file2" (modified and unmerged/deleted by us, respectively). You could write a git-merge wrapper for your deployment branch which attempts the merge, and automatically cleans up the expected conflicts:
git checkout deploy
if ! git merge master; then
git rm $(git status --porcelain | awk '/^DU/ {print $NF}')
fi
(The reason I printed $NF instead of $2 is that if the file's renamed, it'll look like "DU original_name -> new_name", and the copy placed in the work tree will be new_name, not original_name.)
Of course, the script could get more complex if your situation is - you could look for only certain extensions (add them to the limiting awk pattern), or even capture the whole output in a perl script so you can easily do some more fancy logic...
There isn't a direct easy way to do that. It's certainly manageable, but with a lot of pain (git wasn't designed to do this).
It would be easier probably if you ask Heroku to provide a way to exclude some files from the deploy.

Resources