Changes
Jump to navigation
Jump to search
← Older edit
Newer edit →
BASH
(view source)
Revision as of 13:18, 31 May 2017
1,097 bytes added
,
13:18, 31 May 2017
→Git check for updates and prompt to update
Line 315:
Line 315:
</source>
</source>
+
=== Git check version ===
+
<source lang="bash">#!/bin/bash
+
+
function set_upstream() {
+
echo "No upstream found, setting up branch to track "
+
exit
+
}
+
+
function set_upstream() {
+
echo "No upstream found"
+
}
+
+
+
function check_latest_version(){
+
UPSTREAM=${1:-'@{u}'}
+
+
if [ -z $(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)) ]; then
+
set_upstream
+
fi
+
+
echo "Upstream: "$UPSTREAM
+
exit
+
# TODO: check if no upstream is configured, ask if should be automatically configured (git branch --set-upstream-to remotes/$TRACK_REPO/$TRACK_BRANCH)
+
# to get the upstream branch: git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
+
+
LOCAL=$(git rev-parse @)
+
REMOTE=$(git rev-parse "$UPSTREAM")
+
BASE=$(git merge-base @ "$UPSTREAM")
+
+
if [ ${LOCAL} = ${REMOTE} ]; then
+
status="Up-to-date"
+
elif [ ${LOCAL} = ${BASE} ]; then
+
status="Need-to-pull"
+
elif [ ${REMOTE} = ${BASE} ]; then
+
status="Need-to-push"
+
else
+
status="Diverged"
+
fi
+
}
+
check_latest_version</source>
=== Git check for updates and prompt to update ===
=== Git check for updates and prompt to update ===
<source lang="bash">
<source lang="bash">
Rafahsolis
Bureaucrats
,
Administrators
2,306
edits
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
Variants
Views
Read
View source
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
Special pages
Printable version