Skip to content

Instantly share code, notes, and snippets.

View smit9612's full-sized avatar
🏠
Working from home

Smitesh Patel smit9612

🏠
Working from home
View GitHub Profile
@smit9612
smit9612 / pre-commit
Created September 27, 2022 08:16 — forked from candostdagdeviren/pre-commit
Git Pre-Commit hook with SwiftLInt
#!/bin/bash
#Path to swiftlint
SWIFT_LINT=/usr/local/bin/swiftlint
#if $SWIFT_LINT >/dev/null 2>&1; then
if [[ -e "${SWIFT_LINT}" ]]; then
count=0
for file_path in $(git ls-files -m --exclude-from=.gitignore | grep ".swift$"); do
export SCRIPT_INPUT_FILE_$count=$file_path
@smit9612
smit9612 / remove_swift_headers.sh
Created March 3, 2022 04:57 — forked from fe9lix/remove_swift_headers.sh
Xcode: Remove header comments in Swift files
find . -type f -name "*.swift" -not -path "./Pods/*" -exec sed -i '' -e '1,/^import/{/^\/\/.*/d;}' -e '/./,$!d' {} \;
#!/bin/bash
git diff --cached --name-only | grep "\.swift" | while read filename; do
if which swiftlint >/dev/null; then
swiftlint lint --path "$filename";
else
echo "warning: SwiftLint not installed, download from https://github.com/ realm/SwiftLint"
fi
done
git-format-staged --formatter "swiftformat stdin --stdinpath '{}'" "*.swift"
@smit9612
smit9612 / gist:328ecf4892d8dfbe2c340cde82ae144d
Created January 26, 2019 06:01
Show last commit git branch in history
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ci %cr" $branch | head -n 1` \\t$branch; done | sort -r
@smit9612
smit9612 / gist:598acb64487913e7e3554c4af686ad7f
Last active March 11, 2019 03:26
JIRA ID in front of git commit message.
#!/bin/bash
# Include any branches for which you wish to disable this script
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD | grep -o '[A-Z]\+-[0-9]\+')
BRANCH_NAME="${BRANCH_NAME##*/}"
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")

Automatically Prepend a Jira Issue ID to Git Commit Messages

Use a git hook to match a Jira issue ID from the current branch, and prepend it to every commit message

Assuming the current branch contains a Jira issue ID, you can use a git hook script to prepend it to every commit message.

  1. Create an empty commit-msg git hook file, and make it executable. From your project's root directory:

     install -b -m 755 /dev/null .git/hooks/commit-msg
    
  2. Save the following script to the newly-created .git/hooks/commit-msg file: