diff --git a/hooks/git_attrs.py b/hooks/git_attrs.py index 1f16a15..430ae7f 100644 --- a/hooks/git_attrs.py +++ b/hooks/git_attrs.py @@ -129,13 +129,16 @@ def git_attribute(commit_rev, filename_list, attr_name): for filename in filename_list: assert not os.path.isabs(filename) dir_path = filename + dir_created = False while dir_path: dir_path = os.path.dirname(dir_path) if dir_path in dirs_with_changes: continue gitattributes_rel_file = os.path.join(dir_path, '.gitattributes') if cached_file_exists(commit_rev, gitattributes_rel_file): - os.makedirs(os.path.join(tmp_checkout_dir, dir_path)) + if not dir_created: + os.makedirs(os.path.join(tmp_checkout_dir, dir_path)) + dir_created = True git.show("%s:%s" % (commit_rev, gitattributes_rel_file), _outfile=os.path.join(tmp_checkout_dir, gitattributes_rel_file)) diff --git a/testsuite/tests/P601-011__gitattributes_handling/bare_repo_config b/testsuite/tests/P601-011__gitattributes_handling/bare_repo_config new file mode 100644 index 0000000..07d359d --- /dev/null +++ b/testsuite/tests/P601-011__gitattributes_handling/bare_repo_config @@ -0,0 +1,4 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true diff --git a/testsuite/tests/P601-011__gitattributes_handling/git-repos.tar.bz2 b/testsuite/tests/P601-011__gitattributes_handling/git-repos.tar.bz2 new file mode 100644 index 0000000..8214f51 Binary files /dev/null and b/testsuite/tests/P601-011__gitattributes_handling/git-repos.tar.bz2 differ diff --git a/testsuite/tests/P601-011__gitattributes_handling/hooks_config b/testsuite/tests/P601-011__gitattributes_handling/hooks_config new file mode 100644 index 0000000..93a508c --- /dev/null +++ b/testsuite/tests/P601-011__gitattributes_handling/hooks_config @@ -0,0 +1,3 @@ +[hooks] + from-domain = adacore.com + mailinglist = git-hooks-ci@example.com diff --git a/testsuite/tests/P601-011__gitattributes_handling/test.py b/testsuite/tests/P601-011__gitattributes_handling/test.py new file mode 100644 index 0000000..fb0b1b6 --- /dev/null +++ b/testsuite/tests/P601-011__gitattributes_handling/test.py @@ -0,0 +1,65 @@ +from support import * + +class TestRun(TestCase): + def test_push_commit_on_master(self): + """Try pushing one single-file commit on master. + """ + cd ('%s/repo' % TEST_DIR) + + # Push master to the `origin' remote. The delta should be one + # commit with one file being modified. + p = Run('git push origin master'.split()) + expected_out = """\ +remote: DEBUG: Content-Type: text/plain; charset="us-ascii" +remote: MIME-Version: 1.0 +remote: Content-Transfer-Encoding: 7bit +remote: From: Test Suite +remote: To: git-hooks-ci@example.com +remote: Bcc: file-ci@gnat.com +remote: Subject: [repo] Minor reformatting. +remote: X-Act-Checkin: repo +remote: X-Git-Author: Joel Brobecker +remote: X-Git-Refname: refs/heads/master +remote: X-Git-Oldrev: 937ea8ac48994bdef9928dc6e246bb1d3efb8acd +remote: X-Git-Newrev: 4b27b37bcd68460e2ec2ccd97a4e93660ed4cd16 +remote: +remote: commit 4b27b37bcd68460e2ec2ccd97a4e93660ed4cd16 +remote: Author: Joel Brobecker +remote: Date: Wed Jun 1 09:38:20 2016 -0700 +remote: +remote: Minor reformatting. +remote: +remote: Diff: +remote: --- +remote: gms/hello.adb | 1 + +remote: sec/README | 3 +++ +remote: 2 files changed, 4 insertions(+) +remote: +remote: diff --git a/gms/hello.adb b/gms/hello.adb +remote: index 9a6ff61..93db53d 100644 +remote: --- a/gms/hello.adb +remote: +++ b/gms/hello.adb +remote: @@ -1,4 +1,5 @@ +remote: with Ada.Text_IO; use Ada.Text_IO; +remote: + +remote: procedure Hello is +remote: begin +remote: Put_Line ("Hello World."); +remote: diff --git a/sec/README b/sec/README +remote: index a7e57ad..93f282d 100644 +remote: --- a/sec/README +remote: +++ b/sec/README +remote: @@ -1 +1,4 @@ +remote: +REPO's sec/ README: +remote: +------------------- +remote: + +remote: This directory contains interesting stuff. +To ../bare/repo.git + 937ea8a..4b27b37 master -> master +""" + + self.assertEqual(p.status, 0, p.image) + self.assertRunOutputEqual(p, expected_out) + +if __name__ == '__main__': + runtests()