Gitolite delete hook - gitolite

I'm trying to delete a Gitolite repository with a trigger (hook) since Gitolite forces this cleanup on the admin.
The $GL_REPO variable is necessary, but would I know the repo is being deleted ?
Thank you.

You don't need a hook.
You can use commands (with the latest 3.x gitolite).
Those commands include the command 'D'
ssh git#host D unlock repo
ssh git#host D rm repo
And your repo is gone.
Note that (commit b9bbb7):
you can completely disable the 'rm' command by setting an rc variable
(meaning in the .gitolite.rc file)
# called D_DISABLE_RM to "1".

Related

Use git shortcuts with a new version, overriding old

I'm using git on a shared hosting plan which runs a Linux distribution. Because it's shared, I don't have access to sudo. The machine already has git version 1.7.1 installed in /usr/bin/, but this version is rather prehistoric at this point. I've already used make install to get the current version 2.14.1, which is in ~/git-2.14.1/. As detailed by this answer, I can access the correct version of git from the command line like so:
$ git --version
git version 2.14.1
which was a simple change to the $PATH variable, in the ~/.bash_profile, so I can use git just fine.
I have a list of shortcuts in my ~/.gitconfig file that make git much faster for me to use:
[alias]
co = checkout
st = status
ci = commit
... etc etc etc
When I invoke these (e.g. git st), I get the results from the wrong version of git. It goes back to 1.7.1. If I type out the full command (e.g. git status), it uses the correct version of git.
I also have these commands in my ~./bashrc:
git () {
case "$*" in
st* ) shift 1; command ~/git-2.14.1/git status "$#" ;;
* ) shift 1; command ~/git-2.14.1/git "$#" ;;
esac
}
Which I have source-ed since writing.
I have also tried:
alias git="~/git-2.14.1/git"
To no avail.
Is there a work-around that would allow me to use these shortcuts with my preferred version of git? I am imagining a way to hide the config file from the other version by redirecting the pointer to a different location, but I have no knowledge of the existence of any such pointer.
Alternatively, is there a way to totally disable the previous version of git without root access?
When I invoke these (e.g. git st), I get the results from the wrong version of git. It goes back to 1.7.1
That is not what I see in my Ubuntu session.
I have in my .gitconfig
[alias]
st = status
br = branch
v = !git version
That means I type git v, to check git version (which is the same as git --version).
If I change my PATH to a new compiled Git, I do see a different version.
vonc#VONC:~/gits$ echo $PATH
/usr/local/bin:/usr/bin:/bin
vonc#VONC:~/gits$ which git
/usr/bin/git
vonc#VONCAVN7:~/gits$ git v
git version 2.13.0
vonc#VONC:~/gits$ export PATH=~/gits/v2.14.0/bin:$PATH
vonc#VONC:~/gits$ git v
git version 2.14.0
Here's what I found. If I took out the alias section of the .gitconfig, the aforementioned shell wrapper function worked. If I removed that and restarted the ssh connection, nothing worked (as expected).
I found, with help from this answer, that there is a magical GIT_EXEC_PATH variable which tells git where to find tools like git-add, git-commit, git-status, et. al.. Uncommenting my alias section of the .gitconfig file and using
$ export GIT_EXEC_PATH=/path/to/my/new/git's/executables/
made it possible to use the aliases in the .gitconfig file. For me the path that worked was the same folder as I installed into: ~/git-2.14.1.You can check the current value of GIT_EXEC_PATH with:
$ git --exec-path
/path/to/my/new/git's/executables/
Also, echo $GIT_EXEC_PATH works as well. My understanding is that git uses its aliases not through the instance of git which called git <alias>, but rather directly through the executables in it's exec path.
Note: for me,
$ git --exec-path=/path/to/my...
did not work, but if I understand correctly, this is the equivalent command.
TL;DR: add the path to the new executables (git-add, git-status, etc.) in your .bash_profile:
export GIT_EXEC_PATH=/your/path/

How to make current directory a git working directory

I've written multiple *.cpp files in the location ~/Code/CPLUS before I know the existence of git.
Now I want to use git for version control.
I created a folder ~/git_repo/, and in this folder, I ran git init command. When I tried to run the command git add my_first_c.cpp under the path ~/Code/CPLUS, the following message appeared:
fatal: Not a git repository (or any of the parent directories): .git
Then I typed git init ~/git_repo/ under the path ~/Code/CPLUS, the same error still appeared when git status was typed.
If I type git init under the path ~/Code/CPLUS, the add and commit can be executed. The only problem is that .git is stored in ~/Code/CPLUS/, while I'd like it be stored in ~/git_repo.
My question is how to make the folder ~/Code/CPLUS a working directory while the repo info is stored in ~/git_repo/? And my machine has no GUI.
You could try exporting the variables export GIT_WORK_TREE=~/git_repo/ and export GIT_DIR=../Code/CPLUS from terminal (or in your ~/.bashrc) so Git uses these.
Thanks #Alariva , the suggested solution indeed solved this question. With .git created in ~/git_repo/, typing git --git-dir=/abs/path/to/repo/git_repo/.git add my_first_c.cpp works.
The solution comes from this post.

gitolite hook after git push doesn't work

I tried to search to find a solution.
but, I can't.
I installed gitolite. And it works well.
I can git clone on the local machine, and change gitolite-admin repo too.
But I want to use gitolite hooking.
followed this manual
http://sitaramc.github.com/gitolite/hooks.html
custom hooks
You can supply your own, custom, hook scripts if you wish. Install
gitolite as usual, then:
go to ~/.gitolite/hooks/common on the server and put your new hook
there now run "gl-setup" again You can use this procedure to install
new hooks as well as to update hooks that you had previously
installed.
So I tried to hook some basic shell script.
I put bash shell script on
~/.gitolite/hooks/common
and named it
update
update script file's owner is git, and excutable.
the shell script is like this..
#!/bin/bash
touch /tmp/$GL_REPO
and I execute
gl-setup mypubkey.pub
and then,
On my local git folder,
I modified some file, commit and push to gitolite server.
push works well. every file uploaded to the gitolite's repo.
but, hooking doesn't seems to occur. Nothing happened.
on the server's tmp directory, no file is created.
Did I forget something?
any comments plz...
You should realize that (from the "using hooks" page you mention in your question=:
The update hook is used in all repos and is critical to gitolite's access control
In other words, you cannot directly use an "update" script.
You must use the "hook chaining" feature of gitolite, in order to call your own update hook after the one of gitolite:
To run your own 'update' hook, just put it in a file called update.secondary and install it as a hook.
Gitolite's update hook will automatically chain to it, taking care to pass it the same 3 arguments the original update hook received from git.
In the end, the OP Jinbom Heo, rather than using "gitolite hook chaining", went with another hook:
I put post-receive file in /var/gitolite/hooks/common/ folder. And it works.
The doc "Where do I put my hooks" suggest rather to put those under the "user" location (~/.gitolite/hooks/common):
But the system location works too.
( /var/gitolite/hooks/common/ means, by the way, the OP chose the root method installation or the package one, with the default paths /usr/local/bin, /var/gitolite/conf, /var/gitolite/hooks)

gitolite hook for specific repository

I don't understand how do I create a post-receive hook for a specific repository in gitolite (non-root install)
My bare repository contains a website that should copy the working directory to the docRoot
(GIT_WORK_TREE=/path/htdocs git checkout -f) on update
Before gitolite, I would just update the hook for the specific repository.
Gitolite documentation mentions that all hooks should be at hooks/common so I don't understand how it works.
What should be the name of hooks, where it should be located and how it's structure should be changed (if it should)?
Update July 2013: what follows is for gitolite V2 (or 'g2'), which was the version used by the OP at the time (November 2011).
Update August 2013, with the latest gitolite 3.x:
You now have official specific repo hook:
it's basically just creating a symlink in <repo.git>/hooks pointing to some file inside $rc{LOCAL_CODE}/hooks/repo-specific (except the gitolite-admin repo)
All hooks in gitolite/hooks/common are replicated in all repositories managed by Gitolite, as detailed in the hook propagation documentation.
That means your hook script must take specific action depending on the repo which execute said hook.
You can either use the $GL_REPO variable (which gitolite set and pass to all its scripts for any git command it receives).
Or you can use some git configuration registered on the gitolite server, like the mirroring hook does. See the post-receive.mirrorpush hook.
The OP Eyal R adds in the comments:
But I still don't understand how it is done (I understand that $GL_REPO is used to determine which repo I am updating but I'm missing the practical part).
I have created a file called post-receive.test with echo "test", put it in $HOME/gitolite/hooks/common, ran gl-setup, ran push from workstation - nothing happens (no "test" output)
To which I replied:
The hook should appear in the hook directory of your repo on the gitolite server as a link, linking back to the .gitolite/common/hook. Note that it should be in $HOME/.gitolite/common/hook, not /gitolite.
The OP confirms the missing dot was the issue.
The process to add an hook is detailed in Hook propagation in gitolite, and their usage in "Using Hooks".
This is a fairly common need for someone using gitolite, and appears to be a little difficult to tie up loose ends when being not a very advanced user (at leas it was for me).
Following stackoverflow's and gitolite's links back and forth can be a little confusing. These are my conclusions and the path I followed to be able to achieve this.
As #VonC mentioned creating repository specific hooks is already possible since version 3.5.3.1 (github link)
Update/Upgrade Gitolite
The first thing you should do is update your gitolite repo. So ssh into your server that is hosting gitolite and move to the location where gitolite is installed (usually /home/git/gitolite) as the git user (usually git)
Example:
$ ssh myusername#devserver.com
$ sudo su - git
$ pwd
/home/git
$ cd gitolite
Then we have to upgrade gitolite. To do so, first we need to update the gitolite repository
$ git pull
Then we have to repeat the install command (make sure you use the same arguments as before)
$ ./install
And finally run the setup again.
$ gitolite setup
If that doesn't work, you probably haven't set up gitolite executable in your PATH, so you could do something like this:
$ src/gitolite setup
Gitolite Settings (The "RC" file)
This was one of the parts that confused me the most, but it ended up it was pretty straight forward.
The famous "rc" file is located at git's home directory /home/git/.gitolite.rc. There make sure you have a variable called LOCAL_CODE, you should see something like this on that file, if not, add it.
LOCAL_CODE => "$ENV{HOME}/.gitolite/local"
And in the "commands an feature to enable" section you should make sure that repo-specific-hooks is available, if not, add it.
ENABLE => [
# COMMANDS
# These are the commands enabled by default
'help',
'desc',
'info',
...,
...,
...,
'repo-specific-hooks'
...,
...,
...
]
Here is the link to the documentation
Writing Repository Specific Hooks
Finally, in your local gitolite-admin repository create the following directories hooks/repo-specific under the directory you just set in the LOCAL_CODE variable, for example:
gitolite_admin/local/hooks/repo-specific
After that you can actually add your hooks scripts to that location and manage them through the gitolite conf file as stated in the documentation. Make sure the scripts are executable.
repo foo
RW+ = #all
option hook.post-receive = deploy
Again, I hope this helps some of you guys.
Cheers!

Gitolite access repair

I have set up gitolite on my linux server and added my laptop to the gitolite-admin repository. I was forced to format my laptop (bad hard drive) so I need to figure out a way to regain access to my other repositories gitolite controls. It's worth mentioning, I have root access on my linux server, if that helps. I am not very proficient with SSH/public keys, etc, so if someone can help, I would greatly appreciate it.
If you have version 2.0.3 or later installed, you can use the gl-admin-push command to push from a local clone of the admin repository:
See gl-admin-push: bypassing gitolite for the gitolite-admin repo :
su to your Gitolite user
cd /tmp && git clone ~/repositories/gitolite-admin.git
replace your old public key in keydir/ with your new one, then commit
~/.gitolite/src/gl-admin-push to push it; this will update the user’s .ssh/authorized_keys to integrate your new key
If you are using something earlier than 2.0.3, you can use the gl-dont-panic command to replace a key:
su to your Gitolite user
copy your new public key to /tmp/username.pub
username.pub should be the same as a filename that is currently in your keydir/; you can list the contents of the existing keydir/ with
GIT_DIR="$HOME"/repositories/gitolite-admin.git git ls-tree master:keydir
run cd /tmp && ~/.gitolite/src/gl-dont-panic username.pub to install the replacement key
The answer above was helpful.
But for gitolite 3.04 (and probably later) use gitolite push instead of gl-admin-push.

Resources