View Javadoc
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  
12  package org.eclipse.jgit.pgm.debug;
13  
14  import org.eclipse.jgit.dircache.DirCache;
15  import org.eclipse.jgit.pgm.Command;
16  import org.eclipse.jgit.pgm.TextBuiltin;
17  import org.eclipse.jgit.pgm.internal.CLIText;
18  
19  @Command(usage = "usage_WriteDirCache")
20  class WriteDirCache extends TextBuiltin {
21  	/** {@inheritDoc} */
22  	@Override
23  	protected void run() throws Exception {
24  		final DirCache cache = db.readDirCache();
25  		if (!cache.lock())
26  			throw die(CLIText.get().failedToLockIndex);
27  		cache.read();
28  		cache.write();
29  		if (!cache.commit())
30  			throw die(CLIText.get().failedToCommitIndex);
31  	}
32  }