2 * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com>
3 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
7 * Redistribution and use in source and binary forms, with or
8 * without modification, are permitted provided that the following
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * - Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
19 * - Neither the name of the Git Development Community nor the
20 * names of its contributors may be used to endorse or promote
21 * products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 package org
.spearce
.jgit
.transport
;
41 import java
.io
.IOException
;
43 import org
.spearce
.jgit
.lib
.AnyObjectId
;
44 import org
.spearce
.jgit
.lib
.ObjectId
;
45 import org
.spearce
.jgit
.lib
.RefUpdate
;
46 import org
.spearce
.jgit
.lib
.Repository
;
47 import org
.spearce
.jgit
.lib
.RefUpdate
.Result
;
48 import org
.spearce
.jgit
.revwalk
.RevWalk
;
50 /** Update of a locally stored tracking branch. */
51 public class TrackingRefUpdate
{
52 private final RefSpec spec
;
54 private final RefUpdate update
;
56 TrackingRefUpdate(final Repository db
, final RefSpec s
,
57 final AnyObjectId nv
, final String msg
) throws IOException
{
59 update
= db
.updateRef(s
.getDestination());
60 update
.setForceUpdate(spec
.isForceUpdate());
61 update
.setNewObjectId(nv
);
62 update
.setRefLogMessage(msg
, true);
66 * Get the name of the remote ref.
68 * Usually this is of the form "refs/heads/master".
70 * @return the name used within the remote repository.
72 public String
getRemoteName() {
73 return spec
.getSource();
77 * Get the name of the local tracking ref.
79 * Usually this is of the form "refs/remotes/origin/master".
81 * @return the name used within this local repository.
83 public String
getLocalName() {
84 return update
.getName();
88 * Get the new value the ref will be (or was) updated to.
90 * @return new value. Null if the caller has not configured it.
92 public ObjectId
getNewObjectId() {
93 return update
.getNewObjectId();
97 * The old value of the ref, prior to the update being attempted.
99 * This value may differ before and after the update method. Initially it is
100 * populated with the value of the ref before the lock is taken, but the old
101 * value may change if someone else modified the ref between the time we
102 * last read it and when the ref was locked for update.
104 * @return the value of the ref prior to the update being attempted; null if
105 * the updated has not been attempted yet.
107 public ObjectId
getOldObjectId() {
108 return update
.getOldObjectId();
112 * Get the status of this update.
114 * @return the status of the update.
116 public Result
getResult() {
117 return update
.getResult();
120 void update(final RevWalk walk
) throws IOException
{