Git command works in terminal but not from groovy script

前端 未结 1 1969
温柔的废话
温柔的废话 2021-01-23 15:34

The following git command works in the Android Studio Terminal

git --no-pager show -s --format=\'%an <%ae>\' c1ff6aa

But it doesn\'t work whe

1条回答
  •  死守一世寂寞
    2021-01-23 16:20

    Use the "array" syntax to execute it:

    groovy:000> ["git", "--no-pager", "show", "-s", "--format='%an <%ae>'"].execute().text
    ===> 'John Doe '
    

    Without properly separated params there is some hickup and the command results in an error:

    groovy:000> sout = new StringBuilder()
    ===> 
    groovy:000> serr = new StringBuilder()
    ===> 
    groovy:000> p="git  --no-pager show -s --format='%an <%ae>'".execute()
    ===> java.lang.UNIXProcess@5dcb4f5f
    groovy:000> p.consumeProcessOutput(sout,serr)
    ===> null
    groovy:000> p.waitFor()
    // XXX exit code!
    ===> 128
    groovy:000> serr
    // XXX error
    ===> fatal: ambiguous argument '<%ae>'': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git  [...] -- [...]'
    

    0 讨论(0)
提交回复
热议问题