I have a certain file UPDATE.sh. The task of this file is to update my program using git merge.
UPDATE.sh:
#!/usr/bin/env bash
git fetch https://xxxxx
newUpdatesAvailable=`git diff HEAD FETCH_HEAD`
if [[ "$newUpdatesAvailable" != "" ]]
then
git branch backup
git checkout backup
git add .
git add -u
git commit -m date "+%d.%m.%Y"
git checkout master
git merge FETCH_HEAD
else
echo "No updates..."
fi
I have to write the same thing but on Make syntax.
I tried to figure out the conditions in Make, but it didn't work out for me.
Please tell me how to write this correctly in Makefile without using:
update:
./UPDATE.sh
Another alternative, that does not require extensive quoting, semi-colons, etc, is to take advantage of the fact that make will stop executing a rule when the exit code is non zero.
This will usually result in easier to maintain Makefile, with simpler rules.
update:
git fetch https://xxxxx
git diff -q HEAD FETCH_HEAD || { echo "No Update" ; false ; }
git branch backup
git checkout backup
git add .
git add -u
git commit -m date "+%d.%m.%Y"
git checkout master
git merge FETCH_HEAD
You don't need to capture the output of git diff; you just need to know if there is a diff or not. Use the -q option.
if ! git diff -q HEAD FETCH_HEAD; then
git branch backup
...
else
echo "No updates"
fi
-q suppresses output and implies --exit-code, which causes git diff to exit with a non-zero exit status if there are differences.
In a Makefile, this would be
.PHONY: update
update:
git fetch https://xxxxx
if ! git diff -q HEAD FETCH_HEAD; then \
git branch backup && \
git checkout backup && \
git add . && \
git add -u && \
git commit -m date "+%d.%m.%Y" && \
git checkout master && \
git merge FETCH_HEAD; \
else \
echo "No updates"; \
fi
The semicolons and backslashes are necessary because the entire if statement has to appear on one logical line.
Related
so i tried castlevania game decomp and I follow this steps and I'm new to git
Inside the folder of your choice git clone https://github.com/Xeeynamo/sotn-decomp.git
Run sudo apt-get install -y $(cat tools/requirements-debian.txt) and everything worked
until this happen after i run this command: make update-dependencies
I got this error pathspec 'tools/n64 splat' did not match any file(s) known to git any idea on how to fix it, plz? I searched so much.
And this is the link to the decomp: https://github.com/Xeeynamo/sotn-decomp
I am trying to export Neptune RDF data using the following tools.
amazon-neptune-tools/neptune-export at master ยท awslabs/amazon-neptune-tools
https://github.com/awslabs/amazon-neptune-tools/tree/master/neptune-export
But, Error occurs.
Error
[ec2-user#bastin neptune-export]$ sh ./bin/neptune-export.sh export-rdf -e neptestdb-cluster.cluster-xxxxxx.ap-northeast-1.neptune.amazonaws.com -d /home/ec2-user/output
Creating statement files
Completed export-rdf in 1 seconds
An error occurred while exporting from Neptune:
java.lang.RuntimeException: java.lang.NullPointerException
at com.amazonaws.services.neptune.rdf.NeptuneSparqlClient.executeQuery(NeptuneSparqlClient.java:166)
at com.amazonaws.services.neptune.rdf.io.ExportRdfGraphJob.execute(ExportRdfGraphJob.java:31)
at com.amazonaws.services.neptune.ExportRdfGraph.run(ExportRdfGraph.java:55)
at com.amazonaws.services.neptune.NeptuneExportCli.main(NeptuneExportCli.java:54)
Caused by: java.lang.NullPointerException
at com.amazonaws.services.neptune.rdf.io.EnhancedTurtleWriter.handleStatement(EnhancedTurtleWriter.java:42)
at com.amazonaws.services.neptune.rdf.NeptuneSparqlClient$2.handleSolution(NeptuneSparqlClient.java:161)
at org.eclipse.rdf4j.query.resultio.binary.BinaryQueryResultParser.parse(BinaryQueryResultParser.java:192)
at org.eclipse.rdf4j.query.resultio.AbstractTupleQueryResultParser.parseQueryResult(AbstractTupleQueryResultParser.java:48)
at org.eclipse.rdf4j.http.client.SPARQLProtocolSession.getTupleQueryResult(SPARQLProtocolSession.java:693)
at org.eclipse.rdf4j.http.client.SPARQLProtocolSession.sendTupleQuery(SPARQLProtocolSession.java:372)
at org.eclipse.rdf4j.repository.sparql.query.SPARQLTupleQuery.evaluate(SPARQLTupleQuery.java:55)
at com.amazonaws.services.neptune.rdf.NeptuneSparqlClient.executeQuery(NeptuneSparqlClient.java:126)
... 3 more
[ec2-user#bastin neptune-export]$
The procedure is as follows.
Command
1. download tool
git clone https://github.com/awslabs/amazon-neptune-tools.git
2. install mvn for build
sudo wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
mvn --version
3. execute build
cd /home/ec2-user/amazon-neptune-tools/neptune-export
mvn clean install
4. exexute neptune-export.sh
cd /home/ec2-user/amazon-neptune-tools/neptune-export
sh ./bin/neptune-export.sh export-rdf -e https://neptestdb-cluster.cluster-xxxxxxx.ap-northeast-1.neptune.amazonaws.com -d /home/ec2-user/output
If you have any idea, please contact us.
thank you for your cooperation.
Thanks for reporting this. I've identified the problem and will push an update to the repository later today or tomorrow. In the meantime, you can replace line 42 in EnhancedTutleWriter.java with the following:
Resource context = statement.getContext();
if (context != null){
prefixes.parse(context.stringValue(), this);
}
When I try to install gitpython via pip normally under python 2.7, it fails telling me python 3.x is required.
This particular script/process has worked until this morning.
$ sudo pip install gitpython
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting gitpython
Using cached https://www.piwheels.org/simple/gitpython/GitPython-2.1.12-py2.py3-none-any.whl
GitPython requires Python '>=3.0, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*' but the running Python is 2.7.16
I am running Python 2.7.16
$ python --version
Python 2.7.16
When I check the current documentation I see that Python 2.7 or newer is listed as a requirement. What am I missing?
Turns out the documentation was lagging, and Python 2.7 support was dropped in dac619e.
Assuming other folks are procrastinating as I am in getting to Python 3, I've created a fork of GitPython which is current with 2.1.12 and reverts only those changes which eliminated stated compatibility for Python 2.7. My fork is expected to remain static with the 0.2.12a release and otherwise even with mainline GitPython 2.1.12.
I've created a small batch file for folks who may want/need to automate the installation process of this fork:
#!/bin/bash
gitpython() {
local cwd repo pipList found
pipList=$(pip list)
found=$(grep -o "GitPython" <<< "$pipList" | wc -l)
repo="https://github.com/lbussy/GitPython.git"
if [ "$found" -eq "0" ]; then
echo -e "\nDownloading and installing GitPython for Python 2.7."
cwd=$(pwd)
git clone "$repo" "$HOME/git-python" &>/dev/null || die "$#"
cd "$HOME/git-python" || die "$#"
eval "python setup.py install" &>/dev/null || die "$#"
cd "$cwd" || die "$#"
rm -fr "$HOME/git-python"
echo -e "\nGitPython for Python 2.7 install complete."
else
echo -e "\nGitPython for Python 2.7 already installed."
fi
}
function die
{
local message=$1
[ -z "$message" ] && message="Died"
echo "${BASH_SOURCE[1]}: line ${BASH_LINENO[0]}: ${FUNCNAME[1]}: $message." >&2
exit 1
}
main() {
gitpython "$#"
}
main "$?" && exit 0
Installed in this manner, it is still able to be managed by pip going forward.
I am trying to put together a simple script that does a regex on a git clone output and captions the directory that the default clone cmd is cloning too and then captures this into a shell for or something that can then be piped into xargs?
E.g:
git clone git#github.com:thorchain/instaswap-sdk.git |& grep "\'\S*\'" | xargs cd
In this example grep is not the right tool as its output is the matching line and not the match. However, for the life of me, I can't seem to find a simple regex matching tool?
Thanks in adv
Luke
Turns out the missing bit was the grep -o that I needed. What I was trying to do was built a bash function the git cloned and cd into the repos directory.
End solution here:
function gitc() {
cd `git clone "$#" |& grep -o "\'\S*\'" | tr -d "'"`
}
My team uses a common naming convention for branch names, which include the Jira task number in the branch name.
feature/ACD-1664_update-api-call
feature/VZ-1943_new-provider-template
hotfix/RV-977_fix-loading-issue
I want to create a git alias that will automatically stub out a commit message which includes the Jira task number. Ideally some bash script that will parse the branch name and echo out the commit -m command with the first part of the message pre-created.
I need to regex out the commmit message.
I need to pull ACD-1664 from feature/ACD-1664_update-api-call
Echo this string out into the terminal in a stubbed-out commit command like:
git commit -m "ACD-1664 | <cursor>"
Although this is not the solution you requested, I'd like to hint at another way to cover this, with a commit hook :
You can put in .git/hooks a commit-msg file with these contents :
#!/bin/bash
current_branch="$(git rev-parse --abbrev-ref HEAD)"
tmp=$(mktemp) || exit
echo "$current_branch $(cat "$1")" > "$tmp"
mv "$tmp" "$1"
(Thanks guys for the improvements in bash syntax made with your help here)
Then it would automatically prepend your commit messages with the branch name, which does the trick in JIRA.
For the rare occasions when you'd prefer NOT to trigger the hook, do this :
git commit -n -m"Your message"