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

Re: [PATCH/RFC] git-remote-mediawiki: new tool to preview local changes without pushing

From
Jeff King <peff@peff.net>
Date
Jun 9, 2013, 18:32 UTC
Message-ID
<20130609183247.GF810@sigill.intra.peff.net>
In-Reply-To
<CAETqRCh9frekD8yiR0bE+WQ7b_et1th8p_LsqrL8NhPnC8yaow@mail.gmail.com>
On Sun, Jun 09, 2013 at 02:35:45PM +0200, Benoît Person wrote:
Show 10 quoted lines
> On 9 June 2013 08:08, Jeff King <peff@peff.net> wrote:
> > I also wonder if it would be useful to be able to specify not only files
> > in the filesystem, but also arbitrary blobs. So in 4b above, you could
> > "git mw preview origin:page.mw" to see the rendered version of what
> > upstream has done.
> 
> Hum, so `git mw preview origin:page.mw` would just do the get
> request to the remote mediawiki, save it locally and - maybe - load it
> in the browser ? Is it really better than just opening the browser and
> typing the right URL ?

Not really, but when you start doing "origin^:page.mw", it may make more of a difference.

Show 13 quoted lines
> > If you just care about the remote name and not the name of the local
> > branch, you can just ask for
> >
> >   my $curr_branch = `git symbolic-ref HEAD`;
> >   my $remote = `git config "branch.$curr_branch.remote"`;
> >   my $url = `git config "remote.$remote.url"`;
> >
> > Of course you would want some error checks and probably some chomp()s in
> > there, too.
> 
> The fact is, `git symbolic-ref HEAD` result would have to be parsed in order
> to extract the current branch name like I currently extract the remote name.
> So, is it really better than `git rev-parse --symbolic-full-name @{upstream}` ?

It is, because it is not strictly true that an upstream of "refs/remotes/foo/*" is for the remote "foo" (though in 99% of cases, it is). To find the upstream, git looks at branch.$curr_branch.remote, then calculates the upstream based on the fetch refspecs. Then you try to undo that by converting it back from the right-hand side of the fetch refspec into a remote name. It would be much easier to just look at the config. :)

And yes, you do need the short name of the branch from HEAD, not the full refname. You can use "git symbolic-ref --short" for that. You also should check that it returns something useful (i.e., that we are not on a detached HEAD).

Show 10 quoted lines
> > That is probably OK as long as there is only one such remote, and it
> > would help the case where you have branched off of a local branch (so
> > your upstream remote is ".").  If there are two mediawiki remotes,
> > though, it would make sense to simply fail, as you don't know which to
> > use. But I'd expect the common case by far to be that you simply have
> > one such remote.
> 
> Well, I thought that `git mw preview` could provide an interactive mode
> where, if the first search fails, it would find all the mediawiki remotes, and
> offers to the user a way to choose the remote ?

That's fine; just as long as we do not silently produce output from an unknown source when there is ambiguity.

You can do an interactive selection, or even just say something like:
  There are multiple mediawiki remotes, and I do not know which one you
  want to use for your preview. Which of:
    remote1
    remote2
  did you mean? Try using the "-r" option to specify the remote.

and then let the user repeat their command with the "-r" option using shell history. That saves you from having to write an interactive component, and teaches the user how to script it.

-Peff
Previous: Matthieu MoyNext: Benoît Person
Message 10 of 14 in “git-remote-mediawiki: new tool to preview local changes without pushing”
  1. git-remote-mediawiki: new tool to preview local changes without pushingbenoit.person@ensimag.fr, Jun 7, 2013
  2. Matthieu MoyJun 8, 2013
  3. Jeff KingJun 9, 2013
  4. Jeff KingJun 9, 2013
  5. Matthieu MoyJun 9, 2013
  6. Benoît PersonJun 9, 2013
  7. Jeff KingJun 9, 2013
  8. Benoît PersonJun 9, 2013
  9. Matthieu MoyJun 9, 2013
  10. Jeff KingJun 9, 2013
  11. Benoît PersonJun 11, 2013
  12. Jeff KingJun 11, 2013
  13. Matthieu MoyJun 12, 2013
  14. Jeff KingJun 12, 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.