git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 4/5][Outreachy] t7201: avoid using cd outside of subshells

From
Charvi Mendiratta <charvi077@gmail.com>
Date
Oct 19, 2020, 17:24 UTC
Message-ID
<CAPSFM5fvBt+x840XOwzwPBvXK7_1qB-sb+_M3LoPuKv_P=VvDA@mail.gmail.com>
In-Reply-To
<3b501a3a-b675-3eb7-975a-cc9206f15057@gmail.com>
On Mon, 19 Oct 2020 at 19:16, Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 56 quoted lines
>
> Hi Charvi
>
> On 19/10/2020 13:55, Charvi Mendiratta wrote:
> > On Sun, 18 Oct 2020 at 21:09, Phillip Wood <phillip.wood123@gmail.com> wrote:
> >>
> >> Hi Charvi
> >>
> >> Congratulations on posting your first patch series.
> >>
> >> On 17/10/2020 08:54, Charvi Mendiratta wrote:
> >>> Avoid using `cd` outside of subshells since, if the test fails, there is no guarantee that the current working directory is the expected one, which may cause subsequent tests to run in the wrong directory.
> >>
> >> That is an accurate description of why we want to avoid using `cd`
> >> outside of subshells. However this conversion is converting `cd` inside
> >> a subshell to use `git -C`. I think that is worthwhile as it avoids
> >> having to use a subshell but the description should say explain that the
> >> conversion is desirable to avoid the cost of starting a subshell as the
> >> original test does not suffer from the problem described in your commit
> >> message.
> >>
> >
> > Thank you Philip, for corrections . I somewhat able to understand that
> > commit message
> > should be " avoid using cd inside the subshells " because running a
> > shell script itselfs starts
> > a new subshell, please correct me if I am wrong . But still I am
> > unable to get that why you
> > mentioned the description as "cost of starting a new subshell " . Will
> > this not be the same subshell ?
>
> The original test looks something like
> (
>         cd sub &&
>         git something
> ) &&
>
> The commands between the ( and ) are executed in a subshell, any changes
> made to the current directory or shell variables in the subshell do not
> affect the rest of the test script. This is because the subshell starts
> a separate shell process, but creating this separate process has a cost
> associated with it.
>
> The modified test looks like
>         git -C sub something
>
> Here we tell git to change directory before it runs the 'something'
> command, this is more efficient as we don't need to start any extra
> processes - there are no subshells.
>
> So the purpose of this change is not to "avoid using cd inside a
> subshell" but to avoid having to use a subshell at all.
>
> I hope that helps explain what a subshell is and why we want to avoid
> using it if we can, do let me know if you want me to clarify anything.
>

Yes, thanks a lot Philip I understood the reason. I will do the corrections in commit message and commit body as below : t7201: using 'git -C' to avoid subshell

Using 'git-C' instead of 'cd' inside of subshell, to avoid the extra process of starting a new subshell

Please confirm, if any other changes are required .
> Best Wishes
>
> Phillip
>

Thanks and Regards, Charvi

Show 47 quoted lines
>
> >> Best Wishes
> >>
> >> Phillip
> >>
> >>>
> >>> Signed-off-by: Charvi Mendiratta <charvi077@gmail.com>
> >>> ---
> >>>    t/t7201-co.sh | 10 ++--------
> >>>    1 file changed, 2 insertions(+), 8 deletions(-)
> >>>
> >>> diff --git a/t/t7201-co.sh b/t/t7201-co.sh
> >>> index 74553f991b..5898182fd2 100755
> >>> --- a/t/t7201-co.sh
> >>> +++ b/t/t7201-co.sh
> >>> @@ -339,10 +339,7 @@ test_expect_success 'switch branches while in subdirectory' '
> >>>        git checkout master &&
> >>>
> >>>        mkdir subs &&
> >>> -     (
> >>> -             cd subs &&
> >>> -             git checkout side
> >>> -     ) &&
> >
> > Is there any specific meaning of writing these above two commands in
> > parentheses . Will this not work the same without it ?
> >
> >>> +     git -C subs checkout side &&
> >>>        ! test -f subs/one &&
> >>>        rm -fr subs
> >>>    '
> >>> @@ -357,10 +354,7 @@ test_expect_success 'checkout specific path while in subdirectory' '
> >>>
> >>>        git checkout master &&
> >>>        mkdir -p subs &&
> >>> -     (
> >>> -             cd subs &&
> >>> -             git checkout side -- bero
> >>> -     ) &&
> >>> +     git -C subs checkout side -- bero &&
> >>>        test -f subs/bero
> >>>    '
> >>>
> >>>
> > Thanks and Regards ,
> > Charvi
> >
Previous: Phillip WoodNext: Taylor Blau
Message 20 of 60 in “[Outreachy] modernizing the test scripts”
  1. 0/5 [Outreachy] modernizing the test scriptscharvi-077, Oct 15, 2020
  2. 1/5 [Outreachy] t7101,t7102,t7201: modernize test formattingcharvi-077, Oct 15, 2020
  3. Christian CouderOct 16, 2020
  4. 2/5 [Outreachy] t7102,t7201: remove unnecessary blank spaces in test bodycharvi-077, Oct 15, 2020
  5. 3/5 [Outreachy] t7102,t7201: remove whitespace after redirect operatorcharvi-077, Oct 15, 2020
  6. 4/5 [Outreachy] t7201: avoid using cd outside of subshellscharvi-077, Oct 15, 2020
  7. 5/5 [Outreachy] t7201: place each command in its own linecharvi-077, Oct 15, 2020
  8. Christian CouderOct 16, 2020
  9. Charvi MendirattaOct 17, 2020
  10. 0/5 [Outreachy] modernizing the test scriptsCharvi Mendiratta, Oct 17, 2020
  11. 1/5 [Outreachy] t7101,t7102,t7201: modernize test formattingCharvi Mendiratta, Oct 17, 2020
  12. 2/5 [Outreachy] t7102,t7201: remove unnecessary blank spaces in test bodyCharvi Mendiratta, Oct 17, 2020
  13. Đoàn Trần Công DanhOct 17, 2020
  14. Charvi MendirattaOct 18, 2020
  15. 3/5 [Outreachy] t7102,t7201: remove whitespace after redirect operatorCharvi Mendiratta, Oct 17, 2020
  16. 4/5 [Outreachy] t7201: avoid using cd outside of subshellsCharvi Mendiratta, Oct 17, 2020
  17. Phillip WoodOct 18, 2020
  18. Charvi MendirattaOct 19, 2020
  19. Phillip WoodOct 19, 2020
  20. Charvi MendirattaOct 19, 2020
  21. Taylor BlauOct 19, 2020
  22. Charvi MendirattaOct 20, 2020
  23. Taylor BlauOct 20, 2020
  24. Phillip WoodOct 20, 2020
  25. Charvi MendirattaOct 20, 2020
  26. 5/5 [Outreachy] t7201: place each command in its own lineCharvi Mendiratta, Oct 17, 2020
  27. 0/5 [Outreachy] modernize the test scriptsCharvi Mendiratta, Oct 20, 2020
  28. 1/5 [Outreachy] t7101,t7102,t7201: modernize test formattingCharvi Mendiratta, Oct 20, 2020
  29. 2/5 [Outreachy] t7102,t7201: remove unnecessary blank spaces in test bodyCharvi Mendiratta, Oct 20, 2020
  30. 3/5 [Outreachy] t7102,t7201: remove whitespace after redirect operatorCharvi Mendiratta, Oct 20, 2020
  31. 4/5 [Outreachy] t7201: use 'git -C' to avoid subshellCharvi Mendiratta, Oct 20, 2020
  32. 5/5 [Outreachy] t7201: put each command on a seperate lineCharvi Mendiratta, Oct 20, 2020
  33. t7201: put each command on a separate lineCharvi Mendiratta, Oct 20, 2020
  34. Junio C HamanoOct 20, 2020
  35. Taylor BlauOct 20, 2020
  36. Junio C HamanoOct 20, 2020
  37. Taylor BlauOct 20, 2020
  38. Junio C HamanoOct 20, 2020
  39. Charvi MendirattaOct 21, 2020
  40. Junio C HamanoOct 20, 2020
  41. Charvi MendirattaOct 21, 2020
  42. 0/5 [Outreachy] modernize the test scriptsCharvi Mendiratta, Oct 21, 2020
  43. 1/5 [Outreachy] t7101,t7102,t7201: modernize test formattingCharvi Mendiratta, Oct 21, 2020
  44. 2/5 [Outreachy] t7102,t7201: remove unnecessary blank spaces in test bodyCharvi Mendiratta, Oct 21, 2020
  45. 3/5 [Outreachy] t7102,t7201: remove whitespace after redirect operatorCharvi Mendiratta, Oct 21, 2020
  46. Eric SunshineOct 21, 2020
  47. Junio C HamanoOct 22, 2020
  48. Eric SunshineOct 22, 2020
  49. Junio C HamanoOct 22, 2020
  50. Eric SunshineOct 22, 2020
  51. Junio C HamanoOct 22, 2020
  52. Charvi MendirattaOct 22, 2020
  53. 4/5 [Outreachy] t7201: use 'git -C' to avoid subshellCharvi Mendiratta, Oct 21, 2020
  54. 5/5 [Outreachy] t7201: put each command on a separate lineCharvi Mendiratta, Oct 21, 2020
  55. 0/5 [Outreachy] modernize test scriptsCharvi Mendiratta, Oct 22, 2020
  56. 1/5 [Outreachy] t7101,t7102,t7201: modernize test formattingCharvi Mendiratta, Oct 22, 2020
  57. 2/5 [Outreachy] t7102,t7201: remove unnecessary blank spaces in test bodyCharvi Mendiratta, Oct 22, 2020
  58. 3/5 [Outreachy] t7102,t7201: remove whitespace after redirect operatorCharvi Mendiratta, Oct 22, 2020
  59. 4/5 [Outreachy] t7201: use 'git -C' to avoid subshellCharvi Mendiratta, Oct 22, 2020
  60. 5/5 [Outreachy] t7201: put each command on a separate lineCharvi Mendiratta, Oct 22, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.