UNPKG

611 BJavaScriptView Raw
1var exec = require('./exec')
2var log = require('debug')('ggit')
3var _ = require('lodash')
4
5function fileContents (filename, at) {
6 if (!at) {
7 at = 'HEAD'
8 }
9 var gitCommand = _.template('git show <%= at %>:<%= filename %>')
10 var cmd = gitCommand({
11 at: at,
12 filename: filename
13 })
14 log('file contents command', cmd)
15
16 return exec(cmd).then(function (data) {
17 return data.trim()
18 })
19}
20
21module.exports = fileContents
22
23if (!module.parent) {
24 fileContents('src/file-contents.js').then(function (text) {
25 console.log('the source for this file in the repo HEAD')
26 console.log(text)
27 })
28}