-
Notifications
You must be signed in to change notification settings - Fork 697
Open
Description
- Run the code below.
- You will see that stuff gets printed indicating a dirty index.
cd merge-commit-buggit status
> git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
All the tests in merge.js merges two random branches so the bug doesn't appear. The bug will only surfaces if you merge HEAD with another branch.
var path = require("path");
var fs = require("fs");
var git = require('.');
var repoDir = path.resolve(__dirname, "merge-commit-bug");
var name = "test.txt";
var name2 = "test2.txt";
var fileName = path.resolve(repoDir, name);
var fileName2 = path.resolve(repoDir, name2);
var repository;
var index;
var head;
var leftBranch;
return git.Repository.init(repoDir, 0)
.then(function(repo) {
repository = repo;
fs.writeFileSync(fileName, "A", null);
return repository.refreshIndex();
})
.then(function(idx) {
index = idx;
return index.addByPath(name);
})
.then(function() {
return index.writeTree();
})
.then(function(oid) {
return repository.createCommit("HEAD",
git.Signature.default(repository),
git.Signature.default(repository),
"message", oid, []);
})
.then(function(oid) {
head = oid;
fs.writeFileSync(fileName, "B", null);
return repository.refreshIndex();
})
.then(function(idx) {
index = idx;
return index.addByPath(name);
})
.then(function() {
return index.write();
})
.then(function() {
return index.writeTree();
})
.then(function(oid) {
return repository.createCommit("HEAD",
git.Signature.default(repository),
git.Signature.default(repository),
"left", oid, [ head ]);
})
.then(function(left) {
return repository.getCommit(left);
})
.then(function(commit) {
return git.Branch.create(repository, "leftBranch", commit, false);
})
.then(function(branch) {
leftBranch = branch;
return repository.getCommit(head);
})
.then(function(commit) {
return git.Reset.reset(repository, commit, git.Reset.TYPE.HARD, {});
})
.then(function() {
fs.writeFileSync(fileName2, "C", null);
return repository.refreshIndex();
})
.then(function(idx) {
index = idx;
return index.addByPath(name2);
})
.then(function() {
return index.write();
})
.then(function() {
return index.writeTree();
})
.then(function(oid) {
return repository.createCommit("HEAD",
git.Signature.default(repository),
git.Signature.default(repository),
"right", oid, [ head ]);
})
.then(function(commit) {
return repository.mergeBranches("master", leftBranch, git.Signature.default(repository), null, null);
})
.then(function() {
return repository.getStatus();
})
.then(function(statuses) {
console.log(statuses);
console.log(statuses[0].path());
})
.catch(function(err) {
console.log(err);
});dima11221122
Metadata
Metadata
Assignees
Labels
No labels