2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 using GitSharp
.Core
.Transport
;
41 namespace GitSharp
.Commands
43 public abstract class AbstractFetchCommand
: AbstractCommand
45 protected bool verbose
;
47 protected void showFetchResult(GitSharp
.Core
.Transport
.Transport tn
, FetchResult r
)
49 bool shownURI
= false;
50 foreach (TrackingRefUpdate u
in r
.TrackingRefUpdates
)
52 if (!verbose
&& u
.Result
== RefUpdate
.RefUpdateResult
.NO_CHANGE
)
55 char type
= shortTypeOf(u
.Result
);
56 string longType
= longTypeOf(u
);
57 string src
= AbbreviateRef(u
.RemoteName
, false);
58 string dst
= AbbreviateRef(u
.LocalName
, true);
62 OutputStream
.Write("From ");
63 OutputStream
.WriteLine(tn
.Uri
);
67 OutputStream
.WriteLine(" " + type
+ " " + longType
+ " " + src
+ " -> " + dst
);
71 private string longTypeOf(TrackingRefUpdate u
)
73 RefUpdate
.RefUpdateResult r
= u
.Result
;
74 if (r
== RefUpdate
.RefUpdateResult
.LOCK_FAILURE
)
76 if (r
== RefUpdate
.RefUpdateResult
.IO_FAILURE
)
78 if (r
== RefUpdate
.RefUpdateResult
.REJECTED
)
80 if (ObjectId
.ZeroId
.Equals(u
.NewObjectId
))
83 if (r
== RefUpdate
.RefUpdateResult
.NEW
)
85 if (u
.RemoteName
.StartsWith(Constants
.R_HEADS
))
86 return "[new branch]";
87 if (u
.LocalName
.StartsWith(Constants
.R_TAGS
))
92 if (r
== RefUpdate
.RefUpdateResult
.FORCED
)
94 string aOld
= u
.OldObjectId
.Abbreviate(Repository
).name();
95 string aNew
= u
.NewObjectId
.Abbreviate(Repository
).name();
96 return aOld
+ "..." + aNew
;
99 if (r
== RefUpdate
.RefUpdateResult
.FAST_FORWARD
)
101 string aOld
= u
.OldObjectId
.Abbreviate(Repository
).name();
102 string aNew
= u
.NewObjectId
.Abbreviate(Repository
).name();
103 return aOld
+ ".." + aNew
;
106 if (r
== RefUpdate
.RefUpdateResult
.NO_CHANGE
)
107 return "[up to date]";
109 return "[" + r
+ "]";
112 private static char shortTypeOf(RefUpdate
.RefUpdateResult r
)
116 case RefUpdate
.RefUpdateResult
.LOCK_FAILURE
:
117 case RefUpdate
.RefUpdateResult
.IO_FAILURE
:
118 case RefUpdate
.RefUpdateResult
.REJECTED
:
121 case RefUpdate
.RefUpdateResult
.NEW
:
124 case RefUpdate
.RefUpdateResult
.FORCED
:
127 case RefUpdate
.RefUpdateResult
.NO_CHANGE
: