Made previously protected methods public to introduce a method with r… · gitpython-developers/GitPython@a17c43d · GitHub
Skip to content

Commit a17c43d

Browse files
committed
Made previously protected methods public to introduce a method with reflog support which cannot be exposed using the respective property. Ref-Creation is now fully implemented in python. For details, see doc/source/changes.rst
1 parent 8dd51f1 commit a17c43d

6 files changed

Lines changed: 118 additions & 111 deletions

File tree

doc/source/changes.rst

Lines changed: 28 additions & 5 deletions

refs/head.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -112,38 +112,6 @@ class Head(Reference):
112112
k_config_remote = "remote"
113113
k_config_remote_ref = "merge" # branch to merge from remote
114114

115-
@classmethod
116-
def create(cls, repo, path, commit='HEAD', force=False, **kwargs):
117-
"""Create a new head.
118-
:param repo: Repository to create the head in
119-
:param path:
120-
The name or path of the head, i.e. 'new_branch' or
121-
feature/feature1. The prefix refs/heads is implied.
122-
123-
:param commit:
124-
Commit to which the new head should point, defaults to the
125-
current HEAD
126-
127-
:param force:
128-
if True, force creation even if branch with that name already exists.
129-
130-
:param kwargs:
131-
Additional keyword arguments to be passed to git-branch, i.e.
132-
track, no-track, l
133-
134-
:return: Newly created Head
135-
:note: This does not alter the current HEAD, index or Working Tree"""
136-
if cls is not Head:
137-
raise TypeError("Only Heads can be created explicitly, not objects of type %s" % cls.__name__)
138-
139-
args = ( path, commit )
140-
if force:
141-
kwargs['f'] = True
142-
143-
repo.git.branch(*args, **kwargs)
144-
return cls(repo, "%s/%s" % ( cls._common_path_default, path))
145-
146-
147115
@classmethod
148116
def delete(cls, repo, *heads, **kwargs):
149117
"""Delete the given heads
@@ -157,7 +125,6 @@ def delete(cls, repo, *heads, **kwargs):
157125
flag = "-D"
158126
repo.git.branch(flag, *heads)
159127

160-
161128
def set_tracking_branch(self, remote_reference):
162129
"""
163130
Configure this branch to track the given remote reference. This will alter

refs/reference.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
1818
"""Represents a named reference to any object. Subclasses may apply restrictions though,
1919
i.e. Heads can only point to commits."""
2020
__slots__ = tuple()
21+
_resolve_ref_on_create = True
2122
_common_path_default = "refs"
2223

2324
def __init__(self, repo, path):
@@ -52,7 +53,7 @@ def _set_object(self, ref):
5253
5354
:note:
5455
TypeChecking is done by the git command"""
55-
abs_path = self._abs_path()
56+
abs_path = self.abspath
5657
existed = True
5758
if not isfile(abs_path):
5859
existed = False
@@ -81,31 +82,7 @@ def name(self):
8182
return self.path # could be refs/HEAD
8283
return '/'.join(tokens[2:])
8384

84-
8585
@classmethod
86-
def create(cls, repo, path, commit='HEAD', force=False ):
87-
"""Create a new reference.
88-
89-
:param repo: Repository to create the reference in
90-
:param path:
91-
The relative path of the reference, i.e. 'new_branch' or
92-
feature/feature1. The path prefix 'refs/' is implied if not
93-
given explicitly
94-
95-
:param commit:
96-
Commit to which the new reference should point, defaults to the
97-
current HEAD
98-
99-
:param force:
100-
if True, force creation even if a reference with that name already exists.
101-
Raise OSError otherwise
102-
103-
:return: Newly created Reference
104-
105-
:note: This does not alter the current HEAD, index or Working Tree"""
106-
return cls._create(repo, path, True, commit, force)
107-
108-
@classmethod
10986
def iter_items(cls, repo, common_path = None):
11087
"""Equivalent to SymbolicReference.iter_items, but will return non-detached
11188
references as well."""

refs/remote.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ def delete(cls, repo, *refs, **kwargs):
5656
except OSError:
5757
pass
5858
# END for each ref
59+
60+
@classmethod
61+
def create(cls, *args, **kwargs):
62+
"""Used to disable this method"""
63+
raise TypeError("Cannot explicitly create remote references")

refs/symbolic.py

Lines changed: 69 additions & 45 deletions

0 commit comments

Comments
 (0)