git autodeploy script within post-receive hook on ubuntu - linux

I have an autodeploy bash script to get updated repo to /tmp in 'post-receive' hook on gitosis
#!/bin/bash
PWD=$PWD
REPO_NAME=${PWD##/*/}
cd /tmp
git clone git#atom-desktop:$REPO_NAME
But anytime when I push repository I got error like this:
Host key verification failed.
fatal: The remote end hung up unexpectedly
error: hooks/post-receive exited with error code 128
How to cope with that ?

You can simply do:
git clone --local $REPO_NAME
As git also supports cloning from local directories:
git-clone
For local respositories, also
supported by git natively, the
following syntaxes may be used:
/path/to/repo.git/
file:///path/to/repo.git/
These two syntaxes are mostly
equivalent, except the former implies
--local option.

Sounds like there is a key mismatch in the SSH connection from wherever /tmp is and atom-desktop. What happens if you try to SSH from the machine that /tmp is located at to atom-desktop?

Related

Git did not exit cleanly (exit code 1)

I can't push and I already tried all solution in this question. I'm using Windows10 and TortoiseGit.
I generated my SSH key with PuTTYgen and I already tried to replace the key in case my older was corrupted. When I try with git bash I got this error:
$ git fetch -p Permission denied (public key).
fatal: Could not read from remote repository. Please make sure you
have the correct access rights and the repository exists.
In TortoiseGit I get:
git did not exit cleanly (exit code 1)
For My case i did 3 steps to achieve the sucessful build.
revert all the local changes if any (or just keep a copy of it in case you need it for future use)
Do a git clean up, do a pull and check the logs for error
GO to the git bash option and the error i was getting in log in above stem (i my case )
as "error: cannot lock ref and the branch details", so in the git bash i ran the following command
git update-ref -d 'Branch_name'
For example if the error was something like
**
ISSUE
**error: cannot lock ref 'refs/remotes/origin/EXMPLEISSUE/EXAMPLE-1011_DEMO_web_interface_DOES_NOT_GET_GIT_UPDATE':
Then i ran following command
git update-ref -d 'refs/remotes/origin/EXMPLEISSUE/EXAMPLE-1011_DEMO_web_interface_DOES_NOT_GET_GIT_UPDATE'
We have to ensure all the error in logs to be solved similarly before getting a successful pull by doing git update-ref -d 'Branch_name' and finally i can get the take the successful pull from git.

Issue with GIT command

I am trying to execute git clone command to clone source code from github repository. I am using 2.11.1 version. command I run is
git clone https://username:password#github.com/repository.git ./localpath
This works fine at windows machine. But when I am executing from linux machine command is removing # and throwing error. Execution failure is like
git clone https://username:passwordgithub.com/repository.git ./localpath Cloning into './localpath'...
error: Couldn't resolve host username:passwordgithub.com while accessing
Could someone help me to fix this?
Register your ssh-keygen generated id to Github so it would not prompt you for password.
$ ssh-keygen
No need to enter pass-phrase. Output your public key, then copy it to github
$ cat ~/.ssh/id-rsa.pub
But, if you really want to go that route.
Enclose them in a single quotation, or do them like below.
#!/bin/bash
REPO='https://username:password#github.com/repository.git'
LOCAL_PATH='path/to/wherever'
git clone "$REPO" "$LOCAL_PATH"
Note: Use double quotations for variables

make git clone with sudo

when I make git clone with ssh from a user prompt it works properly.
git clone ssh://URL.com/soft.git soft_git
the ssh key id_rsa and id_rsa.pub are under /home/user/.ssh
my purpose is the execute git with sudo but I got the following error
Cloning into '/home/user/git/soft'...
Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I create a folder /root/.ssh and I copy the ssh keys into it but I got the same error
how to execute git with sudo properly.
When you run git using sudo, git will run as root. Because git is running as root, ssh is running as root. Because ssh is running as root, it is trying to log on to the remote server as root. The remote server is not okay with this (as it should be!)
You will need to do two things:
Put the username in your URL: ssh://myusername#URL.com/soft.git.
Make your SSH key available to the root user, because it will look under /root/.ssh instead of /home/user/.ssh. (You could also probably point SSH at the correct key, but I don't know how to do this, and SSH is picky about permissions.)
On my computer (Ubunutu 18.04), adding SSH_AUTH_SOCK=$SSH_AUTH_SOCK after sudo and before git fixed the problem:
sudo SSH_AUTH_SOCK=$SSH_AUTH_SOCK git clone git#github.com:my-github-account/my-repo.git
Normally, sudo's SSH_AUTH_SOCK environment variable won't be set properly. Executing the git clone with SSH_AUTH_SOCK=$SSH_AUTH_SOCK sets sudo's SSH_AUTH_SOCK environment variable to whatever it is for you.
This way, you don't need to add an extra .ssh dir for sudo with copies of your keys, which is what I think one of the other answers suggests.
The solution is more fully explained in this rather old github gist:
https://gist.github.com/scottjacobsen/4281310
P.S. I'm adding a new answer several years later; I googled a solution to this problem, and this SO Q/A is one of the first things that comes up.
Normally the default remote ssh user is the same as your user name. If you're using sudo this will be root which probably isnt' going to work. You need to supply the remote username.
sudo git clone ssh://username#URL.com/soft.git soft_git
You can generally resolve git ssh issues easier by trying to login to the remote with plain ssh. You'll get better diagnostics and can see what's going wrong.
sudo ssh ssh://URL.com/

Unable to complete svn2git in a shell script

I am migrating a SVN codebase to Git and need to create more than 30 projects. Hence I approached this problem by automating the steps in a shell script.
Below is the code snippet
test.sh
#!/bin/sh
svn2git http(s)://svn.yyy.xxx.com:1080/SVNROOT/PROJECTSUITE --trunk trunk/SOURCES/Project1 --notags --nobranches --authors /Users/praveen/users.txt --verbose > log.txt
git remote add origin git#gitlab.yyy.xxx.com:PROJECTSUITE/Project1.git
git push origin --all
I am able to perform this migration successfully when the commands are executed individually from the terminal.
Terminal
$ svn2git http(s)://svn.yyy.xxx.com:1080/SVNROOT/MERLINSUITE --username praveen --trunk trunk/SERVER_SOURCES/MerlinTMS --notags --nobranches --authors /Users/praveen/users.txt --verbose
Running command: git svn init --prefix=svn/ --no-metadata --trunk=trunk/SOURCES/Project1 http(s)://svn.yyy.xxx.com:1080/SVNROOT/PROJECTSUITE
Initialized empty Git repository in /Users/praveen/projectFolder/.git/
Running command: git config --local --get user.name
Running command: git config --local svn.authorsfile /Users/praveen/users.txt
Running command: git svn fetch
W: Ignoring error from SVN, path probably does not exist: (160013): Filesystem has no item: File not found: revision 100, path '/trunk/SOURCES/Project1'
W: Do not be alarmed at the above message git-svn is just searching aggressively for old history.
This may take a while on large repositories
....
....
success :)
But when the above shell script is executed using verbose it gets stuck. The project tested was around 30MB in size.
log.txt
Running command: git svn init --prefix=svn/ --no-metadata --trunk=trunk/SOURCES/Project1 http(s)://svn.yyy.xxx.com:1080/SVNROOT/PROJECTSUITE
What am I doing wrong? Is it that svn2git cannot be called within a shell script?

error 127 when running "git svn init" on cygwin

I'm trying to convert a local SVN repository to git using git-svn under cygwin and failing. This is what happens:
$ git svn init -t tags -b branches -T trunk file:///cygdrive/e/repository/project
init: command returned error: 127
Any ideas?
I installed msysgit and it failed as well, but with a much better error message (Expected FS format '2'; found format '4') which turned up helpful discussions on Google. It seems like git-svn can't handle the local filesystem format of a current TortoiseSVN. The solution is to run svnserve and use the svn: protocol via localhost.

Resources