Skip to content

Commit

Permalink
Merge pull request #1 from angel-git/diff-tags
Browse files Browse the repository at this point in the history
Diff tags
  • Loading branch information
angel-git authored May 11, 2022
2 parents 46171e1 + c279e3b commit 754a0ae
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
47 changes: 39 additions & 8 deletions gw.v
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@ import os
import cli
import chalk

struct ExecuteCommand {
command string
filter string
sort bool = true
}


fn main() {
mut cmd := cli.Command{
name: 'gw'
description: 'Where is my commit?\nUsage: gs search -help'
version: '1.0.0'
description: 'Where is my commit?\nUsage:\ngw search -help\ngw diff -help'
version: '1.1.0'
}
mut search_cmd := cli.Command{
name: 'search'
Expand All @@ -32,7 +39,16 @@ fn main() {
description: 'Containing tag name that you want to filter'
})

mut diff_cmd := cli.Command{
name: 'diff'
description: 'Shows the commits between 2 tags'
usage: '<tag1> <tag2>'
required_args: 2
execute: diff
}

cmd.add_command(search_cmd)
cmd.add_command(diff_cmd)
cmd.setup()
cmd.parse(os.args)
}
Expand All @@ -58,7 +74,7 @@ fn search_branches(commit_message string, branch string) []string {
git branch -r --contains \$sha1
done
'
return execute_command(git_command, branch)
return execute_command(ExecuteCommand{command: git_command, filter: branch})
}

fn search_tag(commit_message string, tag string) []string {
Expand All @@ -68,23 +84,38 @@ fn search_tag(commit_message string, tag string) []string {
git tag --contains \$sha1
done
'
return execute_command(git_command, tag)
return execute_command(ExecuteCommand{command: git_command, filter: tag})
}

fn execute_command(command string, filter string) []string {
fn diff(cli_command cli.Command) ? {
tag1 := cli_command.args[0]
tag2 := cli_command.args[1]

git_command :='git log --oneline ${tag1}..${tag2}'
diff_commits := execute_command(ExecuteCommand{command: git_command, filter: "", sort: false})
for d in diff_commits {
commit_id := d.all_before(" ")
commit_message := d.after_char(` `)
println('${chalk.fg(commit_id, 'green')} ${commit_message}')
}
}

fn execute_command(execute_command ExecuteCommand) []string {
mut s := []string{}
mut cmd := os.Command{
path: command
path: execute_command.command
redirect_stdout: true
}
cmd.start() or { panic('Failed to start git command: $err') }
for !cmd.eof {
line := cmd.read_line().trim_space()
if line.len > 0 && line.contains(filter) {
if line.len > 0 && line.contains(execute_command.filter) {
s << line
}
}
cmd.close() or { panic('Failed to stop git command: $err') }
s.sort()
if execute_command.sort {
s.sort()
}
return s
}
15 changes: 14 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Simple pet project to find commits by commit message inside branches and tags. B

## Usage

### Find commits in branches and tags

```
Usage: gw search [flags] <commit message>
Expand Down Expand Up @@ -31,13 +33,24 @@ MY_TAG_NAME-10.0.12
MY_TAG_NAME-10.0.12-alp
```

### Commits between 2 tags

```
Usage: gw diff <tag1> <tag2>
Shows the commits between 2 tags
Flags:
-help Prints help information.
```

## Building

```bash
# for linux
v -os linux . -o build/gw-linux
# for mac
v . -o build/gw-mac
# for windows, this doesnt work from M1
# for windows
v -os windows . -o build/gw-win
```

0 comments on commit 754a0ae

Please sign in to comment.