git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: How to pre-empt git pull merge error?

From
PFPete Forman <petef4+usenet@gmail.com>
Date
Nov 28, 2013, 08:25 UTC
Message-ID
<864n6x2arg.fsf@gmail.com>
In-Reply-To
<878uw9hdf0.fsf@thomasrast.ch>
Thomas Rast <tr@thomasrast.ch> writes:
Show 36 quoted lines
> Antoine Pelisse <apelisse@gmail.com> writes:
>
>>>> On Wed, 27 Nov 2013 15:17:27 +0000
>>>> Pete Forman <petef4+usenet@gmail.com> wrote:
>>>>
>>>>> I am looking for a way of detecting up front whether a git pull or
>>>>> git merge would fail. The sort of script I want to perform is to
>>>>> update a server.
>>>>>
>>>>>     git fetch
>>>>>     git okay
>>>>>     stop server
>>>>>     backup data
>>>>>     git merge
>>>>>     start server
>>>>>
>>> I don't know a simple way to do the pre-merge check without actually
>>> doing the merge (other than patching git merge to add a --dry-run
>>> option)
>>
>> Wouldn't that be a nice use-case for git-recursive-merge --index-only
>> ($gmane/236753) ?
>
> Possibly, but most of the use-cases for merge --dry-run are better
> answered by the XY Problem question:
>
> Can you step back and explain what the *underlying* goal is?
>
> The above sounds a lot like a deployment script, and such scripts are
> almost always better served by using an actual deployment tool, or
> failing that, by using some form of checkout -f instead, to ensure
> that they get whatever they are supposed to deploy.
>
> (Using a merge to update is really terrible in the face of
> non-fast-forward updates, especially when caused by rewriting history
> to not include some commits.)

It is a deployment script and updates are fast-forward. There was a problem on a test server where a file had been hacked to investigate an issue. The next deploy failed with the merge error.

There are three approaches, which might all be done with git or an actual deployment tool.

1. test early, bail out if deploy would fail
2. set target to good state before applying the merge
2a. discard changes
2b. stash changes

I intend to use (1). First I will need to clean up the stray files or add more entries into .gitignore.

  test -z "$(git status --porcelain)"
-- 
Pete Forman
http://petef.22web.org/payg.html
Previous: Thomas RastNext: Junio C Hamano
Message 6 of 7 in “How to pre-empt git pull merge error?”
  1. Pete FormanNov 27, 2013
  2. Konstantin KhomoutovNov 27, 2013
  3. Matthieu MoyNov 27, 2013
  4. Antoine PelisseNov 27, 2013
  5. Thomas RastNov 27, 2013
  6. Pete FormanNov 28, 2013
  7. Junio C HamanoNov 27, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.