Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3 :adding feature rm-gitignore #27

Closed

Conversation

piyushkumar079
Copy link

#3 : Clean Ignored Files in Git Repos
This script removes ignored files from Git repositories using git clean -Xdf.
Added Comments in code to explain the same
image

@piyushkumar079 piyushkumar079 changed the title adding feature rm-gitignore #3 :adding feature rm-gitignore Mar 15, 2024
@rootCircle
Copy link
Member

hi @piyushkumar079, clean implementation! can you briefly explain what your code does?

@rootCircle
Copy link
Member

also, you can print a helpful message if current working directory is not a git directory rather than Finished cleaning ignored files in Git repositories.

@rootCircle
Copy link
Member

ping me here when you're done with those, so we can move forward with your PR!

@piyushkumar079
Copy link
Author

piyushkumar079 commented Mar 15, 2024

ping me here when you're done with those, so we can move forward with your PR!

@rootCircle
explanation
git_repos=$(find . -name .git -type d -prune)
this line finds the ./git folder
cd ..
this is done since .gitignore file lives outside of ./git folder
git clean -Xdf
with -Xdf flag this line forcefull deletes the files mentioned inside the .gitignore file
cd -
this takes us back to the previous directory (like in back in a browser)
>/dev/null 2>&1
this is a popular method that supresses error messages

Changes
made the recommeded change
-z flag checks if the array is empty

@rootCircle
Copy link
Member

explanation
git_repos=$(find . -name .git -type d -prune)
this line finds the ./git folder

In the comment in code you wrote and I quote # Loop through each Git repository, what do you mean by that, there can be one and only more .git in CWD or am I mistaken somewhere?

@rootCircle
Copy link
Member

rootCircle commented Mar 15, 2024

Changes
made the recommeded change

LGTM 👍 I have accepted your PR, but haven't closed it until for your explanation!

@piyushkumar079
Copy link
Author

piyushkumar079 commented Mar 16, 2024

explanation
git_repos=$(find . -name .git -type d -prune)
this line finds the ./git folder

In the comment in code you wrote and I quote # Loop through each Git repository, what do you mean by that, there can be one and only more .git in CWD or am I mistaken somewhere?

yes as quoted from the moderator
To find list of all git repos inside current directory you can use: "find . -name .git -type d -prune"
it starts searching from the current directory (represented by the dot, ".") and descends into all subdirectories.
a example would be if a project has both frontend and backend in a single directory and both the directories are tracked by git independently. and if the script is run on the root of both the directories it will actually find both the .git directory and then clean .gitignore by looping thru each repo

@rootCircle
Copy link
Member

To find list of all git repos inside current directory you can use: "find . -name .git -type d -prune"
it starts searching from the current directory (represented by the dot, ".") and descends into all subdirectories.
a example would be if a project has both frontend and backend in a single directory and both the directories are tracked by git independently. and if the script is run on the root of both the directories it will actually find both the .git directory and then clean .gitignore by looping thru each repo

great explanation @piyushkumar079! LGTM, accepted

@rootCircle rootCircle closed this Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants