git-time-metric / gtm

Simple, seamless, lightweight time tracking for Git
MIT License
973 stars 52 forks source link

[Feature Request] Transparent Integration with Push and Pull #68

Open mehcode opened 7 years ago

mehcode commented 7 years ago

First off, brilliant git extension. I'm evaluating this over something more traditional like an issue time tracker (eg. Tempo). I really like the usage of the tool. It just needs some polish to be readily used in my company's workflow. I'll be posting some requests that I'd need to get this done. I have some time I can spend working on them too if we agree they need done.


Currently this is an entirely local plugin unless a user explicitly runs git pushgtm when pushing and git fetchgtm when fetching.

It seems simple enough to automate fetch. When running gtm init we could modify .git/config as follows:

[remote "origin"]
    fetch = +refs/notes/gtm-data:refs/notes/gtm-data
    fetch = +refs/heads/*:refs/remotes/origin/*

Push seems a lot harder. A couple ideas:

mschenk42 commented 7 years ago

Here's something I've been experimenting with. This works with bash or zsh. You add this to either .bashrc or .zshrc. This only works from the command line and not with a git client.

function git {
  command git "$@"
  rc=$?
  if [ $rc -ne 0 ]; then
    return $rc
  fi
  case "$1" in
    'init'|'clone')
      output=$(gtm init)
      if [ $? -eq 0 ]; then
        echo "$output"
      fi
      ;;
    'status')
      output=$(gtm status)
      if [ $? -eq 0 ]; then
        echo "$output"
      fi
      ;;
    'push')
      output=$(gtm status)
      if [ $? -ne 0 ]; then
          break
      fi
      echo "git pushgtm..."
      output=$(git pushgtm)
      if [ $? -eq 0 ]; then
        echo "$output"
      fi
      ;;
    'fetch'|'pull')
      output=$(gtm status)
      if [ $? -ne 0 ]; then
          break
      fi
      echo "git fetchgtm..."
      output=$(git fetchgtm)
      if [ $? -eq 0 ]; then
        echo "$output"
      fi
      ;;
  esac
  return $rc
}

I've tried the hook for pushing in the past but ran into some odd issue. However it still may be a possible solution.

If we can find a better way to make this more seamless we're open to adding new features.

Thanks for your kind feedback.

dazinator commented 4 years ago

I'm here from a seperate repo that I also use notes. Trying to solve the auto push problem so that an alias isn't necessary. I tried with a pre-push hook but git hangs when I attempt to push another branch during the pre-push hook. Wondering if it was just an issue with my implementation or not.

dazinator commented 4 years ago

The best I can come up with is to use the pre-push hook to prevent a push if the notes haven't been pushed. This acts as a safety net of sorts. The user still has to push notes separately though or use the alias I have set up.