-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gitCatFile for getting file contents without git checkouts, #355
Signed-off-by: Michael Kauzmann <[email protected]>
- Loading branch information
Showing
2 changed files
with
36 additions
and
9 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,30 @@ | ||
// Copyright 2017, University of Colorado Boulder | ||
|
||
/** | ||
* retrieve the contents of a file without changing the git tree via checkouts. | ||
* | ||
* @author Michael Kauzmann (PhET Interactive Simulations) | ||
* @author Jonathan Olson <[email protected]> | ||
*/ | ||
|
||
const assert = require( 'assert' ); | ||
const execute = require( './execute' ); | ||
|
||
/** | ||
* Gets the contents of the file at a given state in the git tree | ||
* @public | ||
* | ||
* @param {string} repo - The repository name | ||
* @param {string} file - Path to the file from the repo root, like js/myFile.js | ||
* @param {string} branchOrSha - what revision to get the contents of the file at. "buoyancy-1.0" or "main" or | ||
* "{{SHA}}". Defaults to the current checkout (HEAD) | ||
* @returns {Promise.<string>} - Stdout | ||
* @rejects {ExecuteError} | ||
*/ | ||
module.exports = async function gitCatFile( repo, file, branchOrSha = 'HEAD' ) { | ||
assert( typeof repo === 'string' ); | ||
assert( typeof file === 'string' ); | ||
assert( typeof branchOrSha === 'string' ); | ||
|
||
return execute( 'git', [ 'cat-file', 'blob', `${branchOrSha}:${file}` ], `../${repo}` ); | ||
}; |