WriteDirCache.java

  1. /*
  2.  * Copyright (C) 2008, Google Inc.
  3.  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> 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. package org.eclipse.jgit.pgm.debug;

  12. import org.eclipse.jgit.dircache.DirCache;
  13. import org.eclipse.jgit.pgm.Command;
  14. import org.eclipse.jgit.pgm.TextBuiltin;
  15. import org.eclipse.jgit.pgm.internal.CLIText;

  16. @Command(usage = "usage_WriteDirCache")
  17. class WriteDirCache extends TextBuiltin {
  18.     /** {@inheritDoc} */
  19.     @Override
  20.     protected void run() throws Exception {
  21.         final DirCache cache = db.readDirCache();
  22.         if (!cache.lock())
  23.             throw die(CLIText.get().failedToLockIndex);
  24.         cache.read();
  25.         cache.write();
  26.         if (!cache.commit())
  27.             throw die(CLIText.get().failedToCommitIndex);
  28.     }
  29. }