17
17
* along with this program. If not, see <https://www.gnu.org/licenses/>.
18
18
*/
19
19
import git from 'isomorphic-git' ;
20
- import { find_repo_root } from '../git-helpers.js' ;
20
+ import { find_repo_root , group_positional_arguments } from '../git-helpers.js' ;
21
21
import { commit_formatting_options , format_commit , process_commit_formatting_options } from '../format.js' ;
22
+ import { SHOW_USAGE } from '../help.js' ;
22
23
23
24
export default {
24
25
name : 'log' ,
25
- usage : 'git log [<formatting-option>...] [--max-count <n>] <revision>' ,
26
+ usage : 'git log [<formatting-option>...] [--max-count <n>] [ <revision>] [[--] <path>] ' ,
26
27
description : 'Show commit logs, starting at the given revision.' ,
27
28
args : {
28
- allowPositionals : false ,
29
+ allowPositionals : true ,
30
+ tokens : true ,
29
31
options : {
30
32
...commit_formatting_options ,
31
33
'max-count' : {
@@ -38,23 +40,27 @@ export default {
38
40
execute : async ( ctx ) => {
39
41
const { io, fs, env, args } = ctx ;
40
42
const { stdout, stderr } = io ;
41
- const { options, positionals } = args ;
43
+ const { options, positionals, tokens } = args ;
42
44
43
45
process_commit_formatting_options ( options ) ;
44
46
45
- // TODO: Log of a specific file
46
- // TODO: Log of a specific branch
47
- // TODO: Log of a specific commit
48
-
49
47
const depth = Number ( options [ 'max-count' ] ) || undefined ;
50
48
51
49
const { dir, gitdir } = await find_repo_root ( fs , env . PWD ) ;
52
50
51
+ const { before : refs , after : paths } = group_positional_arguments ( tokens ) ;
52
+ if ( refs . length > 1 || paths . length > 1 ) {
53
+ stderr ( 'error: Too many revisions or paths given. Expected [<revision>] [[--] <path>]' ) ;
54
+ throw SHOW_USAGE ;
55
+ }
56
+
53
57
const log = await git . log ( {
54
58
fs,
55
59
dir,
56
60
gitdir,
57
61
depth,
62
+ ref : refs [ 0 ] ,
63
+ filepath : paths [ 0 ] ,
58
64
} ) ;
59
65
60
66
for ( const commit of log ) {
0 commit comments