[PATCH] [Kimchi] Issue #585: 'make clean' does not revert its changes from 'make rpm'

From: Bianca Carvalho <bianca@linux.vnet.ibm.com> Edited Makefile.am to check if there is any file to be stashed or commited before run 'make rpm' to avoid losing any changes. Also included 'git clean -df & git reset --hard' command to remove untracked files from the working tree and to revert changes made by 'make rpm' command. Signed-off-by: Bianca Carvalho <bianca@linux.vnet.ibm.com> --- Makefile.am | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9bebb65..dcdf6bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,17 +135,30 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse /bin/false ; \ fi -rpm: dist kimchi.spec +check_files: + @if [ -d '.git' ]; then \ + if [ `git status --porcelain | wc -l` -gt 0 ]; then \ + echo "***** Aborting 'make rpm' command *****"; \ + echo "There are some changes not commited in your working \ +directory. To avoid losing them, please commit or stage before run 'make rpm' command."; \ + exit 1; \ + fi \ + fi + +rpm: check_files dist kimchi.spec $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec cp $(DIST_ARCHIVES) rpm/SOURCES rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec + @if [ -d '.git' ]; then \ + git clean -df & git reset --hard; \ + fi -fedora-rpm: contrib/kimchi.spec.fedora +fedora-rpm: check_files contrib/kimchi.spec.fedora ln -sf contrib/kimchi.spec.fedora kimchi.spec $(MAKE) rpm -suse-rpm: contrib/kimchi.spec.suse +suse-rpm: check_files contrib/kimchi.spec.suse ln -sf contrib/kimchi.spec.suse kimchi.spec $(MAKE) rpm -- 2.7.4

Almost there. The command you're using to check for changes in the working dir is considering untracked files as well: (...) config.status: executing depfiles commands ***** Aborting 'make rpm' command ***** There are some changes not commited in your working directory. To avoid losing them, please commit or stage before run 'make rpm' command. Makefile:1123: recipe for target 'check_files' failed make: *** [check_files] Error 1 [danielhb@arthas kimchi]$ [danielhb@arthas kimchi]$ git status On branch issue585 Untracked files: (use "git add <file>..." to include in what will be committed) 0000-cover-letter.patch 0001-model.py-use-the-new-get_all_model_instances-utils-f.patch [Kimchi-devel] [PATCH] [Kimchi] Issue #585: 'make clean' does not revert its changes from 'make rpm'.eml test_vv.vv nothing added to commit but untracked files present (use "git add" to track) [danielhb@arthas kimchi]$ This is the output of the command you're using to verify for changes in the working dir: [danielhb@arthas kimchi]$ git status --porcelain | wc -l 4 [danielhb@arthas kimchi]$ Checking the man file of git status I've found that there is a parameter called --untracked-files that you can use to ignore them: [danielhb@arthas kimchi]$ git status --porcelain --untracked-files=no | wc -l 0 [danielhb@arthas kimchi]$ This would be the output you want in my scenario (no changes in working dir but some untracked files exists). One more comment below: On 08/11/2016 03:06 PM, bianca@linux.vnet.ibm.com wrote:
From: Bianca Carvalho <bianca@linux.vnet.ibm.com>
Edited Makefile.am to check if there is any file to be stashed or commited before run 'make rpm' to avoid losing any changes. Also included 'git clean -df & git reset --hard' command to remove untracked files from the working tree and to revert changes made by 'make rpm' command.
Signed-off-by: Bianca Carvalho <bianca@linux.vnet.ibm.com> --- Makefile.am | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/Makefile.am b/Makefile.am index 9bebb65..dcdf6bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -135,17 +135,30 @@ kimchi.spec: contrib/kimchi.spec.fedora contrib/kimchi.spec.suse /bin/false ; \ fi
-rpm: dist kimchi.spec +check_files: + @if [ -d '.git' ]; then \ + if [ `git status --porcelain | wc -l` -gt 0 ]; then \ + echo "***** Aborting 'make rpm' command *****"; \ + echo "There are some changes not commited in your working \ +directory. To avoid losing them, please commit or stage before run 'make rpm' command."; \ + exit 1; \ + fi \ + fi + +rpm: check_files dist kimchi.spec $(MKDIR_P) rpm/BUILD rpm/RPMS rpm/SOURCES rpm/SPECS rpm/SRPMS cp $(top_srcdir)/kimchi.spec rpm/SPECS/kimchi.spec cp $(DIST_ARCHIVES) rpm/SOURCES rpmbuild -ba --define "_topdir `pwd`/rpm" rpm/SPECS/kimchi.spec + @if [ -d '.git' ]; then \ + git clean -df & git reset --hard; \ + fi There are trailing whitespaces here ^
(I saw the git warning when applying the patch)
-fedora-rpm: contrib/kimchi.spec.fedora +fedora-rpm: check_files contrib/kimchi.spec.fedora ln -sf contrib/kimchi.spec.fedora kimchi.spec $(MAKE) rpm
-suse-rpm: contrib/kimchi.spec.suse +suse-rpm: check_files contrib/kimchi.spec.suse ln -sf contrib/kimchi.spec.suse kimchi.spec $(MAKE) rpm
participants (2)
-
bianca@linux.vnet.ibm.com
-
Daniel Henrique Barboza