Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #707: failed to set workdir correctly if submodule first opened i… #709

Merged
merged 1 commit into from Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 16 additions & 8 deletions node/lib/util/submodule_config_util.js
Expand Up @@ -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) {
Expand Down
68 changes: 49 additions & 19 deletions node/test/util/submodule_config_util.js
Expand Up @@ -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());
Expand All @@ -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)));
Expand Down Expand Up @@ -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();
Expand Down