View Javadoc
1   /*
2    * Copyright (C) 2008-2009, Google Inc.
3    * Copyright (C) 2009-2010, Robin Rosenberg <robin.rosenberg@dewire.com> and others
4    *
5    * This program and the accompanying materials are made available under the
6    * terms of the Eclipse Distribution License v. 1.0 which is available at
7    * https://www.eclipse.org/org/documents/edl-v10.php.
8    *
9    * SPDX-License-Identifier: BSD-3-Clause
10   */
11  
12  package org.eclipse.jgit.pgm;
13  
14  import java.io.File;
15  import java.io.IOException;
16  import java.text.MessageFormat;
17  
18  import org.eclipse.jgit.errors.RepositoryNotFoundException;
19  import org.eclipse.jgit.lib.RepositoryCache.FileKey;
20  import org.eclipse.jgit.pgm.internal.CLIText;
21  import org.eclipse.jgit.util.FS;
22  import org.kohsuke.args4j.Argument;
23  import org.kohsuke.args4j.Option;
24  
25  @Command(common = false, usage = "usage_ServerSideBackendForJgitFetch")
26  class UploadPack extends TextBuiltin {
27  	@Option(name = "--timeout", metaVar = "metaVar_seconds", usage = "usage_abortConnectionIfNoActivity")
28  	int timeout = -1;
29  
30  	@Argument(index = 0, required = true, metaVar = "metaVar_directory", usage = "usage_RepositoryToReadFrom")
31  	File srcGitdir;
32  
33  	/** {@inheritDoc} */
34  	@Override
35  	protected final boolean requiresRepository() {
36  		return false;
37  	}
38  
39  	/** {@inheritDoc} */
40  	@Override
41  	protected void run() {
42  		try {
43  			FileKey key = FileKey.lenient(srcGitdir, FS.DETECTED);
44  			db = key.open(true /* must exist */);
45  			org.eclipse.jgit.transport.UploadPack up = new org.eclipse.jgit.transport.UploadPack(
46  					db);
47  			if (0 <= timeout) {
48  				up.setTimeout(timeout);
49  			}
50  			up.upload(ins, outs, errs);
51  		} catch (RepositoryNotFoundException notFound) {
52  			throw die(MessageFormat.format(CLIText.get().notAGitRepository,
53  					srcGitdir.getPath()), notFound);
54  		} catch (IOException e) {
55  			throw die(e.getMessage(), e);
56  		}
57  	}
58  }