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  
24  @Command(common = false, usage = "usage_ServerSideBackendForJgitPush")
25  class ReceivePack extends TextBuiltin {
26  	@Argument(index = 0, required = true, metaVar = "metaVar_directory", usage = "usage_RepositoryToReceiveInto")
27  	File dstGitdir;
28  
29  	/** {@inheritDoc} */
30  	@Override
31  	protected final boolean requiresRepository() {
32  		return false;
33  	}
34  
35  	/** {@inheritDoc} */
36  	@Override
37  	protected void run() {
38  		final org.eclipse.jgit.transport.ReceivePack rp;
39  
40  		try {
41  			FileKey key = FileKey.lenient(dstGitdir, FS.DETECTED);
42  			db = key.open(true /* must exist */);
43  		} catch (RepositoryNotFoundException notFound) {
44  			throw die(MessageFormat.format(CLIText.get().notAGitRepository,
45  					dstGitdir.getPath()), notFound);
46  		} catch (IOException e) {
47  			throw die(e.getMessage(), e);
48  		}
49  
50  		rp = new org.eclipse.jgit.transport.ReceivePack(db);
51  		try {
52  			rp.receive(ins, outs, errs);
53  		} catch (IOException e) {
54  			throw die(e.getMessage(), e);
55  		}
56  	}
57  }