I am currently playing with monorepos and I am trying to retrieve a list all 1 level subfolders in the repo which are impacted since a given commit.
So far I can retrieve all the files impacted using git diff --name-only $COMMIT_ID..head
Using git diff --name-only $COMMIT_ID..head | xargs -L1 dirname
I manage to get only the folder names.
To remove all the duplicates I added sort | uniq
to the mix: git diff --name-only $COMMIT_ID..head | xargs -L1 dirname | sort | uniq
All I need now is to ensure I only retrieve the first level folders i.e. project1
not project1/src
and project1/lib
I have tried a few options but I have not managed to keep it as a one liner so far.
Here is a solution with
awk
-F'/'
sets the delimiter field to slash/
NF!=1{print $1}
prints out the first field which is the first level directory name if the line contain slashes/
, this filters out files that exists in the first levelsort -u
combined sort and unique