Remove GIT Hook in Windows - windows

I've this script for macOS that removes temporarily a GIT Hook. This script is triggered by an npm script defined in my package.json. This project is shared across the whole team, so it has to work on every machine.
gitdir="$(git rev-parse --git-dir)"
hook="$gitdir/hooks/post-commit"
# disable post-commit hook temporarily
[ -x $hook ] && chmod -x $hook
git add -A
git commit --amend --allow-empty --no-edit --no-verify
# enable it again
chmod +x $hook
Can someone help me transcribe this to a .bat in order to be able to excute this in windows?

Related

Why all the script in my git hooks (pre-commit, post-commit, pre-receive, pre-push etc) do not run?

Why all the script in my git hooks (pre-commit, post-commit, pre-receive, pre-push etc) do not run?
Note:
this question is not a duplicate;
I have try the answer to each of the other questions but none of them work.
I did chmod +x, added the path to hook. rename script, neither of them solve my issue.
Inside my git
branches config description HEAD hooks info objects refs
Inside hooks:
applypatch-msg.sample fsmonitor-watchman.sample post-update.sample pre-commit prepare-commit-msg.sample pre-rebase.sample update.sample
commit-msg post-merge.sh pre-applypatch.sample pre-commit.sample pre-push pre-receive
I run them manually and they are all working fine.:
$ bash pre-commit
You are about to commit to master
Do you really want to do this? [y/n] y
pre-commit script
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
echo "You are about to commit" $(git diff --cached --name-only --diff-filter=ACM)
echo "to" $(git branch --show-current)
while : ; do
read -p "Do you really want to do this? [y/n] " RESPONSE < /dev/tty
case "${RESPONSE}" in
[Yy]* ) exit 0; break;;
[Nn]* ) exit 1;;
esac
done
But when i git commit and git push to the repository none of the scripts work.
$git commit -m "Test hooks"
[master] Test hooks 1 file
changed, 1 insertion(+)
My git version is 2.39.1
I created the repository on a VM with Ubuntu 18.04.6 LTS installed
Here was the procedure fro creating the repo.
mkdir project1.git
cd project1.git
git init --bare
After the creation i clone the repo to my local computer (windows).
Clone the git repository
git clone git#{ip}:/home/git/git_repositories/project1.git/
But I want use the scripts in project1.git/hooks to make this work.
A pre-commit hook for instance would not work in a bare repository (which has no working tree).
It would work only in your cloned repository, on Windows, where you can create a myClonedRepo/.git/hook/pre-commit script (no extension, no .sh), which will be run before each commit.
From the comments:
all users could create/clone their repositories from a shared Git template repository. The article "Creating a Custom Git Template" gives an illustration of that approach, but means that:
every user must access the same shared folder
they need to activate the init.templateDir config setting in their global Git configuration
any check which must be enforced for all the team members, especially for a distributed team, is best managed by server-side hooks instead.

unity cloud build Post-Build Script upload to github pages

I run my game on my Github pages.
and recently started using unity cloud builds.
I managed to get the post-build script running.
but have no clue on how to get it to pull the repository, apply the new build, and push it to GitHub.
So far I have tried this script, without much luck
#!/bin/sh
set -x
ssh-agent $(ssh-add ./id_rsa; git clone git#github.com:triktron/Road-Rage.git tmpResp; cp -r ./WebGL/Build ./tmpResp/;cd ./tmpResp/; git add Build; git commit -m "auto build"; git push)
the logs responded with this
2838: Executing Post-Build Script at upload.sh
2839: ###########################################################
2840: # WARNING: UNPROTECTED PRIVATE KEY FILE! #
2841: ###########################################################
2842: It is required that your private key files are NOT accessible by others.
2843: This private key will be ignored.
2844: ++ git clone git#github.com:triktron/Road-Rage.git tmpResp
2845: Cloning into 'tmpResp'...
2846: ++ cp -r ./WebGL/Build ./tmpResp/
2847: cp: ./WebGL/Build: No such file or directory
2848: ++ cd ./tmpResp/
2849: ++ git add Build
2850: ++ git commit -m 'auto build'
2851: *** Please tell me who you are.
2852: Run
2853: to set your account's default identity.
2854: Omit --global to set the identity only in this repository.
2855: ++ git push
2856: Everything up-to-date
2857: + ssh-agent
2858: SSH_AGENT_PID=5387; export SSH_AGENT_PID;
2859: WORKSPACESIZE | ARTIFACTSSIZE
2860: --------------|--------------
2861: 154.10 MiB | 12.79 MiB
thanks already for your time!
[Update 23 march 2020]
so i've spent more time on this then i'm willing to say but i figured it out.
here is my solution if anyone ever wants to do the same.
i placed this script in my files
#!/bin/sh
set -x
export buildfolder="$(find . -regex '.\/temp[^\/]*\/WebGL\/Build' -print -quit)"
if [ -z "$buildfolder" ]; then
echo "Could not find build folder"
exit 1
fi
if [ ! -d ./tmp ]; then
git clone "https://${nickname}:${githubkey}#github.com/${nickname}/${repositorie}" ./tmp
fi
cp -r "$buildfolder" ./tmp
cd ./tmp
git add Build
git config --global user.email "$githubemail"
git config --global user.name "$nickname"
git commit -m "unity cloud build"
git push --force
and added these envirement varibles in my unity cloud build console
picture of envirement vars

Setting a sh file to git bash

I've created a Python "automation" task that will initialize a repository on github and then on my bash function I'll be creating a folder, initialize the repository as the code bellow shows:
#!/usr/bin/env sh
function repo() {
cd
python C:/Users/wsm/PycharmProjects/GitAutomation/create.py $1
cd C:/Users/wsm/$1
start .
git init
git remote add origin <mygithublink>/$1.git
touch README.md
git add .
git commit -m "Initial commit"
git push -u origin master
code .
}
The only problem is that I have to use source command everytime I close a git bash to enable the command repo (Name of the function) again. Any ideas on how to make that command permanent on Windows 10?

Add new command on Windows Git Bash

I would like to add new command on my Git Bash (just now i am under Windows OS). I tryed to look on Web different solutions but I did not find anything. The command that i like to add is:
commitall -> git add --all && git commit -m "$*"
There is a way to add this command on Windows Git Bash?
Thanks
Use Git aliases, like so:
git config --global alias.commitall '!git add --all && git commit -m'
There's no need to use $* because all the arguments you specify will simply be appended to the line above, i.e. if you run:
git comitall "a message"
…the following will be executed:
git add --all && git commit -m "a message"

git commit and push via batch file on Windows

I do same task often of committing and pushing changes to remote branch. Being lazy sometimes, I needed to put set of git commands to automatically perform these steps:
cd D:\wamp\www\projectName
git checkout dev
git add .
git commit -am "made changes"
git push
pause
I also tried:
cd D:\wamp\www\projectName
call git checkout dev
call git add .
call git commit -am "made changes"
call git push
pause
and
cd D:\wamp\www\projectName
git.exe checkout dev
git.exe add .
git.exe commit -am "made changes"
git.exe push
pause
Everything works excpet for the final push command. Here is output:
D:\wamp\www\givingcircle>git checkout dev
Already on 'dev'
Your branch is ahead of 'origin/dev' by 1 commit.
D:\wamp\www\givingcircle>git add .
D:\wamp\www\givingcircle>git commit -am "made changes"
# On branch dev
# Your branch is ahead of 'origin/dev' by 1 commit.
#
nothing to commit, working directory clean
D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
D:\wamp\www\givingcircle>pause
Press any key to continue . . .
As you can see, for push, I am getting:
D:\wamp\www\givingcircle>git push
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
When I run above commands via git shell itself, everything works fine. I have also added git to Windows Path env variables.
Does anyone have an idea of why it works on git shell and not on batch command ? (even though other commands work but not push)
For me, by default, Windows executes .sh files correctly using Git Bash. So I would write your script as a regular bash shell script:
#!/bin/sh
cd /d/wamp/www/projectName
git checkout dev
git add .
git commit -am "made changes"
git push
echo Press Enter...
read
I had a similar need, to be able to move code from BBCloud to our development test servers, for stage 1 testing.
To do this, I created a Windows scheduled task:
Under "Actions", I added "C:\Program Files\Git\bin\bash.exe" in Program/script field (the quotes were required).
In the "Add arguments" field, I entered c:\path\to\bash script\pull.sh.
I then completed the Task Scheduler wizard (run frequency, time, etc.).
I then created a bash script, using Nano in Git Bash for Windows containing:
#!/bin/bash
cd /c/path/to/bash script
git pull
I would prefer a push to the repository automatically pushing down to the test server, but Pipes, Webhooks, and DeployHQ don't seem to be a solution for our environment.
Try this one !!
cd c://TESTS/path
set HOME=%USERPROFILE%
GIT COMMAND GOES HERE
pause

Resources