diff --git a/bin/mp-commit b/bin/mp-commit new file mode 100755 index 00000000..6c88a446 --- /dev/null +++ b/bin/mp-commit @@ -0,0 +1,21 @@ +#!/bin/sh +# commit the directory ($1) with a message ($2) to git + +. shell-error + +[ -d "$1" ] || fatal "$1 is not an existing directory" + +if type -t git >&/dev/null && pushd "$1" >/dev/null; then + if [ -z "$(git config --global user.name)" ]; then + exit 0 + fi + if [ ! -d .git ]; then + git init -q || fatal "git init failed" + fi + if [ -n "$(git status -s)" ]; then + git add . \ + && git commit -qam "$2" \ + || fatal "git add/commit failed" + fi + popd >/dev/null +fi diff --git a/bin/mp-showref b/bin/mp-showref new file mode 100755 index 00000000..89920889 --- /dev/null +++ b/bin/mp-showref @@ -0,0 +1,11 @@ +#!/bin/sh +# report on git repo in the current directory + +if type -t git >&/dev/null; then + if pushd "$1" >/dev/null && [ -d .git ]; then + git show-ref --head -ds -- HEAD + git status -s + echo + popd >/dev/null + fi +fi diff --git a/features.in/Makefile b/features.in/Makefile index 2149ffd3..6557b3c9 100644 --- a/features.in/Makefile +++ b/features.in/Makefile @@ -108,29 +108,16 @@ $(FEATURES): done; \ popd >&/dev/null; \ done; \ - if type -t git >&/dev/null && \ - pushd "$(BUILDDIR)/$$dst/" >/dev/null; then \ - test -n "`git status -s`" && \ - git add . && \ - if [ -n "$$dst" ]; then \ - the="$$sub subprofile"; \ - else \ - the="toplevel"; \ - fi && \ - git commit -qam "$$feat feature: $$the part added"; \ - popd >/dev/null; \ + if [ -n "$$dst" ]; then \ + the="$$sub subprofile"; \ + else \ + the="toplevel"; \ fi; \ + mp-commit "$(BUILDDIR)/$$dst/" "$$feat feature: $$the part added"; \ done; \ if [ -x "generate.sh" ]; then sh generate.sh; fi; \ if [ -s "generate.mk" ]; then $(MAKE) -f generate.mk; fi; \ - if type -t git >&/dev/null && \ - pushd "$(BUILDDIR)/" >/dev/null; then \ - if [ -n "`git status -s`" ]; then \ - git add . && \ - git commit -qam "$$feat feature generation complete"; \ - fi; \ - popd >/dev/null; \ - fi; \ + mp-commit "$(BUILDDIR)" "$$feat feature generation complete"; \ popd >/dev/null finalize: diff --git a/features.in/build-distro/lib/90-build-distro.mk b/features.in/build-distro/lib/90-build-distro.mk index 9c485d32..4a879258 100644 --- a/features.in/build-distro/lib/90-build-distro.mk +++ b/features.in/build-distro/lib/90-build-distro.mk @@ -24,6 +24,7 @@ all: $(GLOBAL_DEBUG) prep copy-subdirs copy-tree run-scripts pack-image \ prep: $(GLOBAL_DEBUG) dot-disk $(WHATEVER) +# can't use mp-showref which belongs to the metaprofile dot-disk: @mkdir -p files/.disk @echo "ALT Linux based" >files/.disk/info diff --git a/lib/profile.mk b/lib/profile.mk index f3d85f18..7147dd02 100644 --- a/lib/profile.mk +++ b/lib/profile.mk @@ -44,13 +44,7 @@ profile/init: distclean @$(call put,ifndef DISTCFG_MK) @$(call put,DISTCFG_MK = 1) @{ \ - if type -t git >&/dev/null; then \ - if [ -d .git ]; then \ - git show-ref --head -d -s -- HEAD && \ - git status -s && \ - echo; \ - fi $(LOG); \ - fi; \ + mp-showref $(LOG); \ { \ APTCONF="$(wildcard $(APTCONF))"; \ echo "** using $${APTCONF:-system apt configuration}:"; \ @@ -71,14 +65,7 @@ profile/init: distclean fi >&2; \ exit 1; \ fi; \ - if type -t git >&/dev/null; then \ - if cd $(BUILDDIR); then \ - git init -q && \ - git add . && \ - git commit -qam 'derivative profile initialized'; \ - cd ->&/dev/null; \ - fi; \ - fi; \ + mp-commit "$(BUILDDIR)" "derivative profile initialized"; \ if [ -w . ]; then \ rm -f "$(SYMLINK)" && \ ln -s "$(BUILDDIR)" "$(SYMLINK)" && \ @@ -99,20 +86,12 @@ profile/bare: profile/init @$(call try,LOGDIR,$(LOGDIR)) @$(call try,BRANDING,altlinux-sisyphus) @$(call set,IMAGE_INIT_LIST,+branding-$$(BRANDING)-release) - @if type -t git >&/dev/null && cd $(BUILDDIR); then \ - git init -q && \ - git add . && \ - git commit -qam 'image configuration defaults set'; \ - fi + @mp-commit "$(BUILDDIR)" "image configuration defaults set" profile/finalize: @if [ -s $(RC) ]; then $(call put,-include $(RC)); fi @$(call put,endif) - @if type -t git >&/dev/null && cd $(BUILDDIR); then \ - git init -q && \ - git add . && \ - git commit -qam 'image configuration finalized'; \ - fi + @mp-commit "$(BUILDDIR)" "image configuration finalized" # requires already formed distcfg.mk for useful output profile/dump-vars: diff --git a/pkg.in/groups/Makefile b/pkg.in/groups/Makefile index 5a69b429..1e98d0c9 100644 --- a/pkg.in/groups/Makefile +++ b/pkg.in/groups/Makefile @@ -14,13 +14,7 @@ all: $(GLOBAL_DEBUG) mkdir -p $(TARGET) && \ cp -at $(TARGET) -- \ $(addsuffix .directory,$(THE_GROUPS) $(MAIN_GROUPS)); \ - if type -t git >&/dev/null && cd $(TARGET); then \ - if [ -n "`git status -s`" ]; then \ - git add . && \ - git commit -qam "requested $(SUFFIX) copied over"; \ - fi; \ - cd - >&/dev/null; \ - fi; \ + mp-commit "$(TARGET)" "requested $(SUFFIX) copied over"; \ fi debug: diff --git a/pkg.in/lists/Makefile b/pkg.in/lists/Makefile index 34fa8d61..fa50d2e8 100644 --- a/pkg.in/lists/Makefile +++ b/pkg.in/lists/Makefile @@ -19,13 +19,7 @@ SUFFIX := pkg/lists TARGET := $(BUILDDIR)/$(SUFFIX) all: $(TARGET) $(GLOBAL_DEBUG) $(DOTBASE) copy-lists copy-groups - @if type -t git >&/dev/null && cd $(TARGET); then \ - if [ -n "`git status -s`" ]; then \ - git add . && \ - git commit -qam "requested $(SUFFIX) copied over"; \ - fi; \ - cd - >&/dev/null; \ - fi + @mp-commit "$(TARGET)" "requested $(SUFFIX) copied over" copy-lists: @# env | sort -u | grep _LISTS | xargs cp diff --git a/sub.in/Makefile b/sub.in/Makefile index c5a08671..fe5fb834 100644 --- a/sub.in/Makefile +++ b/sub.in/Makefile @@ -14,13 +14,8 @@ all: dst="$${sub#*/}" && \ neq="$${src#$$dst}" && \ rsync -qa "$$src/" "$(BUILDDIR)/$$dst/" && \ - if type -t git >&/dev/null && cd "$(BUILDDIR)/$$dst/"; then \ - if [ -n "`git status -s`" ]; then \ - git add . && \ - git commit -qam "$$dst subprofile initialized$${neq:+ (using $$src)}"; \ - fi; \ - cd - >&/dev/null; \ - fi; \ + mp-commit "$(BUILDDIR)/$$dst/" \ + "$$dst subprofile initialized$${neq:+ (using $$src)}"; \ done clean: