# [StGIT PATCH] Better diagnostic for wrong branch configuration.

6 messages from 2007-10-05 to 2007-10-08. Participants: Yann Dirson, Karl Hasselström, Catalin Marinas.
Thread: https://gitlist.dev/t/10165

## Yann Dirson, 2007-10-05 20:44

Subject: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <20071005204452.30902.60246.stgit@gandelf.nowhere.earth>
URL: https://gitlist.dev/e/20071005204452.30902.60246.stgit%40gandelf.nowhere.earth

```
If the branch.*.merge parameter does not name a valid remote head,
stgit would not rebase after a fetch, and would write instead
'Rebasing to "None" ... done'.

This patch makes this situation an error and tells the user what
to fix in his repo configuration.
---

 stgit/commands/pull.py |    9 ++++++++-
 stgit/git.py           |    5 ++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/stgit/commands/pull.py b/stgit/commands/pull.py
index 052ea2b..070db99 100644
--- a/stgit/commands/pull.py
+++ b/stgit/commands/pull.py
@@ -90,7 +90,14 @@ def func(parser, options, args):
     elif policy == 'fetch-rebase':
         out.info('Fetching from "%s"' % repository)
         git.fetch(repository)
-        rebase(git.fetch_head())
+        try:
+            target = git.fetch_head()
+        except git.GitException:
+            out.error('Could not find the remote head to rebase onto, pushing any patches back...')
+            post_rebase(applied, False, False)
+            raise CmdException, 'Could not find the remote head to rebase onto - fix branch.%s.merge in .git/config' % crt_series.get_name()
+
+        rebase(target)
     elif policy == 'rebase':
         rebase(crt_series.get_parent_branch())
 
diff --git a/stgit/git.py b/stgit/git.py
index 9e0f771..a0493bc 100644
--- a/stgit/git.py
+++ b/stgit/git.py
@@ -1003,11 +1003,14 @@ def fetch_head():
         m = re.match('^([^\t]*)\t\t', line)
         if m:
             if fetch_head:
-                raise GitException, "StGit does not support multiple FETCH_HEAD"
+                raise GitException, 'StGit does not support multiple FETCH_HEAD'
             else:
                 fetch_head=m.group(1)
     stream.close()
 
+    if not fetch_head:
+        raise GitException, 'No for-merge remote head found in FETCH_HEAD'
+
     # here we are sure to have a single fetch_head
     return fetch_head
 

```

## Karl Hasselström, 2007-10-07 13:14

Subject: Re: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <20071007131417.GA28492@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20071007131417.GA28492%40diana.vm.bytemark.co.uk
In-Reply-To: <20071005204452.30902.60246.stgit@gandelf.nowhere.earth>

```
On 2007-10-05 22:44:52 +0200, Yann Dirson wrote:

> If the branch.*.merge parameter does not name a valid remote head,
> stgit would not rebase after a fetch, and would write instead
> 'Rebasing to "None" ... done'.
>
> This patch makes this situation an error and tells the user what to
> fix in his repo configuration.

Good. Sign-off?

> -                raise GitException, "StGit does not support multiple FETCH_HEAD"
> +                raise GitException, 'StGit does not support multiple FETCH_HEAD'

Unrelated quote fixup. No big deal, though.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Yann Dirson, 2007-10-07 14:17

Subject: Re: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <20071007141744.GY26436@nan92-1-81-57-214-146.fbx.proxad.net>
URL: https://gitlist.dev/e/20071007141744.GY26436%40nan92-1-81-57-214-146.fbx.proxad.net
In-Reply-To: <20071007131417.GA28492@diana.vm.bytemark.co.uk>

```
On Sun, Oct 07, 2007 at 03:14:17PM +0200, Karl Hasselström wrote:
> On 2007-10-05 22:44:52 +0200, Yann Dirson wrote:
> 
> > If the branch.*.merge parameter does not name a valid remote head,
> > stgit would not rebase after a fetch, and would write instead
> > 'Rebasing to "None" ... done'.
> >
> > This patch makes this situation an error and tells the user what to
> > fix in his repo configuration.
> 
> Good. Sign-off?

Oops, sorry - "Signed-off-by: Yann Dirson <ydirson@altern.org>"

> > -                raise GitException, "StGit does not support multiple FETCH_HEAD"
> > +                raise GitException, 'StGit does not support multiple FETCH_HEAD'
> 
> Unrelated quote fixup. No big deal, though.

Right - did not seem to warrant a patch of its own :)

Best regards,
-- 
Yann

```

## Karl Hasselström, 2007-10-07 15:25

Subject: Re: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <20071007152502.GA29566@diana.vm.bytemark.co.uk>
URL: https://gitlist.dev/e/20071007152502.GA29566%40diana.vm.bytemark.co.uk
In-Reply-To: <20071007141744.GY26436@nan92-1-81-57-214-146.fbx.proxad.net>

```
On 2007-10-07 16:17:44 +0200, Yann Dirson wrote:

> Oops, sorry - "Signed-off-by: Yann Dirson <ydirson@altern.org>"

Thanks; I'll include that when I push out my branches tonight.

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

```

## Catalin Marinas, 2007-10-07 21:04

Subject: Re: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <b0943d9e0710071404i549f4290u4f5ba7ada355bb54@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0710071404i549f4290u4f5ba7ada355bb54%40mail.gmail.com
In-Reply-To: <20071005204452.30902.60246.stgit@gandelf.nowhere.earth>

```
On 05/10/2007, Yann Dirson <ydirson@altern.org> wrote:
> If the branch.*.merge parameter does not name a valid remote head,
> stgit would not rebase after a fetch, and would write instead
> 'Rebasing to "None" ... done'.

Applied, thanks. I'll try it tomorrow with my StGIT over SVN
configuration as well (it works OK with the latter patches).

-- 
Catalin

```

## Catalin Marinas, 2007-10-08 13:00

Subject: Re: [StGIT PATCH] Better diagnostic for wrong branch configuration.
Message-ID: <b0943d9e0710080600y55aeeeeei8dbd27d069c681e@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e0710080600y55aeeeeei8dbd27d069c681e%40mail.gmail.com
In-Reply-To: <20071005204452.30902.60246.stgit@gandelf.nowhere.earth>

```
On 05/10/2007, Yann Dirson <ydirson@altern.org> wrote:
> --- a/stgit/git.py
> +++ b/stgit/git.py
> @@ -1003,11 +1003,14 @@ def fetch_head():
>          m = re.match('^([^\t]*)\t\t', line)
>          if m:
>              if fetch_head:
> -                raise GitException, "StGit does not support multiple FETCH_HEAD"
> +                raise GitException, 'StGit does not support multiple FETCH_HEAD'
>              else:
>                  fetch_head=m.group(1)
>      stream.close()
>
> +    if not fetch_head:
> +        raise GitException, 'No for-merge remote head found in FETCH_HEAD'

OK, I tried and it doesn't work with my StGIT over SVN configuration.

What I did is defining 'pull-policy' as 'fetch-rebase', 'fetchcmd' as
'git svn fetch' which doesn't create any FETCH_HEAD. The 'pullcmd' is
defined as 'git svn rebase' and it doesn't use any argument if
git.fetch_head() return None.

I also think it is better for the pull command to re-raise the
git.fetch_head exception as this one contains more detailed
information about the error (after the out.error call). It currently
shows that the remote head couldn't be found but there is the multiple
heads case raised by git.fetch_head.

-- 
Catalin

```
