How to check if GIT has fully cloned a repository? - linux

How can I check if git has successfully cloned a repository, and based on that result, execute commands inside the bash script?
I was trying some combinations of grep checking the output of git status but I've only managed to confuse myself more.
I'm ruining timeout 60s git clone ... so I must make sure the repository has cloned fully, and if it has not to skip whatever it would have done with the cloned data.

Have a look at it.
I think You are expecting this code.
https://stackoverflow.com/a/13715406/2959196
Also Have a look at the conversation. It might help you better.
How to detect if a git clone failed in a bash script

Your timeout command will return a non zero exit code if it terminates the program. Use that rather than checking the repository to see if it's cloned.

Related

How to fix merge conflicts for a lot of files in git?

I am using the git mergetool command to fix conflicts. However I have thousands of conflicts, is there way to simplify this so I get everything from the remote?
I am asked to enter c, d or a in the command.
{local}: deleted
{remote}: created file
Use (c)reated or (d)eleted file, or (a)bort?
Since I have thousands of files, I don't want to keep sending c. Is there way to just do this in bulk?
You can solve this outside of git mergetool: run git status --porcelain to get a list of all unmerged files and their states in machine-readable format.
If your Git is new enough, it will support --porcelain=v2. See the git status documentation for details on the output formats. Output format v2 is generally superior for all purposes, but you should be able to make do with either one.
Next, you must write a program. Unfortunately Git has no supplied programs for this. Your program can be fairly simple depending on the specific cases you want to solve, and you can use shell scripting (sh or bash) as the programming language, to keep it easy.
Since you're concerned about the cases where git mergetool says:
Use (m)odified or (d)eleted file, or (a)bort?
you are interested in those cases where the file name is missing in the stage 1 ("base") version and also missing in the stage 2 ("local") version, but exists in the stage 3 ("remote") version. (See the git status documentation again and look at examples of your git status --porcelain=v2 output to see how to detect these cases. Two of the three modes will be zero.) For those particular path names, simply run git add on the path name to mark the file as resolved in favor of the created file.
Once you have marked all such files, you can go back to running git mergetool to resolve additional conflicts, if there are any.
Note that your "program" can consist of running:
git status --porcelain=v2 > /tmp/commands.sh
and then editing /tmp/commands.sh to delete all but the lines containing files that you want to git add. Then change all of those lines to read git add <filename> where <filename> is the name of the file. Exit the editor and run sh /tmp/commands.sh to execute all the git add commands. That's your program!
supposing you want their change and modified yours you can do a pull as like:
git pull -X theirs
Other stackOverflow answers
git pull -X
git merge strategies this link will help understand any other merge strategies for the futuro
If you want that all the change you did will be deleted and you will be sync with the remote.
You should do the following:
git stash
git pull
And if you want to restore the change you did you should type:
git stash pop
Basically 'git stash' is moving the change to a temp repository.
you can learn more in:
NDP software:: Git Cheatsheet

The "git fetch" does nothing on repo

I noticed with git log origin/master that new a commit is up.
So I want to "see" this commit on my local repo.
I do this
$ git fetch -v
From xxx.xxx:proj/test
= [up to date] master -> origin/master
Everything seems fine... But nothing has changed on my local repo !?
To update your branches (as opposed to your Git's memory of some other Git's branches—git fetch updates this memory only), you must run a second Git command.
The second command to run is sometimes git merge and sometimes git rebase, depending on how you prefer to work. If you have no preference yet, use either one until you do have a preference.
There is a convenience command spelled git pull, that runs both git fetch and then the second command. The second command it runs is the one you tell it to. You must configure it based on your choice of second command to use. I recommend avoiding this until you really understand what the second command is and does, because eventually something will go wrong when running the second command. If you do not know that git pull is running this second command, you will not only not know what to do about this failure ... you won't even know that you need to look for how to fix problems with the other command!

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

Setting up and testing a pre-commit hook in SVN running on Linux machine which I access remotely

I'm gonna try to be as forthcoming as I can about my problem.
I'm on a Windows computer. The SVN repository is on a Linux machine.
I access the Linux machine remotely, using Putty and logging in as root. Everything is done through the command line.
Now, I have to set up a pre-commit hook that won't allow special characters like [éáú] on source code files. In order to do that, I set out to find out how to setup a pre-commit hook.
Here's what I've done:
Found a script
Went to the hooks folder in the repository. Removed the extension of the file pre-commit.tmpl
Pasted the script there and saved
Ran the chmod command on file pre-commit.tmpl
Then I tried commiting a change to the repository and I got:
Commit blocked by pre-commit hook (exit code 255) with no output
Alright, I figured something was wrong in how I set up the pre-commit file, so I removed the script and added a simple echo "hello world".
Now the commit goes through, but the echo message doesn't show up at all. If I put exit 1 at the end of the script, I get error code 1 and the echo message still doesn't show up.
I have literally searched high and low on the internet and have found no solution to my problem.
What I need:
An explanation as to why the echo messages are not showing up
If possible, a step-by-step on how to set up and test a simple script
For example, I've seen a lot of scripts where there's something like this:
#!/bin/bash
REPOS="$1"
TXN="$2"
What am I supposed to put in REPOS and in TXN? I assume in REPOS I should put the repository path? What about TXN?
Any help is appreciated.
Cheers
Billet of the pre-commit hook (*Nix-adopted)
Always failing
#!/bin/bash
echo You failed 1>&2
exit 1
commit sample
>svn commit -m "Changes"
Sending Folder1\Folder2\Folder3
Sending Folder4
svn: E165001: Commit failed (details follow):
svn: E165001: Commit blocked by pre-commit hook (exit code 1) with output:
You failed
Note correct redirection of output in echo
About $REPO and $TXN (already linked) SVN Book chapter have full explanation
The command-line arguments passed to the hook program, in order, are:
Repository path
Commit transaction name
because these parameters are needed for most often used in pre-commit hooks commands, like svnlook

Git fatal: cannot simplify commit

I have a repo that I have been committing for 2 months. I do not seem to get any error when I commit daily. However I was looking at git logs and I see that first ever git log (or maybe git can't see beyond that log point) has an error message like this
:100755 100755 1948ac6... 2af905e... M document.doc"
error: Could not read 190d54eb3278746a4e35fd4be82689eb4b1d20a8
fatal: cannot simplify commit cb0c2a3bf0a4ad665eb376b818bdcb0652a06eec (because of 190d54eb3278746a4e35fd4be82689eb4b1d20a8)
I tried the recommendation on: https://git.wiki.kernel.org/index.php/GitFaq#How_to_fix_a_broken_repository.3F
But I did not get what I was trying to achieve, whatever was recommended did not help my case.
This solution could help you:
Make a backup of your .git directory in case you corrupt things more in this process. Then, put back the best version of the packfiles you have available.
For each of the corrupt packfiles, run:
mv .git/objects/pack/pack-**yourpack**.pack oldpack
git-unpack-objects -r < oldpack
Run git fsck --full and git checkout again, give us the output.
Looks like now you should be able to check out, but you will have to run git checkout -f yourbranch, as you have changes in your working dir that are not yet committed. These changes will get lost when you run git checkout -f, though.
Note: This solution was sugested by #Chronial

Resources