2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50
/// <summary>A RefUpdate combination for renaming a reference.</summary>
52
/// A RefUpdate combination for renaming a reference.
54
/// If the source reference is currently pointed to by
57
/// HEAD symbolic reference is updated to point to the new destination.
59
public abstract class RefRename
61
/// <summary>Update operation to read and delete the source reference.</summary>
62
/// <remarks>Update operation to read and delete the source reference.</remarks>
63
protected internal readonly RefUpdate source;
65
/// <summary>Update operation to create/overwrite the destination reference.</summary>
66
/// <remarks>Update operation to create/overwrite the destination reference.</remarks>
67
protected internal readonly RefUpdate destination;
69
private RefUpdate.Result result = RefUpdate.Result.NOT_ATTEMPTED;
71
/// <summary>Initialize a new rename operation.</summary>
72
/// <remarks>Initialize a new rename operation.</remarks>
73
/// <param name="src">operation to read and delete the source.</param>
74
/// <param name="dst">operation to create (or overwrite) the destination.</param>
75
protected internal RefRename(RefUpdate src, RefUpdate dst)
79
string cmd = string.Empty;
80
if (source.GetName().StartsWith(Constants.R_HEADS) && destination.GetName().StartsWith
85
SetRefLogMessage(cmd + "renamed " + Repository.ShortenRefName(source.GetName()) +
86
" to " + Repository.ShortenRefName(destination.GetName()));
89
/// <returns>identity of the user making the change in the reflog.</returns>
90
public virtual PersonIdent GetRefLogIdent()
92
return destination.GetRefLogIdent();
95
/// <summary>Set the identity of the user appearing in the reflog.</summary>
97
/// Set the identity of the user appearing in the reflog.
99
/// The timestamp portion of the identity is ignored. A new identity with the
100
/// current timestamp will be created automatically when the rename occurs
101
/// and the log record is written.
103
/// <param name="pi">
104
/// identity of the user. If null the identity will be
105
/// automatically determined based on the repository
108
public virtual void SetRefLogIdent(PersonIdent pi)
110
destination.SetRefLogIdent(pi);
113
/// <summary>Get the message to include in the reflog.</summary>
114
/// <remarks>Get the message to include in the reflog.</remarks>
116
/// message the caller wants to include in the reflog; null if the
117
/// rename should not be logged.
119
public virtual string GetRefLogMessage()
121
return destination.GetRefLogMessage();
124
/// <summary>Set the message to include in the reflog.</summary>
125
/// <remarks>Set the message to include in the reflog.</remarks>
126
/// <param name="msg">the message to describe this change.</param>
127
public virtual void SetRefLogMessage(string msg)
135
destination.SetRefLogMessage(msg, false);
139
/// <summary>Don't record this rename in the ref's associated reflog.</summary>
140
/// <remarks>Don't record this rename in the ref's associated reflog.</remarks>
141
public virtual void DisableRefLog()
143
destination.SetRefLogMessage(string.Empty, false);
146
/// <returns>result of rename operation</returns>
147
public virtual RefUpdate.Result GetResult()
152
/// <returns>the result of the new ref update</returns>
153
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
154
public virtual RefUpdate.Result Rename()
161
catch (IOException err)
163
result = RefUpdate.Result.IO_FAILURE;
168
/// <returns>the result of the rename operation.</returns>
169
/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
170
protected internal abstract RefUpdate.Result DoRename();
174
/// <code>Constants#HEAD</code>
175
/// reference needs to be linked
176
/// to the new destination name.
178
/// <exception cref="System.IO.IOException">
179
/// the current value of
180
/// <code>HEAD</code>
183
protected internal virtual bool NeedToUpdateHEAD()
185
Ref head = source.GetRefDatabase().GetRef(Constants.HEAD);
186
if (head.IsSymbolic())
188
head = head.GetTarget();
189
return head.GetName().Equals(source.GetName());