1 |
Fix updates to respect sync-depth (previously it was only respected |
2 |
for clone operations). Since the default merge strategy typically |
3 |
fails when the the depth is not unlimited, use `git fetch` followed |
4 |
by `git reset --hard`. |
5 |
|
6 |
X-Gentoo-Bug: 552814 |
7 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=552814 |
8 |
--- |
9 |
pym/portage/sync/modules/git/git.py | 22 +++++++++++++++++++++- |
10 |
1 file changed, 21 insertions(+), 1 deletion(-) |
11 |
|
12 |
diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py |
13 |
index 02eeb16..62c24f6 100644 |
14 |
--- a/pym/portage/sync/modules/git/git.py |
15 |
+++ b/pym/portage/sync/modules/git/git.py |
16 |
@@ -83,7 +83,21 @@ class GitSync(NewBase): |
17 |
git_cmd_opts += " --quiet" |
18 |
if self.repo.module_specific_options.get('sync-git-pull-extra-opts'): |
19 |
git_cmd_opts += " %s" % self.repo.module_specific_options['sync-git-pull-extra-opts'] |
20 |
- git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts) |
21 |
+ if self.repo.sync_depth is None: |
22 |
+ git_cmd = "%s pull%s" % (self.bin_command, git_cmd_opts) |
23 |
+ else: |
24 |
+ # Since the default merge strategy typically fails when |
25 |
+ # the depth is not unlimited, use `git fetch` followed by |
26 |
+ # `git reset --hard`. |
27 |
+ remote_branch = portage._unicode_decode( |
28 |
+ subprocess.check_output([self.bin_command, 'rev-parse', |
29 |
+ '--abbrev-ref', '--symbolic-full-name', '@{upstream}'], |
30 |
+ cwd=portage._unicode_encode(self.repo.location))).rstrip('\n') |
31 |
+ |
32 |
+ git_cmd_opts += " --depth %d" % self.repo.sync_depth |
33 |
+ git_cmd = "%s fetch %s%s" % (self.bin_command, |
34 |
+ remote_branch.partition('/')[0], git_cmd_opts) |
35 |
+ |
36 |
writemsg_level(git_cmd + "\n") |
37 |
|
38 |
rev_cmd = [self.bin_command, "rev-list", "--max-count=1", "HEAD"] |
39 |
@@ -93,6 +107,12 @@ class GitSync(NewBase): |
40 |
exitcode = portage.process.spawn_bash("cd %s ; exec %s" % ( |
41 |
portage._shell_quote(self.repo.location), git_cmd), |
42 |
**self.spawn_kwargs) |
43 |
+ |
44 |
+ if exitcode == os.EX_OK and self.repo.sync_depth is not None: |
45 |
+ exitcode = subprocess.call( |
46 |
+ [self.bin_command, 'reset', '--hard', remote_branch], |
47 |
+ cwd=portage._unicode_encode(self.repo.location)) |
48 |
+ |
49 |
if exitcode != os.EX_OK: |
50 |
msg = "!!! git pull error in %s" % self.repo.location |
51 |
self.logger(self.xterm_titles, msg) |
52 |
-- |
53 |
2.7.4 |