Ejemplo n.º 1
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<Repository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    A_txt = src.blob("A");
    A = src.commit().add("A_txt", A_txt).create();
    B = src.commit().parent(A).add("A_txt", "C").add("B", "B").create();
    src.update(master, B);
  }
Ejemplo n.º 2
0
  @Before
  public void setUp() throws Exception {
    super.setUp();

    final TestRepository<FileRepository> src = createTestRepository();
    final String srcName = src.getRepository().getDirectory().getName();

    ServletContextHandler app = server.addContext("/git");
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            if (!name.equals(srcName)) throw new RepositoryNotFoundException(name);

            final Repository db = src.getRepository();
            db.incrementOpen();
            return db;
          }
        });
    app.addServlet(new ServletHolder(gs), "/*");

    server.setUp();

    remoteRepository = src.getRepository();
    remoteURI = toURIish(app, srcName);

    FileBasedConfig cfg = remoteRepository.getConfig();
    cfg.setBoolean("http", null, "receivepack", true);
    cfg.save();

    a_blob = src.blob("a");
  }
Ejemplo n.º 3
0
  @Override
  public void init(final ServletConfig config) throws ServletException {
    this.config = config;

    setRepositoryResolver(new FileResolver<HttpServletRequest>((ResourceManager) resourceManager));
    super.init(this);
  }
Ejemplo n.º 4
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jgit.http.server.GitServlet#init(javax.servlet.ServletConfig)
  */
 @Override
 public void init(final ServletConfig config) throws ServletException {
   // initial resolver.
   File root = getFile(config, "base-path");
   if (!root.exists()) {
     root.mkdirs();
   }
   boolean exportAll = getBoolean(config, "export-all");
   this.setRepositoryResolver(new AuthorizationFileResolver(root, exportAll));
   this.log.info(
       "initial by(base-path:" + root.getAbsolutePath() + ",export-all:" + exportAll + ")");
   //
   // System.out.println("<-----ssssssddddddddddd------>");
   // System.out.println(config.getInitParameter("base-path"));
   // SyncMgr.smgr().setWsDir(new File("/tmp/mgit"));
   // SyncMgr.smgr().setSync2Remoete(true);
   // AutoMerge am = SyncMgr.smgr().amerge("jgd");
   // if (am == null) {
   // try {
   // SyncMgr.smgr().addAMerge("jgd",
   // "file:///Users/Scorpion/Temp/jgd.git",
   // "file:///Users/Scorpion/Temp/jgdt.git");
   // } catch (Exception e) {
   // e.printStackTrace();
   // }
   // }
   super.init(config);
 }
Ejemplo n.º 5
0
  private ServletContextHandler smart(final String path) {
    GitServlet gs = new GitServlet();
    gs.setRepositoryResolver(
        new RepositoryResolver<HttpServletRequest>() {
          public Repository open(HttpServletRequest req, String name)
              throws RepositoryNotFoundException, ServiceNotEnabledException {
            final FileRepository db = remoteRepository.getRepository();
            if (!name.equals(nameOf(db))) throw new RepositoryNotFoundException(name);

            db.incrementOpen();
            return db;
          }
        });

    ServletContextHandler ctx = server.addContext(path);
    ctx.addServlet(new ServletHolder(gs), "/*");
    return ctx;
  }
Ejemplo n.º 6
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jgit.http.server.glue.MetaServlet#service(javax.servlet.http
  * .HttpServletRequest, javax.servlet.http.HttpServletResponse)
  */
 @Override
 protected void service(HttpServletRequest req, HttpServletResponse res)
     throws IOException, ServletException {
   String name = req.getPathInfo();
   while (name != null && 0 < name.length() && name.charAt(0) == '/') name = name.substring(1);
   if (name == null || name.length() == 0) {
     sendError(req, res, SC_NOT_FOUND);
     return;
   }
   this.log.debug("git server for " + name);
   name = name.replaceAll("\\.git.*$", "");
   AutoMerge am = SyncMgr.smgr().amerge(name);
   if (am != null) {
     if (SyncMgr.smgr().isSync2Remoete()) {
       try {
         am.pullR2L();
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
     if (am.isConflict()) {
       sendError(req, res, SC_INTERNAL_SERVER_ERROR, "repository conflicting...");
       return;
     }
   }
   // System.out.println(req.getPathInfo());
   super.service(req, res);
   if (GitSmartHttpTools.isReceivePack(req) && am != null && SyncMgr.smgr().isSync2Remoete()) {
     try {
       log.debug("check git log and sync local to remote");
       String result = am.checkLogAndL2R();
       log.debug("checkLogAndL2R:" + result);
     } catch (Exception e) {
       log.warn("checkLogAndL2R error", e);
     }
   }
 }