1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.lfs;
11
12 import java.io.IOException;
13
14 import org.eclipse.jgit.api.errors.InvalidConfigurationException;
15 import org.eclipse.jgit.errors.ConfigInvalidException;
16 import org.eclipse.jgit.lib.ConfigConstants;
17 import org.eclipse.jgit.lib.Repository;
18 import org.eclipse.jgit.lib.StoredConfig;
19 import org.eclipse.jgit.util.FS;
20 import org.eclipse.jgit.util.LfsFactory.LfsInstallCommand;
21 import org.eclipse.jgit.util.SystemReader;
22
23
24
25
26
27
28
29 public class InstallBuiltinLfsCommand implements LfsInstallCommand {
30
31 private static final String[] ARGS_USER = new String[] { "lfs", "install" };
32
33 private static final String[] ARGS_LOCAL = new String[] { "lfs", "install",
34 "--local" };
35
36 private Repository repository;
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @Override
51 public Void call() throws IOException, InvalidConfigurationException,
52 InterruptedException {
53 StoredConfig cfg = null;
54 if (repository == null) {
55 try {
56 cfg = SystemReader.getInstance().getUserConfig();
57 } catch (ConfigInvalidException e) {
58 throw new InvalidConfigurationException(e.getMessage(), e);
59 }
60 } else {
61 cfg = repository.getConfig();
62 }
63
64 cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION,
65 ConfigConstants.CONFIG_SECTION_LFS,
66 ConfigConstants.CONFIG_KEY_USEJGITBUILTIN, true);
67 cfg.setBoolean(ConfigConstants.CONFIG_FILTER_SECTION,
68 ConfigConstants.CONFIG_SECTION_LFS,
69 ConfigConstants.CONFIG_KEY_REQUIRED, true);
70
71 cfg.save();
72
73
74
75 ProcessBuilder builder = FS.DETECTED.runInShell("git",
76 repository == null ? ARGS_USER : ARGS_LOCAL);
77 if (repository != null) {
78 builder.directory(repository.isBare() ? repository.getDirectory()
79 : repository.getWorkTree());
80 }
81 FS.DETECTED.runProcess(builder, null, null, (String) null);
82
83 return null;
84 }
85
86
87
88
89
90
91
92
93
94 @Override
95 public LfsInstallCommand setRepository(Repository repo) {
96 this.repository = repo;
97 return this;
98 }
99
100 }