-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Add a function to clean and update local repositories #124
base: master
Are you sure you want to change the base?
Conversation
#!/bin/bash | ||
|
||
repos_dir="${HOME}/repos" | ||
exclude_dir=("$@") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean-local-repos my-repo
Will in fact ignore my-repo
. I'm not sure, but it doesn't seem very intuitive.
Maybe you can use argbash to make your script accept flags like:
clean-local-repos -e my-repo
-e
being the same as the git clean
command: --exclude
(or except
).
folders=$(find "${repos_dir}" -maxdepth 1 -mindepth 1 -type d -exec basename {} \;) | ||
if [[ ${#exclude_dir[@]} -ne 0 ]]; then | ||
folders=$(echo "${folders}" | grep -v -E "$(IFS="|"; echo "${exclude_dir[*]}")") | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can simplify this, just add the exclusions in find command itself. Raw example:
cd $repos_dir
repos=$(find . -type d ! -name "felipe" ! -name "cassio")
folders=$(echo "${folders}" | grep -v -E "$(IFS="|"; echo "${exclude_dir[*]}")") | ||
fi | ||
|
||
for folder in ${folders}; do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use bash arrays:
readarray -t repos <<<"${repos}"
for repo in "${repos[@]}"; do
repos_dir="${HOME}/repos" | ||
exclude_dir=("$@") | ||
|
||
folders=$(find "${repos_dir}" -maxdepth 1 -mindepth 1 -type d -exec basename {} \;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This find command can return folders which are not git repos. You can protect against it, all git repos will have a .git
folder at their root.
git reset --hard origin/"${branch}" | ||
git checkout "${branch}" | ||
git pull |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a crazy idea, but I think it's really nice.
Why don't you make this script even more generic? Like:
git-run-in-all-repos -e my-repo -- git pull --rebase
Then, you can create a git alias that does reset
+ checkout
+ pull
, although it's very likely there is one already.
No description provided.