From eb51c1e48530571873d11a7d6cbc6debbe21bf26 Mon Sep 17 00:00:00 2001 From: mrjk Date: Thu, 1 Mar 2018 08:35:31 -0500 Subject: [PATCH] Add: mod_ssh pull latest branch in sync --- lib/idmgr_mod_git.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/idmgr_mod_git.sh b/lib/idmgr_mod_git.sh index fd9fcdd..3d1070b 100644 --- a/lib/idmgr_mod_git.sh +++ b/lib/idmgr_mod_git.sh @@ -351,6 +351,9 @@ idm_git__repo_sync () # If i well undertood, never do a push ! done + # update local worktree + idm_git_pull_most_recent $id + } @@ -495,6 +498,26 @@ idm_git__perm_restore () ## Internal lib ############################## +idm_git_pull_most_recent () +{ + local id=${1} + + most_recent=$(lib_git git branch -a --sort=-committerdate | sed 's/..//' | head -n 1 ) + + # Check if we are fine + if [[ ! "$most_recent" =~ ^remote ]] ; then + lib_log NOTICE "Already up to date" + return 0 + fi + + # Apply changes to most recent branch + branch=$( sed -e 's@remotes/@@' -e 's@/@ @' ) + lib_git git pull $branch || + lib_log ERR "Could not update branch" + + lib_log NOTICE "Repo updated" +} + idm_git_get_files_of_interest () { local id=${1}