git-time-metric / gtm

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

gtm configure to auto push notes when pushing #81

Open tsikerdekis opened 6 years ago

tsikerdekis commented 6 years ago

Is there any way that gtm can be setup so that it will automatically push notes whenever a user pushes to git?

mschenk42 commented 6 years ago

One option is to wrap the git command by using a shell function. This is tested on zsh, not sure if this will work in bash as is. Will likely need to tweak it some. You can remove the commands you don't want from the case statement. I add this to my .zshrc (for bash it would be the .bashrc) so it's sourced and available. Use at your own risk :).

function git {
  command git "$@"
  rc=$?
  if [ $rc -ne 0 ]; then
    return $rc
  fi
  case "$1" in
    init)
      output=$(gtm init)
      echo "$output"
      ;;
    clone)
      # hack to get git repo root directory
      output=$(command git "$@" 2>&1 >/dev/null)
      d=$(echo "${output}"|awk '{print $4}'|tr -d "'")
      output=$(cd "${PWD}/${d}" && gtm init)
      echo "$output"
      ;;
    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
}
mschenk42 commented 6 years ago

Here's another option.

git config --add remote.origin.push '+refs/notes/gtm-data:refs/notes/gtm-data'
git config --add remote.origin.push '+refs/notes/gtm-data:refs/notes/gtm-data'

Use with caution, still testing to see how well this works.

You can learn more about this here https://harrow.io/blog/effortlessly-maintain-a-high-quality-change-log-with-little-known-git-tricks/#fnref-1765-howgitnotesworks

I might add this as an option for the gtm init command.

tsikerdekis commented 6 years ago

Yes that's even better! Thanks so much. I am thinking about using gtm in one of my classes to track how much work students are putting towards assignments. Given that some may forget to push the notes, the automated way will ensure that they will be always pushing the notes to their repo (and from there I can track their progress).

mschenk42 commented 6 years ago

After some further testing I don't think this is going to work the way we'd want it to. When doing a git push it will only push the notes and not the branch. At least that's what it did for me when working on a branch off of master. I think the pushing of notes is similar to what git expects for when you push tags. It seems to be purposely designed to not be automatic. It would be nice if they provided an option for configuring it to always include the notes when pushing. Here's some more info on the issue https://stackoverflow.com/questions/19504544/git-config-remote-origin-push-vs-push-default/19504666?noredirect=1#comment87519950_19504666