1 | var exec = require('./exec')
|
2 | var log = require('debug')('ggit')
|
3 | var _ = require('lodash')
|
4 |
|
5 | function 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 |
|
21 | module.exports = fileContents
|
22 |
|
23 | if (!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 | }
|