Skip to content
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

gtm configure to auto push notes when pushing #81

Open
tsikerdekis opened this issue May 2, 2018 · 4 comments
Open

gtm configure to auto push notes when pushing #81

tsikerdekis opened this issue May 2, 2018 · 4 comments
Assignees

Comments

@tsikerdekis
Copy link

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

@mschenk42
Copy link
Member

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
Copy link
Member

mschenk42 commented May 11, 2018

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.

@mschenk42 mschenk42 self-assigned this May 11, 2018
@tsikerdekis
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants