Creating a shell environment for git hooks and Git Tower - linux

I'm using Git Tower. My project has some git hooks that aren't running. According go the Git Tower FAQ:
You need to make sure you're creating the required shell environment
in the hook script itself (like modifying "PATH"), not in your shell
profile, as the hook script is called from the Tower process
environment which is not running in a shell environment (hence your
shell profile is not loaded).
This is quite foreign to me. My shell script is quite simply:
#!/bin/sh
git ftp push
What do I need to do in order to get Tower "permission" to process my hooks?

Related

Maintain code on bash scripts or Jenkins?

I'm currently working with Linux VMs and I use Jenkins Pipelines to run various jobs written in bash. I have 2 options regarding where the code is wrote and maintained:
In pipelines with sh '#some code' (Git integrated)
In bash scripts placed in the VM with sh './bashscript'
Which one would you suggest?
Use GIT to store scripts or code related, as GIT is a version control system, and all users who have access can access the file for viewing or making changes.
When the Jenkins job runs, a workspace folder is created on the server in which the job is running on, and the script would be copied from GIT into the folder.

Custom git command autocompletion

I have implemented a custom git command by writing a shell script located in /usr/local/bin. It works fine, but I would like the script to autocomplete branches in the command line, just like git checkout [TAB][TAB]. How could this be done?
EDIT:
Just adding some context: git allows you to very easily add your own commands by creating a script git-$subcommandName. In my case here git-install, the script facilitates checking out a branch, building, packaging, and installing the source code.
Figured it out. I needed to download git bash completion (here), create a new file in /etc/bash_completion.d with the following contents:
source ~/.git-completion.bash
_git_install ()
{
__gitcomp_nl "$(__git_refs)"
}
and then exec bash to reload completion scripts.

Execute a script after every git push

There is a server running and has a git instance on it. I want a script to run everytime a user does git push to the server. I want my script to be executed then git push to continue.
Any work arounds?
You've tagged this GitHub so I'm assuming that you are referring to public GitHub and not GitHub enterprise.
You cannot run a script "server-side" on GitHub's servers because that would obviously be a massive vulnerability but you can set up a web hook to trigger a script on another server.
Basically whenever someone does a push, a specific URL will be sent data about the push. You can then trigger a script from this. For more information on web hooks, see the GitHub API docs.
I am not sure If you want a scipt to run prior to push or after. So here is my answer for pre-push. But if you want post-push (i.e after push) you have to change the pre-push hooks accordingly to check if pushed successfully and then you can do post push thing.
As suggested by #Travis, git hooks is the one that you are looking for. So to execute a script pre-push, you have to do is to create a pre-push file in the .git/hooks. So in this case put your bunch of code in the pre-post script file .git/hooks/pre-push and save it. Then make it executable by chmod +x .git/hooks/pre-push. After you done with this successfully you will be able to see the script gets executed each time you do run push command.
PS: Please note that I haven't tested this whole but expected to work in this way.
In Short, assuming you(Linux user) are in the project directory
vim .git/hooks/pre-push # then add your code and save the file
# Also put the shebang on top to identify the interpreter
chmod +x .git/hooks/pre-push # make it executable
You should look into git hooks:
8.3 Customizing Git - Git Hooks
and, another site regarding this technology:
githooks.com

Autorun Bash Script after Login to Sync Git Repos

I have already a gitupdate.sh that I found on the internet.
My problem now is how to make the script run automatically every time I log into my Ubuntu 14.04 computer.
I have tried adding this line to .bashrc
sh '/path/to/git/repo/gitupdate.sh'
The problem here is the script is executed not in the context or path of the repo thus the script runs in a folder that is not initialized with git. (I don't actually know what folder bashrc run on)
What want to do is that the update script to be run by Ubuntu in the context of the path so the script will not fail. And also show the running script in a Terminal window that will not automatically close.
And the ultimate goal, is to be able automatically upon login, that git cloned repos to be synced with the public repos.
Try
(cd repo && bash /path/to/gitupdate.sh)
Just open the gitupdate.sh and at the beginning of the file just add the command to go to the selected direcotry. For example:
cd /var/test

Svn post-commit hook failing on command not found

I'm trying to call a script using a post-commit hook, but it fails because it cannot find various commands.
My research has shown that there are basically no environment variables loaded when a post-commit hook is run, so I suppose that's why it can't find commands like ping.
Is there anyway to define enough in my post-commit hook so that I can call a script that runs on baseline POSIX commands?
Subversion hook scripts are executed with an empty environment. Best practice is to specify full paths in your scripts (and any other scripts that they may call), or set up the environment variables you require in the hook script itself.
From the manual:
For security reasons, the Subversion repository executes hook programs with an empty environment—that is, no environment variables are set at all, not even $PATH (or %PATH%, under Windows). Because of this, many administrators are baffled when their hook program runs fine by hand, but doesn't work when run by Subversion. Be sure to explicitly set any necessary environment variables in your hook program and/or use absolute paths to programs.
At the start of your hook, you can set up PATH and other environment variables:
LANG=en_US.UTF-8
PATH=/path/to/bin:/another/bin:$PATH

Resources