alibaba / git-repo-go

git-repo is a command-line tool for centralized workflow, can work with Gerrit, AGit-Flow compatible servers. It is written in Golang, and it can be installed easily without further dependency. It provides an easy-to-use solution for multiple repositories which is introduced by Android repo first, and it can also work with a single repository.
https://git-repo.info/
Apache License 2.0
262 stars 60 forks source link

git pr can not deal with shell variable expansion correctly #45

Closed xiejingf closed 2 years ago

xiejingf commented 2 years ago

git pr will truncate the shell variable if the variable contains whitespace characters. 1

2

I have double checked the value expansion expression, it seems correct, so there must be something wrong during the processing of git pr 3

jiangxin commented 2 years ago

I am sure that the whole one line title can be sent to git using push-options, see test case:

Please check the code of "proc-receive" hook. May be only part of the title is sent to merge-request API.

jiangxin commented 2 years ago

It's wrong to add backslash before double quote characters. Please use --title "..." instead of --tiltle \"...\".

xiejingf commented 2 years ago

after some tests, I finally get it work. My script use expect programe to spawn a process

the code below does not work as expected

/usr/bin/expect <<-EOF
    set time 10
    spawn git pr --no-edit --reviewers $REVER --title "$DESC"
    expect {
    "*(y/N)?" { send "y\r"; exp_continue }
    "*did you forget to amend?)" { send "y\r" }
    }

use curly brackets ({}) to make the content inside {} passed as a whole

/usr/bin/expect <<-EOF
    set time 10
    spawn git pr --no-edit --reviewers $REVER --title {$DESC}
    expect {
    "*(y/N)?" { send "y\r"; exp_continue }
    "*did you forget to amend?)" { send "y\r" }
    }

similar issue in stackoverflow : https://stackoverflow.com/questions/12518354/use-expect-to-spawn-command-with-arguments-containing-spaces