Pushing notes to a remote repository

We have tried and succeeded in retrieving the notes from the remote repository, but what about your notes? How can you push them to the server? This has to be done with the push command just as with any other references, such as branches and commits, when you want to publish them to a remote repository.

How to do it...

Before we can push the notes from the shareNotes repository, we have to create a note to be pushed, as the notes we have now are all available on the remote repository. The remote repository in this case is the chapter5 directory:

  1. I have found a commit I would like to add a note to, and I want to add the note in the verified reference:
    $ git notes --ref verified add -m "Verified by [email protected]" 871ee53b52a
    
  2. Now that we have added the note, we can list it with the git log command:
    $ git log --notes=verified -1 871ee53b52a
    commit 871ee53b52a7e7f6a0fe600a054ec78f8e4bff5a
    Author: Robin Rosenberg <[email protected]>
    Date:   Sun Feb 2 23:26:34 2014 +0100
    
        Reset internal state canonical length in WorkingTreeIterator when moving
    
        Bug: 426514
        Change-Id: Ifb75a4fa12291aeeece3dda129a65f0c1fd5e0eb
        Signed-off-by: Matthias Sohn <[email protected]>
    
    Notes (verified):
        Verified by [email protected]
    
  3. As expected, we can see the note. If you cannot see the note, you probably missed --notes=verified for the git log command, since we have not configured verified as notes.displayRef. To push the note, we must use the git push command, because the default push rule in Git is to push branches to refs/heads/<branchname>. So, if we just try to push the note to the remote, nothing happens:
    $ git push
    Everything up-to-date
    
  4. You will probably see a warning about git push.default not being configured; you can safely ignore this for these examples. The important part is that Git shows that everything is up-to-date. But we know we have created a Git note for a commit. So to push these notes, we need to push our note references to the remote notes references. This can be done as follows:
    $ git push origin refs/notes/*
    Counting objects: 15, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (4/4), done.
    Writing objects: 100% (5/5), 583 bytes | 0 bytes/s, done.
    Total 5 (delta 0), reused 0 (delta 0)
    To c:/Users/Rasmus/repos/./chapter5/
     * [new branch]      refs/notes/verified -> refs/notes/verified
    
  5. Now something happened; we have a new branch on the remote named refs/notes/verified. This is because we have pushed the notes to the remote. What we can do to verify it is go to the chapter5 directory and check if the 871ee53b52a commit has a Git note:
    $ cd ../chapter5/
    $ git log --notes=verified -1 871ee53b52a
    commit 871ee53b52a7e7f6a0fe600a054ec78f8e4bff5a
    Author: Robin Rosenberg <[email protected]>
    Date:   Sun Feb 2 23:26:34 2014 +0100
    
        Reset internal state canonical length in WorkingTreeIterator when moving
    
        Bug: 426514
        Change-Id: Ifb75a4fa12291aeeece3dda129a65f0c1fd5e0eb
        Signed-off-by: Matthias Sohn <[email protected]>
    
    Notes (verified):
        Verified by [email protected]
    
  6. As predicted, we can see the note in this directory.

There's more...

Since Git notes do not work as normal branches, it can be a little difficult to push them back and forth to a repository when you are trying to collaborate on them. Since you cannot just fetch and merge the Git notes branches as easily with other branches, a clear recommendation is to build some tools to add these notes so you only have one server adding the notes.

A very simple but value adding note could be the Jenkins build and test information that published notes about which tests have passed on a commit hash; this is very valid when you have to reopen a defect. You can then actually see in the repository which test has been executed on the commit hash.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset