Skip to content
Permalink
Browse files

Merge pull request #709 from shijinglu/fixBareReopenIssue

fix #707: failed to set workdir correctly if submodule first opened i…
  • Loading branch information...
novalis committed Jun 10, 2019
2 parents 44fd9c7 + f21ed7f commit 14716bd722711a51004abd69e18a945ee11e0bd6
Showing with 65 additions and 27 deletions.
  1. +16 −8 node/lib/util/submodule_config_util.js
  2. +49 −19 node/test/util/submodule_config_util.js
@@ -548,23 +548,31 @@ exports.initSubmoduleAndRepo = co.wrap(function *(repoUrl,

const FLAGS = NodeGit.Repository.INIT_FLAG;

const initRepo = co.wrap(function *() {
return bare ?
yield NodeGit.Repository.init(subRepoDir, 1) :
yield NodeGit.Repository.initExt(subRepoDir, {
workdirPath: exports.computeRelativeWorkDir(name),
flags: FLAGS.NO_DOTGIT_DIR | FLAGS.MKPATH |
FLAGS.RELATIVE_GITLINK |
(null === templatePath ? 0 : FLAGS.EXTERNAL_TEMPLATE),
templatePath: templatePath
});
});
// See if modules repo exists.
let subRepo = null;
try {
subRepo = bare ?
yield NodeGit.Repository.openBare(subRepoDir) :
yield NodeGit.Repository.open(subRepoDir);
// re-init if previously opened as bare
if (!bare && subRepo.isBare()) {
subRepo = yield initRepo();
}
}
catch (e) {
// Or, make it if not.

subRepo = yield NodeGit.Repository.initExt(subRepoDir, {
workdirPath: bare ? null : exports.computeRelativeWorkDir(name),
flags: FLAGS.NO_DOTGIT_DIR | FLAGS.MKPATH |
FLAGS.RELATIVE_GITLINK |
(null === templatePath ? 0 : FLAGS.EXTERNAL_TEMPLATE),
templatePath: templatePath
});
subRepo = yield initRepo();
}

if (bare) {
@@ -639,19 +639,11 @@ foo

describe("initSubmoduleAndRepo", function () {

const runTest = co.wrap(function *(repo,
subRootRepo,
url,
subName,
originUrl) {
if (undefined === originUrl) {
originUrl = "";
}
/** Setup a simple meta repo with one submodule (not opened). */
const setupMeta = co.wrap(function *(subRootRepo, repo, url, subName) {
const subHead = yield subRootRepo.getHeadCommit();
const submodule = yield NodeGit.Submodule.addSetup(repo,
url,
subName,
1);
const submodule =
yield NodeGit.Submodule.addSetup(repo,url, subName, 1);
const subRepo = yield submodule.open();
yield subRepo.fetchAll();
subRepo.setHeadDetached(subHead.id());
@@ -666,14 +658,26 @@ foo
sig,
"my message");
yield SubmoduleConfigUtil.deinit(repo, [subName]);
return subHead;
});

const runTest = co.wrap(function *(repo,
subRootRepo,
url,
subName,
originUrl) {
if (undefined === originUrl) {
originUrl = "";
}
const subHead = yield setupMeta(subRootRepo, repo, url, subName);
const repoPath = repo.workdir();
const result = yield SubmoduleConfigUtil.initSubmoduleAndRepo(
originUrl,
repo,
subName,
url,
null,
false);
const result =
yield SubmoduleConfigUtil.initSubmoduleAndRepo(originUrl,
repo,
subName,
url,
null,
false);
assert.instanceOf(result, NodeGit.Repository);
assert(TestUtil.isSameRealPath(result.workdir(),
path.join(repoPath, subName)));
@@ -722,6 +726,32 @@ foo
assert.equal(newUrl, url);
}));

it("reset workdir if open in bare first", co.wrap(function *() {
const repo = yield TestUtil.createSimpleRepository();
const subRootRepo = yield TestUtil.createSimpleRepository();
const url = subRootRepo.workdir();
const originUrl = "";
const subName = "foo";
yield setupMeta(subRootRepo, repo, url, subName);
const newSub1 =
yield SubmoduleConfigUtil.initSubmoduleAndRepo(originUrl,
repo,
subName,
url,
null,
true);
assert.notExists(newSub1.workdir());
const newSub2 =
yield SubmoduleConfigUtil.initSubmoduleAndRepo(originUrl,
repo,
subName,
url,
null,
false);
assert.equal(path.relative(repo.workdir(), newSub2.workdir()),
subName);
}));

it("deep name", co.wrap(function *() {
const repo = yield TestUtil.createSimpleRepository();
const subRootRepo = yield TestUtil.createSimpleRepository();

0 comments on commit 14716bd

Please sign in to comment.
You can’t perform that action at this time.