diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 22:53:51 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-21 22:53:51 +0200 |
commit | 3c9f55dd8e6697ab2f9eaf384315abd4cbefad38 (patch) | |
tree | 06cc50a0ed54e375ce8ca182f3307949ca25b666 | |
parent | bb509603e8303cd8ada7cfa1aaa626085b9bb6d6 (diff) | |
download | gitpython-3c9f55dd8e6697ab2f9eaf384315abd4cbefad38.tar.gz |
remote: Added fetch, pull, push methods to the interface to make these operations more convenient, like repo.remotes.origin.fetch
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | lib/git/cmd.py | 6 | ||||
-rw-r--r-- | lib/git/remote.py | 62 | ||||
-rw-r--r-- | test/git/test_remote.py | 7 |
5 files changed, 82 insertions, 5 deletions
@@ -50,6 +50,12 @@ Blob ---- * former 'name' member renamed to path as it suits the actual data better +GitCommand +----------- +* git.subcommand call scheme now prunes out None from the argument list, allowing + to be called more confortably as None can never be a valid to the git command + if converted to a string. + Commit ------ * 'count' method is not an instance method to increase its ease of use @@ -41,6 +41,11 @@ Index * Index Merge ( merge two trees into the index to quickly see conflicts ). Its possible to write it into a separate index file that can be read separately. +Remote +------ +* 'push' method needs a test, a true test repository is required though, a fork + of a fork would do :)! + Repo ---- * Nice fetch/pull handling, at least supported/wired throuhg to the git command @@ -66,5 +71,6 @@ Testing read-only testing scheme that operates on the own repository. Doing this could be a simple as forking a shared repo in a tmp directory. In that moment, we probably want to facility committing and checkouts as well. + - Use these tests for git-remote as we need to test push diff --git a/lib/git/cmd.py b/lib/git/cmd.py index d04a2bd0..485a1553 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -261,7 +261,9 @@ class Git(object): such as in 'ls_files' to call 'ls-files'. ``args`` - is the list of arguments + is the list of arguments. If None is included, it will be pruned. + This allows your commands to call git more conveniently as None + is realized as non-existent ``kwargs`` is a dict of keyword arguments. @@ -287,7 +289,7 @@ class Git(object): # Prepare the argument list opt_args = self.transform_kwargs(**kwargs) - ext_args = self.__unpack_args(args) + ext_args = self.__unpack_args([a for a in args if a is not None]) args = opt_args + ext_args call = ["git", dashify(method)] diff --git a/lib/git/remote.py b/lib/git/remote.py index 4ecae813..7febf2ee 100644 --- a/lib/git/remote.py +++ b/lib/git/remote.py @@ -185,7 +185,9 @@ class Remote(LazyMixin, Iterable): def update(self, **kwargs): """ - Fetch all changes for this remote, including new branches + Fetch all changes for this remote, including new branches which will + be forced in ( in case your local remote branch is not part the new remote branches + ancestry anymore ). ``kwargs`` Additional arguments passed to git-remote update @@ -196,6 +198,64 @@ class Remote(LazyMixin, Iterable): self.repo.git.remote("update", self.name) return self + def fetch(self, refspec=None, **kwargs): + """ + Fetch the latest changes for this remote + + ``refspec`` + A "refspec" is used by fetch and push to describe the mapping + between remote ref and local ref. They are combined with a colon in + the format <src>:<dst>, preceded by an optional plus sign, +. + For example: git fetch $URL refs/heads/master:refs/heads/origin means + "grab the master branch head from the $URL and store it as my origin + branch head". And git push $URL refs/heads/master:refs/heads/to-upstream + means "publish my master branch head as to-upstream branch at $URL". + See also git-push(1). + + Taken from the git manual + + ``**kwargs`` + Additional arguments to be passed to git-fetch + + Returns + self + """ + self.repo.git.fetch(self, refspec, **kwargs) + return self + + def pull(self, refspec=None, **kwargs): + """ + Pull changes from the given branch, being the same as a fetch followed + by a merge of branch with your local branch. + + ``refspec`` + see 'fetch' method + + ``**kwargs`` + Additional arguments to be passed to git-pull + + Returns + self + """ + self.repo.git.pull(self, refspec, **kwargs) + return self + + def push(self, refspec=None, **kwargs): + """ + Push changes from source branch in refspec to target branch in refspec. + + ``refspec`` + see 'fetch' method + + ``**kwargs`` + Additional arguments to be passed to git-push + + Returns + self + """ + self.repo.git.push(self, refspec, **kwargs) + return self + @property def config_reader(self): """ diff --git a/test/git/test_remote.py b/test/git/test_remote.py index 4cbb0b7b..aeb6b4af 100644 --- a/test/git/test_remote.py +++ b/test/git/test_remote.py @@ -32,7 +32,8 @@ class TestRemote(TestCase): # END for each ref # OPTIONS - for opt in ("url", "fetch"): + # cannot use 'fetch' key anymore as it is now a method + for opt in ("url", ): val = getattr(remote, opt) reader = remote.config_reader assert reader.get(opt) == val @@ -61,8 +62,10 @@ class TestRemote(TestCase): assert remote.rename(prev_name).name == prev_name # END for each rename ( back to prev_name ) + remote.fetch() + self.failUnlessRaises(GitCommandError, remote.pull) remote.update() - + self.fail("test push once there is a test-repo") # END for each remote assert num_remotes assert num_remotes == len(remote_set) |