File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 3333 flagNoFetch = flag .Bool ("nofetch" , false , "don't fetch remote tags" )
3434 flagNoNewline = flag .Bool ("nonewline" , false , "don't print a newline after the output" )
3535 flagIncPatch = flag .Bool ("incpatch" , false , "increment the patch level and create a new tag" )
36+ flagBranch = flag .Bool ("branch" , false , "print the current branch name" )
3637)
3738
3839func mainfn () int {
@@ -58,6 +59,9 @@ func mainfn() int {
5859 createTag = vi .IncPatch ()
5960 }
6061 content := vi .Version ()
62+ if * flagBranch {
63+ content = vi .Branch
64+ }
6165 if * flagGoPackage {
6266 content , err = vi .GoPackage (repoDir , * flagName )
6367 }
Original file line number Diff line number Diff line change @@ -24,6 +24,23 @@ func TestMainFn(t *testing.T) {
2424 }
2525}
2626
27+ func TestMainFnBranch (t * testing.T ) {
28+ flag .Parse ()
29+ * flagBranch = true
30+ * flagOut = "test.out"
31+ mainfn ()
32+ b , err := os .ReadFile ("test.out" )
33+ if err == nil {
34+ defer os .Remove ("test.out" )
35+ s := string (b )
36+ if ! strings .Contains (s , "main" ) {
37+ t .Error (s )
38+ }
39+ } else {
40+ t .Error (err )
41+ }
42+ }
43+
2744func TestMainError (t * testing.T ) {
2845 exitFn = func (i int ) {
2946 if i == 0 {
You can’t perform that action at this time.
0 commit comments