github.com/stackdocker/rkt@v0.10.1-0.20151109095037-1aa827478248/makelib/git-refresh.mk (about)

     1  # This file refreshes the given repository. If new changes are
     2  # available in a given branch on remote repo, this does the hard reset
     3  # and complete clean of the directory. Treat this file rather as an
     4  # implementation detail of makelib/git.mk
     5  #
     6  # Inputs:
     7  #
     8  # GR_TARGET - target that will be invalidated if new changes are
     9  # available.
    10  #
    11  # GR_PREREQS - stuff needed to be done before we can do the check
    12  # (something like initial clone).
    13  #
    14  # GR_SRCDIR - repository directory
    15  #
    16  # GR_BRANCH - a branch to check
    17  
    18  # Just some target, it is a phony target, so it does not need to exist
    19  # or be meaningful in any way.
    20  _GR_CONFIG_FORCE_CHECK_ := $(GR_SRCDIR)/FORCE_CHECK
    21  # git with src dir as its working directory
    22  _GR_GIT_ := "$(GIT)" -C "$(GR_SRCDIR)"
    23  # git's config file
    24  _GR_CONFIG_FILE_ := $(GR_SRCDIR)/.git/config
    25  
    26  # target depends on git config file; we assume that updating the
    27  # config with "git config" will update the timestamp of the config
    28  # file, which in turn will invalidate the target
    29  $(GR_TARGET): $(_GR_CONFIG_FILE_) $(GR_PREREQS)
    30  
    31  # This checks if there are new changes in the upstream repository. If
    32  # so, it updates the config file with new FETCH_HEAD.
    33  #
    34  # It depends on a phony target, so the check is always performed.
    35  $(call forward-vars,$(_GR_CONFIG_FILE_), \
    36  	_GR_GIT_ GR_BRANCH GR_SRCDIR)
    37  $(_GR_CONFIG_FILE_): $(_GR_CONFIG_FORCE_CHECK_) $(GR_PREREQS)
    38  	$(VQ) \
    39  	set -e; \
    40  	$(call vb,vt,GIT CHECK,$$($(_GR_GIT_) config remote.origin.url) ($(GR_BRANCH)) => $(call vsp,$(GR_SRCDIR))) \
    41  	$(_GR_GIT_) fetch $(call vl3,--quiet) origin "$(GR_BRANCH)"; \
    42  	old_rev="$$($(_GR_GIT_) config rkt.fetch-head)"; \
    43  	new_rev="$$($(_GR_GIT_) rev-parse FETCH_HEAD)"; \
    44  	if [ "$${old_rev}" != "$${new_rev}" ]; then \
    45  		$(call vb,vt,GIT RESET,$(call vsp,$(GR_SRCDIR)) => $(GR_BRANCH)) \
    46  		$(_GR_GIT_) reset --hard $(call vl3,--quiet) "$${new_rev}"; \
    47  		$(call vb,vt,GIT CLEAN,$(call vsp,$(GR_SRCDIR))) \
    48  		$(_GR_GIT_) clean -ffdx $(call vl3,--quiet); \
    49  		$(_GR_GIT_) config rkt.fetch-head "$${new_rev}"; \
    50  	fi
    51  
    52  .PHONY: $(_GR_CONFIG_FORCE_CHECK_)
    53  
    54  $(call undefine-namespaces,GR _GR)