This repository has been archived by the owner on May 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(git): support git packed refs --all mode (#77)
* test: git-pack-refs vs gitHead also, let's have gitHead tests for both refs-packed and non-packed modes re #76 (git packed refs --all mode not supported) * Fall back to .git/packed-refs if .git/<ref> does not exist * refactor: minor
- Loading branch information
Showing
2 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
var childProcess = require('child_process') | ||
var fs = require('fs') | ||
var path = require('path') | ||
|
||
var tap = require('tap') | ||
|
||
var readJson = require('../') | ||
|
||
var isGit | ||
try { | ||
fs.readFileSync(path.resolve(__dirname, '../.git/HEAD')) | ||
isGit = true | ||
} catch (e) { | ||
isGit = false | ||
} | ||
|
||
if (isGit) { | ||
tap.test('gitHead tests', function (t) { | ||
t.plan(3) | ||
|
||
const repoProjectName = 'read-package-json' | ||
const repo = 'https://github.com/npm/' + repoProjectName + '.git' | ||
var repoDirs = [] | ||
|
||
t.test('detached case', function (tt) { | ||
var p = path.resolve(__dirname, '..', 'package.json') | ||
readJson(p, function (er, data) { | ||
if (er) throw er | ||
tt.ok(data) | ||
tt.similar(data.gitHead, /^[a-f0-9]{40}$/) | ||
tt.end() | ||
}) | ||
}) | ||
|
||
function testGitRepo (kind, extraRepoCommand, t) { | ||
var repoDirName = repoProjectName + '-' + kind | ||
var cmd = `cd ${__dirname} && git clone ${repo} ${repoDirName} && cd ${repoDirName}` | ||
if (extraRepoCommand) cmd += ` && ${extraRepoCommand}` | ||
childProcess.execSync(cmd) | ||
repoDirs.push(repoDirName) | ||
var p = path.resolve(__dirname, repoDirName, 'package.json') | ||
readJson(p, function (er, data) { | ||
if (er) throw er | ||
t.ok(data) | ||
t.similar(data.gitHead, /^[a-f0-9]{40}$/) | ||
t.end() | ||
}) | ||
} | ||
|
||
t.test('basic case', function (tt) { | ||
testGitRepo('basic', '', tt) | ||
}) | ||
|
||
t.test('git-pack-refs vs gitHead', function (tt) { | ||
testGitRepo('git-pack-refs', 'git pack-refs --all', tt) | ||
}) | ||
|
||
t.tearDown(function () { | ||
repoDirs.forEach(function (d) { | ||
childProcess.execSync(`rm -rf ${path.resolve(__dirname, d)}`) | ||
}) | ||
}) | ||
}) | ||
} |