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

Added rm-gitignore script #3 #30

Closed
wants to merge 19 commits into from

Conversation

Priyanshu-2005
Copy link

@Priyanshu-2005 Priyanshu-2005 commented Mar 15, 2024

issue #3
Added the entire functional script with comments to improve readablity.
The script would first check all the files in .gitignore file and move to the corresponding location accordingly and then delete that file mentioned in .gitignore file.

The output can be seen in the images:

Files mentioned in .gitignore file
Command Used:
cat .gitignore
Screenshot from 2024-03-15 11-29-05

Before running the script
Command Used:
tree
Screenshot from 2024-03-15 11-26-58

After running the script
Commands Used:
bash rm-gitignore
tree
Screenshot from 2024-03-15 11-27-53

as we can see index2.js and index.js present in src2 folder got deleted

Kindly look into this

@rootCircle
Copy link
Member

Added the entire functional script with comments to improve readablity.

Please use AI with sanity!

@rootCircle
Copy link
Member

please remove scripts/color and .gitignore file from the PR and can you explain your approach please!

@Priyanshu-2005
Copy link
Author

Priyanshu-2005 commented Mar 15, 2024

@rootCircle Sure here is the explanation for the code

Explanation of the code
find . -type f -name .gitignore | while read -r gitignore;
To search for all .gitignore files. and pipe them to the while loop which iterates over them one by one

cd "$(dirname "$gitignore")" || continue
To change the directory accordingly mentioned in the .gitignore file
example)
If .gitignore files contains src/index file then it would route to that folder src

echo "Removing files listed in .gitignore for directory: $(pwd)"
Prints the message and mentions the present working directory

while IFS= read -r pattern; do
Starts reading the file line by line -r option prevents confusion of / with escape characters

if [[ ! "$pattern" =~ ^(\s*#|\s*$) ]]; then
It helps to skip the comments line and blank lines. It uses regular expression to do so

rm -rf -- $pattern
Removes the file

done < "$gitignore
done implies that while loop has been finished < is basically a redirectional operator that allows us to take input from the file.

Also I have removed the unnecessary files.

@rootCircle
Copy link
Member

Your explanation looks great!

Also, @Priyanshu-2005 actually you didn't have to delete the color script just restore it to status quo! See the files changes section, the upstream (the main repo) has color script, but you deleted them! Trying fixing that if you can

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

@rootCircle
Copy link
Member

Explanation of the code
find . -type f -name .gitignore | while read -r gitignore;
To search for all .gitignore files. and pipe them to the while loop which iterates over them one by one

Why do you think that there might be multiple .gitignore in one CWD? Any specific purpose/motive?

@Priyanshu-2005
Copy link
Author

Priyanshu-2005 commented Mar 15, 2024

@rootCircle I have restored it by adding the color file but now it is showing an empty file. Is it okay?

@Priyanshu-2005
Copy link
Author

Priyanshu-2005 commented Mar 15, 2024

There might be multiple .gitignore files present in subdirectories too (if they had been there) .
The find command will check all the subdirectories

@rootCircle
Copy link
Member

@rootCircle I have restored it by adding the color file but now it is showing an empty file. Is it okay?

Sorry, it doesn't! You can take help from https://www.freecodecamp.org/news/git-revert-file-reverting-a-file-to-a-previous-commit/

Simply, you need to restore the file using git checkout <commit-hash-before-the-changes(first commit hash)> -- scripts/color

@rootCircle
Copy link
Member

There might be multiple .gitignore files present in subdirectories too (if they had been there) .
The find command will check all the subdirectories

oh, that's cool.

@rootCircle
Copy link
Member

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

@Priyanshu-2005
Copy link
Author

@rootCircle Changes made. Kindly look into this.

@rootCircle
Copy link
Member

@rootCircle Changes made. Kindly look into this.

LGTM 👍 Accepted! Thanks for your contribution!

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.

3 participants