Home > Net >  find and mass edit git folders
find and mass edit git folders

Time:04-20

i try sommething like that

me="$(whoami)";

sudo find vendor/Mea/ -maxdepth 1 -type d \( ! -name . \) -exec bash -c "chmod 777 '{}' -R && chown $me:1000 '{}' -R &&  cd '{}' & echo '{}' & echo $(pwd) & git config --global --add safe.directory $(pwd) & git config core.filemode false;   " \;

i get

user: grek
vendor/Mea/
/mnt/data1/PhpstormProjects/vista_bralion_docker
vendor/Mea/MementoBundle
/mnt/data1/PhpstormProjects/vista_bralion_docker
vendor/Mea/InvoiceBundle
/mnt/data1/PhpstormProjects/vista_bralion_docker
vendor/Mea/AccountancyBundle

so $(pwd) - is always in /mnt/data1/PhpstormProjects/vista_bralion_docker so git command not work , why ?

update 1 :

sudo find vendor/Mea/ -maxdepth 1 -type d \( ! -name . \) -exec bash -c "chmod 777 '{}' -R && chown $me:1000 '{}' -R &&  cd '{}' & echo '{}' & echo \$(pwd) & git config --global --add safe.directory \$(pwd) & git config core.filemode false;   " \;

same situation like before

CodePudding user response:

Try this with -execdir:

sudo find vendor/Mea/ -maxdepth 1 -type d \( ! -name . \) -execdir bash -c "chmod 777 '{}' -R && chown $:1000 '{}' -R && cd '{}' && echo '{}' && echo \$(pwd) && git config --global --add safe.directory \$(pwd) && git config core.filemode false;   " \;

CodePudding user response:

You need to escape $(pwd) it and use && to combine commands.

sudo find vendor/Mea/ -maxdepth 1 -type d \( ! -name . \) -exec bash -c "chmod 777 '{}' -R && chown $:1000 '{}' -R && cd '{}' && echo '{}' && echo \$(pwd) && git config --global --add safe.directory \$(pwd) && git config core.filemode false;   " \;

This should work. I've tested locally as such:

$ find . -maxdepth 1 -exec bash -c "cd '{}' && echo \$(pwd)" \;
/home/bayou/tmp
/home/bayou/tmp/lala
/home/bayou/tmp/framebuffer-vncserver

CodePudding user response:

From the documentation for find:

-exec utility [argument ...] ; True if the program named utility returns a zero value as its exit status. Optional arguments may be passed to the utility. The expression must be terminated by a semicolon (“;”). If you invoke find from a shell you may need to quote the semicolon if the shell would otherwise treat it as a control operator. If the string “{}” appears anywhere in the utility name or the arguments it is replaced by the pathname of the current file. Utility will be executed from the directory from which find was executed. Utility and arguments are not subject to the further expansion of shell patterns and constructs.

Note the bolded "utility will be executed from the directory from which find was executed". If you wish to execute from the lower level directory, use -execdir.

  • Related