Pre-commit hook works in Git bash not in EGit - hook

Environment: EGit 4.0.1.201506240215-r on Windows 7
I can commit with Git bash and the pre-commit hook is invoked, but when I try to commit in EGit, the pre-commit hook is not invoked.

GIT hooks are nothing but scripts which are to be executed by /bin/sh. Which you cannot do since you are running on Windows OS and you don't have sh.exe.
Install Cygwin
Add the cygwin_root/bin to your PATH
Make sure you install GIT during the cygwin installation(Since git hook scripts will execute git commands)
Hope this will help

Related

Is there a way for Jenkins or Crontab to push commits automatically to a GitHub repo?

I've been trying to push commits created with a simple shell script:
cd $dir
git add . && git commit -m "Test commit" &&
git push --all origin
The script does the job perfectly. Yet Crontab is stuck at making commits locally and Jenkins is getting 'Permission denied' when accessing a local git folder even if I assign Jenkins a group that owns the folder.
I tried Jenkins jobs with Execute shell either with the code or the path to the script. Any help would much appreciated.
One thing to note is that Jenkins goes back to the original workspace to run each command. So when you run cd $dir, the script will switch to $dir, but once you start the git add... command, it will go back to your workspace directory. To prevent this, either chain the commands together:
cd $dir && git add . && git commit -m "Test commit" && git push --all origin
or use dir to wrap the git commands so that they always run in that specific directory.
As advised by #M B summarizing:
Crontab:
For the cron commits to be pushed automatically:
Add a hook file to your git directory:
How can I automatically push after committing in Git?
Jenkins:
To commit and push automatically add a node. I also added to a sudoers file by sudo visudo:
jenkins ALL=(ALL) NOPASSWD: ALL
%sudo ALL=(ALL:ALL) ALL
I have also assigned a safe directory:
git config --global --add safe.directory /path/to/your/git/dir
EDIT: Just tested with Amazon EC2 Plugin, after cloning the repo on an EC2 instance use:
git remote remove origin
git remote add origin https://ghp_TOKEN#github.com/USER/REPO.git
git add . && git commit -m "COMMIT" && git push --all origin
And these 3 also work for Crontab and Terraform (no other settings needed).
Hope this helps.

Uninstalled pre-commit preventing 'git commit' (pipenv)

I recently uninstalled pre-commit from my environment. I performed the following in pipenv:
pipenv --rm
<deleted Pipfile and Pipfile.lock>
pipenv install -r requirements.txt
I ensured that the pre-commit module was no longer in the requirements.txt. When I make a git commit I get:
~/my_project/.venv/bin/python: No module named pre_commit
This is preventing me from committing, and I have no idea where this is coming from, since pre-commit is not being installed. Further, the traceback path specified is pointing to python and not python3. What am I missing?
typically the way to remove the hook installed by pre-commit install is to call pre-commit uninstall -- though if you've removed pre-commit from your system you can remove the hook scripts manually
you can usually find them by doing:
grep pre-commit.com .git/hooks/*
as that marker is listed in the hook files
from there you can delete them:
grep -l pre-commit.com .git/hooks/* | xargs rm
disclaimer: I made pre-commit
There are still pre-commit hooks installed in your git repository. You can remove them by simply deleting .git/hooks/pre-commit in you repository, after which pre-commit won't be called anymore when commiting.

Can I use Git in the Node.js console? If yes, how to install?

Is it possible to set so
mpm install nodegit
and then just write Git commands in the Node.js console? To use one console for Git and Gulp it will be more convenient to me ..
Nodegit is a library to use in an app you're writing or to be installed alongside another app or service that uses it. It's not meant to be a way to install your personal git command line tool. Download git for windows and install it. By default it installs its own git bash prompt (which is probably what you're complaining about) but during install there is a screen that allows you to use git in the normal Windows command prompt or PowerShell.
The screen above defaults to "Use Git Bash only". Change it to "Run Git from the Windows Command Prompt" and it will work like you want in the same shell that you're running node and npm in.

git: 'pull' is not a git command - CentOS VPS server

I recently set up a new VPS and have installed Git via yum and wget etc. All seemed well - I can add, commit, set up a remote and push to github.
However, when I try to pull from github:
user#domain.com [~]# git pull github master
git: 'pull' is not a git command. See 'git --help'.
Did you mean this?
shell
No, I didn't mean shell, I meant pull!
Now I've googled the heck outta this - including reading several posts on Stackoverflow:
"git pull" broken
git: 'pull' is not a git command. See 'git --help'
Although most posts seem to be about Mac issues (I'm on a CentOS server), it seems to be an issue with the git exec path, which is
user#domain.com [~]# git --exec-path
/usr/local/libexec/git-core
I've tried adding a various things to .bashrc with no success.
The key thing is that when I cd down to /usr/local/ and ls -l, I can't see a libexec directory.
But if I log in as root, I can cd to /usr/local/ and see libexec/, inside which is git-core. I can also git pull as root.
So - I suspect the problem is more to do with permissions and the server setup than git itself.
I've tried
sudo chmod a+rx /usr/local/libexec
But that did nowt too...
When I ssh into another server, as an account user, I can cd down to /usr/local and see libexec - so there's something wrong with this server setup.
Any ideas gratefully received.
Solved it now - the server is using jailshell... Disabling jailshell and using 'normal' shell works a treat

Git Archive of local Git repository

I have a Git repository on a server and on the same server I have a script which needs to do a git archive of the repository.
Here's my sample git archive command which works well for remote Git repositories:
sudo git archive --remote=ssh://uname#dev.example.com/var/repo/myrepo.git --format=tar --output=src.tar development
What would I need to do/change to execute the aforementioned command on the same server so that I don't need to put all the SSH stuff? Since the command is running on the same machine as the repository, can I get away with directly accessing the Git directory.
Thanks
Use
cd .../yourcode
sudo git archive --format=tar --output=src.tar development
(it is probably unnecessary to sudo)
Sure. Just run git archive from the directory that contains the local repo, and don't specify --remote.
From the directory that is your git repository run:
git archive | bzip2 > full/relative/or/qualified/path/to/place/you/want/to/store/your/archive.tar.bz2

Resources