-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Catching git-commit from zsh #1
Comments
What platform? I only tested this on Ubuntu 14.10 and I have no device to test it on OS X... 😢 Since it's a syntax error, something should be in the override function, not being related to Would be nice to output the ...
echo $cmdToRun # Add this and post the output in the issue
bash -c "$cmdToRun"
... |
Oh, it seems that when it tries to run Can you check if the Maybe we can use the |
OK, so let's try the # My own Git
git() {
cmd=$1
shift
extra=""
quoted_args=""
whitespace="[[:space:]]"
for i in "$@"
do
quoted_args="$quoted_args \"$i\""
done
cmdToRun="git "$cmd" $quoted_args"
cmdToRun=`echo $cmdToRun | sed -e 's/^ *//' -e 's/ *$//'`
bash -c "$cmdToRun"
if [ $? -eq 0 ]; then
# Commit stats
if [ "$cmd" == "commit" ]; then
commit_hash=`git rev-parse HEAD`
repo_url=`git config --get remote.origin.url`
commit_date=`git log -1 --format=%cd`
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "$commit_data"
fi
fi
} |
Whoups, in the previous code I didn't use So, let's try it (this will also output the command that is run by git() {
cmd=$1
shift
extra=""
quoted_args=""
whitespace="[[:space:]]"
for i in "$@"
do
quoted_args="$quoted_args \"$i\""
done
cmdToRun="git "$cmd" $quoted_args"
cmdToRun=`echo $cmdToRun | sed -e 's/^ *//' -e 's/ *$//'`
echo ">>> $cmdToRun"
command $cmdToRun
if [ $? -eq 0 ]; then
# Commit stats
if [ "$cmd" == "commit" ]; then
commit_hash=`git rev-parse HEAD`
repo_url=`git config --get remote.origin.url`
commit_date=`git log -1 --format=%cd`
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "$commit_data"
fi
fi
} |
OK! Let's try do_git() {
cmd=$1
shift
extra=""
quoted_args=""
whitespace="[[:space:]]"
for i in "$@"
do
quoted_args="$quoted_args \"$i\""
done
cmdToRun="git "$cmd" $quoted_args"
cmdToRun=`echo $cmdToRun | sed -e 's/^ *//' -e 's/ *$//'`
echo ">>> $cmdToRun"
bash -c $cmdToRun
if [ $? -eq 0 ]; then
# Commit stats
if [ "$cmd" == "commit" ]; then
commit_hash=`git rev-parse HEAD`
repo_url=`git config --get remote.origin.url`
commit_date=`git log -1 --format=%cd`
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "$commit_data"
fi
fi
}
alias git="do_git" |
This is called screenshare via GitHub comments. 😄 The below code works fine on Linux. git() {
cmd=$1
shift
extra=""
quoted_args=""
whitespace="[[:space:]]"
for i in "$@"
do
quoted_args="$quoted_args \"$i\""
done
cmdToRun="command git "$cmd" $quoted_args"
cmdToRun=`echo $cmdToRun | sed -e 's/^ *//' -e 's/ *$//'`
echo ">>> $cmdToRun"
$cmdToRun
echo $?
if [ $? -eq 0 ]; then
# Commit stats
if [ "$cmd" == "commit" ]; then
commit_hash=`git rev-parse HEAD`
repo_url=`git config --get remote.origin.url`
commit_date=`git log -1 --format=%cd`
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "$commit_data"
fi
fi
} |
Maybe some OS X geeks will see this and come with a fix! 😄 |
This isn't an OS X bug. This same issue exists using zsh on linux (tested with zsh 5.0.5 on linux and OS X). Your function works properly on OS X with bash (tested with bash 3.2.53 on OS X) |
I couldn't reproduce it in zsh, but anyway I'm removing the |
Run this script on your machine. It will add the Then do BTW, does the importer tool work on Mac? |
@IonicaBizau, It does work on Mac, but for some reason, it only imports a couple of the commits. Is there a restriction limit set by default? |
@revolt666 The git-stats-importer tool imports only your commits, it filters them based on the email address you have set. $ git config user.email This will output the email address that |
Oh, forgot about that. Can't it get all the commits? Because I'm the only developer but I forgot (or didn't know how) to change the email for a couple of months, and I would be more interested for a general calendar, knowing that the project was being developed by one person at a time. |
@revolt666 Sure, if you hack it! 😏 You just need to remove this property. So:
|
@IonicaBizau, Awesome, I will try it later on. Thanks for the detailed guide too 😄 |
mac 10.10.2 |
@rambo-panda Even using the git hooks? 😮 |
@atuttle Did you try the git hooks version? |
Not yet, swamped at work. Adam On Tue, Feb 10, 2015 at 12:21 PM, Ionică Bizău notifications@github.com
|
I've just had a chance to try the script. It doesn't cause any errors, which is good, but it doesn't seem to capture my commits either. I've run it, and it did create |
Add it in Hmmm, it should work. I tested it on OS X Yosemite in virtual machine (also in zsh). Can you confirm that at least the |
|
The beginning of good news. 😄 Run the following commands, exactly like below. $ mkdir foo
$ cd foo
$ git init
$ git-stats # Store the total number of commits
$ echo "foo" > foo
$ git remote add foo
$ git add .
$ git commit -m 'initial'
$ git-stats # Check if the total number is with one more If this doesn't work in zsh, check if it work out of zsh. |
I think I was missing the |
Cooool! 👍
|
After adding your sample script for catching
git commit
to my .zshrc file:So for now I'll have to live without it. Would be nice if there was an alternative, for zsh users though. :)
The text was updated successfully, but these errors were encountered: