#!/usr/bin/bash
###SHELLPACK preamble gitsource-install v2.16.6
GIT_LOCATION=https://github.com/git/git
MIRROR_LOCATION="$WEBROOT/extra/gitsource/"

install-depends libcurl-devel gettext-runtime glibc-locale python
install-depends unzip perl-IO-Tty acl perl-libintl-perl perl-MailTools

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK git_fetch gitsource-${VERSION}.tar.gz gitsource-${VERSION}-installed

shellpack-check-libz
###SHELLPACK build_start gitsource-${VERSION}-installed
if [ -e .git ]; then
	git checkout $VERSION || die Failed to checkout version $VERSION
fi

###SHELLPACK self_extract Gitsource-t0021-make-sure-clean-filter-runs.patch
cat $SHELLPACK_TEMP/Gitsource-t0021-make-sure-clean-filter-runs.patch | patch -p1 || \
	die Failed to apply gitsource t0021-make-sure-clean-filter-runs  patch
###SHELLPACK self_extract Gitsource-t5404-relax-overzealous-test.patch
cat $SHELLPACK_TEMP/Gitsource-t5404-relax-overzealous-test.patch | patch -p1 || \
	die Failed to apply gitsource t5404-relax-overzealous-test  patch

make configure || die Failed to run make configure
###SHELLPACK build_configure gitsource-${VERSION}
###SHELLPACK make

echo gitsource installed successfully
exit $SHELLPACK_SUCCESS

==== BEGIN Gitsource-t0021-make-sure-clean-filter-runs.patch ====
Author: Thomas Gummerer <t.gummerer@gmail.com>
Date:   Thu Aug 22 20:22:40 2019 +0100

    t0021: make sure clean filter runs
    
    In t0021.15 one of the things we are checking is that the clean filter
    is run when checking out empty-branch.  The clean filter needs to be
    run to make sure there are no modifications on the file system for the
    test.r file, and thus it isn't dangerous to overwrite it.
    
    However in the current test setup it is not always necessary to run
    the clean filter, and thus the test sometimes fails, as debug.log
    isn't written.
    
    This happens when test.r has an older mtime than the index itself.
    That mtime is also recorded as stat data for test.r in the index, and
    based on the heuristic we're using for index entries, git correctly
    assumes this file is up-to-date.
    
    Usually this test succeeds because the mtime of test.r is the same as
    the mtime of the index.  In this case test.r is racily clean, so git
    actually checks the contents, for which the clean filter is run.
    
    Fix the test by updating the mtime of test.r, so git is forced to
    check the contents of the file, and the clean filter is run as the
    test expects.
    
    Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index e10f5f787f..c954c709ad 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -390,6 +390,9 @@ test_expect_success PERL 'required process filter should filter data' '
 		EOF
 		test_cmp_exclude_clean expected.log debug.log &&
 
+		# Make sure that the file appears dirty, so checkout below has to
+		# run the configured filter.
+		touch test.r &&
 		filter_git checkout --quiet --no-progress empty-branch &&
 		cat >expected.log <<-EOF &&
 			START
==== END Gitsource-t0021-make-sure-clean-filter-runs.patch ====

==== BEGIN Gitsource-t5404-relax-overzealous-test.patch ====
Author: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Date:   Fri Apr 6 21:31:22 2018 +0200

    t5404: relax overzealous test
    
    In 0b294c0abf0 (make deleting a missing ref more quiet, 2008-07-08), we
    added a test to verify that deleting an already-deleted ref does not
    show an error.
    
    Our test simply looks for the substring 'error' in the output of the
    `git push`, which might look innocuous on the face of it.
    
    Suppose, however, that you are a big fan of whales. Or even better: your
    IT administrator has a whale of a time picking cute user names, e.g.
    referring to you (due to your like of India Pale Ales) as "one of the
    cuter rorquals" (see https://en.wikipedia.org/wiki/Rorqual to learn a
    thing or two about rorquals) and hence your home directory becomes
    /home/cuterrorqual. If you now run t5404, it fails! Why? Because the
    test calls `git push origin :b3` which outputs:
    
        To /home/cuterrorqual/git/t/trash directory.t5404-tracking-branches/.
         - [deleted]         b3
    
    Note how there is no error displayed in that output? But of course
    "error" is a substring of "cuterrorqual". And so that `grep error
    output` finds something.
    
    This bug was not, actually, caught having "error" as a substring of the
    user name but while working in a worktree called "colorize-push-errors",
    whose name was part of that output, too, suggesting that not even
    testing for the *word* `error` via `git grep -w error output` would fix
    the underlying issue.
    
    This patch chooses instead to look for the prefix "error:" at the
    beginning of the line, so that there can be no ambiguity that any catch
    was indeed a message generated by Git's `error_builtin()` function.
    
    Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
    Acked-by: Jeff King <peff@peff.net>
    Signed-off-by: Junio C Hamano <gitster@pobox.com>

diff --git a/t/t5404-tracking-branches.sh b/t/t5404-tracking-branches.sh
index 2b8c0bac7d..2762f420bc 100755
--- a/t/t5404-tracking-branches.sh
+++ b/t/t5404-tracking-branches.sh
@@ -56,7 +56,7 @@ test_expect_success 'deleted branches have their tracking branches removed' '
 test_expect_success 'already deleted tracking branches ignored' '
 	git branch -d -r origin/b3 &&
 	git push origin :b3 >output 2>&1 &&
-	! grep error output
+	! grep "^error: " output
 '
 
 test_done
==== END Gitsource-t5404-relax-overzealous-test.patch ====
