Browse Source

ReflogWriter: Align auto-creation defaults with C git

Per git-config(1), core.logAllRefUpdates auto-creates reflogs for HEAD
and for refs under heads, notes, tags, and for HEAD. Add notes and
remove stash from ReflogWriter#shouldAutoCreateLog. Explicitly force
writing reflogs for refs/stash at call sites, now that this is
supported.

Change-Id: I3a46d2c2703b7c243e0ee2bbf6948279800c485c
stable-4.9
Dave Borowitz 7 years ago committed by David Pursehouse
parent
commit
2bbe15abd4
  1. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashListCommandTest.java
  2. 1
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  3. 1
      org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java
  4. 4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashListCommandTest.java

@ -51,6 +51,7 @@ import java.util.Iterator;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
@ -94,9 +95,7 @@ public class StashListCommandTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call();
RevCommit commit = git.commit().setMessage("create file").call();
RefUpdate update = db.updateRef(Constants.R_STASH);
update.setNewObjectId(commit);
assertEquals(Result.NEW, update.update());
assertEquals(Result.NEW, newStashUpdate(commit).update());
StashListCommand command = git.stashList();
Collection<RevCommit> stashed = command.call();
@ -117,13 +116,8 @@ public class StashListCommandTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call();
RevCommit commit2 = git.commit().setMessage("edit file").call();
RefUpdate create = db.updateRef(Constants.R_STASH);
create.setNewObjectId(commit1);
assertEquals(Result.NEW, create.update());
RefUpdate update = db.updateRef(Constants.R_STASH);
update.setNewObjectId(commit2);
assertEquals(Result.FAST_FORWARD, update.update());
assertEquals(Result.NEW, newStashUpdate(commit1).update());
assertEquals(Result.FAST_FORWARD, newStashUpdate(commit2).update());
StashListCommand command = git.stashList();
Collection<RevCommit> stashed = command.call();
@ -133,4 +127,11 @@ public class StashListCommandTest extends RepositoryTestCase {
assertEquals(commit2, iter.next());
assertEquals(commit1, iter.next());
}
private RefUpdate newStashUpdate(ObjectId newId) throws Exception {
RefUpdate ru = db.updateRef(Constants.R_STASH);
ru.setNewObjectId(newId);
ru.setForceRefLog(true);
return ru;
}
}

1
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

@ -425,6 +425,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
refUpdate.setRefLogMessage(refLogMessage, false);
refUpdate.setForceRefLog(true);
if (currentRef != null)
refUpdate.setExpectedOldObjectId(currentRef.getObjectId());
else

1
org.eclipse.jgit/src/org/eclipse/jgit/api/StashCreateCommand.java

@ -212,6 +212,7 @@ public class StashCreateCommand extends GitCommand<RevCommit> {
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
refUpdate.setRefLogMessage(refLogMessage, false);
refUpdate.setForceRefLog(true);
if (currentRef != null)
refUpdate.setExpectedOldObjectId(currentRef.getObjectId());
else

4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/ReflogWriter.java

@ -47,9 +47,9 @@ package org.eclipse.jgit.internal.storage.file;
import static org.eclipse.jgit.lib.Constants.HEAD;
import static org.eclipse.jgit.lib.Constants.R_HEADS;
import static org.eclipse.jgit.lib.Constants.R_NOTES;
import static org.eclipse.jgit.lib.Constants.R_REFS;
import static org.eclipse.jgit.lib.Constants.R_REMOTES;
import static org.eclipse.jgit.lib.Constants.R_STASH;
import java.io.File;
import java.io.FileNotFoundException;
@ -250,6 +250,6 @@ public class ReflogWriter {
return refName.equals(HEAD)
|| refName.startsWith(R_HEADS)
|| refName.startsWith(R_REMOTES)
|| refName.equals(R_STASH);
|| refName.startsWith(R_NOTES);
}
}

Loading…
Cancel
Save