Skip to content

Commit 0f84b7d

Browse files
committed
move update checking code to feature/update-checker while in dev
1 parent 2f4e846 commit 0f84b7d

1 file changed

Lines changed: 0 additions & 99 deletions

File tree

git-clone-completion.bash

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,105 +1357,6 @@ _complete_url()
13571357
return 1
13581358
}
13591359

1360-
#################
1361-
# #
1362-
# Update checks #
1363-
# #
1364-
#################
1365-
1366-
GG_NO_UPDATE_MARKER="$GG_CFGDIR/no-update-checks"
1367-
GG_NEW_VERSION="$GG_CACHEDIR/git-clone-completion.bash"
1368-
GG_SELF="${BASH_SOURCE[0]}"
1369-
#GG_UPDATE_CHECK_INTERVAL='-1 weeks'
1370-
#GG_UPDATE_NAG_INTERVAL='-1 weeks'
1371-
GG_UPDATE_CHECK_INTERVAL='-30 seconds'
1372-
GG_UPDATE_NAG_INTERVAL='-2 minutes'
1373-
1374-
__check_and_download_update()
1375-
{
1376-
# don't check if we've checked within the last week
1377-
if [[ -n $(find "$GG_NEW_VERSION" -newermt "$GG_UPDATE_CHECK_INTERVAL" 2>/dev/null) ]]; then
1378-
return
1379-
fi
1380-
1381-
# to avoid having multiple instances downloading the same file
1382-
mkdir -p "$(dirname "$GG_NEW_VERSION")"
1383-
touch "$GG_NEW_VERSION"
1384-
1385-
# download the current version
1386-
local tmp="$GG_NEW_VERSION.$$.$RANDOM.tmp"
1387-
1388-
if curl -f -s "https://raw.githubusercontent.com/mjuric/git-utils/master/git-clone-completion.bash" -o "$tmp" >/dev/null 1>&2 && # download
1389-
[[ -s "$tmp" ]] && # continue if not empty
1390-
! cmp -s "$GG_SELF" "$tmp" 2>/dev/null && # continue if not the same
1391-
bash -n "$tmp" 2>/dev/null; # continue if not malformed
1392-
then
1393-
# we have a new update ready to install!
1394-
mv "$tmp" "$GG_NEW_VERSION"
1395-
else
1396-
rm -f "$tmp"
1397-
fi
1398-
}
1399-
1400-
gg-update()
1401-
{
1402-
if [[ ! -f "$GG_NEW_VERSION" ]]; then
1403-
echo "git-clone-completion: no new version available for update." 1>&2
1404-
return
1405-
fi
1406-
1407-
# save a backup
1408-
local backup="$GG_CACHEDIR/git-clone-completion.bash.$(date)"
1409-
cp -a "$GG_SELF" "$backup"
1410-
1411-
echo
1412-
echo "saved the current version to:"
1413-
echo " $backup"
1414-
echo
1415-
1416-
# replace self with the new version
1417-
echo "Now run: "
1418-
echo
1419-
echo " mv '$GG_NEW_VERSION' '$GG_SELF'"
1420-
echo
1421-
echo "to update."
1422-
#echo "git-clone-completion: update complete! source $SELF to activate."
1423-
}
1424-
1425-
gg-stop()
1426-
{
1427-
rm -f "$GG_NEW_VERSION"
1428-
1429-
mkdir -p "$(dirname "$GG_NO_UPDATE_MARKER")"
1430-
touch "$GG_NO_UPDATE_MARKER"
1431-
1432-
echo "git-clone-completion: won't check for updates going forward."
1433-
}
1434-
1435-
__check_update()
1436-
{
1437-
# don't check if the user told us not to
1438-
[[ -f $GG_NO_UPDATE_MARKER ]] && return
1439-
1440-
# asynchronously check for updates
1441-
( __check_and_download_update & )
1442-
1443-
# if an update is ready to be installed, let the user know (but don't nag too much)
1444-
nagfile="$GG_CACHEDIR/last_update_nag"
1445-
if [[
1446-
-s "$GG_NEW_VERSION" &&
1447-
-z $(find "$nagfile" -newermt "$GG_UPDATE_NAG_INTERVAL" 2>/dev/null)
1448-
]]; then
1449-
mkdir -p "$(basename "$nagfile")"
1450-
touch "$nagfile"
1451-
1452-
echo "message: new git-clone-completion available; run gg-update to update. run gg-stop to stop update checks." 1>&2
1453-
fi
1454-
}
1455-
1456-
# Enable for everyone once we're happy with how well this works
1457-
: __check_update
1458-
14591360
#######################
14601361
# #
14611362
# Install completions #

0 commit comments

Comments
 (0)