diff options
author | Mike Frysinger <vapier@google.com> | 2020-02-21 00:04:15 -0500 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2020-02-21 23:46:54 +0000 |
commit | 7951e143852bd861da21253275131d1fa79714d0 (patch) | |
tree | 2787c21296ad34c5451eba0ca4b2b21b9c165194 /project.py | |
parent | 8c268c0e7bd18d1e2f4f526cd406c569312a5f23 (diff) | |
download | git-repo-7951e143852bd861da21253275131d1fa79714d0.tar.gz |
project: fallback to hardlinks with git hooks
Windows requires Administrator access to create symlinks. We can
mitigate this a bit by falling back to hardlinks as those may be
created by any user on the system. Do this with the git hooks as
these are supposed to be internal only and people shouldn't be
modifying them. If they do, they'll have to delink first. This
seems worth it to allow repo usage without extra privileges.
Change-Id: I996ea9c9238f7bd7d27d1d9b1f2786593bf75ef7
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256312
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -2860,19 +2860,23 @@ class Project(object): | |||
2860 | if platform_utils.islink(dst): | 2860 | if platform_utils.islink(dst): |
2861 | continue | 2861 | continue |
2862 | if os.path.exists(dst): | 2862 | if os.path.exists(dst): |
2863 | if filecmp.cmp(stock_hook, dst, shallow=False): | 2863 | # If the files are the same, we'll leave it alone. We create symlinks |
2864 | platform_utils.remove(dst) | 2864 | # below by default but fallback to hardlinks if the OS blocks them. |
2865 | else: | 2865 | # So if we're here, it's probably because we made a hardlink below. |
2866 | if not filecmp.cmp(stock_hook, dst, shallow=False): | ||
2866 | if not quiet: | 2867 | if not quiet: |
2867 | _warn("%s: Not replacing locally modified %s hook", | 2868 | _warn("%s: Not replacing locally modified %s hook", |
2868 | self.relpath, name) | 2869 | self.relpath, name) |
2869 | continue | 2870 | continue |
2870 | try: | 2871 | try: |
2871 | platform_utils.symlink( | 2872 | platform_utils.symlink( |
2872 | os.path.relpath(stock_hook, os.path.dirname(dst)), dst) | 2873 | os.path.relpath(stock_hook, os.path.dirname(dst)), dst) |
2873 | except OSError as e: | 2874 | except OSError as e: |
2874 | if e.errno == errno.EPERM: | 2875 | if e.errno == errno.EPERM: |
2875 | raise GitError(self._get_symlink_error_message()) | 2876 | try: |
2877 | os.link(stock_hook, dst) | ||
2878 | except OSError: | ||
2879 | raise GitError(self._get_symlink_error_message()) | ||
2876 | else: | 2880 | else: |
2877 | raise | 2881 | raise |
2878 | 2882 | ||