Ensure post-commit hook is called after index lock was released
Otherwise a post-commit hook cannot modify the index. Bug: 566934 Change-Id: I0093dccd93b2064f243544b516bdce198afdb18b Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
parent
fd3edc7bfc
commit
f43cb3605c
|
@ -529,6 +529,7 @@ peeledRefIsRequired=Peeled ref is required.
|
||||||
peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph
|
peerDidNotSupplyACompleteObjectGraph=peer did not supply a complete object graph
|
||||||
personIdentEmailNonNull=E-mail address of PersonIdent must not be null.
|
personIdentEmailNonNull=E-mail address of PersonIdent must not be null.
|
||||||
personIdentNameNonNull=Name of PersonIdent must not be null.
|
personIdentNameNonNull=Name of PersonIdent must not be null.
|
||||||
|
postCommitHookFailed=Execution of post-commit hook failed: {0}.
|
||||||
prefixRemote=remote:
|
prefixRemote=remote:
|
||||||
problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0}
|
problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0}
|
||||||
progressMonUploading=Uploading {0}
|
progressMonUploading=Uploading {0}
|
||||||
|
|
|
@ -67,6 +67,8 @@
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk.OperationType;
|
import org.eclipse.jgit.treewalk.TreeWalk.OperationType;
|
||||||
import org.eclipse.jgit.util.ChangeIdUtil;
|
import org.eclipse.jgit.util.ChangeIdUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class used to execute a {@code Commit} command. It has setters for all
|
* A class used to execute a {@code Commit} command. It has setters for all
|
||||||
|
@ -78,6 +80,9 @@
|
||||||
* >Git documentation about Commit</a>
|
* >Git documentation about Commit</a>
|
||||||
*/
|
*/
|
||||||
public class CommitCommand extends GitCommand<RevCommit> {
|
public class CommitCommand extends GitCommand<RevCommit> {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(CommitCommand.class);
|
||||||
|
|
||||||
private PersonIdent author;
|
private PersonIdent author;
|
||||||
|
|
||||||
private PersonIdent committer;
|
private PersonIdent committer;
|
||||||
|
@ -212,6 +217,7 @@ public RevCommit call() throws GitAPIException, AbortedByHookException,
|
||||||
.setCommitMessage(message).call();
|
.setCommitMessage(message).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RevCommit revCommit;
|
||||||
// lock the index
|
// lock the index
|
||||||
DirCache index = repo.lockDirCache();
|
DirCache index = repo.lockDirCache();
|
||||||
try (ObjectInserter odi = repo.newObjectInserter()) {
|
try (ObjectInserter odi = repo.newObjectInserter()) {
|
||||||
|
@ -267,7 +273,7 @@ public RevCommit call() throws GitAPIException, AbortedByHookException,
|
||||||
ObjectId commitId = odi.insert(commit);
|
ObjectId commitId = odi.insert(commit);
|
||||||
odi.flush();
|
odi.flush();
|
||||||
|
|
||||||
RevCommit revCommit = rw.parseCommit(commitId);
|
revCommit = rw.parseCommit(commitId);
|
||||||
RefUpdate ru = repo.updateRef(Constants.HEAD);
|
RefUpdate ru = repo.updateRef(Constants.HEAD);
|
||||||
ru.setNewObjectId(commitId);
|
ru.setNewObjectId(commitId);
|
||||||
if (!useDefaultReflogMessage) {
|
if (!useDefaultReflogMessage) {
|
||||||
|
@ -302,11 +308,7 @@ public RevCommit call() throws GitAPIException, AbortedByHookException,
|
||||||
repo.writeMergeCommitMsg(null);
|
repo.writeMergeCommitMsg(null);
|
||||||
repo.writeRevertHead(null);
|
repo.writeRevertHead(null);
|
||||||
}
|
}
|
||||||
Hooks.postCommit(repo,
|
break;
|
||||||
hookOutRedirect.get(PostCommitHook.NAME),
|
|
||||||
hookErrRedirect.get(PostCommitHook.NAME)).call();
|
|
||||||
|
|
||||||
return revCommit;
|
|
||||||
}
|
}
|
||||||
case REJECTED:
|
case REJECTED:
|
||||||
case LOCK_FAILURE:
|
case LOCK_FAILURE:
|
||||||
|
@ -320,6 +322,15 @@ public RevCommit call() throws GitAPIException, AbortedByHookException,
|
||||||
} finally {
|
} finally {
|
||||||
index.unlock();
|
index.unlock();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
Hooks.postCommit(repo, hookOutRedirect.get(PostCommitHook.NAME),
|
||||||
|
hookErrRedirect.get(PostCommitHook.NAME)).call();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(MessageFormat.format(
|
||||||
|
JGitText.get().postCommitHookFailed, e.getMessage()),
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
return revCommit;
|
||||||
} catch (UnmergedPathException e) {
|
} catch (UnmergedPathException e) {
|
||||||
throw new UnmergedPathsException(e);
|
throw new UnmergedPathsException(e);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -557,6 +557,7 @@ public static JGitText get() {
|
||||||
/***/ public String peerDidNotSupplyACompleteObjectGraph;
|
/***/ public String peerDidNotSupplyACompleteObjectGraph;
|
||||||
/***/ public String personIdentEmailNonNull;
|
/***/ public String personIdentEmailNonNull;
|
||||||
/***/ public String personIdentNameNonNull;
|
/***/ public String personIdentNameNonNull;
|
||||||
|
/***/ public String postCommitHookFailed;
|
||||||
/***/ public String prefixRemote;
|
/***/ public String prefixRemote;
|
||||||
/***/ public String problemWithResolvingPushRefSpecsLocally;
|
/***/ public String problemWithResolvingPushRefSpecsLocally;
|
||||||
/***/ public String progressMonUploading;
|
/***/ public String progressMonUploading;
|
||||||
|
|
Loading…
Reference in New Issue