From 22a1f29685e90f2b467784024d2884c8d358ba78 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Mon, 5 Aug 2019 12:33:54 +0200 Subject: [PATCH 1/4] Method stating which commit is being played during an halted rebase This will be useful to me at least. This way, I know that I can tell my script to omit some specific commits. If you accept to merge it, I may also do similar method for merges and cherry pick. --- AUTHORS | 1 + git/repo/base.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/AUTHORS b/AUTHORS index a0aa707c7..e91fd78b1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -33,5 +33,6 @@ Contributors are: -Steven Whitman -Stefan Stancu -César Izurieta +-Arthur Milchior Portions derived from other open source works and are clearly marked. diff --git a/git/repo/base.py b/git/repo/base.py index f35870803..33148e556 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -1061,3 +1061,14 @@ def has_separate_working_tree(self): def __repr__(self): return '' % self.git_dir + + def currentlyRebasingOn(self): + """ + :return: The hash of the commit which is currently being replayed while rebasing. + + None if we are not currently rebasing. + """ + rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD") + if not osp.isfile(rebase_head_file): + return None + return open(rebase_head_file, "rt").readline().strip() From 8faf5253fef1f402df90b634c8bf503cea09e95f Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 11 Aug 2019 13:35:48 +0200 Subject: [PATCH 2/4] Snack case as requested in #903 --- git/repo/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git/repo/base.py b/git/repo/base.py index 33148e556..12f7dfb81 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -1062,7 +1062,7 @@ def has_separate_working_tree(self): def __repr__(self): return '' % self.git_dir - def currentlyRebasingOn(self): + def currently_rebasing_on(self): """ :return: The hash of the commit which is currently being replayed while rebasing. From 41ca06db26d5669c4966c710a8bafac3cf0a6c3e Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sun, 11 Aug 2019 13:45:15 +0200 Subject: [PATCH 3/4] Returning commit object instead of hash value --- git/repo/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git/repo/base.py b/git/repo/base.py index 12f7dfb81..e733e3bbb 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -1064,11 +1064,11 @@ def __repr__(self): def currently_rebasing_on(self): """ - :return: The hash of the commit which is currently being replayed while rebasing. + :return: The commit which is currently being replayed while rebasing. None if we are not currently rebasing. """ rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD") if not osp.isfile(rebase_head_file): return None - return open(rebase_head_file, "rt").readline().strip() + return self.commit(open(rebase_head_file, "rt").readline().strip()) From 9334614cc954d3149399c529019ae7e981b64e04 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Tue, 13 Aug 2019 01:09:04 +0200 Subject: [PATCH 4/4] Adding test --- git/test/test_repo.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/git/test/test_repo.py b/git/test/test_repo.py index 0577bd589..c74d4ef41 100644 --- a/git/test/test_repo.py +++ b/git/test/test_repo.py @@ -1023,3 +1023,25 @@ def test_git_work_tree_env(self, rw_dir): self.assertEqual(r.working_dir, repo_dir) finally: os.environ = oldenv + + @with_rw_directory + def test_rebasing(self, rw_dir): + r = Repo.init(rw_dir) + fp = osp.join(rw_dir, 'hello.txt') + r.git.commit("--allow-empty", message="init",) + with open(fp, 'w') as fs: + fs.write("hello world") + r.git.add(Git.polish_url(fp)) + r.git.commit(message="English") + self.assertEqual(r.currently_rebasing_on(), None) + r.git.checkout("HEAD^1") + with open(fp, 'w') as fs: + fs.write("Hola Mundo") + r.git.add(Git.polish_url(fp)) + r.git.commit(message="Spanish") + commitSpanish = r.commit() + try: + r.git.rebase("master") + except GitCommandError: + pass + self.assertEqual(r.currently_rebasing_on(), commitSpanish)