Delete old magit
This commit is contained in:
parent
6ca9eb9da5
commit
338e9abf17
99 changed files with 0 additions and 43457 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,5 +5,4 @@ newsticker/
|
||||||
__evo/
|
__evo/
|
||||||
transient
|
transient
|
||||||
bookmarks
|
bookmarks
|
||||||
org-clock-*
|
|
||||||
/history
|
/history
|
||||||
|
|
|
@ -1,341 +0,0 @@
|
||||||
Authors
|
|
||||||
=======
|
|
||||||
|
|
||||||
The following people have contributed to Magit, including the
|
|
||||||
libraries `git-commit.el`, `magit-popup.el`, and `with-editor.el`
|
|
||||||
which are distributed as separate Elpa packages.
|
|
||||||
|
|
||||||
For statistics see https://magit.vc/stats/authors.html.
|
|
||||||
|
|
||||||
Names below are sorted alphabetically.
|
|
||||||
|
|
||||||
Author
|
|
||||||
------
|
|
||||||
|
|
||||||
- Marius Vollmer <marius.vollmer@gmail.com>
|
|
||||||
|
|
||||||
Maintainer
|
|
||||||
----------
|
|
||||||
|
|
||||||
- Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
Developers
|
|
||||||
----------
|
|
||||||
|
|
||||||
- Kyle Meyer <kyle@kyleam.com>
|
|
||||||
- Noam Postavsky <npostavs@users.sourceforge.net>
|
|
||||||
|
|
||||||
Retired Maintainers and Developers
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
- Nicolas Dudebout <nicolas.dudebout@gatech.edu>
|
|
||||||
- Peter J. Weisberg <pj@irregularexpressions.net>
|
|
||||||
- Pieter Praet <pieter@praet.org>
|
|
||||||
- Phil Jackson <phil@shellarchive.co.uk>
|
|
||||||
- Rémi Vanicat <vanicat@debian.org>
|
|
||||||
- Yann Hodique <yann.hodique@gmail.com>
|
|
||||||
|
|
||||||
Contributors
|
|
||||||
------------
|
|
||||||
|
|
||||||
- Aaron Culich <aculich@gmail.com>
|
|
||||||
- Aaron Madlon-Kay <aaron@madlon-kay.com>
|
|
||||||
- Abdo Roig-Maranges <abdo.roig@gmail.com>
|
|
||||||
- Adam Benanti <0entropy@protonmail.com>
|
|
||||||
- Adam Porter <adam@alphapapa.net>
|
|
||||||
- Adam Spiers <emacs@adamspiers.org>
|
|
||||||
- Adeodato Simó <dato@net.com.org.es>
|
|
||||||
- Ævar Arnfjörð Bjarmason <avarab@gmail.com>
|
|
||||||
- Alan Falloon <alan.falloon@gmail.com>
|
|
||||||
- Alban Gruin <alban@pa1ch.fr>
|
|
||||||
- Aleksey Uimanov <s9gf4ult@gmail.com>
|
|
||||||
- Alexander Gramiak <fice-t@protonmail.com>
|
|
||||||
- Alexander Miller <alexanderm@web.de>
|
|
||||||
- Alex Branham <alex.branham@gmail.com>
|
|
||||||
- Alex Dunn <adunn@ucsb.edu>
|
|
||||||
- Alexey Voinov <alexey.v.voinov@gmail.com>
|
|
||||||
- Alex Kost <alezost@gmail.com>
|
|
||||||
- Alex Ott <alexott@gmail.com>
|
|
||||||
- Allen <darkfeline@felesatra.moe>
|
|
||||||
- Allen Li <darkfeline@felesatra.moe>
|
|
||||||
- Andreas Fuchs <asf@boinkor.net>
|
|
||||||
- Andreas Liljeqvist <andreas.liljeqvist@robacks.se>
|
|
||||||
- Andreas Rottmann <a.rottmann@gmx.at>
|
|
||||||
- Andrei Chițu <andrei.chitu1@gmail.com>
|
|
||||||
- Andrew Eggenberger <andrew.eggenberger@gmail.com>
|
|
||||||
- Andrew Kirkpatrick <andrew.kirkpatrick@adelaide.edu.au>
|
|
||||||
- Andrew Schwartzmeyer <andrew@schwartzmeyer.com>
|
|
||||||
- Andrey Smirnov <andrew.smirnov@gmail.com>
|
|
||||||
- Andriy Kmit' <dev@madand.net>
|
|
||||||
- Andy Sawyer <git@pureabstract.org>
|
|
||||||
- Aria Edmonds <aria@ar1as.space>
|
|
||||||
- Arialdo Martini <arialdomartini@gmail.com>
|
|
||||||
- Barak A. Pearlmutter <barak+git@pearlmutter.net>
|
|
||||||
- Bar Magal <bmagamb@gmail.com>
|
|
||||||
- Bart Bakker <bart@thesoftwarecraft.com>
|
|
||||||
- Basil L. Contovounesios <contovob@tcd.ie>
|
|
||||||
- Bastian Beischer <beischer@physik.rwth-aachen.de>
|
|
||||||
- Benjamin Motz <benjamin.motz@mailbox.org>
|
|
||||||
- Ben North <ben@redfrontdoor.org>
|
|
||||||
- Ben Walton <bwalton@artsci.utoronto.ca>
|
|
||||||
- Bob Uhl <buhl@zvelo.com>
|
|
||||||
- Bradley Wright <brad@intranation.com>
|
|
||||||
- Brandon W Maister <quodlibetor@gmail.com>
|
|
||||||
- Brian Warner <warner@lothar.com>
|
|
||||||
- Bryan Shell <bryan.shell@orbitz.com>
|
|
||||||
- Buster Copley <buster@buster.me.uk>
|
|
||||||
- Carl Lieberman <liebermancarl@gmail.com>
|
|
||||||
- Chillar Anand <anand21nanda@gmail.com>
|
|
||||||
- Chris Bernard <cebernard@gmail.com>
|
|
||||||
- Chris Done <chrisdone@gmail.com>
|
|
||||||
- Chris LaRose <cjlarose@gmail.com>
|
|
||||||
- Chris Moore <dooglus@gmail.com>
|
|
||||||
- Chris Ring <chris@ringthis.com>
|
|
||||||
- Chris Shoemaker <chris@mojotech.com>
|
|
||||||
- Christian Dietrich <christian.dietrich@informatik.uni-erlangen.de>
|
|
||||||
- Christian Kluge <ckfrakturfreak@web.de>
|
|
||||||
- Christophe Junke <junke.christophe@gmail.com>
|
|
||||||
- Christopher Monsanto <chris@monsan.to>
|
|
||||||
- Cornelius Mika <cornelius.mika@gmail.com>
|
|
||||||
- Craig Andera <candera@wangdera.com>
|
|
||||||
- Dale Hagglund <dale.hagglund@gmail.com>
|
|
||||||
- Damien Cassou <damien@cassou.me>
|
|
||||||
- Dan Erikson <derikson3@gmail.com>
|
|
||||||
- Daniel Brockman <daniel@gointeractive.se>
|
|
||||||
- Daniel Farina <drfarina@acm.org>
|
|
||||||
- Daniel Gröber <daniel@dps.uibk.ac.at>
|
|
||||||
- Daniel Hackney <dan@haxney.org>
|
|
||||||
- Daniel Kraus <daniel@kraus.my>
|
|
||||||
- Daniel Mai <daniel@danielmai.net>
|
|
||||||
- Daniel Martín <mardani29@yahoo.es>
|
|
||||||
- Dan LaManna <dan.lamanna@gmail.com>
|
|
||||||
- Danny Zhu <dzhu@dzhu.us>
|
|
||||||
- Dato Simó <dato@net.com.org.es>
|
|
||||||
- David Abrahams <dave@boostpro.com>
|
|
||||||
- David Ellison <davidehellison@gmail.com>
|
|
||||||
- David Ellison <davide@voicebox.com>
|
|
||||||
- David Hull <david.hull@openx.com>
|
|
||||||
- David L. Rager <ragerdl@gmail.com>
|
|
||||||
- David Wallin <david.wallin@gmail.com>
|
|
||||||
- Dean Kariniemi <8913263+d3k4r@users.noreply.github.com>
|
|
||||||
- Dennis Paskorz <dennis@walltowall.com>
|
|
||||||
- Divye Kapoor <divye@google.com>
|
|
||||||
- Dominique Quatravaux <dominique.quatravaux@epfl.ch>
|
|
||||||
- Dominique Quatravaux <domq@google.com>
|
|
||||||
- Duianto Vebotci <vebotci@openmailbox.org>
|
|
||||||
- Eli Barzilay <eli@barzilay.org>
|
|
||||||
- Eric Davis <ed@npri.org>
|
|
||||||
- Eric Prud'hommeaux <eric@w3.org>
|
|
||||||
- Eric Schulte <schulte.eric@gmail.com>
|
|
||||||
- Erik Anderson <erikbpanderson@gmail.com>
|
|
||||||
- Evan Torrie <etorrie@gmail.com>
|
|
||||||
- Evgkeni Sampelnikof <esabof@gmail.com>
|
|
||||||
- Eyal Lotem <eyal.lotem@gmail.com>
|
|
||||||
- Fabian Wiget <fabacino@gmail.com>
|
|
||||||
- Felix Geller <fgeller@gmail.com>
|
|
||||||
- Felix Yan <felixonmars@archlinux.org>
|
|
||||||
- Feng Li <fengli@blackmagicdesign.com>
|
|
||||||
- Florian Ragwitz <rafl@debian.org>
|
|
||||||
- Fritz Grabo <fritz.grabo@gmail.com>
|
|
||||||
- Fritz Stelzer <brotzeitmacher@gmail.com>
|
|
||||||
- Geoff Shannon <geoffpshannon@gmail.com>
|
|
||||||
- George Kadianakis <desnacked@gmail.com>
|
|
||||||
- Graham Clark <grclark@gmail.com>
|
|
||||||
- Graham Dobbins <gdobbins@protonmail.com>
|
|
||||||
- Greg A. Woods <woods@planix.com>
|
|
||||||
- Greg Lucas <greg@glucas.net>
|
|
||||||
- Greg Sexton <gregsexton@gmail.com>
|
|
||||||
- Guillaume Martres <smarter@ubuntu.com>
|
|
||||||
- Hannu Koivisto <azure@iki.fi>
|
|
||||||
- Hans-Peter Deifel <hpdeifel@gmx.de>
|
|
||||||
- Hussein Ait-Lahcen <hussein.ait-lahcen@fretlink.com>
|
|
||||||
- Ian Eure <ian.eure@gmail.com>
|
|
||||||
- Ingo Lohmar <i.lohmar@gmail.com>
|
|
||||||
- Ioan-Adrian Ratiu <adi@adirat.com>
|
|
||||||
- Ivan Brennan <ivan.brennan@gmail.com>
|
|
||||||
- Jan Tatarik <jan.tatarik@xing.com>
|
|
||||||
- Jasper St. Pierre <jstpierre@mecheye.net>
|
|
||||||
- Jeff Bellegarde <jbellegarde@whitepages.com>
|
|
||||||
- Jeff Dairiki <dairiki@dairiki.org>
|
|
||||||
- Jeremy Meng <yumeng@microsoft.com>
|
|
||||||
- Jesse Alama <jesse.alama@gmail.com>
|
|
||||||
- Jim Blandy <jimb@red-bean.com>
|
|
||||||
- Joakim Jalap <JOJA@stoneridge.com>
|
|
||||||
- Johannes Altmanninger <aclopte@gmail.com>
|
|
||||||
- Johann Klähn <kljohann@gmail.com>
|
|
||||||
- John Mastro <john.b.mastro@gmail.com>
|
|
||||||
- John Morris <john@zultron.com>
|
|
||||||
- John Wiegley <johnw@newartisans.com>
|
|
||||||
- Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
- Jonathan Arnett <jonathan@scriptdrop.co>
|
|
||||||
- Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com>
|
|
||||||
- Jonathan Roes <jroes@jroes.net>
|
|
||||||
- Jon Vanderwijk <jonathn@github.com>
|
|
||||||
- Jordan Galby <gravemind2a@gmail.com>
|
|
||||||
- Jordan Greenberg <jordan@softwareslave.com>
|
|
||||||
- Josh Elsasser <jelsasser@appneta.com>
|
|
||||||
- Josiah Schwab <jschwab@gmail.com>
|
|
||||||
- Julien Danjou <julien@danjou.info>
|
|
||||||
- Justin Burkett <justin@burkett.cc>
|
|
||||||
- Justin Caratzas <justin.caratzas@gmail.com>
|
|
||||||
- Justin Guenther <jguenther@gmail.com>
|
|
||||||
- Justin Thomas <justin.thomas1@gmail.com>
|
|
||||||
- Kan-Ru Chen <kanru@kanru.info>
|
|
||||||
- Kenny Ballou <kballou@devnulllabs.io>
|
|
||||||
- Keshav Kini <keshav.kini@gmail.com>
|
|
||||||
- Kevin Brubeck Unhammer <unhammer@fsfe.org>
|
|
||||||
- Kevin J. Foley <kfoley15@gmail.com>
|
|
||||||
- Kévin Le Gouguec <kevin.legouguec@gmail.com>
|
|
||||||
- Kimberly Wolk <kimwolk@hotmail.com>
|
|
||||||
- Knut Olav Bøhmer <bohmer@gmail.com>
|
|
||||||
- Kyle Meyer <kyle@kyleam.com>
|
|
||||||
- Laurent Laffont <laurent.laffont@gmail.com>
|
|
||||||
- Laverne Schrock <laverne@schrock.email>
|
|
||||||
- Leandro Facchinetti <me@leafac.com>
|
|
||||||
- Lele Gaifax <lele@metapensiero.it>
|
|
||||||
- Leo Liu <sdl.web@gmail.com>
|
|
||||||
- Leonardo Etcheverry <leo@kalio.net>
|
|
||||||
- Lingchao Xin <douglarek@users.noreply.github.com>
|
|
||||||
- Li-Yun Chang <michael142536@gmail.com>
|
|
||||||
- Lluís Vilanova <vilanova@ac.upc.edu>
|
|
||||||
- Loic Dachary <loic@dachary.org>
|
|
||||||
- Louis Roché <louis@louisroche.net>
|
|
||||||
- Luís Oliveira <luismbo@gmail.com>
|
|
||||||
- Luke Amdor <luke.amdor@gmail.com>
|
|
||||||
- Mak Kolybabi <mak@kolybabi.com>
|
|
||||||
- Manuel Vázquez Acosta <mva.led@gmail.com>
|
|
||||||
- Marcel Wolf <mwolf@ml1.net>
|
|
||||||
- Marc Herbert <marc.herbert@gmail.com>
|
|
||||||
- Marcin Bachry <hegel666@gmail.com>
|
|
||||||
- Marco Craveiro <marco.craveiro@gmail.com>
|
|
||||||
- Marco Wahl <marcowahlsoft@gmail.com>
|
|
||||||
- Marc Sherry <msherry@gmail.com>
|
|
||||||
- Marian Schubert <marian.schubert@gmail.com>
|
|
||||||
- Mario Rodas <marsam@users.noreply.github.com>
|
|
||||||
- Marius Vollmer <marius.vollmer@gmail.com>
|
|
||||||
- Mark Hepburn <Mark.Hepburn@csiro.au>
|
|
||||||
- Mark Karpov <markkarpov@opmbx.org>
|
|
||||||
- Mark Oteiza <mvoteiza@udel.edu>
|
|
||||||
- Matthew Fluet <matthew.fluet@gmail.com>
|
|
||||||
- Matthieu Hauglustaine <matt.hauglustaine@gmail.com>
|
|
||||||
- Matus Goljer <dota.keys@gmail.com>
|
|
||||||
- Michael Fogleman <michaelwfogleman@gmail.com>
|
|
||||||
- Michael Griffiths <mikey@cich.li>
|
|
||||||
- Michael Heerdegen <michael_heerdegen@web.de>
|
|
||||||
- Michal Sojka <sojkam1@fel.cvut.cz>
|
|
||||||
- Miciah Masters <miciah.masters@gmail.com>
|
|
||||||
- Miles Bader <miles@gnu.org>
|
|
||||||
- Miloš Mošić <mosic.milos@gmail.com>
|
|
||||||
- Mitchel Humpherys <mitch.special@gmail.com>
|
|
||||||
- Moritz Bunkus <moritz@bunkus.org>
|
|
||||||
- Naoya Yamashita <conao3@gmail.com>
|
|
||||||
- Natalie Weizenbaum <nex342@gmail.com>
|
|
||||||
- Nguyễn Tuấn Anh <ubolonton@gmail.com>
|
|
||||||
- Nic Ferier <nic@ferrier.me.uk>
|
|
||||||
- Nick Alcock <nick.alcock@oracle.com>
|
|
||||||
- Nick Alexander <nalexander@mozilla.com>
|
|
||||||
- Nick Dimiduk <ndimiduk@gmail.com>
|
|
||||||
- Nicklas Lindgren <nili@gulmohar.se>
|
|
||||||
- Nicolas Dudebout <nicolas.dudebout@gatech.edu>
|
|
||||||
- Nicolas Petton <nicolas@petton.fr>
|
|
||||||
- Nicolas Richard <theonewiththeevillook@yahoo.fr>
|
|
||||||
- Nikolay Martynov <mar.kolya@gmail.com>
|
|
||||||
- Noam Postavsky <npostavs@users.sourceforge.net>
|
|
||||||
- N. Troy de Freitas <me@ntdef.com>
|
|
||||||
- Ole Arndt <oliver.arndt@cegedim.com>
|
|
||||||
- Oleh Krehel <ohwoeowho@gmail.com>
|
|
||||||
- Orivej Desh <orivej@gmx.fr>
|
|
||||||
- Óscar Fuentes <ofv@wanadoo.es>
|
|
||||||
- Paul Stadig <paul@stadig.name>
|
|
||||||
- Pavel Holejsovsky <pavel.holejsovsky@upek.com>
|
|
||||||
- Pekka Pessi <nospam@pessi.fi>
|
|
||||||
- Peter Eisentraut <peter@eisentraut.org>
|
|
||||||
- Peter Jaros <peter.a.jaros@gmail.com>
|
|
||||||
- Peter J. Weisberg <pj@irregularexpressions.net>
|
|
||||||
- Peter Vasil <mail@petervasil.net>
|
|
||||||
- Philippe Vaucher <philippe.vaucher@gmail.com>
|
|
||||||
- Philipp Haselwarter <philipp@haselwarter.org>
|
|
||||||
- Philipp Stephani <phst@google.com>
|
|
||||||
- Philip Weaver <philip.weaver@gmail.com>
|
|
||||||
- Phil Jackson <phil@shellarchive.co.uk>
|
|
||||||
- Phil Sainty <phil@catalyst.net.nz>
|
|
||||||
- Pierre Neidhardt <ambrevar@gmail.com>
|
|
||||||
- Pieter Praet <pieter@praet.org>
|
|
||||||
- Prathamesh Sonpatki <csonpatki@gmail.com>
|
|
||||||
- rabio <rabiodev@o2.pl>
|
|
||||||
- Radon Rosborough <radon.neon@gmail.com>
|
|
||||||
- Rafael Laboissiere <rafael@laboissiere.net>
|
|
||||||
- Raimon Grau <raimon@3scale.net>
|
|
||||||
- Ramkumar Ramachandra <artagnon@gmail.com>
|
|
||||||
- Remco van 't Veer <rwvtveer@xs4all.nl>
|
|
||||||
- Rémi Vanicat <vanicat@debian.org>
|
|
||||||
- René Stadler <mail@renestadler.de>
|
|
||||||
- Richard Kim <emacs18@gmail.com>
|
|
||||||
- Robert Boone <robo4288@gmail.com>
|
|
||||||
- Robin Green <greenrd@greenrd.org>
|
|
||||||
- Roger Crew <crew@cs.stanford.edu>
|
|
||||||
- Romain Francoise <romain@orebokech.com>
|
|
||||||
- Ron Parker <rparker@a123systems.com>
|
|
||||||
- Roy Crihfield <rscrihf@gmail.com>
|
|
||||||
- Rüdiger Sonderfeld <ruediger@c-plusplus.net>
|
|
||||||
- Russell Black <black.russell@gmail.com>
|
|
||||||
- Ryan C. Thompson <rct@thompsonclan.org>
|
|
||||||
- Samuel Bronson <naesten@gmail.com>
|
|
||||||
- Samuel W. Flint <swflint@flintfam.org>
|
|
||||||
- Sanjoy Das <sanjoy@playingwithpointers.com>
|
|
||||||
- Sean Allred <code@seanallred.com>
|
|
||||||
- Sean Bryant <sbryant@hackinggibsons.com>
|
|
||||||
- Sean Whitton <spwhitton@spwhitton.name>
|
|
||||||
- Sebastian Wiesner <lunaryorn@gmail.com>
|
|
||||||
- Sébastien Gross <seb@chezwam.org>
|
|
||||||
- Seong-Kook Shin <cinsky@gmail.com>
|
|
||||||
- Sergey Pashinin <sergey@pashinin.com>
|
|
||||||
- Sergey Vinokurov <serg.foo@gmail.com>
|
|
||||||
- Servilio Afre Puentes <afrepues@mcmaster.ca>
|
|
||||||
- Silent Sphere <silentsphere110@gmail.com>
|
|
||||||
- Štěpán Němec <stepnem@gmail.com>
|
|
||||||
- Steven Chow <steve@myfreestuffapp.com>
|
|
||||||
- Steven E. Harris <seh@panix.com>
|
|
||||||
- Steven Thomas <sthomas314@gmail.com>
|
|
||||||
- Steven Vancoillie <steven.vancoillie@runbox.com>
|
|
||||||
- Steve Purcell <steve@sanityinc.com>
|
|
||||||
- Suhail Shergill <suhailshergill@gmail.com>
|
|
||||||
- Sylvain Rousseau <thisirs@gmail.com>
|
|
||||||
- Syohei Yoshida <syohex@gmail.com>
|
|
||||||
- Takafumi Arakaki <aka.tkf@gmail.com>
|
|
||||||
- Tassilo Horn <tsdh@gnu.org>
|
|
||||||
- Teemu Likonen <tlikonen@iki.fi>
|
|
||||||
- Teruki Shigitani <teruki.shigitani@gmail.com>
|
|
||||||
- Thierry Volpiatto <thierry.volpiatto@gmail.com>
|
|
||||||
- Thomas A Caswell <tcaswell@gmail.com>
|
|
||||||
- Thomas Fini Hansen <xen@xen.dk>
|
|
||||||
- Thomas Frössman <thomasf@jossystem.se>
|
|
||||||
- Thomas Jost <thomas.jost@gmail.com>
|
|
||||||
- Thomas Riccardi <riccardi.thomas@gmail.com>
|
|
||||||
- Tibor Simko <tibor.simko@cern.ch>
|
|
||||||
- Timo Juhani Lindfors <timo.lindfors@iki.fi>
|
|
||||||
- Tim Perkins <tprk77@gmail.com>
|
|
||||||
- Tim Wraight <tim@wraight.net>
|
|
||||||
- Ting-Yu Lin <aethanyc@gmail.com>
|
|
||||||
- Tom Feist <shabble@metavore.org>
|
|
||||||
- Topi Miettinen <toiwoton@gmail.com>
|
|
||||||
- Troy Hinckley <t.macman@gmail.com>
|
|
||||||
- Tunc Uzlu <bb2020@users.noreply.github.com>
|
|
||||||
- Vineet Naik <vineet@helpshift.com>
|
|
||||||
- Vitaly Ostashov <hotosho@yandex-team.ru>
|
|
||||||
- Vladimir Panteleev <git@thecybershadow.net>
|
|
||||||
- Wei Huang <weih@opera.com>
|
|
||||||
- Wilfred Hughes <me@wilfred.me.uk>
|
|
||||||
- Win Treese <treese@acm.org>
|
|
||||||
- Wouter Bolsterlee <wouter@bolsterl.ee>
|
|
||||||
- Xavier Noria <fxn@hashref.com>
|
|
||||||
- Xu Chunyang <mail@xuchunyang.me>
|
|
||||||
- Yann Hodique <yann.hodique@gmail.com>
|
|
||||||
- Ynilu <ynilu.chang@gmail.com>
|
|
||||||
- York Zhao <gtdplatform@gmail.com>
|
|
||||||
- Yuichi Higashi <aaa707b@gmail.com>
|
|
||||||
- Yuri Khan <yurivkhan@gmail.com>
|
|
||||||
- Zach Latta <zach@zachlatta.com>
|
|
||||||
- zakora <zakora@users.noreply.github.com>
|
|
||||||
- Zhu Zihao <all_but_last@163.com>
|
|
||||||
- zilongshanren <guanghui8827@126.com>
|
|
|
@ -1,676 +0,0 @@
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type `show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
This is the file .../info/dir, which contains the
|
|
||||||
topmost node of the Info hierarchy, called (dir)Top.
|
|
||||||
The first time you invoke Info you start off looking at this node.
|
|
||||||
|
|
||||||
File: dir, Node: Top This is the top of the INFO tree
|
|
||||||
|
|
||||||
This (the Directory node) gives a menu of major topics.
|
|
||||||
Typing "q" exits, "H" lists all Info commands, "d" returns here,
|
|
||||||
"h" gives a primer for first-timers,
|
|
||||||
"mEmacs<Return>" visits the Emacs manual, etc.
|
|
||||||
|
|
||||||
In Emacs, you can click mouse button 2 on a menu item or cross reference
|
|
||||||
to select it.
|
|
||||||
|
|
||||||
* Menu:
|
|
||||||
|
|
||||||
Emacs
|
|
||||||
* Magit: (magit). Using Git from Emacs with Magit.
|
|
|
@ -1,818 +0,0 @@
|
||||||
;;; git-rebase.el --- Edit Git rebase files -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Phil Jackson <phil@shellarchive.co.uk>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; This file is not part of GNU Emacs.
|
|
||||||
|
|
||||||
;; This file is free software; you can redistribute it and/or modify
|
|
||||||
;; it under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
|
|
||||||
;; This file is distributed in the hope that it will be useful,
|
|
||||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
;; GNU General Public License for more details.
|
|
||||||
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with this file. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This package assists the user in editing the list of commits to be
|
|
||||||
;; rewritten during an interactive rebase.
|
|
||||||
|
|
||||||
;; When the user initiates an interactive rebase, e.g. using "r e" in
|
|
||||||
;; a Magit buffer or on the command line using "git rebase -i REV",
|
|
||||||
;; Git invokes the `$GIT_SEQUENCE_EDITOR' (or if that is undefined
|
|
||||||
;; `$GIT_EDITOR' or even `$EDITOR') letting the user rearrange, drop,
|
|
||||||
;; reword, edit, and squash commits.
|
|
||||||
|
|
||||||
;; This package provides the major-mode `git-rebase-mode' which makes
|
|
||||||
;; doing so much more fun, by making the buffer more colorful and
|
|
||||||
;; providing the following commands:
|
|
||||||
;;
|
|
||||||
;; C-c C-c Tell Git to make it happen.
|
|
||||||
;; C-c C-k Tell Git that you changed your mind, i.e. abort.
|
|
||||||
;;
|
|
||||||
;; p Move point to previous line.
|
|
||||||
;; n Move point to next line.
|
|
||||||
;;
|
|
||||||
;; M-p Move the commit at point up.
|
|
||||||
;; M-n Move the commit at point down.
|
|
||||||
;;
|
|
||||||
;; k Drop the commit at point.
|
|
||||||
;; c Don't drop the commit at point.
|
|
||||||
;; r Change the message of the commit at point.
|
|
||||||
;; e Edit the commit at point.
|
|
||||||
;; s Squash the commit at point, into the one above.
|
|
||||||
;; f Like "s" but don't also edit the commit message.
|
|
||||||
;; b Break for editing at this point in the sequence.
|
|
||||||
;; x Add a script to be run with the commit at point
|
|
||||||
;; being checked out.
|
|
||||||
;; z Add noop action at point.
|
|
||||||
;;
|
|
||||||
;; SPC Show the commit at point in another buffer.
|
|
||||||
;; RET Show the commit at point in another buffer and
|
|
||||||
;; select its window.
|
|
||||||
;; C-/ Undo last change.
|
|
||||||
;;
|
|
||||||
;; Commands for --rebase-merges:
|
|
||||||
;; l Associate label with current HEAD in sequence.
|
|
||||||
;; MM Merge specified revisions into HEAD.
|
|
||||||
;; Mt Toggle whether the merge will invoke an editor
|
|
||||||
;; before committing.
|
|
||||||
;; t Reset HEAD to the specified label.
|
|
||||||
|
|
||||||
;; You should probably also read the `git-rebase' manpage.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'dash)
|
|
||||||
(require 'easymenu)
|
|
||||||
(require 'server)
|
|
||||||
(require 'with-editor)
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
(and (require 'async-bytecomp nil t)
|
|
||||||
(let ((pkgs (bound-and-true-p async-bytecomp-allowed-packages)))
|
|
||||||
(if (consp pkgs)
|
|
||||||
(cl-intersection '(all magit) pkgs)
|
|
||||||
(memq pkgs '(all t))))
|
|
||||||
(fboundp 'async-bytecomp-package-mode)
|
|
||||||
(async-bytecomp-package-mode 1))
|
|
||||||
|
|
||||||
(eval-when-compile (require 'recentf))
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
;;;; Variables
|
|
||||||
|
|
||||||
(defgroup git-rebase nil
|
|
||||||
"Edit Git rebase sequences."
|
|
||||||
:link '(info-link "(magit)Editing Rebase Sequences")
|
|
||||||
:group 'tools)
|
|
||||||
|
|
||||||
(defcustom git-rebase-auto-advance t
|
|
||||||
"Whether to move to next line after changing a line."
|
|
||||||
:group 'git-rebase
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom git-rebase-show-instructions t
|
|
||||||
"Whether to show usage instructions inside the rebase buffer."
|
|
||||||
:group 'git-rebase
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom git-rebase-confirm-cancel t
|
|
||||||
"Whether confirmation is required to cancel."
|
|
||||||
:group 'git-rebase
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;;; Faces
|
|
||||||
|
|
||||||
(defgroup git-rebase-faces nil
|
|
||||||
"Faces used by Git-Rebase mode."
|
|
||||||
:group 'faces
|
|
||||||
:group 'git-rebase)
|
|
||||||
|
|
||||||
(defface git-rebase-hash '((t (:inherit magit-hash)))
|
|
||||||
"Face for commit hashes."
|
|
||||||
:group 'git-rebase-faces)
|
|
||||||
|
|
||||||
(defface git-rebase-label '((t (:inherit magit-refname)))
|
|
||||||
"Face for labels in label, merge, and reset lines."
|
|
||||||
:group 'git-rebase-faces)
|
|
||||||
|
|
||||||
(defface git-rebase-description nil
|
|
||||||
"Face for commit descriptions."
|
|
||||||
:group 'git-rebase-faces)
|
|
||||||
|
|
||||||
(defface git-rebase-killed-action
|
|
||||||
'((t (:inherit font-lock-comment-face :strike-through t)))
|
|
||||||
"Face for commented commit action lines."
|
|
||||||
:group 'git-rebase-faces)
|
|
||||||
|
|
||||||
(defface git-rebase-comment-hash
|
|
||||||
'((t (:inherit git-rebase-hash :weight bold)))
|
|
||||||
"Face for commit hashes in commit message comments."
|
|
||||||
:group 'git-rebase-faces)
|
|
||||||
|
|
||||||
(defface git-rebase-comment-heading
|
|
||||||
'((t :inherit font-lock-keyword-face))
|
|
||||||
"Face for headings in rebase message comments."
|
|
||||||
:group 'git-commit-faces)
|
|
||||||
|
|
||||||
;;; Keymaps
|
|
||||||
|
|
||||||
(defvar git-rebase-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map special-mode-map)
|
|
||||||
(cond ((featurep 'jkl)
|
|
||||||
(define-key map [return] 'git-rebase-show-commit)
|
|
||||||
(define-key map (kbd "i") 'git-rebase-backward-line)
|
|
||||||
(define-key map (kbd "k") 'forward-line)
|
|
||||||
(define-key map (kbd "M-i") 'git-rebase-move-line-up)
|
|
||||||
(define-key map (kbd "M-k") 'git-rebase-move-line-down)
|
|
||||||
(define-key map (kbd "p") 'git-rebase-pick)
|
|
||||||
(define-key map (kbd ",") 'git-rebase-kill-line))
|
|
||||||
(t
|
|
||||||
(define-key map (kbd "C-m") 'git-rebase-show-commit)
|
|
||||||
(define-key map (kbd "p") 'git-rebase-backward-line)
|
|
||||||
(define-key map (kbd "n") 'forward-line)
|
|
||||||
(define-key map (kbd "M-p") 'git-rebase-move-line-up)
|
|
||||||
(define-key map (kbd "M-n") 'git-rebase-move-line-down)
|
|
||||||
(define-key map (kbd "c") 'git-rebase-pick)
|
|
||||||
(define-key map (kbd "k") 'git-rebase-kill-line)
|
|
||||||
(define-key map (kbd "C-k") 'git-rebase-kill-line)))
|
|
||||||
(define-key map (kbd "b") 'git-rebase-break)
|
|
||||||
(define-key map (kbd "e") 'git-rebase-edit)
|
|
||||||
(define-key map (kbd "l") 'git-rebase-label)
|
|
||||||
(define-key map (kbd "MM") 'git-rebase-merge)
|
|
||||||
(define-key map (kbd "Mt") 'git-rebase-merge-toggle-editmsg)
|
|
||||||
(define-key map (kbd "m") 'git-rebase-edit)
|
|
||||||
(define-key map (kbd "f") 'git-rebase-fixup)
|
|
||||||
(define-key map (kbd "q") 'undefined)
|
|
||||||
(define-key map (kbd "r") 'git-rebase-reword)
|
|
||||||
(define-key map (kbd "w") 'git-rebase-reword)
|
|
||||||
(define-key map (kbd "s") 'git-rebase-squash)
|
|
||||||
(define-key map (kbd "t") 'git-rebase-reset)
|
|
||||||
(define-key map (kbd "x") 'git-rebase-exec)
|
|
||||||
(define-key map (kbd "y") 'git-rebase-insert)
|
|
||||||
(define-key map (kbd "z") 'git-rebase-noop)
|
|
||||||
(define-key map (kbd "SPC") 'git-rebase-show-or-scroll-up)
|
|
||||||
(define-key map (kbd "DEL") 'git-rebase-show-or-scroll-down)
|
|
||||||
(define-key map (kbd "C-x C-t") 'git-rebase-move-line-up)
|
|
||||||
(define-key map [M-up] 'git-rebase-move-line-up)
|
|
||||||
(define-key map [M-down] 'git-rebase-move-line-down)
|
|
||||||
(define-key map [remap undo] 'git-rebase-undo)
|
|
||||||
map)
|
|
||||||
"Keymap for Git-Rebase mode.")
|
|
||||||
|
|
||||||
(cond ((featurep 'jkl)
|
|
||||||
(put 'git-rebase-reword :advertised-binding "r")
|
|
||||||
(put 'git-rebase-move-line-up :advertised-binding (kbd "M-i"))
|
|
||||||
(put 'git-rebase-kill-line :advertised-binding ","))
|
|
||||||
(t
|
|
||||||
(put 'git-rebase-reword :advertised-binding "r")
|
|
||||||
(put 'git-rebase-move-line-up :advertised-binding (kbd "M-p"))
|
|
||||||
(put 'git-rebase-kill-line :advertised-binding "k")))
|
|
||||||
|
|
||||||
(easy-menu-define git-rebase-mode-menu git-rebase-mode-map
|
|
||||||
"Git-Rebase mode menu"
|
|
||||||
'("Rebase"
|
|
||||||
["Pick" git-rebase-pick t]
|
|
||||||
["Reword" git-rebase-reword t]
|
|
||||||
["Edit" git-rebase-edit t]
|
|
||||||
["Squash" git-rebase-squash t]
|
|
||||||
["Fixup" git-rebase-fixup t]
|
|
||||||
["Kill" git-rebase-kill-line t]
|
|
||||||
["Noop" git-rebase-noop t]
|
|
||||||
["Execute" git-rebase-exec t]
|
|
||||||
["Move Down" git-rebase-move-line-down t]
|
|
||||||
["Move Up" git-rebase-move-line-up t]
|
|
||||||
"---"
|
|
||||||
["Cancel" with-editor-cancel t]
|
|
||||||
["Finish" with-editor-finish t]))
|
|
||||||
|
|
||||||
(defvar git-rebase-command-descriptions
|
|
||||||
'((with-editor-finish . "tell Git to make it happen")
|
|
||||||
(with-editor-cancel . "tell Git that you changed your mind, i.e. abort")
|
|
||||||
(git-rebase-backward-line . "move point to previous line")
|
|
||||||
(forward-line . "move point to next line")
|
|
||||||
(git-rebase-move-line-up . "move the commit at point up")
|
|
||||||
(git-rebase-move-line-down . "move the commit at point down")
|
|
||||||
(git-rebase-show-or-scroll-up . "show the commit at point in another buffer")
|
|
||||||
(git-rebase-show-commit
|
|
||||||
. "show the commit at point in another buffer and select its window")
|
|
||||||
(undo . "undo last change")
|
|
||||||
(git-rebase-kill-line . "drop the commit at point")
|
|
||||||
(git-rebase-insert . "insert a line for an arbitrary commit")
|
|
||||||
(git-rebase-noop . "add noop action at point")))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
(defun git-rebase-pick ()
|
|
||||||
"Use commit on current line."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase-set-action "pick"))
|
|
||||||
|
|
||||||
(defun git-rebase-reword ()
|
|
||||||
"Edit message of commit on current line."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase-set-action "reword"))
|
|
||||||
|
|
||||||
(defun git-rebase-edit ()
|
|
||||||
"Stop at the commit on the current line."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase-set-action "edit"))
|
|
||||||
|
|
||||||
(defun git-rebase-squash ()
|
|
||||||
"Meld commit on current line into previous commit, edit message."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase-set-action "squash"))
|
|
||||||
|
|
||||||
(defun git-rebase-fixup ()
|
|
||||||
"Meld commit on current line into previous commit, discard its message."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase-set-action "fixup"))
|
|
||||||
|
|
||||||
(defvar-local git-rebase-comment-re nil)
|
|
||||||
|
|
||||||
(defvar git-rebase-short-options
|
|
||||||
'((?b . "break")
|
|
||||||
(?e . "edit")
|
|
||||||
(?f . "fixup")
|
|
||||||
(?l . "label")
|
|
||||||
(?m . "merge")
|
|
||||||
(?p . "pick")
|
|
||||||
(?r . "reword")
|
|
||||||
(?s . "squash")
|
|
||||||
(?t . "reset")
|
|
||||||
(?x . "exec"))
|
|
||||||
"Alist mapping single key of an action to the full name.")
|
|
||||||
|
|
||||||
(defclass git-rebase-action ()
|
|
||||||
(;; action-type: commit, exec, bare, label, merge
|
|
||||||
(action-type :initarg :action-type :initform nil)
|
|
||||||
;; Examples for each action type:
|
|
||||||
;; | action | action options | target | trailer |
|
|
||||||
;; |--------+----------------+---------+---------|
|
|
||||||
;; | pick | | hash | subject |
|
|
||||||
;; | exec | | command | |
|
|
||||||
;; | noop | | | |
|
|
||||||
;; | reset | | name | subject |
|
|
||||||
;; | merge | -C hash | name | subject |
|
|
||||||
(action :initarg :action :initform nil)
|
|
||||||
(action-options :initarg :action-options :initform nil)
|
|
||||||
(target :initarg :target :initform nil)
|
|
||||||
(trailer :initarg :trailer :initform nil)
|
|
||||||
(comment-p :initarg :comment-p :initform nil)))
|
|
||||||
|
|
||||||
(defvar git-rebase-line-regexps
|
|
||||||
`((commit . ,(concat
|
|
||||||
(regexp-opt '("e" "edit"
|
|
||||||
"f" "fixup"
|
|
||||||
"p" "pick"
|
|
||||||
"r" "reword"
|
|
||||||
"s" "squash")
|
|
||||||
"\\(?1:")
|
|
||||||
" \\(?3:[^ \n]+\\) \\(?4:.*\\)"))
|
|
||||||
(exec . "\\(?1:x\\|exec\\) \\(?3:.*\\)")
|
|
||||||
(bare . ,(concat (regexp-opt '("b" "break" "noop") "\\(?1:")
|
|
||||||
" *$"))
|
|
||||||
(label . ,(concat (regexp-opt '("l" "label"
|
|
||||||
"t" "reset")
|
|
||||||
"\\(?1:")
|
|
||||||
" \\(?3:[^ \n]+\\) ?\\(?4:.*\\)"))
|
|
||||||
(merge . ,(concat "\\(?1:m\\|merge\\) "
|
|
||||||
"\\(?:\\(?2:-[cC] [^ \n]+\\) \\)?"
|
|
||||||
"\\(?3:[^ \n]+\\)"
|
|
||||||
" ?\\(?4:.*\\)"))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun git-rebase-current-line ()
|
|
||||||
"Parse current line into a `git-rebase-action' instance.
|
|
||||||
If the current line isn't recognized as a rebase line, an
|
|
||||||
instance with all nil values is returned."
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(if-let ((re-start (concat "^\\(?5:" (regexp-quote comment-start)
|
|
||||||
"\\)? *"))
|
|
||||||
(type (-some (lambda (arg)
|
|
||||||
(let ((case-fold-search nil))
|
|
||||||
(and (looking-at (concat re-start (cdr arg)))
|
|
||||||
(car arg))))
|
|
||||||
git-rebase-line-regexps)))
|
|
||||||
(git-rebase-action
|
|
||||||
:action-type type
|
|
||||||
:action (when-let ((action (match-string-no-properties 1)))
|
|
||||||
(or (cdr (assoc action git-rebase-short-options))
|
|
||||||
action))
|
|
||||||
:action-options (match-string-no-properties 2)
|
|
||||||
:target (match-string-no-properties 3)
|
|
||||||
:trailer (match-string-no-properties 4)
|
|
||||||
:comment-p (and (match-string 5) t))
|
|
||||||
;; Use default empty class rather than nil to ease handling.
|
|
||||||
(git-rebase-action))))
|
|
||||||
|
|
||||||
(defun git-rebase-set-action (action)
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(with-slots (action-type target trailer)
|
|
||||||
(git-rebase-current-line)
|
|
||||||
(if (eq action-type 'commit)
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(magit-delete-line)
|
|
||||||
(insert (concat action " " target " " trailer "\n"))
|
|
||||||
(unless git-rebase-auto-advance
|
|
||||||
(forward-line -1)))
|
|
||||||
(ding))))
|
|
||||||
|
|
||||||
(defun git-rebase-line-p (&optional pos)
|
|
||||||
(save-excursion
|
|
||||||
(when pos (goto-char pos))
|
|
||||||
(and (oref (git-rebase-current-line) action-type)
|
|
||||||
t)))
|
|
||||||
|
|
||||||
(defun git-rebase-region-bounds ()
|
|
||||||
(when (use-region-p)
|
|
||||||
(let ((beg (save-excursion (goto-char (region-beginning))
|
|
||||||
(line-beginning-position)))
|
|
||||||
(end (save-excursion (goto-char (region-end))
|
|
||||||
(line-end-position))))
|
|
||||||
(when (and (git-rebase-line-p beg)
|
|
||||||
(git-rebase-line-p end))
|
|
||||||
(list beg (1+ end))))))
|
|
||||||
|
|
||||||
(defun git-rebase-move-line-down (n)
|
|
||||||
"Move the current commit (or command) N lines down.
|
|
||||||
If N is negative, move the commit up instead. With an active
|
|
||||||
region, move all the lines that the region touches, not just the
|
|
||||||
current line."
|
|
||||||
(interactive "p")
|
|
||||||
(pcase-let* ((`(,beg ,end)
|
|
||||||
(or (git-rebase-region-bounds)
|
|
||||||
(list (line-beginning-position)
|
|
||||||
(1+ (line-end-position)))))
|
|
||||||
(pt-offset (- (point) beg))
|
|
||||||
(mark-offset (and mark-active (- (mark) beg))))
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region
|
|
||||||
(point-min)
|
|
||||||
(1-
|
|
||||||
(if git-rebase-show-instructions
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (or (git-rebase-line-p)
|
|
||||||
;; The output for --rebase-merges has empty
|
|
||||||
;; lines and "Branch" comments interspersed.
|
|
||||||
(looking-at-p "^$")
|
|
||||||
(looking-at-p (concat git-rebase-comment-re
|
|
||||||
" Branch")))
|
|
||||||
(forward-line))
|
|
||||||
(line-beginning-position))
|
|
||||||
(point-max))))
|
|
||||||
(if (or (and (< n 0) (= beg (point-min)))
|
|
||||||
(and (> n 0) (= end (point-max)))
|
|
||||||
(> end (point-max)))
|
|
||||||
(ding)
|
|
||||||
(goto-char (if (< n 0) beg end))
|
|
||||||
(forward-line n)
|
|
||||||
(atomic-change-group
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(insert (delete-and-extract-region beg end)))
|
|
||||||
(let ((new-beg (- (point) (- end beg))))
|
|
||||||
(when (use-region-p)
|
|
||||||
(setq deactivate-mark nil)
|
|
||||||
(set-mark (+ new-beg mark-offset)))
|
|
||||||
(goto-char (+ new-beg pt-offset))))))))
|
|
||||||
|
|
||||||
(defun git-rebase-move-line-up (n)
|
|
||||||
"Move the current commit (or command) N lines up.
|
|
||||||
If N is negative, move the commit down instead. With an active
|
|
||||||
region, move all the lines that the region touches, not just the
|
|
||||||
current line."
|
|
||||||
(interactive "p")
|
|
||||||
(git-rebase-move-line-down (- n)))
|
|
||||||
|
|
||||||
(defun git-rebase-highlight-region (start end window rol)
|
|
||||||
(let ((inhibit-read-only t)
|
|
||||||
(deactivate-mark nil)
|
|
||||||
(bounds (git-rebase-region-bounds)))
|
|
||||||
(mapc #'delete-overlay magit-section-highlight-overlays)
|
|
||||||
(when bounds
|
|
||||||
(magit-section-make-overlay (car bounds) (cadr bounds)
|
|
||||||
'magit-section-heading-selection))
|
|
||||||
(if (and bounds (not magit-keep-region-overlay))
|
|
||||||
(funcall (default-value 'redisplay-unhighlight-region-function) rol)
|
|
||||||
(funcall (default-value 'redisplay-highlight-region-function)
|
|
||||||
start end window rol))))
|
|
||||||
|
|
||||||
(defun git-rebase-unhighlight-region (rol)
|
|
||||||
(mapc #'delete-overlay magit-section-highlight-overlays)
|
|
||||||
(funcall (default-value 'redisplay-unhighlight-region-function) rol))
|
|
||||||
|
|
||||||
(defun git-rebase-kill-line ()
|
|
||||||
"Kill the current action line."
|
|
||||||
(interactive)
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(unless (oref (git-rebase-current-line) comment-p)
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(insert comment-start)
|
|
||||||
(insert " "))
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(when git-rebase-auto-advance
|
|
||||||
(forward-line))))
|
|
||||||
|
|
||||||
(defun git-rebase-insert (rev)
|
|
||||||
"Read an arbitrary commit and insert it below current line."
|
|
||||||
(interactive (list (magit-read-branch-or-commit "Insert revision")))
|
|
||||||
(forward-line)
|
|
||||||
(--if-let (magit-rev-format "%h %s" rev)
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(insert "pick " it ?\n))
|
|
||||||
(user-error "Unknown revision")))
|
|
||||||
|
|
||||||
(defun git-rebase-set-noncommit-action (action value-fn arg)
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(pcase-let* ((inhibit-read-only t)
|
|
||||||
(`(,initial ,trailer ,comment-p)
|
|
||||||
(and (not arg)
|
|
||||||
(with-slots ((ln-action action)
|
|
||||||
target trailer comment-p)
|
|
||||||
(git-rebase-current-line)
|
|
||||||
(and (equal ln-action action)
|
|
||||||
(list target trailer comment-p)))))
|
|
||||||
(value (funcall value-fn initial)))
|
|
||||||
(pcase (list value initial comment-p)
|
|
||||||
(`("" nil ,_)
|
|
||||||
(ding))
|
|
||||||
(`("" ,_ ,_)
|
|
||||||
(magit-delete-line))
|
|
||||||
(_
|
|
||||||
(if initial
|
|
||||||
(magit-delete-line)
|
|
||||||
(forward-line))
|
|
||||||
(insert (concat action " " value
|
|
||||||
(and (equal value initial)
|
|
||||||
trailer
|
|
||||||
(concat " " trailer))
|
|
||||||
"\n"))
|
|
||||||
(unless git-rebase-auto-advance
|
|
||||||
(forward-line -1))))))
|
|
||||||
|
|
||||||
(defun git-rebase-exec (arg)
|
|
||||||
"Insert a shell command to be run after the current commit.
|
|
||||||
|
|
||||||
If there already is such a command on the current line, then edit
|
|
||||||
that instead. With a prefix argument insert a new command even
|
|
||||||
when there already is one on the current line. With empty input
|
|
||||||
remove the command on the current line, if any."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-noncommit-action
|
|
||||||
"exec"
|
|
||||||
(lambda (initial) (read-shell-command "Execute: " initial))
|
|
||||||
arg))
|
|
||||||
|
|
||||||
(defun git-rebase-label (arg)
|
|
||||||
"Add a label after the current commit.
|
|
||||||
If there already is a label on the current line, then edit that
|
|
||||||
instead. With a prefix argument, insert a new label even when
|
|
||||||
there is already a label on the current line. With empty input,
|
|
||||||
remove the label on the current line, if any."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-noncommit-action
|
|
||||||
"label"
|
|
||||||
(lambda (initial)
|
|
||||||
(read-from-minibuffer
|
|
||||||
"Label: " initial magit-minibuffer-local-ns-map))
|
|
||||||
arg))
|
|
||||||
|
|
||||||
(defun git-rebase-buffer-labels ()
|
|
||||||
(let (labels)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(while (re-search-forward "^\\(?:l\\|label\\) \\([^ \n]+\\)" nil t)
|
|
||||||
(push (match-string-no-properties 1) labels)))
|
|
||||||
(nreverse labels)))
|
|
||||||
|
|
||||||
(defun git-rebase-reset (arg)
|
|
||||||
"Reset the current HEAD to a label.
|
|
||||||
If there already is a reset command on the current line, then
|
|
||||||
edit that instead. With a prefix argument, insert a new reset
|
|
||||||
line even when point is already on a reset line. With empty
|
|
||||||
input, remove the reset command on the current line, if any."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-noncommit-action
|
|
||||||
"reset"
|
|
||||||
(lambda (initial)
|
|
||||||
(or (magit-completing-read "Label" (git-rebase-buffer-labels)
|
|
||||||
nil t initial)
|
|
||||||
""))
|
|
||||||
arg))
|
|
||||||
|
|
||||||
(defun git-rebase-merge (arg)
|
|
||||||
"Add a merge command after the current commit.
|
|
||||||
If there is already a merge command on the current line, then
|
|
||||||
replace that command instead. With a prefix argument, insert a
|
|
||||||
new merge command even when there is already one on the current
|
|
||||||
line. With empty input, remove the merge command on the current
|
|
||||||
line, if any."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-noncommit-action
|
|
||||||
"merge"
|
|
||||||
(lambda (_)
|
|
||||||
(or (magit-completing-read "Merge" (git-rebase-buffer-labels))
|
|
||||||
""))
|
|
||||||
arg))
|
|
||||||
|
|
||||||
(defun git-rebase-merge-toggle-editmsg ()
|
|
||||||
"Toggle whether an editor is invoked when performing the merge at point.
|
|
||||||
When a merge command uses a lower-case -c, the message for the
|
|
||||||
specified commit will be opened in an editor before creating the
|
|
||||||
commit. For an upper-case -C, the message will be used as is."
|
|
||||||
(interactive)
|
|
||||||
(with-slots (action-type target action-options trailer)
|
|
||||||
(git-rebase-current-line)
|
|
||||||
(if (eq action-type 'merge)
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(magit-delete-line)
|
|
||||||
(insert
|
|
||||||
(format "merge %s %s %s\n"
|
|
||||||
(replace-regexp-in-string
|
|
||||||
"-[cC]" (lambda (c)
|
|
||||||
(if (equal c "-c") "-C" "-c"))
|
|
||||||
action-options t t)
|
|
||||||
target
|
|
||||||
trailer)))
|
|
||||||
(ding))))
|
|
||||||
|
|
||||||
(defun git-rebase-set-bare-action (action arg)
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(with-slots ((ln-action action) comment-p)
|
|
||||||
(git-rebase-current-line)
|
|
||||||
(let ((same-action-p (equal action ln-action))
|
|
||||||
(inhibit-read-only t))
|
|
||||||
(when (or arg
|
|
||||||
(not ln-action)
|
|
||||||
(not same-action-p)
|
|
||||||
(and same-action-p comment-p))
|
|
||||||
(unless (or arg (not same-action-p))
|
|
||||||
(magit-delete-line))
|
|
||||||
(insert action ?\n)
|
|
||||||
(unless git-rebase-auto-advance
|
|
||||||
(forward-line -1))))))
|
|
||||||
|
|
||||||
(defun git-rebase-noop (&optional arg)
|
|
||||||
"Add noop action at point.
|
|
||||||
|
|
||||||
If the current line already contains a noop action, leave it
|
|
||||||
unchanged. If there is a commented noop action present, remove
|
|
||||||
the comment. Otherwise add a new noop action. With a prefix
|
|
||||||
argument insert a new noop action regardless of what is already
|
|
||||||
present on the current line.
|
|
||||||
|
|
||||||
A noop action can be used to make git perform a rebase even if
|
|
||||||
no commits are selected. Without the noop action present, git
|
|
||||||
would see an empty file and therefore do nothing."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-bare-action "noop" arg))
|
|
||||||
|
|
||||||
(defun git-rebase-break (&optional arg)
|
|
||||||
"Add break action at point.
|
|
||||||
|
|
||||||
If there is a commented break action present, remove the comment.
|
|
||||||
If the current line already contains a break action, add another
|
|
||||||
break action only if a prefix argument is given.
|
|
||||||
|
|
||||||
A break action can be used to interrupt the rebase at the
|
|
||||||
specified point. It is particularly useful for pausing before
|
|
||||||
the first commit in the sequence. For other cases, the
|
|
||||||
equivalent behavior can be achieved with `git-rebase-edit'."
|
|
||||||
(interactive "P")
|
|
||||||
(git-rebase-set-bare-action "break" arg))
|
|
||||||
|
|
||||||
(defun git-rebase-undo (&optional arg)
|
|
||||||
"Undo some previous changes.
|
|
||||||
Like `undo' but works in read-only buffers."
|
|
||||||
(interactive "P")
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(undo arg)))
|
|
||||||
|
|
||||||
(defun git-rebase--show-commit (&optional scroll)
|
|
||||||
(let ((disable-magit-save-buffers t))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(--if-let (with-slots (action-type target) (git-rebase-current-line)
|
|
||||||
(and (eq action-type 'commit)
|
|
||||||
target))
|
|
||||||
(pcase scroll
|
|
||||||
(`up (magit-diff-show-or-scroll-up))
|
|
||||||
(`down (magit-diff-show-or-scroll-down))
|
|
||||||
(_ (apply #'magit-show-commit it
|
|
||||||
(magit-diff-arguments 'magit-revision-mode))))
|
|
||||||
(ding)))))
|
|
||||||
|
|
||||||
(defun git-rebase-show-commit ()
|
|
||||||
"Show the commit on the current line if any."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase--show-commit))
|
|
||||||
|
|
||||||
(defun git-rebase-show-or-scroll-up ()
|
|
||||||
"Update the commit buffer for commit on current line.
|
|
||||||
|
|
||||||
Either show the commit at point in the appropriate buffer, or if
|
|
||||||
that buffer is already being displayed in the current frame and
|
|
||||||
contains information about that commit, then instead scroll the
|
|
||||||
buffer up."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase--show-commit 'up))
|
|
||||||
|
|
||||||
(defun git-rebase-show-or-scroll-down ()
|
|
||||||
"Update the commit buffer for commit on current line.
|
|
||||||
|
|
||||||
Either show the commit at point in the appropriate buffer, or if
|
|
||||||
that buffer is already being displayed in the current frame and
|
|
||||||
contains information about that commit, then instead scroll the
|
|
||||||
buffer down."
|
|
||||||
(interactive)
|
|
||||||
(git-rebase--show-commit 'down))
|
|
||||||
|
|
||||||
(defun git-rebase-backward-line (&optional n)
|
|
||||||
"Move N lines backward (forward if N is negative).
|
|
||||||
Like `forward-line' but go into the opposite direction."
|
|
||||||
(interactive "p")
|
|
||||||
(forward-line (- (or n 1))))
|
|
||||||
|
|
||||||
;;; Mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-derived-mode git-rebase-mode special-mode "Git Rebase"
|
|
||||||
"Major mode for editing of a Git rebase file.
|
|
||||||
|
|
||||||
Rebase files are generated when you run 'git rebase -i' or run
|
|
||||||
`magit-interactive-rebase'. They describe how Git should perform
|
|
||||||
the rebase. See the documentation for git-rebase (e.g., by
|
|
||||||
running 'man git-rebase' at the command line) for details."
|
|
||||||
:group 'git-rebase
|
|
||||||
(setq comment-start (or (magit-get "core.commentChar") "#"))
|
|
||||||
(setq git-rebase-comment-re (concat "^" (regexp-quote comment-start)))
|
|
||||||
(setq font-lock-defaults (list (git-rebase-mode-font-lock-keywords) t t))
|
|
||||||
(unless git-rebase-show-instructions
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(flush-lines git-rebase-comment-re)))
|
|
||||||
(unless with-editor-mode
|
|
||||||
;; Maybe already enabled when using `shell-command' or an Emacs shell.
|
|
||||||
(with-editor-mode 1))
|
|
||||||
(when git-rebase-confirm-cancel
|
|
||||||
(add-hook 'with-editor-cancel-query-functions
|
|
||||||
'git-rebase-cancel-confirm nil t))
|
|
||||||
(setq-local redisplay-highlight-region-function 'git-rebase-highlight-region)
|
|
||||||
(setq-local redisplay-unhighlight-region-function 'git-rebase-unhighlight-region)
|
|
||||||
(add-hook 'with-editor-pre-cancel-hook 'git-rebase-autostash-save nil t)
|
|
||||||
(add-hook 'with-editor-post-cancel-hook 'git-rebase-autostash-apply nil t)
|
|
||||||
(setq imenu-prev-index-position-function
|
|
||||||
#'magit-imenu--rebase-prev-index-position-function)
|
|
||||||
(setq imenu-extract-index-name-function
|
|
||||||
#'magit-imenu--rebase-extract-index-name-function)
|
|
||||||
(when (boundp 'save-place)
|
|
||||||
(setq save-place nil)))
|
|
||||||
|
|
||||||
(defun git-rebase-cancel-confirm (force)
|
|
||||||
(or (not (buffer-modified-p))
|
|
||||||
force
|
|
||||||
(magit-confirm 'abort-rebase "Abort this rebase" nil 'noabort)))
|
|
||||||
|
|
||||||
(defun git-rebase-autostash-save ()
|
|
||||||
(--when-let (magit-file-line (magit-git-dir "rebase-merge/autostash"))
|
|
||||||
(push (cons 'stash it) with-editor-cancel-alist)))
|
|
||||||
|
|
||||||
(defun git-rebase-autostash-apply ()
|
|
||||||
(--when-let (cdr (assq 'stash with-editor-cancel-alist))
|
|
||||||
(magit-stash-apply it)))
|
|
||||||
|
|
||||||
(defun git-rebase-match-comment-line (limit)
|
|
||||||
(re-search-forward (concat git-rebase-comment-re ".*") limit t))
|
|
||||||
|
|
||||||
(defun git-rebase-mode-font-lock-keywords ()
|
|
||||||
"Font lock keywords for Git-Rebase mode."
|
|
||||||
`((,(concat "^" (cdr (assq 'commit git-rebase-line-regexps)))
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(3 'git-rebase-hash)
|
|
||||||
(4 'git-rebase-description))
|
|
||||||
(,(concat "^" (cdr (assq 'exec git-rebase-line-regexps)))
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(3 'git-rebase-description))
|
|
||||||
(,(concat "^" (cdr (assq 'bare git-rebase-line-regexps)))
|
|
||||||
(1 'font-lock-keyword-face))
|
|
||||||
(,(concat "^" (cdr (assq 'label git-rebase-line-regexps)))
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(3 'git-rebase-label)
|
|
||||||
(4 'font-lock-comment-face))
|
|
||||||
("^\\(m\\(?:erge\\)?\\) -[Cc] \\([^ \n]+\\) \\([^ \n]+\\)\\( #.*\\)?"
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(2 'git-rebase-hash)
|
|
||||||
(3 'git-rebase-label)
|
|
||||||
(4 'font-lock-comment-face))
|
|
||||||
("^\\(m\\(?:erge\\)?\\) \\([^ \n]+\\)"
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(2 'git-rebase-label))
|
|
||||||
(,(concat git-rebase-comment-re " *"
|
|
||||||
(cdr (assq 'commit git-rebase-line-regexps)))
|
|
||||||
0 'git-rebase-killed-action t)
|
|
||||||
(git-rebase-match-comment-line 0 'font-lock-comment-face)
|
|
||||||
("\\[[^[]*\\]"
|
|
||||||
0 'magit-keyword t)
|
|
||||||
("\\(?:fixup!\\|squash!\\)"
|
|
||||||
0 'magit-keyword-squash t)
|
|
||||||
(,(format "^%s Rebase \\([^ ]*\\) onto \\([^ ]*\\)" comment-start)
|
|
||||||
(1 'git-rebase-comment-hash t)
|
|
||||||
(2 'git-rebase-comment-hash t))
|
|
||||||
(,(format "^%s \\(Commands:\\)" comment-start)
|
|
||||||
(1 'git-rebase-comment-heading t))
|
|
||||||
(,(format "^%s Branch \\(.*\\)" comment-start)
|
|
||||||
(1 'git-rebase-label t))))
|
|
||||||
|
|
||||||
(defun git-rebase-mode-show-keybindings ()
|
|
||||||
"Modify the \"Commands:\" section of the comment Git generates
|
|
||||||
at the bottom of the file so that in place of the one-letter
|
|
||||||
abbreviation for the command, it shows the command's keybinding.
|
|
||||||
By default, this is the same except for the \"pick\" command."
|
|
||||||
(let ((inhibit-read-only t))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-min))
|
|
||||||
(when (and git-rebase-show-instructions
|
|
||||||
(re-search-forward
|
|
||||||
(concat git-rebase-comment-re "\\s-+p, pick")
|
|
||||||
nil t))
|
|
||||||
(goto-char (line-beginning-position))
|
|
||||||
(pcase-dolist (`(,cmd . ,desc) git-rebase-command-descriptions)
|
|
||||||
(insert (format "%s %-8s %s\n"
|
|
||||||
comment-start
|
|
||||||
(substitute-command-keys (format "\\[%s]" cmd))
|
|
||||||
desc)))
|
|
||||||
(while (re-search-forward (concat git-rebase-comment-re
|
|
||||||
"\\( ?\\)\\([^\n,],\\) "
|
|
||||||
"\\([^\n ]+\\) ")
|
|
||||||
nil t)
|
|
||||||
(let ((cmd (intern (concat "git-rebase-" (match-string 3)))))
|
|
||||||
(if (not (fboundp cmd))
|
|
||||||
(delete-region (line-beginning-position) (1+ (line-end-position)))
|
|
||||||
(replace-match " " t t nil 1)
|
|
||||||
(replace-match
|
|
||||||
(format "%-8s"
|
|
||||||
(mapconcat #'key-description
|
|
||||||
(--remove (eq (elt it 0) 'menu-bar)
|
|
||||||
(reverse (where-is-internal
|
|
||||||
cmd git-rebase-mode-map)))
|
|
||||||
", "))
|
|
||||||
t t nil 2))))))))
|
|
||||||
|
|
||||||
(add-hook 'git-rebase-mode-hook 'git-rebase-mode-show-keybindings t)
|
|
||||||
|
|
||||||
(defun git-rebase-mode-disable-before-save-hook ()
|
|
||||||
(set (make-local-variable 'before-save-hook) nil))
|
|
||||||
|
|
||||||
(add-hook 'git-rebase-mode-hook 'git-rebase-mode-disable-before-save-hook)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defconst git-rebase-filename-regexp "/git-rebase-todo\\'")
|
|
||||||
;;;###autoload
|
|
||||||
(add-to-list 'auto-mode-alist
|
|
||||||
(cons git-rebase-filename-regexp 'git-rebase-mode))
|
|
||||||
|
|
||||||
(add-to-list 'with-editor-server-window-alist
|
|
||||||
(cons git-rebase-filename-regexp 'switch-to-buffer))
|
|
||||||
|
|
||||||
(eval-after-load 'recentf
|
|
||||||
'(add-to-list 'recentf-exclude git-rebase-filename-regexp))
|
|
||||||
|
|
||||||
(add-to-list 'with-editor-file-name-history-exclude git-rebase-filename-regexp)
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'git-rebase)
|
|
||||||
;;; git-rebase.el ends here
|
|
Binary file not shown.
|
@ -1,739 +0,0 @@
|
||||||
;;; magit-apply.el --- apply Git diffs -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements commands for applying Git diffs or parts
|
|
||||||
;; of such a diff. The supported "apply variants" are apply, stage,
|
|
||||||
;; unstage, discard, and reverse - more than Git itself knows about,
|
|
||||||
;; at least at the porcelain level.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit-core)
|
|
||||||
(require 'magit-diff)
|
|
||||||
(require 'magit-wip)
|
|
||||||
|
|
||||||
(require 'transient) ; See #3732.
|
|
||||||
|
|
||||||
;; For `magit-apply'
|
|
||||||
(declare-function magit-am "magit-sequence" ())
|
|
||||||
(declare-function magit-patch-apply "magit-files" ())
|
|
||||||
;; For `magit-discard-files'
|
|
||||||
(declare-function magit-checkout-stage "magit-merge" (file arg))
|
|
||||||
(declare-function magit-checkout-read-stage "magit-merge" (file))
|
|
||||||
(defvar auto-revert-verbose)
|
|
||||||
;; For `magit-stage-untracked'
|
|
||||||
(declare-function magit-submodule-add-1 "magit-submodule"
|
|
||||||
(url &optional path name args))
|
|
||||||
(declare-function magit-submodule-read-name-for-path "magit-submodule"
|
|
||||||
(path &optional prefer-short))
|
|
||||||
(declare-function borg--maybe-absorb-gitdir "borg" (pkg))
|
|
||||||
(declare-function borg--sort-submodule-sections "borg" (file))
|
|
||||||
(defvar borg-user-emacs-directory)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-delete-by-moving-to-trash t
|
|
||||||
"Whether Magit uses the system's trash can.
|
|
||||||
|
|
||||||
You should absolutely not disable this and also remove `discard'
|
|
||||||
from `magit-no-confirm'. You shouldn't do that even if you have
|
|
||||||
all of the Magit-Wip modes enabled, because those modes do not
|
|
||||||
track any files that are not tracked in the proper branch."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-essentials
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-unstage-committed t
|
|
||||||
"Whether unstaging a committed change reverts it instead.
|
|
||||||
|
|
||||||
A committed change cannot be unstaged, because staging and
|
|
||||||
unstaging are actions that are concerned with the differences
|
|
||||||
between the index and the working tree, not with committed
|
|
||||||
changes.
|
|
||||||
|
|
||||||
If this option is non-nil (the default), then typing \"u\"
|
|
||||||
\(`magit-unstage') on a committed change, causes it to be
|
|
||||||
reversed in the index but not the working tree. For more
|
|
||||||
information see command `magit-reverse-in-index'."
|
|
||||||
:package-version '(magit . "2.4.1")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-reverse-atomically nil
|
|
||||||
"Whether to reverse changes atomically.
|
|
||||||
|
|
||||||
If some changes can be reversed while others cannot, then nothing
|
|
||||||
is reversed if the value of this option is non-nil. But when it
|
|
||||||
is nil, then the changes that can be reversed are reversed and
|
|
||||||
for the other changes diff files are created that contain the
|
|
||||||
rejected reversals."
|
|
||||||
:package-version '(magit . "2.7.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-post-stage-hook nil
|
|
||||||
"Hook run after staging changes.
|
|
||||||
This hook is run by `magit-refresh' if `this-command'
|
|
||||||
is a member of `magit-post-stage-hook-commands'."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defvar magit-post-stage-hook-commands
|
|
||||||
'(magit-stage magit-stage-file magit-stage-modified))
|
|
||||||
|
|
||||||
(defcustom magit-post-unstage-hook nil
|
|
||||||
"Hook run after unstaging changes.
|
|
||||||
This hook is run by `magit-refresh' if `this-command'
|
|
||||||
is a member of `magit-post-unstage-hook-commands'."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defvar magit-post-unstage-hook-commands
|
|
||||||
'(magit-unstage magit-unstage-file magit-unstage-all))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
;;;; Apply
|
|
||||||
|
|
||||||
(defun magit-apply (&rest args)
|
|
||||||
"Apply the change at point to the working tree.
|
|
||||||
With a prefix argument fallback to a 3-way merge. Doing
|
|
||||||
so causes the change to be applied to the index as well."
|
|
||||||
(interactive (and current-prefix-arg (list "--3way")))
|
|
||||||
(--when-let (magit-apply--get-selection)
|
|
||||||
(pcase (list (magit-diff-type) (magit-diff-scope))
|
|
||||||
(`(,(or `unstaged `staged) ,_)
|
|
||||||
(user-error "Change is already in the working tree"))
|
|
||||||
(`(untracked ,(or `file `files))
|
|
||||||
(call-interactively 'magit-am))
|
|
||||||
(`(,_ region) (magit-apply-region it args))
|
|
||||||
(`(,_ hunk) (magit-apply-hunk it args))
|
|
||||||
(`(,_ hunks) (magit-apply-hunks it args))
|
|
||||||
(`(rebase-sequence file)
|
|
||||||
(call-interactively 'magit-patch-apply))
|
|
||||||
(`(,_ file) (magit-apply-diff it args))
|
|
||||||
(`(,_ files) (magit-apply-diffs it args)))))
|
|
||||||
|
|
||||||
(defun magit-apply--section-content (section)
|
|
||||||
(buffer-substring-no-properties (if (magit-hunk-section-p section)
|
|
||||||
(oref section start)
|
|
||||||
(oref section content))
|
|
||||||
(oref section end)))
|
|
||||||
|
|
||||||
(defun magit-apply-diffs (sections &rest args)
|
|
||||||
(setq sections (magit-apply--get-diffs sections))
|
|
||||||
(magit-apply-patch sections args
|
|
||||||
(mapconcat
|
|
||||||
(lambda (s)
|
|
||||||
(concat (magit-diff-file-header s)
|
|
||||||
(magit-apply--section-content s)))
|
|
||||||
sections "")))
|
|
||||||
|
|
||||||
(defun magit-apply-diff (section &rest args)
|
|
||||||
(setq section (car (magit-apply--get-diffs (list section))))
|
|
||||||
(magit-apply-patch section args
|
|
||||||
(concat (magit-diff-file-header section)
|
|
||||||
(magit-apply--section-content section))))
|
|
||||||
|
|
||||||
(defun magit-apply--adjust-hunk-new-starts (hunks)
|
|
||||||
"Adjust new line numbers in headers of HUNKS for partial application.
|
|
||||||
HUNKS should be a list of ordered, contiguous hunks to be applied
|
|
||||||
from a file. For example, if there is a sequence of hunks with
|
|
||||||
the headers
|
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@
|
|
||||||
@@ -10,6 +11,7 @@
|
|
||||||
@@ -18,6 +20,7 @@
|
|
||||||
|
|
||||||
and only the second and third are to be applied, they would be
|
|
||||||
adjusted as \"@@ -10,6 +10,7 @@\" and \"@@ -18,6 +19,7 @@\"."
|
|
||||||
(let* ((first-hunk (car hunks))
|
|
||||||
(offset (if (string-match diff-hunk-header-re-unified first-hunk)
|
|
||||||
(- (string-to-number (match-string 3 first-hunk))
|
|
||||||
(string-to-number (match-string 1 first-hunk)))
|
|
||||||
(error "Hunk does not have expected header"))))
|
|
||||||
(if (= offset 0)
|
|
||||||
hunks
|
|
||||||
(mapcar (lambda (hunk)
|
|
||||||
(if (string-match diff-hunk-header-re-unified hunk)
|
|
||||||
(replace-match (number-to-string
|
|
||||||
(- (string-to-number (match-string 3 hunk))
|
|
||||||
offset))
|
|
||||||
t t hunk 3)
|
|
||||||
(error "Hunk does not have expected header")))
|
|
||||||
hunks))))
|
|
||||||
|
|
||||||
(defun magit-apply--adjust-hunk-new-start (hunk)
|
|
||||||
(car (magit-apply--adjust-hunk-new-starts (list hunk))))
|
|
||||||
|
|
||||||
(defun magit-apply-hunks (sections &rest args)
|
|
||||||
(let ((section (oref (car sections) parent)))
|
|
||||||
(when (string-match "^diff --cc" (oref section value))
|
|
||||||
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
|
|
||||||
(magit-apply-patch
|
|
||||||
section args
|
|
||||||
(concat (oref section header)
|
|
||||||
(mapconcat #'identity
|
|
||||||
(magit-apply--adjust-hunk-new-starts
|
|
||||||
(mapcar #'magit-apply--section-content sections))
|
|
||||||
"")))))
|
|
||||||
|
|
||||||
(defun magit-apply-hunk (section &rest args)
|
|
||||||
(when (string-match "^diff --cc" (magit-section-parent-value section))
|
|
||||||
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
|
|
||||||
(magit-apply-patch (oref section parent) args
|
|
||||||
(concat (magit-diff-file-header section)
|
|
||||||
(magit-apply--adjust-hunk-new-start
|
|
||||||
(magit-apply--section-content section)))))
|
|
||||||
|
|
||||||
(defun magit-apply-region (section &rest args)
|
|
||||||
(when (string-match "^diff --cc" (magit-section-parent-value section))
|
|
||||||
(user-error "Cannot un-/stage resolution hunks. Stage the whole file"))
|
|
||||||
(magit-apply-patch (oref section parent) args
|
|
||||||
(concat (magit-diff-file-header section)
|
|
||||||
(magit-apply--adjust-hunk-new-start
|
|
||||||
(magit-diff-hunk-region-patch section args)))))
|
|
||||||
|
|
||||||
(defun magit-apply-patch (section:s args patch)
|
|
||||||
(let* ((files (if (atom section:s)
|
|
||||||
(list (oref section:s value))
|
|
||||||
(--map (oref it value) section:s)))
|
|
||||||
(command (symbol-name this-command))
|
|
||||||
(command (if (and command (string-match "^magit-\\([^-]+\\)" command))
|
|
||||||
(match-string 1 command)
|
|
||||||
"apply"))
|
|
||||||
(ignore-context (magit-diff-ignore-any-space-p)))
|
|
||||||
(unless (magit-diff-context-p)
|
|
||||||
(user-error "Not enough context to apply patch. Increase the context"))
|
|
||||||
(when (and magit-wip-before-change-mode (not inhibit-magit-refresh))
|
|
||||||
(magit-wip-commit-before-change files (concat " before " command)))
|
|
||||||
(with-temp-buffer
|
|
||||||
(insert patch)
|
|
||||||
(magit-run-git-with-input
|
|
||||||
"apply" args "-p0"
|
|
||||||
(and ignore-context "-C0")
|
|
||||||
"--ignore-space-change" "-"))
|
|
||||||
(unless inhibit-magit-refresh
|
|
||||||
(when magit-wip-after-apply-mode
|
|
||||||
(magit-wip-commit-after-apply files (concat " after " command)))
|
|
||||||
(magit-refresh))))
|
|
||||||
|
|
||||||
(defun magit-apply--get-selection ()
|
|
||||||
(or (magit-region-sections '(hunk file module) t)
|
|
||||||
(let ((section (magit-current-section)))
|
|
||||||
(pcase (oref section type)
|
|
||||||
((or `hunk `file `module) section)
|
|
||||||
((or `staged `unstaged `untracked
|
|
||||||
`stashed-index `stashed-worktree `stashed-untracked)
|
|
||||||
(oref section children))
|
|
||||||
(_ (user-error "Cannot apply this, it's not a change"))))))
|
|
||||||
|
|
||||||
(defun magit-apply--get-diffs (sections)
|
|
||||||
(magit-section-case
|
|
||||||
([file diffstat]
|
|
||||||
(--map (or (magit-get-section
|
|
||||||
(append `((file . ,(oref it value)))
|
|
||||||
(magit-section-ident magit-root-section)))
|
|
||||||
(error "Cannot get required diff headers"))
|
|
||||||
sections))
|
|
||||||
(t sections)))
|
|
||||||
|
|
||||||
(defun magit-apply--diff-ignores-whitespace-p ()
|
|
||||||
(and (cl-intersection magit-buffer-diff-args
|
|
||||||
'("--ignore-space-at-eol"
|
|
||||||
"--ignore-space-change"
|
|
||||||
"--ignore-all-space"
|
|
||||||
"--ignore-blank-lines")
|
|
||||||
:test #'equal)
|
|
||||||
t))
|
|
||||||
|
|
||||||
;;;; Stage
|
|
||||||
|
|
||||||
(defun magit-stage (&optional intent)
|
|
||||||
"Add the change at point to the staging area.
|
|
||||||
With a prefix argument, INTENT, and an untracked file (or files)
|
|
||||||
at point, stage the file but not its content."
|
|
||||||
(interactive "P")
|
|
||||||
(--if-let (and (derived-mode-p 'magit-mode) (magit-apply--get-selection))
|
|
||||||
(pcase (list (magit-diff-type)
|
|
||||||
(magit-diff-scope)
|
|
||||||
(magit-apply--diff-ignores-whitespace-p))
|
|
||||||
(`(untracked ,_ ,_) (magit-stage-untracked intent))
|
|
||||||
(`(unstaged region ,_) (magit-apply-region it "--cached"))
|
|
||||||
(`(unstaged hunk ,_) (magit-apply-hunk it "--cached"))
|
|
||||||
(`(unstaged hunks ,_) (magit-apply-hunks it "--cached"))
|
|
||||||
(`(unstaged file t) (magit-apply-diff it "--cached"))
|
|
||||||
(`(unstaged files t) (magit-apply-diffs it "--cached"))
|
|
||||||
(`(unstaged list t) (magit-apply-diffs it "--cached"))
|
|
||||||
(`(unstaged file nil) (magit-stage-1 "-u" (list (oref it value))))
|
|
||||||
(`(unstaged files nil) (magit-stage-1 "-u" (magit-region-values nil t)))
|
|
||||||
(`(unstaged list nil) (magit-stage-modified))
|
|
||||||
(`(staged ,_ ,_) (user-error "Already staged"))
|
|
||||||
(`(committed ,_ ,_) (user-error "Cannot stage committed changes"))
|
|
||||||
(`(undefined ,_ ,_) (user-error "Cannot stage this change")))
|
|
||||||
(call-interactively 'magit-stage-file)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stage-file (file)
|
|
||||||
"Stage all changes to FILE.
|
|
||||||
With a prefix argument or when there is no file at point ask for
|
|
||||||
the file to be staged. Otherwise stage the file at point without
|
|
||||||
requiring confirmation."
|
|
||||||
(interactive
|
|
||||||
(let* ((atpoint (magit-section-value-if 'file))
|
|
||||||
(current (magit-file-relative-name))
|
|
||||||
(choices (nconc (magit-unstaged-files)
|
|
||||||
(magit-untracked-files)))
|
|
||||||
(default (car (member (or atpoint current) choices))))
|
|
||||||
(list (if (or current-prefix-arg (not default))
|
|
||||||
(magit-completing-read "Stage file" choices
|
|
||||||
nil t nil nil default)
|
|
||||||
default))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-stage-1 nil (list file))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stage-modified (&optional all)
|
|
||||||
"Stage all changes to files modified in the worktree.
|
|
||||||
Stage all new content of tracked files and remove tracked files
|
|
||||||
that no longer exist in the working tree from the index also.
|
|
||||||
With a prefix argument also stage previously untracked (but not
|
|
||||||
ignored) files."
|
|
||||||
(interactive "P")
|
|
||||||
(when (magit-anything-staged-p)
|
|
||||||
(magit-confirm 'stage-all-changes))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-stage-1 (if all "--all" "-u") magit-buffer-diff-files)))
|
|
||||||
|
|
||||||
(defun magit-stage-1 (arg &optional files)
|
|
||||||
(magit-wip-commit-before-change files " before stage")
|
|
||||||
(magit-run-git "add" arg (if files (cons "--" files) "."))
|
|
||||||
(when magit-auto-revert-mode
|
|
||||||
(mapc #'magit-turn-on-auto-revert-mode-if-desired files))
|
|
||||||
(magit-wip-commit-after-apply files " after stage"))
|
|
||||||
|
|
||||||
(defun magit-stage-untracked (&optional intent)
|
|
||||||
(let* ((section (magit-current-section))
|
|
||||||
(files (pcase (magit-diff-scope)
|
|
||||||
(`file (list (oref section value)))
|
|
||||||
(`files (magit-region-values nil t))
|
|
||||||
(`list (magit-untracked-files))))
|
|
||||||
plain repos)
|
|
||||||
(dolist (file files)
|
|
||||||
(if (and (not (file-symlink-p file))
|
|
||||||
(magit-git-repo-p file t))
|
|
||||||
(push file repos)
|
|
||||||
(push file plain)))
|
|
||||||
(magit-wip-commit-before-change files " before stage")
|
|
||||||
(when plain
|
|
||||||
(magit-run-git "add" (and intent "--intent-to-add")
|
|
||||||
"--" plain)
|
|
||||||
(when magit-auto-revert-mode
|
|
||||||
(mapc #'magit-turn-on-auto-revert-mode-if-desired plain)))
|
|
||||||
(dolist (repo repos)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (oref (magit-get-section
|
|
||||||
`((file . ,repo) (untracked) (status)))
|
|
||||||
start))
|
|
||||||
(let* ((topdir (magit-toplevel))
|
|
||||||
(package
|
|
||||||
(and (equal (bound-and-true-p borg-user-emacs-directory)
|
|
||||||
topdir)
|
|
||||||
(file-name-nondirectory (directory-file-name repo)))))
|
|
||||||
(magit-submodule-add-1
|
|
||||||
(let ((default-directory
|
|
||||||
(file-name-as-directory (expand-file-name repo))))
|
|
||||||
(or (magit-get "remote" (magit-get-some-remote) "url")
|
|
||||||
(concat (file-name-as-directory ".") repo)))
|
|
||||||
repo
|
|
||||||
(magit-submodule-read-name-for-path repo package))
|
|
||||||
(when package
|
|
||||||
(borg--sort-submodule-sections
|
|
||||||
(expand-file-name ".gitmodules" topdir))
|
|
||||||
(let ((default-directory borg-user-emacs-directory))
|
|
||||||
(borg--maybe-absorb-gitdir package))
|
|
||||||
(when (and (y-or-n-p
|
|
||||||
(format "Also build and activate `%s' drone?" package))
|
|
||||||
(fboundp 'borg-build)
|
|
||||||
(fboundp 'borg-activate))
|
|
||||||
(borg-build package)
|
|
||||||
(borg-activate package))))))
|
|
||||||
(magit-wip-commit-after-apply files " after stage")))
|
|
||||||
|
|
||||||
;;;; Unstage
|
|
||||||
|
|
||||||
(defun magit-unstage ()
|
|
||||||
"Remove the change at point from the staging area."
|
|
||||||
(interactive)
|
|
||||||
(--when-let (magit-apply--get-selection)
|
|
||||||
(pcase (list (magit-diff-type)
|
|
||||||
(magit-diff-scope)
|
|
||||||
(magit-apply--diff-ignores-whitespace-p))
|
|
||||||
(`(untracked ,_ ,_) (user-error "Cannot unstage untracked changes"))
|
|
||||||
(`(unstaged file ,_) (magit-unstage-intent (list (oref it value))))
|
|
||||||
(`(unstaged files ,_) (magit-unstage-intent (magit-region-values nil t)))
|
|
||||||
(`(unstaged ,_ ,_) (user-error "Already unstaged"))
|
|
||||||
(`(staged region ,_) (magit-apply-region it "--reverse" "--cached"))
|
|
||||||
(`(staged hunk ,_) (magit-apply-hunk it "--reverse" "--cached"))
|
|
||||||
(`(staged hunks ,_) (magit-apply-hunks it "--reverse" "--cached"))
|
|
||||||
(`(staged file t) (magit-apply-diff it "--reverse" "--cached"))
|
|
||||||
(`(staged files t) (magit-apply-diffs it "--reverse" "--cached"))
|
|
||||||
(`(staged list t) (magit-apply-diffs it "--reverse" "--cached"))
|
|
||||||
(`(staged file nil) (magit-unstage-1 (list (oref it value))))
|
|
||||||
(`(staged files nil) (magit-unstage-1 (magit-region-values nil t)))
|
|
||||||
(`(staged list nil) (magit-unstage-all))
|
|
||||||
(`(committed ,_ ,_) (if magit-unstage-committed
|
|
||||||
(magit-reverse-in-index)
|
|
||||||
(user-error "Cannot unstage committed changes")))
|
|
||||||
(`(undefined ,_ ,_) (user-error "Cannot unstage this change")))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-unstage-file (file)
|
|
||||||
"Unstage all changes to FILE.
|
|
||||||
With a prefix argument or when there is no file at point ask for
|
|
||||||
the file to be unstaged. Otherwise unstage the file at point
|
|
||||||
without requiring confirmation."
|
|
||||||
(interactive
|
|
||||||
(let* ((atpoint (magit-section-value-if 'file))
|
|
||||||
(current (magit-file-relative-name))
|
|
||||||
(choices (magit-staged-files))
|
|
||||||
(default (car (member (or atpoint current) choices))))
|
|
||||||
(list (if (or current-prefix-arg (not default))
|
|
||||||
(magit-completing-read "Unstage file" choices
|
|
||||||
nil t nil nil default)
|
|
||||||
default))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-unstage-1 (list file))))
|
|
||||||
|
|
||||||
(defun magit-unstage-1 (files)
|
|
||||||
(magit-wip-commit-before-change files " before unstage")
|
|
||||||
(if (magit-no-commit-p)
|
|
||||||
(magit-run-git "rm" "--cached" "--" files)
|
|
||||||
(magit-run-git "reset" "HEAD" "--" files))
|
|
||||||
(magit-wip-commit-after-apply files " after unstage"))
|
|
||||||
|
|
||||||
(defun magit-unstage-intent (files)
|
|
||||||
(if-let ((staged (magit-staged-files))
|
|
||||||
(intent (--filter (member it staged) files)))
|
|
||||||
(magit-unstage-1 intent)
|
|
||||||
(user-error "Already unstaged")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-unstage-all ()
|
|
||||||
"Remove all changes from the staging area."
|
|
||||||
(interactive)
|
|
||||||
(when (or (magit-anything-unstaged-p)
|
|
||||||
(magit-untracked-files))
|
|
||||||
(magit-confirm 'unstage-all-changes))
|
|
||||||
(magit-wip-commit-before-change nil " before unstage")
|
|
||||||
(magit-run-git "reset" "HEAD" "--" magit-buffer-diff-files)
|
|
||||||
(magit-wip-commit-after-apply nil " after unstage"))
|
|
||||||
|
|
||||||
;;;; Discard
|
|
||||||
|
|
||||||
(defun magit-discard ()
|
|
||||||
"Remove the change at point."
|
|
||||||
(interactive)
|
|
||||||
(--when-let (magit-apply--get-selection)
|
|
||||||
(pcase (list (magit-diff-type) (magit-diff-scope))
|
|
||||||
(`(committed ,_) (user-error "Cannot discard committed changes"))
|
|
||||||
(`(undefined ,_) (user-error "Cannot discard this change"))
|
|
||||||
(`(,_ region) (magit-discard-region it))
|
|
||||||
(`(,_ hunk) (magit-discard-hunk it))
|
|
||||||
(`(,_ hunks) (magit-discard-hunks it))
|
|
||||||
(`(,_ file) (magit-discard-file it))
|
|
||||||
(`(,_ files) (magit-discard-files it))
|
|
||||||
(`(,_ list) (magit-discard-files it)))))
|
|
||||||
|
|
||||||
(defun magit-discard-region (section)
|
|
||||||
(magit-confirm 'discard "Discard region")
|
|
||||||
(magit-discard-apply section 'magit-apply-region))
|
|
||||||
|
|
||||||
(defun magit-discard-hunk (section)
|
|
||||||
(magit-confirm 'discard "Discard hunk")
|
|
||||||
(magit-discard-apply section 'magit-apply-hunk))
|
|
||||||
|
|
||||||
(defun magit-discard-apply (section apply)
|
|
||||||
(if (eq (magit-diff-type section) 'unstaged)
|
|
||||||
(funcall apply section "--reverse")
|
|
||||||
(if (magit-anything-unstaged-p
|
|
||||||
nil (if (magit-file-section-p section)
|
|
||||||
(oref section value)
|
|
||||||
(magit-section-parent-value section)))
|
|
||||||
(progn (let ((inhibit-magit-refresh t))
|
|
||||||
(funcall apply section "--reverse" "--cached")
|
|
||||||
(funcall apply section "--reverse" "--reject"))
|
|
||||||
(magit-refresh))
|
|
||||||
(funcall apply section "--reverse" "--index"))))
|
|
||||||
|
|
||||||
(defun magit-discard-hunks (sections)
|
|
||||||
(magit-confirm 'discard (format "Discard %s hunks from %s"
|
|
||||||
(length sections)
|
|
||||||
(magit-section-parent-value (car sections))))
|
|
||||||
(magit-discard-apply-n sections 'magit-apply-hunks))
|
|
||||||
|
|
||||||
(defun magit-discard-apply-n (sections apply)
|
|
||||||
(let ((section (car sections)))
|
|
||||||
(if (eq (magit-diff-type section) 'unstaged)
|
|
||||||
(funcall apply sections "--reverse")
|
|
||||||
(if (magit-anything-unstaged-p
|
|
||||||
nil (if (magit-file-section-p section)
|
|
||||||
(oref section value)
|
|
||||||
(magit-section-parent-value section)))
|
|
||||||
(progn (let ((inhibit-magit-refresh t))
|
|
||||||
(funcall apply sections "--reverse" "--cached")
|
|
||||||
(funcall apply sections "--reverse" "--reject"))
|
|
||||||
(magit-refresh))
|
|
||||||
(funcall apply sections "--reverse" "--index")))))
|
|
||||||
|
|
||||||
(defun magit-discard-file (section)
|
|
||||||
(magit-discard-files (list section)))
|
|
||||||
|
|
||||||
(defun magit-discard-files (sections)
|
|
||||||
(let ((auto-revert-verbose nil)
|
|
||||||
(type (magit-diff-type (car sections)))
|
|
||||||
(status (magit-file-status))
|
|
||||||
files delete resurrect rename discard discard-new resolve)
|
|
||||||
(dolist (section sections)
|
|
||||||
(let ((file (oref section value)))
|
|
||||||
(push file files)
|
|
||||||
(pcase (cons (pcase type
|
|
||||||
(`staged ?X)
|
|
||||||
(`unstaged ?Y)
|
|
||||||
(`untracked ?Z))
|
|
||||||
(cddr (assoc file status)))
|
|
||||||
(`(?Z) (dolist (f (magit-untracked-files nil file))
|
|
||||||
(push f delete)))
|
|
||||||
((or `(?Z ?? ??) `(?Z ?! ?!)) (push file delete))
|
|
||||||
((or `(?Z ?D ? ) `(,_ ?D ?D)) (push file delete))
|
|
||||||
((or `(,_ ?U ,_) `(,_ ,_ ?U)) (push file resolve))
|
|
||||||
(`(,_ ?A ?A) (push file resolve))
|
|
||||||
(`(?X ?M ,(or ? ?M ?D)) (push section discard))
|
|
||||||
(`(?Y ,_ ?M ) (push section discard))
|
|
||||||
(`(?X ?A ?M ) (push file discard-new))
|
|
||||||
(`(?X ?C ?M ) (push file discard-new))
|
|
||||||
(`(?X ?A ,(or ? ?D)) (push file delete))
|
|
||||||
(`(?X ?C ,(or ? ?D)) (push file delete))
|
|
||||||
(`(?X ?D ,(or ? ?M )) (push file resurrect))
|
|
||||||
(`(?Y ,_ ?D ) (push file resurrect))
|
|
||||||
(`(?X ?R ,(or ? ?M ?D)) (push file rename)))))
|
|
||||||
(unwind-protect
|
|
||||||
(let ((inhibit-magit-refresh t))
|
|
||||||
(magit-wip-commit-before-change files " before discard")
|
|
||||||
(when resolve
|
|
||||||
(magit-discard-files--resolve (nreverse resolve)))
|
|
||||||
(when resurrect
|
|
||||||
(magit-discard-files--resurrect (nreverse resurrect)))
|
|
||||||
(when delete
|
|
||||||
(magit-discard-files--delete (nreverse delete) status))
|
|
||||||
(when rename
|
|
||||||
(magit-discard-files--rename (nreverse rename) status))
|
|
||||||
(when (or discard discard-new)
|
|
||||||
(magit-discard-files--discard (nreverse discard)
|
|
||||||
(nreverse discard-new)))
|
|
||||||
(magit-wip-commit-after-apply files " after discard"))
|
|
||||||
(magit-refresh))))
|
|
||||||
|
|
||||||
(defun magit-discard-files--resolve (files)
|
|
||||||
(if-let ((arg (and (cdr files)
|
|
||||||
(magit-read-char-case
|
|
||||||
(format "For these %i files\n%s\ncheckout:\n"
|
|
||||||
(length files)
|
|
||||||
(mapconcat (lambda (file)
|
|
||||||
(concat " " file))
|
|
||||||
files "\n"))
|
|
||||||
t
|
|
||||||
(?o "[o]ur stage" "--ours")
|
|
||||||
(?t "[t]heir stage" "--theirs")
|
|
||||||
(?c "[c]onflict" "--merge")
|
|
||||||
(?i "decide [i]ndividually" nil)))))
|
|
||||||
(dolist (file files)
|
|
||||||
(magit-checkout-stage file arg))
|
|
||||||
(dolist (file files)
|
|
||||||
(magit-checkout-stage file (magit-checkout-read-stage file)))))
|
|
||||||
|
|
||||||
(defun magit-discard-files--resurrect (files)
|
|
||||||
(magit-confirm-files 'resurrect files)
|
|
||||||
(if (eq (magit-diff-type) 'staged)
|
|
||||||
(magit-call-git "reset" "--" files)
|
|
||||||
(magit-call-git "checkout" "--" files)))
|
|
||||||
|
|
||||||
(defun magit-discard-files--delete (files status)
|
|
||||||
(magit-confirm-files (if magit-delete-by-moving-to-trash 'trash 'delete)
|
|
||||||
files)
|
|
||||||
(let ((delete-by-moving-to-trash magit-delete-by-moving-to-trash))
|
|
||||||
(dolist (file files)
|
|
||||||
(when (string-match-p "\\`\\\\?~" file)
|
|
||||||
(error "Refusing to delete %S, too dangerous" file))
|
|
||||||
(pcase (nth 3 (assoc file status))
|
|
||||||
((guard (memq (magit-diff-type) '(unstaged untracked)))
|
|
||||||
(dired-delete-file file dired-recursive-deletes
|
|
||||||
magit-delete-by-moving-to-trash)
|
|
||||||
(dired-clean-up-after-deletion file))
|
|
||||||
(?\s (delete-file file t)
|
|
||||||
(magit-call-git "rm" "--cached" "--" file))
|
|
||||||
(?M (let ((temp (magit-git-string "checkout-index" "--temp" file)))
|
|
||||||
(string-match
|
|
||||||
(format "\\(.+?\\)\t%s" (regexp-quote file)) temp)
|
|
||||||
(rename-file (match-string 1 temp)
|
|
||||||
(setq temp (concat file ".~{index}~")))
|
|
||||||
(delete-file temp t))
|
|
||||||
(magit-call-git "rm" "--cached" "--force" "--" file))
|
|
||||||
(?D (magit-call-git "checkout" "--" file)
|
|
||||||
(delete-file file t)
|
|
||||||
(magit-call-git "rm" "--cached" "--force" "--" file))))))
|
|
||||||
|
|
||||||
(defun magit-discard-files--rename (files status)
|
|
||||||
(magit-confirm 'rename "Undo rename %s" "Undo %i renames" nil
|
|
||||||
(mapcar (lambda (file)
|
|
||||||
(setq file (assoc file status))
|
|
||||||
(format "%s -> %s" (cadr file) (car file)))
|
|
||||||
files))
|
|
||||||
(dolist (file files)
|
|
||||||
(let ((orig (cadr (assoc file status))))
|
|
||||||
(if (file-exists-p file)
|
|
||||||
(progn
|
|
||||||
(--when-let (file-name-directory orig)
|
|
||||||
(make-directory it t))
|
|
||||||
(magit-call-git "mv" file orig))
|
|
||||||
(magit-call-git "rm" "--cached" "--" file)
|
|
||||||
(magit-call-git "reset" "--" orig)))))
|
|
||||||
|
|
||||||
(defun magit-discard-files--discard (sections new-files)
|
|
||||||
(let ((files (--map (oref it value) sections)))
|
|
||||||
(magit-confirm-files 'discard (append files new-files)
|
|
||||||
(format "Discard %s changes in" (magit-diff-type)))
|
|
||||||
(if (eq (magit-diff-type (car sections)) 'unstaged)
|
|
||||||
(magit-call-git "checkout" "--" files)
|
|
||||||
(when new-files
|
|
||||||
(magit-call-git "add" "--" new-files)
|
|
||||||
(magit-call-git "reset" "--" new-files))
|
|
||||||
(let ((binaries (magit-binary-files "--cached")))
|
|
||||||
(when binaries
|
|
||||||
(setq sections
|
|
||||||
(--remove (member (oref it value) binaries)
|
|
||||||
sections)))
|
|
||||||
(cond ((= (length sections) 1)
|
|
||||||
(magit-discard-apply (car sections) 'magit-apply-diff))
|
|
||||||
(sections
|
|
||||||
(magit-discard-apply-n sections 'magit-apply-diffs)))
|
|
||||||
(when binaries
|
|
||||||
(let ((modified (magit-unstaged-files t)))
|
|
||||||
(setq binaries (--separate (member it modified) binaries)))
|
|
||||||
(when (cadr binaries)
|
|
||||||
(magit-call-git "reset" "--" (cadr binaries)))
|
|
||||||
(when (car binaries)
|
|
||||||
(user-error
|
|
||||||
(concat
|
|
||||||
"Cannot discard staged changes to binary files, "
|
|
||||||
"which also have unstaged changes. Unstage instead."))))))))
|
|
||||||
|
|
||||||
;;;; Reverse
|
|
||||||
|
|
||||||
(defun magit-reverse (&rest args)
|
|
||||||
"Reverse the change at point in the working tree.
|
|
||||||
With a prefix argument fallback to a 3-way merge. Doing
|
|
||||||
so causes the change to be applied to the index as well."
|
|
||||||
(interactive (and current-prefix-arg (list "--3way")))
|
|
||||||
(--when-let (magit-apply--get-selection)
|
|
||||||
(pcase (list (magit-diff-type) (magit-diff-scope))
|
|
||||||
(`(untracked ,_) (user-error "Cannot reverse untracked changes"))
|
|
||||||
(`(unstaged ,_) (user-error "Cannot reverse unstaged changes"))
|
|
||||||
(`(,_ region) (magit-reverse-region it args))
|
|
||||||
(`(,_ hunk) (magit-reverse-hunk it args))
|
|
||||||
(`(,_ hunks) (magit-reverse-hunks it args))
|
|
||||||
(`(,_ file) (magit-reverse-file it args))
|
|
||||||
(`(,_ files) (magit-reverse-files it args))
|
|
||||||
(`(,_ list) (magit-reverse-files it args)))))
|
|
||||||
|
|
||||||
(defun magit-reverse-region (section args)
|
|
||||||
(magit-confirm 'reverse "Reverse region")
|
|
||||||
(magit-reverse-apply section 'magit-apply-region args))
|
|
||||||
|
|
||||||
(defun magit-reverse-hunk (section args)
|
|
||||||
(magit-confirm 'reverse "Reverse hunk")
|
|
||||||
(magit-reverse-apply section 'magit-apply-hunk args))
|
|
||||||
|
|
||||||
(defun magit-reverse-hunks (sections args)
|
|
||||||
(magit-confirm 'reverse
|
|
||||||
(format "Reverse %s hunks from %s"
|
|
||||||
(length sections)
|
|
||||||
(magit-section-parent-value (car sections))))
|
|
||||||
(magit-reverse-apply sections 'magit-apply-hunks args))
|
|
||||||
|
|
||||||
(defun magit-reverse-file (section args)
|
|
||||||
(magit-reverse-files (list section) args))
|
|
||||||
|
|
||||||
(defun magit-reverse-files (sections args)
|
|
||||||
(pcase-let ((`(,binaries ,sections)
|
|
||||||
(let ((bs (magit-binary-files
|
|
||||||
(cond ((derived-mode-p 'magit-revision-mode)
|
|
||||||
magit-buffer-range)
|
|
||||||
((derived-mode-p 'magit-diff-mode)
|
|
||||||
magit-buffer-range)
|
|
||||||
(t
|
|
||||||
"--cached")))))
|
|
||||||
(--separate (member (oref it value) bs)
|
|
||||||
sections))))
|
|
||||||
(magit-confirm-files 'reverse (--map (oref it value) sections))
|
|
||||||
(cond ((= (length sections) 1)
|
|
||||||
(magit-reverse-apply (car sections) 'magit-apply-diff args))
|
|
||||||
(sections
|
|
||||||
(magit-reverse-apply sections 'magit-apply-diffs args)))
|
|
||||||
(when binaries
|
|
||||||
(user-error "Cannot reverse binary files"))))
|
|
||||||
|
|
||||||
(defun magit-reverse-apply (section:s apply args)
|
|
||||||
(funcall apply section:s "--reverse" args
|
|
||||||
(and (not magit-reverse-atomically)
|
|
||||||
(not (member "--3way" args))
|
|
||||||
"--reject")))
|
|
||||||
|
|
||||||
(defun magit-reverse-in-index (&rest args)
|
|
||||||
"Reverse the change at point in the index but not the working tree.
|
|
||||||
|
|
||||||
Use this command to extract a change from `HEAD', while leaving
|
|
||||||
it in the working tree, so that it can later be committed using
|
|
||||||
a separate commit. A typical workflow would be:
|
|
||||||
|
|
||||||
0. Optionally make sure that there are no uncommitted changes.
|
|
||||||
1. Visit the `HEAD' commit and navigate to the change that should
|
|
||||||
not have been included in that commit.
|
|
||||||
2. Type \"u\" (`magit-unstage') to reverse it in the index.
|
|
||||||
This assumes that `magit-unstage-committed-changes' is non-nil.
|
|
||||||
3. Type \"c e\" to extend `HEAD' with the staged changes,
|
|
||||||
including those that were already staged before.
|
|
||||||
4. Optionally stage the remaining changes using \"s\" or \"S\"
|
|
||||||
and then type \"c c\" to create a new commit."
|
|
||||||
(interactive)
|
|
||||||
(magit-reverse (cons "--cached" args)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-apply)
|
|
||||||
;;; magit-apply.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
|
@ -1,258 +0,0 @@
|
||||||
;;; magit-autorevert.el --- revert buffers when files in repository change -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'cl-lib)
|
|
||||||
(require 'dash)
|
|
||||||
|
|
||||||
(require 'magit-git)
|
|
||||||
|
|
||||||
(require 'autorevert)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-auto-revert nil
|
|
||||||
"Revert buffers when files in repository change."
|
|
||||||
:link '(custom-group-link auto-revert)
|
|
||||||
:link '(info-link "(magit)Automatic Reverting of File-Visiting Buffers")
|
|
||||||
:group 'auto-revert
|
|
||||||
:group 'magit-essentials
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
(defcustom auto-revert-buffer-list-filter nil
|
|
||||||
"Filter that determines which buffers `auto-revert-buffers' reverts.
|
|
||||||
|
|
||||||
This option is provided by Magit, which also advises
|
|
||||||
`auto-revert-buffers' to respect it. Magit users who do not turn
|
|
||||||
on the local mode `auto-revert-mode' themselves, are best served
|
|
||||||
by setting the value to `magit-auto-revert-repository-buffer-p'.
|
|
||||||
|
|
||||||
However the default is nil, so as not to disturb users who do use
|
|
||||||
the local mode directly. If you experience delays when running
|
|
||||||
Magit commands, then you should consider using one of the
|
|
||||||
predicates provided by Magit - especially if you also use Tramp.
|
|
||||||
|
|
||||||
Users who do turn on `auto-revert-mode' in buffers in which Magit
|
|
||||||
doesn't do that for them, should likely not use any filter.
|
|
||||||
Users who turn on `global-auto-revert-mode', do not have to worry
|
|
||||||
about this option, because it is disregarded if the global mode
|
|
||||||
is enabled."
|
|
||||||
:package-version '(magit . "2.4.2")
|
|
||||||
:group 'auto-revert
|
|
||||||
:group 'magit-auto-revert
|
|
||||||
:group 'magit-related
|
|
||||||
:type '(radio (const :tag "No filter" nil)
|
|
||||||
(function-item magit-auto-revert-buffer-p)
|
|
||||||
(function-item magit-auto-revert-repository-buffer-p)
|
|
||||||
function))
|
|
||||||
|
|
||||||
(defcustom magit-auto-revert-tracked-only t
|
|
||||||
"Whether `magit-auto-revert-mode' only reverts tracked files."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-auto-revert
|
|
||||||
:type 'boolean
|
|
||||||
:set (lambda (var val)
|
|
||||||
(set var val)
|
|
||||||
(when (and (bound-and-true-p magit-auto-revert-mode)
|
|
||||||
(featurep 'magit-autorevert))
|
|
||||||
(magit-auto-revert-mode -1)
|
|
||||||
(magit-auto-revert-mode))))
|
|
||||||
|
|
||||||
(defcustom magit-auto-revert-immediately t
|
|
||||||
"Whether Magit reverts buffers immediately.
|
|
||||||
|
|
||||||
If this is non-nil and either `global-auto-revert-mode' or
|
|
||||||
`magit-auto-revert-mode' is enabled, then Magit immediately
|
|
||||||
reverts buffers by explicitly calling `auto-revert-buffers'
|
|
||||||
after running Git for side-effects.
|
|
||||||
|
|
||||||
If `auto-revert-use-notify' is non-nil (and file notifications
|
|
||||||
are actually supported), then `magit-auto-revert-immediately'
|
|
||||||
does not have to be non-nil, because the reverts happen
|
|
||||||
immediately anyway.
|
|
||||||
|
|
||||||
If `magit-auto-revert-immediately' and `auto-revert-use-notify'
|
|
||||||
are both nil, then reverts happen after `auto-revert-interval'
|
|
||||||
seconds of user inactivity. That is not desirable."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-auto-revert
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;; Mode
|
|
||||||
|
|
||||||
(defun magit-turn-on-auto-revert-mode-if-desired (&optional file)
|
|
||||||
(if file
|
|
||||||
(--when-let (find-buffer-visiting file)
|
|
||||||
(with-current-buffer it
|
|
||||||
(magit-turn-on-auto-revert-mode-if-desired)))
|
|
||||||
(when (and buffer-file-name
|
|
||||||
(file-readable-p buffer-file-name)
|
|
||||||
(magit-toplevel)
|
|
||||||
(or (not magit-auto-revert-tracked-only)
|
|
||||||
(magit-file-tracked-p buffer-file-name))
|
|
||||||
(not auto-revert-mode) ; see #3014
|
|
||||||
(not global-auto-revert-mode)) ; see #3460
|
|
||||||
(auto-revert-mode 1))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-globalized-minor-mode magit-auto-revert-mode auto-revert-mode
|
|
||||||
magit-turn-on-auto-revert-mode-if-desired
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:link '(info-link "(magit)Automatic Reverting of File-Visiting Buffers")
|
|
||||||
:group 'magit-auto-revert
|
|
||||||
:group 'magit-essentials
|
|
||||||
;; - When `global-auto-revert-mode' is enabled, then this mode is
|
|
||||||
;; redundant.
|
|
||||||
;; - In all other cases enable the mode because if buffers are not
|
|
||||||
;; automatically reverted that would make many very common tasks
|
|
||||||
;; much more cumbersome.
|
|
||||||
:init-value (not (or global-auto-revert-mode
|
|
||||||
noninteractive)))
|
|
||||||
;; - Unfortunately `:init-value t' only sets the value of the mode
|
|
||||||
;; variable but does not cause the mode function to be called.
|
|
||||||
;; - I don't think it works like this on purpose, but since one usually
|
|
||||||
;; should not enable global modes by default, it is understandable.
|
|
||||||
;; - If the user has set the variable `magit-auto-revert-mode' to nil
|
|
||||||
;; after loading magit (instead of doing so before loading magit or
|
|
||||||
;; by using the function), then we should still respect that setting.
|
|
||||||
;; - If the user sets one of these variables after loading magit and
|
|
||||||
;; after `after-init-hook' has run, then that won't have an effect
|
|
||||||
;; and there is nothing we can do about it.
|
|
||||||
(defun magit-auto-revert-mode--init-kludge ()
|
|
||||||
"This is an internal kludge to be used on `after-init-hook'.
|
|
||||||
Do not use this function elsewhere, and don't remove it from
|
|
||||||
the `after-init-hook'. For more information see the comments
|
|
||||||
and code surrounding the definition of this function."
|
|
||||||
(if magit-auto-revert-mode
|
|
||||||
(let ((start (current-time)))
|
|
||||||
(magit-message "Turning on magit-auto-revert-mode...")
|
|
||||||
(magit-auto-revert-mode 1)
|
|
||||||
(magit-message
|
|
||||||
"Turning on magit-auto-revert-mode...done%s"
|
|
||||||
(let ((elapsed (float-time (time-subtract nil start))))
|
|
||||||
(if (> elapsed 0.2)
|
|
||||||
(format " (%.3fs, %s buffers checked)" elapsed
|
|
||||||
(length (buffer-list)))
|
|
||||||
""))))
|
|
||||||
(magit-auto-revert-mode -1)))
|
|
||||||
(if after-init-time
|
|
||||||
;; Since `after-init-hook' has already been
|
|
||||||
;; run, turn the mode on or off right now.
|
|
||||||
(magit-auto-revert-mode--init-kludge)
|
|
||||||
;; By the time the init file has been fully loaded the
|
|
||||||
;; values of the relevant variables might have changed.
|
|
||||||
(add-hook 'after-init-hook #'magit-auto-revert-mode--init-kludge t))
|
|
||||||
|
|
||||||
(put 'magit-auto-revert-mode 'function-documentation
|
|
||||||
"Toggle Magit Auto Revert mode.
|
|
||||||
If called interactively, enable Magit Auto Revert mode if ARG is
|
|
||||||
positive, and disable it if ARG is zero or negative. If called
|
|
||||||
from Lisp, also enable the mode if ARG is omitted or nil, and
|
|
||||||
toggle it if ARG is `toggle'; disable the mode otherwise.
|
|
||||||
|
|
||||||
Magit Auto Revert mode is a global minor mode that reverts
|
|
||||||
buffers associated with a file that is located inside a Git
|
|
||||||
repository when the file changes on disk. Use `auto-revert-mode'
|
|
||||||
to revert a particular buffer. Or use `global-auto-revert-mode'
|
|
||||||
to revert all file-visiting buffers, not just those that visit
|
|
||||||
a file located inside a Git repository.
|
|
||||||
|
|
||||||
This global mode works by turning on the buffer-local mode
|
|
||||||
`auto-revert-mode' at the time a buffer is first created. The
|
|
||||||
local mode is turned on if the visited file is being tracked in
|
|
||||||
a Git repository at the time when the buffer is created.
|
|
||||||
|
|
||||||
If `magit-auto-revert-tracked-only' is non-nil (the default),
|
|
||||||
then only tracked files are reverted. But if you stage a
|
|
||||||
previously untracked file using `magit-stage', then this mode
|
|
||||||
notices that.
|
|
||||||
|
|
||||||
Unlike `global-auto-revert-mode', this mode never reverts any
|
|
||||||
buffers that are not visiting files.
|
|
||||||
|
|
||||||
The behavior of this mode can be customized using the options
|
|
||||||
in the `autorevert' and `magit-autorevert' groups.
|
|
||||||
|
|
||||||
This function calls the hook `magit-auto-revert-mode-hook'.")
|
|
||||||
|
|
||||||
(defun magit-auto-revert-buffers ()
|
|
||||||
(when (and magit-auto-revert-immediately
|
|
||||||
(or global-auto-revert-mode
|
|
||||||
(and magit-auto-revert-mode auto-revert-buffer-list)))
|
|
||||||
(let ((auto-revert-buffer-list-filter
|
|
||||||
(or auto-revert-buffer-list-filter
|
|
||||||
#'magit-auto-revert-repository-buffer-p)))
|
|
||||||
(auto-revert-buffers))))
|
|
||||||
|
|
||||||
(defvar magit-auto-revert-toplevel nil)
|
|
||||||
|
|
||||||
(defvar magit-auto-revert-counter 1
|
|
||||||
"Incremented each time `auto-revert-buffers' is called.")
|
|
||||||
|
|
||||||
(defun magit-auto-revert-buffer-p (buffer)
|
|
||||||
"Return non-nil if BUFFER visits a file inside the current repository.
|
|
||||||
The current repository is the one containing `default-directory'.
|
|
||||||
If there is no current repository, then return t for any BUFFER."
|
|
||||||
(magit-auto-revert-repository-buffer-p buffer t))
|
|
||||||
|
|
||||||
(defun magit-auto-revert-repository-buffer-p (buffer &optional fallback)
|
|
||||||
"Return non-nil if BUFFER visits a file inside the current repository.
|
|
||||||
The current repository is the one containing `default-directory'.
|
|
||||||
If there is no current repository, then return FALLBACK (which
|
|
||||||
defaults to nil) for any BUFFER."
|
|
||||||
;; Call `magit-toplevel' just once per cycle.
|
|
||||||
(unless (and magit-auto-revert-toplevel
|
|
||||||
(= (cdr magit-auto-revert-toplevel)
|
|
||||||
magit-auto-revert-counter))
|
|
||||||
(setq magit-auto-revert-toplevel
|
|
||||||
(cons (or (magit-toplevel) 'no-repo)
|
|
||||||
magit-auto-revert-counter)))
|
|
||||||
(let ((top (car magit-auto-revert-toplevel)))
|
|
||||||
(if (eq top 'no-repo)
|
|
||||||
fallback
|
|
||||||
(let ((dir (buffer-local-value 'default-directory buffer)))
|
|
||||||
(and (equal (file-remote-p dir)
|
|
||||||
(file-remote-p top))
|
|
||||||
;; ^ `tramp-handle-file-in-directory-p' lacks this optimization.
|
|
||||||
(file-in-directory-p dir top))))))
|
|
||||||
|
|
||||||
(defun auto-revert-buffers--buffer-list-filter (fn)
|
|
||||||
(cl-incf magit-auto-revert-counter)
|
|
||||||
(if (or global-auto-revert-mode
|
|
||||||
(not auto-revert-buffer-list)
|
|
||||||
(not auto-revert-buffer-list-filter))
|
|
||||||
(funcall fn)
|
|
||||||
(let ((auto-revert-buffer-list
|
|
||||||
(-filter auto-revert-buffer-list-filter
|
|
||||||
auto-revert-buffer-list)))
|
|
||||||
(funcall fn))
|
|
||||||
(unless auto-revert-timer
|
|
||||||
(auto-revert-set-timer))))
|
|
||||||
|
|
||||||
(advice-add 'auto-revert-buffers :around
|
|
||||||
'auto-revert-buffers--buffer-list-filter)
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-autorevert)
|
|
||||||
;;; magit-autorevert.el ends here
|
|
Binary file not shown.
|
@ -1,239 +0,0 @@
|
||||||
;;; magit-bisect.el --- bisect support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2011-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Use a binary search to find the commit that introduced a bug.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-bisect-show-graph t
|
|
||||||
"Whether to use `--graph' in the log showing commits yet to be bisected."
|
|
||||||
:package-version '(magit . "2.8.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defface magit-bisect-good
|
|
||||||
'((t :foreground "DarkOliveGreen"))
|
|
||||||
"Face for good bisect revisions."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-bisect-skip
|
|
||||||
'((t :foreground "DarkGoldenrod"))
|
|
||||||
"Face for skipped bisect revisions."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-bisect-bad
|
|
||||||
'((t :foreground "IndianRed4"))
|
|
||||||
"Face for bad bisect revisions."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-bisect "magit-bisect" nil t)
|
|
||||||
(define-transient-command magit-bisect ()
|
|
||||||
"Narrow in on the commit that introduced a bug."
|
|
||||||
:man-page "git-bisect"
|
|
||||||
["Actions"
|
|
||||||
:if-not magit-bisect-in-progress-p
|
|
||||||
("B" "Start" magit-bisect-start)
|
|
||||||
("s" "Start script" magit-bisect-run)]
|
|
||||||
["Actions"
|
|
||||||
:if magit-bisect-in-progress-p
|
|
||||||
("B" "Bad" magit-bisect-bad)
|
|
||||||
("g" "Good" magit-bisect-good)
|
|
||||||
("k" "Skip" magit-bisect-skip)
|
|
||||||
("r" "Reset" magit-bisect-reset)
|
|
||||||
("s" "Run script" magit-bisect-run)])
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-start (bad good)
|
|
||||||
"Start a bisect session.
|
|
||||||
|
|
||||||
Bisecting a bug means to find the commit that introduced it.
|
|
||||||
This command starts such a bisect session by asking for a know
|
|
||||||
good and a bad commit. To move the session forward use the
|
|
||||||
other actions from the bisect transient command (\
|
|
||||||
\\<magit-status-mode-map>\\[magit-bisect])."
|
|
||||||
(interactive (if (magit-bisect-in-progress-p)
|
|
||||||
(user-error "Already bisecting")
|
|
||||||
(magit-bisect-start-read-args)))
|
|
||||||
(unless (magit-rev-ancestor-p good bad)
|
|
||||||
(user-error
|
|
||||||
"The good revision (%s) has to be an ancestor of the bad one (%s)"
|
|
||||||
good bad))
|
|
||||||
(when (magit-anything-modified-p)
|
|
||||||
(user-error "Cannot bisect with uncommitted changes"))
|
|
||||||
(magit-git-bisect "start" (list bad good) t))
|
|
||||||
|
|
||||||
(defun magit-bisect-start-read-args ()
|
|
||||||
(let ((b (magit-read-branch-or-commit "Start bisect with bad revision")))
|
|
||||||
(list b (magit-read-other-branch-or-commit "Good revision" b))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-reset ()
|
|
||||||
"After bisecting, cleanup bisection state and return to original `HEAD'."
|
|
||||||
(interactive)
|
|
||||||
(magit-confirm 'reset-bisect)
|
|
||||||
(magit-run-git "bisect" "reset")
|
|
||||||
(ignore-errors (delete-file (magit-git-dir "BISECT_CMD_OUTPUT"))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-good ()
|
|
||||||
"While bisecting, mark the current commit as good.
|
|
||||||
Use this after you have asserted that the commit does not contain
|
|
||||||
the bug in question."
|
|
||||||
(interactive)
|
|
||||||
(magit-git-bisect "good"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-bad ()
|
|
||||||
"While bisecting, mark the current commit as bad.
|
|
||||||
Use this after you have asserted that the commit does contain the
|
|
||||||
bug in question."
|
|
||||||
(interactive)
|
|
||||||
(magit-git-bisect "bad"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-skip ()
|
|
||||||
"While bisecting, skip the current commit.
|
|
||||||
Use this if for some reason the current commit is not a good one
|
|
||||||
to test. This command lets Git choose a different one."
|
|
||||||
(interactive)
|
|
||||||
(magit-git-bisect "skip"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-bisect-run (cmdline &optional bad good)
|
|
||||||
"Bisect automatically by running commands after each step.
|
|
||||||
|
|
||||||
Unlike `git bisect run' this can be used before bisecting has
|
|
||||||
begun. In that case it behaves like `git bisect start; git
|
|
||||||
bisect run'."
|
|
||||||
(interactive (let ((args (and (not (magit-bisect-in-progress-p))
|
|
||||||
(magit-bisect-start-read-args))))
|
|
||||||
(cons (read-shell-command "Bisect shell command: ") args)))
|
|
||||||
(when (and bad good)
|
|
||||||
(magit-bisect-start bad good))
|
|
||||||
(magit-git-bisect "run" (list shell-file-name shell-command-switch cmdline)))
|
|
||||||
|
|
||||||
(defun magit-git-bisect (subcommand &optional args no-assert)
|
|
||||||
(unless (or no-assert (magit-bisect-in-progress-p))
|
|
||||||
(user-error "Not bisecting"))
|
|
||||||
(message "Bisecting...")
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "bisect" subcommand args))
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (> (process-exit-status process) 0)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(when (buffer-live-p (process-buffer process))
|
|
||||||
(with-current-buffer (process-buffer process)
|
|
||||||
(when-let ((section (get-text-property (point) 'magit-section))
|
|
||||||
(output (buffer-substring-no-properties
|
|
||||||
(oref section content)
|
|
||||||
(oref section end))))
|
|
||||||
(with-temp-file (magit-git-dir "BISECT_CMD_OUTPUT")
|
|
||||||
(insert output)))))
|
|
||||||
(magit-refresh))
|
|
||||||
(message "Bisecting...done")))))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
(defun magit-bisect-in-progress-p ()
|
|
||||||
(file-exists-p (magit-git-dir "BISECT_LOG")))
|
|
||||||
|
|
||||||
(defun magit-insert-bisect-output ()
|
|
||||||
"While bisecting, insert section with output from `git bisect'."
|
|
||||||
(when (magit-bisect-in-progress-p)
|
|
||||||
(let* ((lines
|
|
||||||
(or (magit-file-lines (magit-git-dir "BISECT_CMD_OUTPUT"))
|
|
||||||
(list "Bisecting: (no saved bisect output)"
|
|
||||||
"It appears you have invoked `git bisect' from a shell."
|
|
||||||
"There is nothing wrong with that, we just cannot display"
|
|
||||||
"anything useful here. Consult the shell output instead.")))
|
|
||||||
(done-re "^\\([a-z0-9]\\{40\\}\\) is the first bad commit$")
|
|
||||||
(bad-line (or (and (string-match done-re (car lines))
|
|
||||||
(pop lines))
|
|
||||||
(--first (string-match done-re it) lines))))
|
|
||||||
(magit-insert-section ((eval (if bad-line 'commit 'bisect-output))
|
|
||||||
(and bad-line (match-string 1 bad-line)))
|
|
||||||
(magit-insert-heading
|
|
||||||
(propertize (or bad-line (pop lines))
|
|
||||||
'font-lock-face 'magit-section-heading))
|
|
||||||
(dolist (line lines)
|
|
||||||
(insert line "\n"))))
|
|
||||||
(insert "\n")))
|
|
||||||
|
|
||||||
(defun magit-insert-bisect-rest ()
|
|
||||||
"While bisecting, insert section visualizing the bisect state."
|
|
||||||
(when (magit-bisect-in-progress-p)
|
|
||||||
(magit-insert-section (bisect-view)
|
|
||||||
(magit-insert-heading "Bisect Rest:")
|
|
||||||
(magit-git-wash (apply-partially 'magit-log-wash-log 'bisect-vis)
|
|
||||||
"bisect" "visualize" "git" "log"
|
|
||||||
"--format=%h%x00%D%x00%s" "--decorate=full"
|
|
||||||
(and magit-bisect-show-graph "--graph")))))
|
|
||||||
|
|
||||||
(defun magit-insert-bisect-log ()
|
|
||||||
"While bisecting, insert section logging bisect progress."
|
|
||||||
(when (magit-bisect-in-progress-p)
|
|
||||||
(magit-insert-section (bisect-log)
|
|
||||||
(magit-insert-heading "Bisect Log:")
|
|
||||||
(magit-git-wash #'magit-wash-bisect-log "bisect" "log")
|
|
||||||
(insert ?\n))))
|
|
||||||
|
|
||||||
(defun magit-wash-bisect-log (_args)
|
|
||||||
(let (beg)
|
|
||||||
(while (progn (setq beg (point-marker))
|
|
||||||
(re-search-forward "^\\(git bisect [^\n]+\n\\)" nil t))
|
|
||||||
(magit-bind-match-strings (heading) nil
|
|
||||||
(magit-delete-match)
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region beg (point))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(magit-insert-section (bisect-item heading t)
|
|
||||||
(insert (propertize heading 'font-lock-face
|
|
||||||
'magit-section-secondary-heading))
|
|
||||||
(magit-insert-heading)
|
|
||||||
(magit-wash-sequence
|
|
||||||
(apply-partially 'magit-log-wash-rev 'bisect-log
|
|
||||||
(magit-abbrev-length)))
|
|
||||||
(insert ?\n)))))
|
|
||||||
(when (re-search-forward
|
|
||||||
"# first bad commit: \\[\\([a-z0-9]\\{40\\}\\)\\] [^\n]+\n" nil t)
|
|
||||||
(magit-bind-match-strings (hash) nil
|
|
||||||
(magit-delete-match)
|
|
||||||
(magit-insert-section (bisect-item)
|
|
||||||
(insert hash " is the first bad commit\n"))))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-bisect)
|
|
||||||
;;; magit-bisect.el ends here
|
|
Binary file not shown.
|
@ -1,954 +0,0 @@
|
||||||
;;; magit-blame.el --- blame support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2012-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Annotates each line in file-visiting buffer with information from
|
|
||||||
;; the revision which last modified the line.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-blame nil
|
|
||||||
"Blame support for Magit."
|
|
||||||
:link '(info-link "(magit)Blaming")
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
(defcustom magit-blame-styles
|
|
||||||
'((headings
|
|
||||||
(heading-format . "%-20a %C %s\n"))
|
|
||||||
(margin
|
|
||||||
(margin-format . (" %s%f" " %C %a" " %H"))
|
|
||||||
(margin-width . 42)
|
|
||||||
(margin-face . magit-blame-margin)
|
|
||||||
(margin-body-face . (magit-blame-dimmed)))
|
|
||||||
(highlight
|
|
||||||
(highlight-face . magit-blame-highlight))
|
|
||||||
(lines
|
|
||||||
(show-lines . t)
|
|
||||||
(show-message . t)))
|
|
||||||
"List of styles used to visualize blame information.
|
|
||||||
|
|
||||||
Each entry has the form (IDENT (KEY . VALUE)...). IDENT has
|
|
||||||
to be a symbol uniquely identifing the style. The following
|
|
||||||
KEYs are recognized:
|
|
||||||
|
|
||||||
`show-lines'
|
|
||||||
Whether to prefix each chunk of lines with a thin line.
|
|
||||||
This has no effect if `heading-format' is non-nil.
|
|
||||||
`show-message'
|
|
||||||
Whether to display a commit's summary line in the echo area
|
|
||||||
when crossing chunks.
|
|
||||||
`highlight-face'
|
|
||||||
Face used to highlight the first line of each chunk.
|
|
||||||
If this is nil, then those lines are not highlighted.
|
|
||||||
`heading-format'
|
|
||||||
String specifying the information to be shown above each
|
|
||||||
chunk of lines. It must end with a newline character.
|
|
||||||
`margin-format'
|
|
||||||
String specifying the information to be shown in the left
|
|
||||||
buffer margin. It must NOT end with a newline character.
|
|
||||||
This can also be a list of formats used for the lines at
|
|
||||||
the same positions within the chunk. If the chunk has
|
|
||||||
more lines than formats are specified, then the last is
|
|
||||||
repeated.
|
|
||||||
`margin-width'
|
|
||||||
Width of the margin, provided `margin-format' is non-nil.
|
|
||||||
`margin-face'
|
|
||||||
Face used in the margin, provided `margin-format' is
|
|
||||||
non-nil. This face is used in combination with the faces
|
|
||||||
that are specific to the used %-specs. If this is nil,
|
|
||||||
then `magit-blame-margin' is used.
|
|
||||||
`margin-body-face'
|
|
||||||
Face used in the margin for all but first line of a chunk.
|
|
||||||
This face is used in combination with the faces that are
|
|
||||||
specific to the used %-specs. This can also be a list of
|
|
||||||
faces (usually one face), in which case only these faces
|
|
||||||
are used and the %-spec faces are ignored. A good value
|
|
||||||
might be `(magit-blame-dimmed)'. If this is nil, then
|
|
||||||
the same face as for the first line is used.
|
|
||||||
|
|
||||||
The following %-specs can be used in `heading-format' and
|
|
||||||
`margin-format':
|
|
||||||
|
|
||||||
%H hash using face `magit-blame-hash'
|
|
||||||
%s summary using face `magit-blame-summary'
|
|
||||||
%a author using face `magit-blame-name'
|
|
||||||
%A author time using face `magit-blame-date'
|
|
||||||
%c committer using face `magit-blame-name'
|
|
||||||
%C committer time using face `magit-blame-date'
|
|
||||||
|
|
||||||
Additionally if `margin-format' ends with %f, then the string
|
|
||||||
that is displayed in the margin is made at least `margin-width'
|
|
||||||
characters wide, which may be desirable if the used face sets
|
|
||||||
the background color.
|
|
||||||
|
|
||||||
The style used in the current buffer can be cycled from the blame
|
|
||||||
popup. Blame commands (except `magit-blame-echo') use the first
|
|
||||||
style as the initial style when beginning to blame in a buffer."
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:group 'magit-blame
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-blame-echo-style 'lines
|
|
||||||
"The blame visualization style used by `magit-blame-echo'.
|
|
||||||
A symbol that has to be used as the identifier for one of the
|
|
||||||
styles defined in `magit-blame-styles'."
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:group 'magit-blame
|
|
||||||
:type 'symbol)
|
|
||||||
|
|
||||||
(defcustom magit-blame-time-format "%F %H:%M"
|
|
||||||
"Format for time strings in blame headings."
|
|
||||||
:group 'magit-blame
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-blame-read-only t
|
|
||||||
"Whether to initially make the blamed buffer read-only."
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:group 'magit-blame
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-blame-disable-modes '(fci-mode yascroll-bar-mode)
|
|
||||||
"List of modes not compatible with Magit-Blame mode.
|
|
||||||
This modes are turned off when Magit-Blame mode is turned on,
|
|
||||||
and then turned on again when turning off the latter."
|
|
||||||
:group 'magit-blame
|
|
||||||
:type '(repeat (symbol :tag "Mode")))
|
|
||||||
|
|
||||||
(defcustom magit-blame-mode-lighter " Blame"
|
|
||||||
"The mode-line lighter of the Magit-Blame mode."
|
|
||||||
:group 'magit-blame
|
|
||||||
:type '(choice (const :tag "No lighter" "") string))
|
|
||||||
|
|
||||||
(defcustom magit-blame-goto-chunk-hook
|
|
||||||
'(magit-blame-maybe-update-revision-buffer
|
|
||||||
magit-blame-maybe-show-message)
|
|
||||||
"Hook run after point entered another chunk."
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:group 'magit-blame
|
|
||||||
:type 'hook
|
|
||||||
:get 'magit-hook-custom-get
|
|
||||||
:options '(magit-blame-maybe-update-revision-buffer
|
|
||||||
magit-blame-maybe-show-message))
|
|
||||||
|
|
||||||
;;; Faces
|
|
||||||
|
|
||||||
(defface magit-blame-highlight
|
|
||||||
`((((class color) (background light))
|
|
||||||
,@(and (>= emacs-major-version 27) '(:extend t))
|
|
||||||
:background "grey80"
|
|
||||||
:foreground "black")
|
|
||||||
(((class color) (background dark))
|
|
||||||
,@(and (>= emacs-major-version 27) '(:extend t))
|
|
||||||
:background "grey25"
|
|
||||||
:foreground "white"))
|
|
||||||
"Face used for highlighting when blaming.
|
|
||||||
Also see option `magit-blame-styles'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-margin
|
|
||||||
'((t :inherit magit-blame-highlight
|
|
||||||
:weight normal
|
|
||||||
:slant normal))
|
|
||||||
"Face used for the blame margin by default when blaming.
|
|
||||||
Also see option `magit-blame-styles'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-dimmed
|
|
||||||
'((t :inherit magit-dimmed
|
|
||||||
:weight normal
|
|
||||||
:slant normal))
|
|
||||||
"Face used for the blame margin in some cases when blaming.
|
|
||||||
Also see option `magit-blame-styles'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-heading
|
|
||||||
`((t ,@(and (>= emacs-major-version 27) '(:extend t))
|
|
||||||
:inherit magit-blame-highlight
|
|
||||||
:weight normal
|
|
||||||
:slant normal))
|
|
||||||
"Face used for blame headings by default when blaming.
|
|
||||||
Also see option `magit-blame-styles'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-summary nil
|
|
||||||
"Face used for commit summaries when blaming."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-hash nil
|
|
||||||
"Face used for commit hashes when blaming."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-name nil
|
|
||||||
"Face used for author and committer names when blaming."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-blame-date nil
|
|
||||||
"Face used for dates when blaming."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
;;; Chunks
|
|
||||||
|
|
||||||
(defclass magit-blame-chunk ()
|
|
||||||
(;; <orig-rev> <orig-line> <final-line> <num-lines>
|
|
||||||
(orig-rev :initarg :orig-rev)
|
|
||||||
(orig-line :initarg :orig-line)
|
|
||||||
(final-line :initarg :final-line)
|
|
||||||
(num-lines :initarg :num-lines)
|
|
||||||
;; previous <prev-rev> <prev-file>
|
|
||||||
(prev-rev :initform nil)
|
|
||||||
(prev-file :initform nil)
|
|
||||||
;; filename <orig-file>
|
|
||||||
(orig-file)))
|
|
||||||
|
|
||||||
(defun magit-current-blame-chunk (&optional type)
|
|
||||||
(or (and (not (and type (not (eq type magit-blame-type))))
|
|
||||||
(magit-blame-chunk-at (point)))
|
|
||||||
(and type
|
|
||||||
(let ((rev (or magit-buffer-refname magit-buffer-revision))
|
|
||||||
(file (magit-file-relative-name nil (not magit-buffer-file-name)))
|
|
||||||
(line (format "%i,+1" (line-number-at-pos))))
|
|
||||||
(unless file
|
|
||||||
(error "Buffer does not visit a tracked file"))
|
|
||||||
(with-temp-buffer
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-git-insert
|
|
||||||
"blame" "--porcelain"
|
|
||||||
(if (memq magit-blame-type '(final removal))
|
|
||||||
(cons "--reverse" (magit-blame-arguments))
|
|
||||||
(magit-blame-arguments))
|
|
||||||
"-L" line rev "--" file)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(car (magit-blame--parse-chunk type))))))))
|
|
||||||
|
|
||||||
(defun magit-blame-chunk-at (pos)
|
|
||||||
(--some (overlay-get it 'magit-blame-chunk)
|
|
||||||
(overlays-at pos)))
|
|
||||||
|
|
||||||
(defun magit-blame--overlay-at (&optional pos key)
|
|
||||||
(unless pos
|
|
||||||
(setq pos (point)))
|
|
||||||
(--first (overlay-get it (or key 'magit-blame-chunk))
|
|
||||||
(nconc (overlays-at pos)
|
|
||||||
(overlays-in pos pos))))
|
|
||||||
|
|
||||||
;;; Keymaps
|
|
||||||
|
|
||||||
(defvar magit-blame-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map (kbd "C-c C-q") 'magit-blame-quit)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-blame-mode'.
|
|
||||||
Note that most blaming key bindings are defined
|
|
||||||
in `magit-blame-read-only-mode-map' instead.")
|
|
||||||
|
|
||||||
(defvar magit-blame-read-only-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(cond ((featurep 'jkl)
|
|
||||||
(define-key map [return] 'magit-show-commit)
|
|
||||||
(define-key map (kbd "i") 'magit-blame-previous-chunk)
|
|
||||||
(define-key map (kbd "I") 'magit-blame-previous-chunk-same-commit)
|
|
||||||
(define-key map (kbd "k") 'magit-blame-next-chunk)
|
|
||||||
(define-key map (kbd "K") 'magit-blame-next-chunk-same-commit)
|
|
||||||
(define-key map (kbd "j") 'magit-blame-addition)
|
|
||||||
(define-key map (kbd "l") 'magit-blame-removal)
|
|
||||||
(define-key map (kbd "f") 'magit-blame-reverse)
|
|
||||||
(define-key map (kbd "b") 'magit-blame))
|
|
||||||
(t
|
|
||||||
(define-key map (kbd "C-m") 'magit-show-commit)
|
|
||||||
(define-key map (kbd "p") 'magit-blame-previous-chunk)
|
|
||||||
(define-key map (kbd "P") 'magit-blame-previous-chunk-same-commit)
|
|
||||||
(define-key map (kbd "n") 'magit-blame-next-chunk)
|
|
||||||
(define-key map (kbd "N") 'magit-blame-next-chunk-same-commit)
|
|
||||||
(define-key map (kbd "b") 'magit-blame-addition)
|
|
||||||
(define-key map (kbd "r") 'magit-blame-removal)
|
|
||||||
(define-key map (kbd "f") 'magit-blame-reverse)
|
|
||||||
(define-key map (kbd "B") 'magit-blame)))
|
|
||||||
(define-key map (kbd "c") 'magit-blame-cycle-style)
|
|
||||||
(define-key map (kbd "q") 'magit-blame-quit)
|
|
||||||
(define-key map (kbd "M-w") 'magit-blame-copy-hash)
|
|
||||||
(define-key map (kbd "SPC") 'magit-diff-show-or-scroll-up)
|
|
||||||
(define-key map (kbd "DEL") 'magit-diff-show-or-scroll-down)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-blame-read-only-mode'.")
|
|
||||||
|
|
||||||
;;; Modes
|
|
||||||
;;;; Variables
|
|
||||||
|
|
||||||
(defvar-local magit-blame-buffer-read-only nil)
|
|
||||||
(defvar-local magit-blame-cache nil)
|
|
||||||
(defvar-local magit-blame-disabled-modes nil)
|
|
||||||
(defvar-local magit-blame-process nil)
|
|
||||||
(defvar-local magit-blame-recursive-p nil)
|
|
||||||
(defvar-local magit-blame-type nil)
|
|
||||||
(defvar-local magit-blame-separator nil)
|
|
||||||
(defvar-local magit-blame-previous-chunk nil)
|
|
||||||
|
|
||||||
(defvar-local magit-blame--style nil)
|
|
||||||
|
|
||||||
(defsubst magit-blame--style-get (key)
|
|
||||||
(cdr (assoc key (cdr magit-blame--style))))
|
|
||||||
|
|
||||||
;;;; Base Mode
|
|
||||||
|
|
||||||
(define-minor-mode magit-blame-mode
|
|
||||||
"Display blame information inline."
|
|
||||||
:lighter magit-blame-mode-lighter
|
|
||||||
(cond (magit-blame-mode
|
|
||||||
(when (called-interactively-p 'any)
|
|
||||||
(setq magit-blame-mode nil)
|
|
||||||
(user-error
|
|
||||||
(concat "Don't call `magit-blame-mode' directly; "
|
|
||||||
"instead use `magit-blame'")))
|
|
||||||
(add-hook 'after-save-hook 'magit-blame--refresh t t)
|
|
||||||
(add-hook 'post-command-hook 'magit-blame-goto-chunk-hook t t)
|
|
||||||
(add-hook 'before-revert-hook 'magit-blame--remove-overlays t t)
|
|
||||||
(add-hook 'after-revert-hook 'magit-blame--refresh t t)
|
|
||||||
(add-hook 'read-only-mode-hook 'magit-blame-toggle-read-only t t)
|
|
||||||
(setq magit-blame-buffer-read-only buffer-read-only)
|
|
||||||
(when (or magit-blame-read-only magit-buffer-file-name)
|
|
||||||
(read-only-mode 1))
|
|
||||||
(dolist (mode magit-blame-disable-modes)
|
|
||||||
(when (and (boundp mode) (symbol-value mode))
|
|
||||||
(funcall mode -1)
|
|
||||||
(push mode magit-blame-disabled-modes)))
|
|
||||||
(setq magit-blame-separator (magit-blame--format-separator))
|
|
||||||
(unless magit-blame--style
|
|
||||||
(setq magit-blame--style (car magit-blame-styles)))
|
|
||||||
(magit-blame--update-margin))
|
|
||||||
(t
|
|
||||||
(when (process-live-p magit-blame-process)
|
|
||||||
(kill-process magit-blame-process)
|
|
||||||
(while magit-blame-process
|
|
||||||
(sit-for 0.01))) ; avoid racing the sentinel
|
|
||||||
(remove-hook 'after-save-hook 'magit-blame--refresh t)
|
|
||||||
(remove-hook 'post-command-hook 'magit-blame-goto-chunk-hook t)
|
|
||||||
(remove-hook 'before-revert-hook 'magit-blame--remove-overlays t)
|
|
||||||
(remove-hook 'after-revert-hook 'magit-blame--refresh t)
|
|
||||||
(remove-hook 'read-only-mode-hook 'magit-blame-toggle-read-only t)
|
|
||||||
(unless magit-blame-buffer-read-only
|
|
||||||
(read-only-mode -1))
|
|
||||||
(magit-blame-read-only-mode -1)
|
|
||||||
(dolist (mode magit-blame-disabled-modes)
|
|
||||||
(funcall mode 1))
|
|
||||||
(kill-local-variable 'magit-blame-disabled-modes)
|
|
||||||
(kill-local-variable 'magit-blame-type)
|
|
||||||
(kill-local-variable 'magit-blame--style)
|
|
||||||
(magit-blame--update-margin)
|
|
||||||
(magit-blame--remove-overlays))))
|
|
||||||
|
|
||||||
(defun magit-blame--refresh ()
|
|
||||||
(magit-blame--refresh (magit-blame-arguments)))
|
|
||||||
|
|
||||||
(defun magit-blame-goto-chunk-hook ()
|
|
||||||
(let ((chunk (magit-blame-chunk-at (point))))
|
|
||||||
(when (cl-typep chunk 'magit-blame-chunk)
|
|
||||||
(unless (eq chunk magit-blame-previous-chunk)
|
|
||||||
(run-hooks 'magit-blame-goto-chunk-hook))
|
|
||||||
(setq magit-blame-previous-chunk chunk))))
|
|
||||||
|
|
||||||
(defun magit-blame-toggle-read-only ()
|
|
||||||
(magit-blame-read-only-mode (if buffer-read-only 1 -1)))
|
|
||||||
|
|
||||||
;;;; Read-Only Mode
|
|
||||||
|
|
||||||
(define-minor-mode magit-blame-read-only-mode
|
|
||||||
"Provide keybindings for Magit-Blame mode.
|
|
||||||
|
|
||||||
This minor-mode provides the key bindings for Magit-Blame mode,
|
|
||||||
but only when Read-Only mode is also enabled because these key
|
|
||||||
bindings would otherwise conflict badly with regular bindings.
|
|
||||||
|
|
||||||
When both Magit-Blame mode and Read-Only mode are enabled, then
|
|
||||||
this mode gets automatically enabled too and when one of these
|
|
||||||
modes is toggled, then this mode also gets toggled automatically.
|
|
||||||
|
|
||||||
\\{magit-blame-read-only-mode-map}")
|
|
||||||
|
|
||||||
;;;; Kludges
|
|
||||||
|
|
||||||
(defun magit-blame-put-keymap-before-view-mode ()
|
|
||||||
"Put `magit-blame-read-only-mode' ahead of `view-mode' in `minor-mode-map-alist'."
|
|
||||||
(--when-let (assq 'magit-blame-read-only-mode
|
|
||||||
(cl-member 'view-mode minor-mode-map-alist :key #'car))
|
|
||||||
(setq minor-mode-map-alist
|
|
||||||
(cons it (delq it minor-mode-map-alist))))
|
|
||||||
(remove-hook 'view-mode-hook #'magit-blame-put-keymap-before-view-mode))
|
|
||||||
|
|
||||||
(add-hook 'view-mode-hook #'magit-blame-put-keymap-before-view-mode)
|
|
||||||
|
|
||||||
;;; Process
|
|
||||||
|
|
||||||
(defun magit-blame--run (args)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(unless magit-blame-mode
|
|
||||||
(magit-blame-mode 1))
|
|
||||||
(message "Blaming...")
|
|
||||||
(magit-blame-run-process
|
|
||||||
(or magit-buffer-refname magit-buffer-revision)
|
|
||||||
(magit-file-relative-name nil (not magit-buffer-file-name))
|
|
||||||
(if (memq magit-blame-type '(final removal))
|
|
||||||
(cons "--reverse" args)
|
|
||||||
args)
|
|
||||||
(list (line-number-at-pos (window-start))
|
|
||||||
(line-number-at-pos (1- (window-end nil t)))))
|
|
||||||
(set-process-sentinel magit-this-process
|
|
||||||
'magit-blame-process-quickstart-sentinel)))
|
|
||||||
|
|
||||||
(defun magit-blame-run-process (revision file args &optional lines)
|
|
||||||
(let ((process (magit-parse-git-async
|
|
||||||
"blame" "--incremental" args
|
|
||||||
(and lines (list "-L" (apply #'format "%s,%s" lines)))
|
|
||||||
revision "--" file)))
|
|
||||||
(set-process-filter process 'magit-blame-process-filter)
|
|
||||||
(set-process-sentinel process 'magit-blame-process-sentinel)
|
|
||||||
(process-put process 'arguments (list revision file args))
|
|
||||||
(setq magit-blame-cache (make-hash-table :test 'equal))
|
|
||||||
(setq magit-blame-process process)))
|
|
||||||
|
|
||||||
(defun magit-blame-process-quickstart-sentinel (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(magit-blame-process-sentinel process event t)
|
|
||||||
(magit-blame-assert-buffer process)
|
|
||||||
(with-current-buffer (process-get process 'command-buf)
|
|
||||||
(when magit-blame-mode
|
|
||||||
(let ((default-directory (magit-toplevel)))
|
|
||||||
(apply #'magit-blame-run-process
|
|
||||||
(process-get process 'arguments)))))))
|
|
||||||
|
|
||||||
(defun magit-blame-process-sentinel (process _event &optional quiet)
|
|
||||||
(let ((status (process-status process)))
|
|
||||||
(when (memq status '(exit signal))
|
|
||||||
(kill-buffer (process-buffer process))
|
|
||||||
(if (and (eq status 'exit)
|
|
||||||
(zerop (process-exit-status process)))
|
|
||||||
(unless quiet
|
|
||||||
(message "Blaming...done"))
|
|
||||||
(magit-blame-assert-buffer process)
|
|
||||||
(with-current-buffer (process-get process 'command-buf)
|
|
||||||
(if magit-blame-mode
|
|
||||||
(progn (magit-blame-mode -1)
|
|
||||||
(message "Blaming...failed"))
|
|
||||||
(message "Blaming...aborted"))))
|
|
||||||
(kill-local-variable 'magit-blame-process))))
|
|
||||||
|
|
||||||
(defun magit-blame-process-filter (process string)
|
|
||||||
(internal-default-process-filter process string)
|
|
||||||
(let ((buf (process-get process 'command-buf))
|
|
||||||
(pos (process-get process 'parsed))
|
|
||||||
(mark (process-mark process))
|
|
||||||
type cache)
|
|
||||||
(with-current-buffer buf
|
|
||||||
(setq type magit-blame-type)
|
|
||||||
(setq cache magit-blame-cache))
|
|
||||||
(with-current-buffer (process-buffer process)
|
|
||||||
(goto-char pos)
|
|
||||||
(while (and (< (point) mark)
|
|
||||||
(save-excursion (re-search-forward "^filename .+\n" nil t)))
|
|
||||||
(pcase-let* ((`(,chunk ,revinfo)
|
|
||||||
(magit-blame--parse-chunk type))
|
|
||||||
(rev (oref chunk orig-rev)))
|
|
||||||
(if revinfo
|
|
||||||
(puthash rev revinfo cache)
|
|
||||||
(setq revinfo
|
|
||||||
(or (gethash rev cache)
|
|
||||||
(puthash rev (magit-blame--commit-alist rev) cache))))
|
|
||||||
(magit-blame--make-overlays buf chunk revinfo))
|
|
||||||
(process-put process 'parsed (point))))))
|
|
||||||
|
|
||||||
(defun magit-blame--parse-chunk (type)
|
|
||||||
(let (chunk revinfo)
|
|
||||||
(looking-at "^\\(.\\{40\\}\\) \\([0-9]+\\) \\([0-9]+\\) \\([0-9]+\\)")
|
|
||||||
(with-slots (orig-rev orig-file prev-rev prev-file)
|
|
||||||
(setq chunk (magit-blame-chunk
|
|
||||||
:orig-rev (match-string 1)
|
|
||||||
:orig-line (string-to-number (match-string 2))
|
|
||||||
:final-line (string-to-number (match-string 3))
|
|
||||||
:num-lines (string-to-number (match-string 4))))
|
|
||||||
(forward-line)
|
|
||||||
(let (done)
|
|
||||||
(while (not done)
|
|
||||||
(cond ((looking-at "^filename \\(.+\\)")
|
|
||||||
(setq done t)
|
|
||||||
(setf orig-file (match-string 1)))
|
|
||||||
((looking-at "^previous \\(.\\{40\\}\\) \\(.+\\)")
|
|
||||||
(setf prev-rev (match-string 1))
|
|
||||||
(setf prev-file (match-string 2)))
|
|
||||||
((looking-at "^\\([^ ]+\\) \\(.+\\)")
|
|
||||||
(push (cons (match-string 1)
|
|
||||||
(match-string 2)) revinfo)))
|
|
||||||
(forward-line)))
|
|
||||||
(when (and (eq type 'removal) prev-rev)
|
|
||||||
(cl-rotatef orig-rev prev-rev)
|
|
||||||
(cl-rotatef orig-file prev-file)
|
|
||||||
(setq revinfo nil)))
|
|
||||||
(list chunk revinfo)))
|
|
||||||
|
|
||||||
(defun magit-blame--commit-alist (rev)
|
|
||||||
(cl-mapcar 'cons
|
|
||||||
'("summary"
|
|
||||||
"author" "author-time" "author-tz"
|
|
||||||
"committer" "committer-time" "committer-tz")
|
|
||||||
(split-string (magit-rev-format "%s\v%an\v%ad\v%cn\v%cd" rev
|
|
||||||
"--date=format:%s\v%z")
|
|
||||||
"\v")))
|
|
||||||
|
|
||||||
(defun magit-blame-assert-buffer (process)
|
|
||||||
(unless (buffer-live-p (process-get process 'command-buf))
|
|
||||||
(kill-process process)
|
|
||||||
(user-error "Buffer being blamed has been killed")))
|
|
||||||
|
|
||||||
;;; Display
|
|
||||||
|
|
||||||
(defun magit-blame--make-overlays (buf chunk revinfo)
|
|
||||||
(with-current-buffer buf
|
|
||||||
(save-excursion
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- (oref chunk final-line)))
|
|
||||||
(let ((beg (point))
|
|
||||||
(end (save-excursion
|
|
||||||
(forward-line (oref chunk num-lines))
|
|
||||||
(point))))
|
|
||||||
(magit-blame--remove-overlays beg end)
|
|
||||||
(magit-blame--make-margin-overlays chunk revinfo beg end)
|
|
||||||
(magit-blame--make-heading-overlay chunk revinfo beg end)
|
|
||||||
(magit-blame--make-highlight-overlay chunk beg))))))
|
|
||||||
|
|
||||||
(defun magit-blame--make-margin-overlays (chunk revinfo _beg end)
|
|
||||||
(save-excursion
|
|
||||||
(let ((line 0))
|
|
||||||
(while (< (point) end)
|
|
||||||
(magit-blame--make-margin-overlay chunk revinfo line)
|
|
||||||
(forward-line)
|
|
||||||
(cl-incf line)))))
|
|
||||||
|
|
||||||
(defun magit-blame--make-margin-overlay (chunk revinfo line)
|
|
||||||
(let* ((end (line-end-position))
|
|
||||||
;; If possible avoid putting this on the first character
|
|
||||||
;; of the line to avoid a conflict with the line overlay.
|
|
||||||
(beg (min (1+ (line-beginning-position)) end))
|
|
||||||
(ov (make-overlay beg end)))
|
|
||||||
(overlay-put ov 'magit-blame-chunk chunk)
|
|
||||||
(overlay-put ov 'magit-blame-revinfo revinfo)
|
|
||||||
(overlay-put ov 'magit-blame-margin line)
|
|
||||||
(magit-blame--update-margin-overlay ov)))
|
|
||||||
|
|
||||||
(defun magit-blame--make-heading-overlay (chunk revinfo beg end)
|
|
||||||
(let ((ov (make-overlay beg end)))
|
|
||||||
(overlay-put ov 'magit-blame-chunk chunk)
|
|
||||||
(overlay-put ov 'magit-blame-revinfo revinfo)
|
|
||||||
(overlay-put ov 'magit-blame-heading t)
|
|
||||||
(magit-blame--update-heading-overlay ov)))
|
|
||||||
|
|
||||||
(defun magit-blame--make-highlight-overlay (chunk beg)
|
|
||||||
(let ((ov (make-overlay beg (1+ (line-end-position)))))
|
|
||||||
(overlay-put ov 'magit-blame-chunk chunk)
|
|
||||||
(overlay-put ov 'magit-blame-highlight t)
|
|
||||||
(magit-blame--update-highlight-overlay ov)))
|
|
||||||
|
|
||||||
(defun magit-blame--update-margin ()
|
|
||||||
(setq left-margin-width (or (magit-blame--style-get 'margin-width) 0))
|
|
||||||
(set-window-buffer (selected-window) (current-buffer)))
|
|
||||||
|
|
||||||
(defun magit-blame--update-overlays ()
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
(dolist (ov (overlays-in (point-min) (point-max)))
|
|
||||||
(cond ((overlay-get ov 'magit-blame-heading)
|
|
||||||
(magit-blame--update-heading-overlay ov))
|
|
||||||
((overlay-get ov 'magit-blame-margin)
|
|
||||||
(magit-blame--update-margin-overlay ov))
|
|
||||||
((overlay-get ov 'magit-blame-highlight)
|
|
||||||
(magit-blame--update-highlight-overlay ov))))))
|
|
||||||
|
|
||||||
(defun magit-blame--update-margin-overlay (ov)
|
|
||||||
(overlay-put
|
|
||||||
ov 'before-string
|
|
||||||
(and (magit-blame--style-get 'margin-width)
|
|
||||||
(propertize
|
|
||||||
"o" 'display
|
|
||||||
(list (list 'margin 'left-margin)
|
|
||||||
(let ((line (overlay-get ov 'magit-blame-margin))
|
|
||||||
(format (magit-blame--style-get 'margin-format))
|
|
||||||
(face (magit-blame--style-get 'margin-face)))
|
|
||||||
(magit-blame--format-string
|
|
||||||
ov
|
|
||||||
(or (and (atom format)
|
|
||||||
format)
|
|
||||||
(nth line format)
|
|
||||||
(car (last format)))
|
|
||||||
(or (and (not (zerop line))
|
|
||||||
(magit-blame--style-get 'margin-body-face))
|
|
||||||
face
|
|
||||||
'magit-blame-margin))))))))
|
|
||||||
|
|
||||||
(defun magit-blame--update-heading-overlay (ov)
|
|
||||||
(overlay-put
|
|
||||||
ov 'before-string
|
|
||||||
(--if-let (magit-blame--style-get 'heading-format)
|
|
||||||
(magit-blame--format-string ov it 'magit-blame-heading)
|
|
||||||
(and (magit-blame--style-get 'show-lines)
|
|
||||||
(or (not (magit-blame--style-get 'margin-format))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (overlay-start ov))
|
|
||||||
;; Special case of the special case described in
|
|
||||||
;; `magit-blame--make-margin-overlay'. For empty
|
|
||||||
;; lines it is not possible to show both overlays
|
|
||||||
;; without the line being to high.
|
|
||||||
(not (= (point) (line-end-position)))))
|
|
||||||
magit-blame-separator))))
|
|
||||||
|
|
||||||
(defun magit-blame--update-highlight-overlay (ov)
|
|
||||||
(overlay-put ov 'font-lock-face (magit-blame--style-get 'highlight-face)))
|
|
||||||
|
|
||||||
(defun magit-blame--format-string (ov format face)
|
|
||||||
(let* ((chunk (overlay-get ov 'magit-blame-chunk))
|
|
||||||
(revinfo (overlay-get ov 'magit-blame-revinfo))
|
|
||||||
(key (list format face))
|
|
||||||
(string (cdr (assoc key revinfo))))
|
|
||||||
(unless string
|
|
||||||
(setq string
|
|
||||||
(and format
|
|
||||||
(magit-blame--format-string-1 (oref chunk orig-rev)
|
|
||||||
revinfo format face)))
|
|
||||||
(nconc revinfo (list (cons key string))))
|
|
||||||
string))
|
|
||||||
|
|
||||||
(defun magit-blame--format-string-1 (rev revinfo format face)
|
|
||||||
(let ((str
|
|
||||||
(if (equal rev "0000000000000000000000000000000000000000")
|
|
||||||
(propertize (concat (if (string-prefix-p "\s" format) "\s" "")
|
|
||||||
"Not Yet Committed"
|
|
||||||
(if (string-suffix-p "\n" format) "\n" ""))
|
|
||||||
'font-lock-face face)
|
|
||||||
(magit--format-spec
|
|
||||||
(propertize format 'font-lock-face face)
|
|
||||||
(cl-flet* ((p0 (s f)
|
|
||||||
(propertize s 'font-lock-face
|
|
||||||
(if face
|
|
||||||
(if (listp face)
|
|
||||||
face
|
|
||||||
(list f face))
|
|
||||||
f)))
|
|
||||||
(p1 (k f)
|
|
||||||
(p0 (cdr (assoc k revinfo)) f))
|
|
||||||
(p2 (k1 k2 f)
|
|
||||||
(p0 (magit-blame--format-time-string
|
|
||||||
(cdr (assoc k1 revinfo))
|
|
||||||
(cdr (assoc k2 revinfo)))
|
|
||||||
f)))
|
|
||||||
`((?H . ,(p0 rev 'magit-blame-hash))
|
|
||||||
(?s . ,(p1 "summary" 'magit-blame-summary))
|
|
||||||
(?a . ,(p1 "author" 'magit-blame-name))
|
|
||||||
(?c . ,(p1 "committer" 'magit-blame-name))
|
|
||||||
(?A . ,(p2 "author-time" "author-tz" 'magit-blame-date))
|
|
||||||
(?C . ,(p2 "committer-time" "committer-tz" 'magit-blame-date))
|
|
||||||
(?f . "")))))))
|
|
||||||
(if-let ((width (and (string-suffix-p "%f" format)
|
|
||||||
(magit-blame--style-get 'margin-width))))
|
|
||||||
(concat str
|
|
||||||
(propertize (make-string (max 0 (- width (length str))) ?\s)
|
|
||||||
'font-lock-face face))
|
|
||||||
str)))
|
|
||||||
|
|
||||||
(defun magit-blame--format-separator ()
|
|
||||||
(propertize
|
|
||||||
(concat (propertize "\s" 'display '(space :height (2)))
|
|
||||||
(propertize "\n" 'line-height t))
|
|
||||||
'font-lock-face (list :background
|
|
||||||
(face-attribute 'magit-blame-heading
|
|
||||||
:background nil t))))
|
|
||||||
|
|
||||||
(defun magit-blame--format-time-string (time tz)
|
|
||||||
(let* ((time-format (or (magit-blame--style-get 'time-format)
|
|
||||||
magit-blame-time-format))
|
|
||||||
(tz-in-second (and (string-match "%z" time-format)
|
|
||||||
(car (last (parse-time-string tz))))))
|
|
||||||
(format-time-string time-format
|
|
||||||
(seconds-to-time (string-to-number time))
|
|
||||||
tz-in-second)))
|
|
||||||
|
|
||||||
(defun magit-blame--remove-overlays (&optional beg end)
|
|
||||||
(save-restriction
|
|
||||||
(widen)
|
|
||||||
(dolist (ov (overlays-in (or beg (point-min))
|
|
||||||
(or end (point-max))))
|
|
||||||
(when (overlay-get ov 'magit-blame-chunk)
|
|
||||||
(delete-overlay ov)))))
|
|
||||||
|
|
||||||
(defun magit-blame-maybe-show-message ()
|
|
||||||
(when (magit-blame--style-get 'show-message)
|
|
||||||
(let ((message-log-max 0))
|
|
||||||
(if-let ((msg (cdr (assoc "summary"
|
|
||||||
(gethash (oref (magit-current-blame-chunk)
|
|
||||||
orig-rev)
|
|
||||||
magit-blame-cache)))))
|
|
||||||
(progn (set-text-properties 0 (length msg) nil msg)
|
|
||||||
(message msg))
|
|
||||||
(message "Commit data not available yet. Still blaming.")))))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-blame-echo "magit-blame" nil t)
|
|
||||||
(define-suffix-command magit-blame-echo (args)
|
|
||||||
"For each line show the revision in which it was added.
|
|
||||||
Show the information about the chunk at point in the echo area
|
|
||||||
when moving between chunks. Unlike other blaming commands, do
|
|
||||||
not turn on `read-only-mode'."
|
|
||||||
:if (lambda ()
|
|
||||||
(and buffer-file-name
|
|
||||||
(or (not magit-blame-mode)
|
|
||||||
buffer-read-only)))
|
|
||||||
(interactive (list (magit-blame-arguments)))
|
|
||||||
(when magit-buffer-file-name
|
|
||||||
(user-error "Blob buffers aren't supported"))
|
|
||||||
(setq-local magit-blame--style
|
|
||||||
(assq magit-blame-echo-style magit-blame-styles))
|
|
||||||
(setq-local magit-blame-disable-modes
|
|
||||||
(cons 'eldoc-mode magit-blame-disable-modes))
|
|
||||||
(if (not magit-blame-mode)
|
|
||||||
(let ((magit-blame-read-only nil))
|
|
||||||
(magit-blame--pre-blame-assert 'addition)
|
|
||||||
(magit-blame--pre-blame-setup 'addition)
|
|
||||||
(magit-blame--run args))
|
|
||||||
(read-only-mode -1)
|
|
||||||
(magit-blame--update-overlays)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-blame-addition "magit-blame" nil t)
|
|
||||||
(define-suffix-command magit-blame-addition (args)
|
|
||||||
"For each line show the revision in which it was added."
|
|
||||||
(interactive (list (magit-blame-arguments)))
|
|
||||||
(magit-blame--pre-blame-assert 'addition)
|
|
||||||
(magit-blame--pre-blame-setup 'addition)
|
|
||||||
(magit-blame--run args))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-blame-removal "magit-blame" nil t)
|
|
||||||
(define-suffix-command magit-blame-removal (args)
|
|
||||||
"For each line show the revision in which it was removed."
|
|
||||||
:if-nil 'buffer-file-name
|
|
||||||
(interactive (list (magit-blame-arguments)))
|
|
||||||
(unless magit-buffer-file-name
|
|
||||||
(user-error "Only blob buffers can be blamed in reverse"))
|
|
||||||
(magit-blame--pre-blame-assert 'removal)
|
|
||||||
(magit-blame--pre-blame-setup 'removal)
|
|
||||||
(magit-blame--run args))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-blame-reverse "magit-blame" nil t)
|
|
||||||
(define-suffix-command magit-blame-reverse (args)
|
|
||||||
"For each line show the last revision in which it still exists."
|
|
||||||
:if-nil 'buffer-file-name
|
|
||||||
(interactive (list (magit-blame-arguments)))
|
|
||||||
(unless magit-buffer-file-name
|
|
||||||
(user-error "Only blob buffers can be blamed in reverse"))
|
|
||||||
(magit-blame--pre-blame-assert 'final)
|
|
||||||
(magit-blame--pre-blame-setup 'final)
|
|
||||||
(magit-blame--run args))
|
|
||||||
|
|
||||||
(defun magit-blame--pre-blame-assert (type)
|
|
||||||
(unless (magit-toplevel)
|
|
||||||
(magit--not-inside-repository-error))
|
|
||||||
(if (and magit-blame-mode
|
|
||||||
(eq type magit-blame-type))
|
|
||||||
(if-let ((chunk (magit-current-blame-chunk)))
|
|
||||||
(unless (oref chunk prev-rev)
|
|
||||||
(user-error "Chunk has no further history"))
|
|
||||||
(user-error "Commit data not available yet. Still blaming."))
|
|
||||||
(unless (magit-file-relative-name nil (not magit-buffer-file-name))
|
|
||||||
(if buffer-file-name
|
|
||||||
(user-error "Buffer isn't visiting a tracked file")
|
|
||||||
(user-error "Buffer isn't visiting a file")))))
|
|
||||||
|
|
||||||
(defun magit-blame--pre-blame-setup (type)
|
|
||||||
(when magit-blame-mode
|
|
||||||
(if (eq type magit-blame-type)
|
|
||||||
(let ((style magit-blame--style))
|
|
||||||
(magit-blame-visit-other-file)
|
|
||||||
(setq-local magit-blame--style style)
|
|
||||||
(setq-local magit-blame-recursive-p t)
|
|
||||||
;; Set window-start for the benefit of quickstart.
|
|
||||||
(redisplay))
|
|
||||||
(magit-blame--remove-overlays)))
|
|
||||||
(setq magit-blame-type type))
|
|
||||||
|
|
||||||
(defun magit-blame-visit-other-file ()
|
|
||||||
"Visit another blob related to the current chunk."
|
|
||||||
(interactive)
|
|
||||||
(with-slots (prev-rev prev-file orig-line)
|
|
||||||
(magit-current-blame-chunk)
|
|
||||||
(unless prev-rev
|
|
||||||
(user-error "Chunk has no further history"))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-find-file prev-rev prev-file))
|
|
||||||
;; TODO Adjust line like magit-diff-visit-file.
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- orig-line))))
|
|
||||||
|
|
||||||
(defun magit-blame-visit-file ()
|
|
||||||
"Visit the blob related to the current chunk."
|
|
||||||
(interactive)
|
|
||||||
(with-slots (orig-rev orig-file orig-line)
|
|
||||||
(magit-current-blame-chunk)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-find-file orig-rev orig-file))
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- orig-line))))
|
|
||||||
|
|
||||||
(define-suffix-command magit-blame-quit ()
|
|
||||||
"Turn off Magit-Blame mode.
|
|
||||||
If the buffer was created during a recursive blame,
|
|
||||||
then also kill the buffer."
|
|
||||||
:if-non-nil 'magit-blame-mode
|
|
||||||
(interactive)
|
|
||||||
(magit-blame-mode -1)
|
|
||||||
(when magit-blame-recursive-p
|
|
||||||
(kill-buffer)))
|
|
||||||
|
|
||||||
(defun magit-blame-next-chunk ()
|
|
||||||
"Move to the next chunk."
|
|
||||||
(interactive)
|
|
||||||
(--if-let (next-single-char-property-change (point) 'magit-blame-chunk)
|
|
||||||
(goto-char it)
|
|
||||||
(user-error "No more chunks")))
|
|
||||||
|
|
||||||
(defun magit-blame-previous-chunk ()
|
|
||||||
"Move to the previous chunk."
|
|
||||||
(interactive)
|
|
||||||
(--if-let (previous-single-char-property-change (point) 'magit-blame-chunk)
|
|
||||||
(goto-char it)
|
|
||||||
(user-error "No more chunks")))
|
|
||||||
|
|
||||||
(defun magit-blame-next-chunk-same-commit (&optional previous)
|
|
||||||
"Move to the next chunk from the same commit.\n\n(fn)"
|
|
||||||
(interactive)
|
|
||||||
(if-let ((rev (oref (magit-current-blame-chunk) orig-rev)))
|
|
||||||
(let ((pos (point)) ov)
|
|
||||||
(save-excursion
|
|
||||||
(while (and (not ov)
|
|
||||||
(not (= pos (if previous (point-min) (point-max))))
|
|
||||||
(setq pos (funcall
|
|
||||||
(if previous
|
|
||||||
'previous-single-char-property-change
|
|
||||||
'next-single-char-property-change)
|
|
||||||
pos 'magit-blame-chunk)))
|
|
||||||
(--when-let (magit-blame--overlay-at pos)
|
|
||||||
(when (equal (oref (magit-blame-chunk-at pos) orig-rev) rev)
|
|
||||||
(setq ov it)))))
|
|
||||||
(if ov
|
|
||||||
(goto-char (overlay-start ov))
|
|
||||||
(user-error "No more chunks from same commit")))
|
|
||||||
(user-error "This chunk hasn't been blamed yet")))
|
|
||||||
|
|
||||||
(defun magit-blame-previous-chunk-same-commit ()
|
|
||||||
"Move to the previous chunk from the same commit."
|
|
||||||
(interactive)
|
|
||||||
(magit-blame-next-chunk-same-commit 'previous-single-char-property-change))
|
|
||||||
|
|
||||||
(defun magit-blame-cycle-style ()
|
|
||||||
"Change how blame information is visualized.
|
|
||||||
Cycle through the elements of option `magit-blame-styles'."
|
|
||||||
(interactive)
|
|
||||||
(setq magit-blame--style
|
|
||||||
(or (cadr (cl-member (car magit-blame--style)
|
|
||||||
magit-blame-styles :key #'car))
|
|
||||||
(car magit-blame-styles)))
|
|
||||||
(magit-blame--update-margin)
|
|
||||||
(magit-blame--update-overlays))
|
|
||||||
|
|
||||||
(defun magit-blame-copy-hash ()
|
|
||||||
"Save hash of the current chunk's commit to the kill ring.
|
|
||||||
|
|
||||||
When the region is active, then save the region's content
|
|
||||||
instead of the hash, like `kill-ring-save' would."
|
|
||||||
(interactive)
|
|
||||||
(if (use-region-p)
|
|
||||||
(call-interactively #'copy-region-as-kill)
|
|
||||||
(kill-new (message "%s" (oref (magit-current-blame-chunk) orig-rev)))))
|
|
||||||
|
|
||||||
;;; Popup
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-blame "magit-blame" nil t)
|
|
||||||
(define-transient-command magit-blame ()
|
|
||||||
"Show the commits that added or removed lines in the visited file."
|
|
||||||
:man-page "git-blame"
|
|
||||||
:value '("-w")
|
|
||||||
["Arguments"
|
|
||||||
("-w" "Ignore whitespace" "-w")
|
|
||||||
("-r" "Do not treat root commits as boundaries" "--root")
|
|
||||||
(magit-blame:-M)
|
|
||||||
(magit-blame:-C)]
|
|
||||||
["Actions"
|
|
||||||
("b" "Show commits adding lines" magit-blame-addition)
|
|
||||||
("r" "Show commits removing lines" magit-blame-removal)
|
|
||||||
("f" "Show last commits that still have lines" magit-blame-reverse)
|
|
||||||
("m" "Blame echo" magit-blame-echo)
|
|
||||||
("q" "Quit blaming" magit-blame-quit)]
|
|
||||||
["Refresh"
|
|
||||||
:if-non-nil magit-blame-mode
|
|
||||||
("c" "Cycle style" magit-blame-cycle-style)])
|
|
||||||
|
|
||||||
(defun magit-blame-arguments ()
|
|
||||||
(transient-args 'magit-blame))
|
|
||||||
|
|
||||||
(define-infix-argument magit-blame:-M ()
|
|
||||||
:description "Detect lines moved or copied within a file"
|
|
||||||
:class 'transient-option
|
|
||||||
:argument "-M"
|
|
||||||
:reader 'transient-read-number-N+)
|
|
||||||
|
|
||||||
(define-infix-argument magit-blame:-C ()
|
|
||||||
:description "Detect lines moved or copied between files"
|
|
||||||
:class 'transient-option
|
|
||||||
:argument "-C"
|
|
||||||
:reader 'transient-read-number-N+)
|
|
||||||
|
|
||||||
;;; Utilities
|
|
||||||
|
|
||||||
(defun magit-blame-maybe-update-revision-buffer ()
|
|
||||||
(when-let ((chunk (magit-current-blame-chunk))
|
|
||||||
(commit (oref chunk orig-rev))
|
|
||||||
(buffer (magit-get-mode-buffer 'magit-revision-mode nil t)))
|
|
||||||
(if magit--update-revision-buffer
|
|
||||||
(setq magit--update-revision-buffer (list commit buffer))
|
|
||||||
(setq magit--update-revision-buffer (list commit buffer))
|
|
||||||
(run-with-idle-timer
|
|
||||||
magit-update-other-window-delay nil
|
|
||||||
(lambda ()
|
|
||||||
(pcase-let ((`(,rev ,buf) magit--update-revision-buffer))
|
|
||||||
(setq magit--update-revision-buffer nil)
|
|
||||||
(when (buffer-live-p buf)
|
|
||||||
(let ((magit-display-buffer-noselect t))
|
|
||||||
(apply #'magit-show-commit rev
|
|
||||||
(magit-diff-arguments 'magit-revision-mode))))))))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-blame)
|
|
||||||
;;; magit-blame.el ends here
|
|
Binary file not shown.
|
@ -1,203 +0,0 @@
|
||||||
;;; magit-bookmark.el --- bookmark support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Inspired by an earlier implementation by Yuri Khan.
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Support for bookmarks for most Magit buffers.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'bookmark)
|
|
||||||
|
|
||||||
;;; Core
|
|
||||||
|
|
||||||
(defun magit--make-bookmark ()
|
|
||||||
"Create a bookmark for the current Magit buffer.
|
|
||||||
Input values are the major-mode's `magit-bookmark-name' method,
|
|
||||||
and the buffer-local values of the variables referenced in its
|
|
||||||
`magit-bookmark-variables' property."
|
|
||||||
(if (plist-member (symbol-plist major-mode) 'magit-bookmark-variables)
|
|
||||||
(let ((bookmark (bookmark-make-record-default 'no-file)))
|
|
||||||
(bookmark-prop-set bookmark 'handler 'magit--handle-bookmark)
|
|
||||||
(bookmark-prop-set bookmark 'mode major-mode)
|
|
||||||
(bookmark-prop-set bookmark 'filename (magit-toplevel))
|
|
||||||
(bookmark-prop-set bookmark 'defaults (list (magit-bookmark-name)))
|
|
||||||
(dolist (var (get major-mode 'magit-bookmark-variables))
|
|
||||||
(bookmark-prop-set bookmark var (symbol-value var)))
|
|
||||||
(bookmark-prop-set
|
|
||||||
bookmark 'magit-hidden-sections
|
|
||||||
(--keep (and (oref it hidden)
|
|
||||||
(cons (oref it type)
|
|
||||||
(if (derived-mode-p 'magit-stash-mode)
|
|
||||||
(replace-regexp-in-string
|
|
||||||
(regexp-quote magit-buffer-revision)
|
|
||||||
magit-buffer-revision-hash
|
|
||||||
(oref it value))
|
|
||||||
(oref it value))))
|
|
||||||
(oref magit-root-section children)))
|
|
||||||
bookmark)
|
|
||||||
(user-error "Bookmarking is not implemented for %s buffers" major-mode)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit--handle-bookmark (bookmark)
|
|
||||||
"Open a bookmark created by `magit--make-bookmark'.
|
|
||||||
Call the `magit-*-setup-buffer' function of the the major-mode
|
|
||||||
with the variables' values as arguments, which were recorded by
|
|
||||||
`magit--make-bookmark'. Ignore `magit-display-buffer-function'."
|
|
||||||
(let ((buffer (let ((default-directory (bookmark-get-filename bookmark))
|
|
||||||
(mode (bookmark-prop-get bookmark 'mode))
|
|
||||||
(magit-display-buffer-function #'identity)
|
|
||||||
(magit-display-buffer-noselect t))
|
|
||||||
(apply (intern (format "%s-setup-buffer"
|
|
||||||
(substring (symbol-name mode) 0 -5)))
|
|
||||||
(--map (bookmark-prop-get bookmark it)
|
|
||||||
(get mode 'magit-bookmark-variables))))))
|
|
||||||
(set-buffer buffer) ; That is the interface we have to adhere to.
|
|
||||||
(when-let ((hidden (bookmark-prop-get bookmark 'magit-hidden-sections)))
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(dolist (child (oref magit-root-section children))
|
|
||||||
(if (member (cons (oref child type)
|
|
||||||
(oref child value))
|
|
||||||
hidden)
|
|
||||||
(magit-section-hide child)
|
|
||||||
(magit-section-show child)))))
|
|
||||||
nil))
|
|
||||||
|
|
||||||
(cl-defgeneric magit-bookmark-name ()
|
|
||||||
"Return name for bookmark to current buffer."
|
|
||||||
(format "%s%s"
|
|
||||||
(substring (symbol-name major-mode) 0 -5)
|
|
||||||
(if-let ((vars (get major-mode 'magit-bookmark-variables)))
|
|
||||||
(cl-mapcan (lambda (var)
|
|
||||||
(let ((val (symbol-value var)))
|
|
||||||
(if (and val (atom val))
|
|
||||||
(list val)
|
|
||||||
val)))
|
|
||||||
vars)
|
|
||||||
"")))
|
|
||||||
|
|
||||||
;;; Diff
|
|
||||||
;;;; Diff
|
|
||||||
|
|
||||||
(put 'magit-diff-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-range-hashed
|
|
||||||
magit-buffer-typearg
|
|
||||||
magit-buffer-diff-args
|
|
||||||
magit-buffer-diff-files))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-diff-mode))
|
|
||||||
(format "magit-diff(%s%s)"
|
|
||||||
(pcase (magit-diff-type)
|
|
||||||
(`staged "staged")
|
|
||||||
(`unstaged "unstaged")
|
|
||||||
(`committed magit-buffer-range)
|
|
||||||
(`undefined
|
|
||||||
(delq nil (list magit-buffer-typearg magit-buffer-range-hashed))))
|
|
||||||
(if magit-buffer-diff-files
|
|
||||||
(concat " -- " (mapconcat #'identity magit-buffer-diff-files " "))
|
|
||||||
"")))
|
|
||||||
|
|
||||||
;;;; Revision
|
|
||||||
|
|
||||||
(put 'magit-revision-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-revision-hash
|
|
||||||
magit-buffer-diff-args
|
|
||||||
magit-buffer-diff-files))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-revision-mode))
|
|
||||||
(format "magit-revision(%s %s)"
|
|
||||||
(magit-rev-abbrev magit-buffer-revision)
|
|
||||||
(if magit-buffer-diff-files
|
|
||||||
(mapconcat #'identity magit-buffer-diff-files " ")
|
|
||||||
(magit-rev-format "%s" magit-buffer-revision))))
|
|
||||||
|
|
||||||
;;;; Stash
|
|
||||||
|
|
||||||
(put 'magit-stash-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-revision-hash
|
|
||||||
magit-buffer-diff-args
|
|
||||||
magit-buffer-diff-files))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-stash-mode))
|
|
||||||
(format "magit-stash(%s %s)"
|
|
||||||
(magit-rev-abbrev magit-buffer-revision)
|
|
||||||
(if magit-buffer-diff-files
|
|
||||||
(mapconcat #'identity magit-buffer-diff-files " ")
|
|
||||||
(magit-rev-format "%s" magit-buffer-revision))))
|
|
||||||
|
|
||||||
;;; Log
|
|
||||||
;;;; Log
|
|
||||||
|
|
||||||
(put 'magit-log-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-revisions
|
|
||||||
magit-buffer-log-args
|
|
||||||
magit-buffer-log-files))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-log-mode))
|
|
||||||
(format "magit-log(%s%s)"
|
|
||||||
(mapconcat #'identity magit-buffer-revisions " ")
|
|
||||||
(if magit-buffer-log-files
|
|
||||||
(concat " -- " (mapconcat #'identity magit-buffer-log-files " "))
|
|
||||||
"")))
|
|
||||||
|
|
||||||
;;;; Cherry
|
|
||||||
|
|
||||||
(put 'magit-cherry-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-refname
|
|
||||||
magit-buffer-upstream))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-cherry-mode))
|
|
||||||
(format "magit-cherry(%s > %s)"
|
|
||||||
magit-buffer-refname
|
|
||||||
magit-buffer-upstream))
|
|
||||||
|
|
||||||
;;;; Reflog
|
|
||||||
|
|
||||||
(put 'magit-reflog-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-refname))
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-reflog-mode))
|
|
||||||
(format "magit-reflog(%s)" magit-buffer-refname))
|
|
||||||
|
|
||||||
;;; Misc
|
|
||||||
|
|
||||||
(put 'magit-status-mode 'magit-bookmark-variables nil)
|
|
||||||
|
|
||||||
(put 'magit-refs-mode 'magit-bookmark-variables
|
|
||||||
'(magit-buffer-upstream
|
|
||||||
magit-buffer-arguments))
|
|
||||||
|
|
||||||
(put 'magit-stashes-mode 'magit-bookmark-variables nil)
|
|
||||||
|
|
||||||
(cl-defmethod magit-bookmark-name (&context (major-mode magit-stashes-mode))
|
|
||||||
(format "magit-states(%s)" magit-buffer-refname))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-bookmark)
|
|
||||||
;;; magit-bookmark.el ends here
|
|
Binary file not shown.
|
@ -1,887 +0,0 @@
|
||||||
;;; magit-branch.el --- branch support -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for branches. It defines commands
|
|
||||||
;; for creating, checking out, manipulating, and configuring branches.
|
|
||||||
;; Commands defined here are mainly concerned with branches as
|
|
||||||
;; pointers, commands that deal with what a branch points at, are
|
|
||||||
;; defined elsewhere.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'magit-reset)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-branch-read-upstream-first t
|
|
||||||
"Whether to read upstream before name of new branch when creating a branch.
|
|
||||||
|
|
||||||
`nil' Read the branch name first.
|
|
||||||
`t' Read the upstream first.
|
|
||||||
`fallback' Read the upstream first, but if it turns out that the chosen
|
|
||||||
value is not a valid upstream (because it cannot be resolved
|
|
||||||
as an existing revision), then treat it as the name of the
|
|
||||||
new branch and continue by reading the upstream next."
|
|
||||||
:package-version '(magit . "2.2.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "read branch name first" nil)
|
|
||||||
(const :tag "read upstream first" t)
|
|
||||||
(const :tag "read upstream first, with fallback" fallback)))
|
|
||||||
|
|
||||||
(defcustom magit-branch-prefer-remote-upstream nil
|
|
||||||
"Whether to favor remote upstreams when creating new branches.
|
|
||||||
|
|
||||||
When a new branch is created, then the branch, commit, or stash
|
|
||||||
at point is suggested as the default starting point of the new
|
|
||||||
branch, or if there is no such revision at point the current
|
|
||||||
branch. In either case the user may choose another starting
|
|
||||||
point.
|
|
||||||
|
|
||||||
If the chosen starting point is a branch, then it may also be set
|
|
||||||
as the upstream of the new branch, depending on the value of the
|
|
||||||
Git variable `branch.autoSetupMerge'. By default this is done
|
|
||||||
for remote branches, but not for local branches.
|
|
||||||
|
|
||||||
You might prefer to always use some remote branch as upstream.
|
|
||||||
If the chosen starting point is (1) a local branch, (2) whose
|
|
||||||
name matches a member of the value of this option, (3) the
|
|
||||||
upstream of that local branch is a remote branch with the same
|
|
||||||
name, and (4) that remote branch can be fast-forwarded to the
|
|
||||||
local branch, then the chosen branch is used as starting point,
|
|
||||||
but its own upstream is used as the upstream of the new branch.
|
|
||||||
|
|
||||||
Members of this option's value are treated as branch names that
|
|
||||||
have to match exactly unless they contain a character that makes
|
|
||||||
them invalid as a branch name. Recommended characters to use
|
|
||||||
to trigger interpretation as a regexp are \"*\" and \"^\". Some
|
|
||||||
other characters which you might expect to be invalid, actually
|
|
||||||
are not, e.g. \".+$\" are all perfectly valid. More precisely,
|
|
||||||
if `git check-ref-format --branch STRING' exits with a non-zero
|
|
||||||
status, then treat STRING as a regexp.
|
|
||||||
|
|
||||||
Assuming the chosen branch matches these conditions you would end
|
|
||||||
up with with e.g.:
|
|
||||||
|
|
||||||
feature --upstream--> origin/master
|
|
||||||
|
|
||||||
instead of
|
|
||||||
|
|
||||||
feature --upstream--> master --upstream--> origin/master
|
|
||||||
|
|
||||||
Which you prefer is a matter of personal preference. If you do
|
|
||||||
prefer the former, then you should add branches such as \"master\",
|
|
||||||
\"next\", and \"maint\" to the value of this options."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(repeat string))
|
|
||||||
|
|
||||||
(defcustom magit-branch-adjust-remote-upstream-alist nil
|
|
||||||
"Alist of upstreams to be used when branching from remote branches.
|
|
||||||
|
|
||||||
When creating a local branch from an ephemeral branch located
|
|
||||||
on a remote, e.g. a feature or hotfix branch, then that remote
|
|
||||||
branch should usually not be used as the upstream branch, since
|
|
||||||
the push-remote already allows accessing it and having both the
|
|
||||||
upstream and the push-remote reference the same related branch
|
|
||||||
would be wasteful. Instead a branch like \"maint\" or \"master\"
|
|
||||||
should be used as the upstream.
|
|
||||||
|
|
||||||
This option allows specifying the branch that should be used as
|
|
||||||
the upstream when branching certain remote branches. The value
|
|
||||||
is an alist of the form ((UPSTREAM . RULE)...). The first
|
|
||||||
matching element is used, the following elements are ignored.
|
|
||||||
|
|
||||||
UPSTREAM is the branch to be used as the upstream for branches
|
|
||||||
specified by RULE. It can be a local or a remote branch.
|
|
||||||
|
|
||||||
RULE can either be a regular expression, matching branches whose
|
|
||||||
upstream should be the one specified by UPSTREAM. Or it can be
|
|
||||||
a list of the only branches that should *not* use UPSTREAM; all
|
|
||||||
other branches will. Matching is done after stripping the remote
|
|
||||||
part of the name of the branch that is being branched from.
|
|
||||||
|
|
||||||
If you use a finite set of non-ephemeral branches across all your
|
|
||||||
repositories, then you might use something like:
|
|
||||||
|
|
||||||
((\"origin/master\" \"master\" \"next\" \"maint\"))
|
|
||||||
|
|
||||||
Or if the names of all your ephemeral branches contain a slash,
|
|
||||||
at least in some repositories, then a good value could be:
|
|
||||||
|
|
||||||
((\"origin/master\" . \"/\"))
|
|
||||||
|
|
||||||
Of course you can also fine-tune:
|
|
||||||
|
|
||||||
((\"origin/maint\" . \"\\\\\\=`hotfix/\")
|
|
||||||
(\"origin/master\" . \"\\\\\\=`feature/\"))
|
|
||||||
|
|
||||||
If you use remote branches as UPSTREAM, then you might also want
|
|
||||||
to set `magit-branch-prefer-remote-upstream' to a non-nil value.
|
|
||||||
However, I recommend that you use local branches as UPSTREAM."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(repeat (cons (string :tag "Use upstream")
|
|
||||||
(choice :tag "for branches"
|
|
||||||
(regexp :tag "matching")
|
|
||||||
(repeat :tag "except"
|
|
||||||
(string :tag "branch"))))))
|
|
||||||
|
|
||||||
(defcustom magit-branch-rename-push-target t
|
|
||||||
"Whether the push-remote setup is preserved when renaming a branch.
|
|
||||||
|
|
||||||
The command `magit-branch-rename' renames a branch named OLD to
|
|
||||||
NEW. This option controls how much of the push-remote setup is
|
|
||||||
preserved when doing so.
|
|
||||||
|
|
||||||
When nil, then preserve nothing and unset `branch.OLD.pushRemote'.
|
|
||||||
|
|
||||||
When `local-only', then first set `branch.NEW.pushRemote' to the
|
|
||||||
same value as `branch.OLD.pushRemote', provided the latter is
|
|
||||||
actually set and unless the former already has another value.
|
|
||||||
|
|
||||||
When t, then rename the branch named OLD on the remote specified
|
|
||||||
by `branch.OLD.pushRemote' to NEW, provided OLD exists on that
|
|
||||||
remote and unless NEW already exists on the remote.
|
|
||||||
|
|
||||||
When `forge-only' and the `forge' package is available, then
|
|
||||||
behave like `t' if the remote points to a repository on a forge
|
|
||||||
(currently Github or Gitlab), otherwise like `local-only'.
|
|
||||||
|
|
||||||
Another supported but obsolete value is `github-only'. It is a
|
|
||||||
misnomer because it now treated as an alias for `forge-only'."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice
|
|
||||||
(const :tag "Don't preserve push-remote setup" nil)
|
|
||||||
(const :tag "Preserve push-remote setup" local-only)
|
|
||||||
(const :tag "... and rename corresponding branch on remote" t)
|
|
||||||
(const :tag "... but only if remote is on a forge" forge-only)))
|
|
||||||
|
|
||||||
(defcustom magit-branch-direct-configure t
|
|
||||||
"Whether the command `magit-branch' shows Git variables.
|
|
||||||
When set to nil, no variables are displayed by this transient
|
|
||||||
command, instead the sub-transient `magit-branch-configure'
|
|
||||||
has to be used to view and change branch related variables."
|
|
||||||
:package-version '(magit . "2.7.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-published-branches '("origin/master")
|
|
||||||
"List of branches that are considered to be published."
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(repeat string))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-branch "magit" nil t)
|
|
||||||
(define-transient-command magit-branch (branch)
|
|
||||||
"Add, configure or remove a branch."
|
|
||||||
:man-page "git-branch"
|
|
||||||
["Variables"
|
|
||||||
:if (lambda ()
|
|
||||||
(and magit-branch-direct-configure
|
|
||||||
(oref transient--prefix scope)))
|
|
||||||
("d" magit-branch.<branch>.description)
|
|
||||||
("u" magit-branch.<branch>.merge/remote)
|
|
||||||
("r" magit-branch.<branch>.rebase)
|
|
||||||
("p" magit-branch.<branch>.pushRemote)]
|
|
||||||
[["Checkout"
|
|
||||||
("b" "branch/revision" magit-checkout)
|
|
||||||
("l" "local branch" magit-branch-checkout)
|
|
||||||
(6 "o" "new orphan" magit-branch-orphan)]
|
|
||||||
[""
|
|
||||||
("c" "new branch" magit-branch-and-checkout)
|
|
||||||
("s" "new spin-off" magit-branch-spinoff)
|
|
||||||
(5 "w" "new worktree" magit-worktree-checkout)]
|
|
||||||
["Create"
|
|
||||||
("n" "new branch" magit-branch-create)
|
|
||||||
("S" "new spin-out" magit-branch-spinout)
|
|
||||||
(5 "W" "new worktree" magit-worktree-branch)]
|
|
||||||
["Do"
|
|
||||||
("C" "configure..." magit-branch-configure)
|
|
||||||
("m" "rename" magit-branch-rename)
|
|
||||||
("x" "reset" magit-branch-reset)
|
|
||||||
("k" "delete" magit-branch-delete)]
|
|
||||||
[""
|
|
||||||
(7 "h" "shelve" magit-branch-shelve)
|
|
||||||
(7 "H" "unshelve" magit-branch-unshelve)]]
|
|
||||||
(interactive (list (magit-get-current-branch)))
|
|
||||||
(transient-setup 'magit-branch nil nil :scope branch))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-checkout (revision)
|
|
||||||
"Checkout REVISION, updating the index and the working tree.
|
|
||||||
If REVISION is a local branch, then that becomes the current
|
|
||||||
branch. If it is something else, then `HEAD' becomes detached.
|
|
||||||
Checkout fails if the working tree or the staging area contain
|
|
||||||
changes.
|
|
||||||
\n(git checkout REVISION)."
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Checkout")))
|
|
||||||
(when (string-match "\\`heads/\\(.+\\)" revision)
|
|
||||||
(setq revision (match-string 1 revision)))
|
|
||||||
(magit-run-git "checkout" revision))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-create (branch start-point)
|
|
||||||
"Create BRANCH at branch or revision START-POINT."
|
|
||||||
(interactive (magit-branch-read-args "Create branch"))
|
|
||||||
(magit-call-git "branch" branch start-point)
|
|
||||||
(magit-branch-maybe-adjust-upstream branch start-point)
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-and-checkout (branch start-point)
|
|
||||||
"Create and checkout BRANCH at branch or revision START-POINT."
|
|
||||||
(interactive (magit-branch-read-args "Create and checkout branch"))
|
|
||||||
(if (string-match-p "^stash@{[0-9]+}$" start-point)
|
|
||||||
(magit-run-git "stash" "branch" branch start-point)
|
|
||||||
(magit-call-git "checkout" "-b" branch start-point)
|
|
||||||
(magit-branch-maybe-adjust-upstream branch start-point)
|
|
||||||
(magit-refresh)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-or-checkout (arg &optional start-point)
|
|
||||||
"Hybrid between `magit-checkout' and `magit-branch-and-checkout'.
|
|
||||||
|
|
||||||
Ask the user for an existing branch or revision. If the user
|
|
||||||
input actually can be resolved as a branch or revision, then
|
|
||||||
check that out, just like `magit-checkout' would.
|
|
||||||
|
|
||||||
Otherwise create and checkout a new branch using the input as
|
|
||||||
its name. Before doing so read the starting-point for the new
|
|
||||||
branch. This is similar to what `magit-branch-and-checkout'
|
|
||||||
does."
|
|
||||||
(interactive
|
|
||||||
(let ((arg (magit-read-other-branch-or-commit "Checkout")))
|
|
||||||
(list arg
|
|
||||||
(and (not (magit-commit-p arg))
|
|
||||||
(magit-read-starting-point "Create and checkout branch" arg)))))
|
|
||||||
(when (string-match "\\`heads/\\(.+\\)" arg)
|
|
||||||
(setq arg (match-string 1 arg)))
|
|
||||||
(if start-point
|
|
||||||
(magit-branch-and-checkout arg start-point)
|
|
||||||
(magit-checkout arg)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-checkout (branch &optional start-point)
|
|
||||||
"Checkout an existing or new local branch.
|
|
||||||
|
|
||||||
Read a branch name from the user offering all local branches and
|
|
||||||
a subset of remote branches as candidates. Omit remote branches
|
|
||||||
for which a local branch by the same name exists from the list
|
|
||||||
of candidates. The user can also enter a completely new branch
|
|
||||||
name.
|
|
||||||
|
|
||||||
- If the user selects an existing local branch, then check that
|
|
||||||
out.
|
|
||||||
|
|
||||||
- If the user selects a remote branch, then create and checkout
|
|
||||||
a new local branch with the same name. Configure the selected
|
|
||||||
remote branch as push target.
|
|
||||||
|
|
||||||
- If the user enters a new branch name, then create and check
|
|
||||||
that out, after also reading the starting-point from the user.
|
|
||||||
|
|
||||||
In the latter two cases the upstream is also set. Whether it is
|
|
||||||
set to the chosen START-POINT or something else depends on the
|
|
||||||
value of `magit-branch-adjust-remote-upstream-alist', just like
|
|
||||||
when using `magit-branch-and-checkout'."
|
|
||||||
(interactive
|
|
||||||
(let* ((current (magit-get-current-branch))
|
|
||||||
(local (magit-list-local-branch-names))
|
|
||||||
(remote (--filter (and (string-match "[^/]+/" it)
|
|
||||||
(not (member (substring it (match-end 0))
|
|
||||||
(cons "HEAD" local))))
|
|
||||||
(magit-list-remote-branch-names)))
|
|
||||||
(choices (nconc (delete current local) remote))
|
|
||||||
(atpoint (magit-branch-at-point))
|
|
||||||
(choice (magit-completing-read
|
|
||||||
"Checkout branch" choices
|
|
||||||
nil nil nil 'magit-revision-history
|
|
||||||
(or (car (member atpoint choices))
|
|
||||||
(and atpoint
|
|
||||||
(car (member (and (string-match "[^/]+/" atpoint)
|
|
||||||
(substring atpoint (match-end 0)))
|
|
||||||
choices)))))))
|
|
||||||
(cond ((member choice remote)
|
|
||||||
(list (and (string-match "[^/]+/" choice)
|
|
||||||
(substring choice (match-end 0)))
|
|
||||||
choice))
|
|
||||||
((member choice local)
|
|
||||||
(list choice))
|
|
||||||
(t
|
|
||||||
(list choice (magit-read-starting-point "Create" choice))))))
|
|
||||||
(if (not start-point)
|
|
||||||
(magit-checkout branch)
|
|
||||||
(when (magit-anything-modified-p)
|
|
||||||
(user-error "Cannot checkout when there are uncommitted changes"))
|
|
||||||
(magit-branch-and-checkout branch start-point)
|
|
||||||
(when (magit-remote-branch-p start-point)
|
|
||||||
(pcase-let ((`(,remote . ,remote-branch)
|
|
||||||
(magit-split-branch-name start-point)))
|
|
||||||
(when (and (equal branch remote-branch)
|
|
||||||
(not (equal remote (magit-get "remote.pushDefault"))))
|
|
||||||
(magit-set remote "branch" branch "pushRemote"))))))
|
|
||||||
|
|
||||||
(defun magit-branch-maybe-adjust-upstream (branch start-point)
|
|
||||||
(--when-let
|
|
||||||
(or (and (magit-get-upstream-branch branch)
|
|
||||||
(magit-get-indirect-upstream-branch start-point))
|
|
||||||
(and (magit-remote-branch-p start-point)
|
|
||||||
(let ((name (cdr (magit-split-branch-name start-point))))
|
|
||||||
(car (--first (if (listp (cdr it))
|
|
||||||
(not (member name (cdr it)))
|
|
||||||
(string-match-p (cdr it) name))
|
|
||||||
magit-branch-adjust-remote-upstream-alist)))))
|
|
||||||
(magit-call-git "branch" (concat "--set-upstream-to=" it) branch)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-orphan (branch start-point)
|
|
||||||
"Create and checkout an orphan BRANCH with contents from revision START-POINT."
|
|
||||||
(interactive (magit-branch-read-args "Create and checkout orphan branch"))
|
|
||||||
(magit-run-git "checkout" "--orphan" branch start-point))
|
|
||||||
|
|
||||||
(defun magit-branch-read-args (prompt &optional default-start)
|
|
||||||
(if magit-branch-read-upstream-first
|
|
||||||
(let ((choice (magit-read-starting-point prompt nil default-start)))
|
|
||||||
(if (magit-rev-verify choice)
|
|
||||||
(list (magit-read-string-ns
|
|
||||||
(if magit-completing-read--silent-default
|
|
||||||
(format "%s (starting at `%s')" prompt choice)
|
|
||||||
"Name for new branch")
|
|
||||||
(let ((def (mapconcat #'identity
|
|
||||||
(cdr (split-string choice "/"))
|
|
||||||
"/")))
|
|
||||||
(and (member choice (magit-list-remote-branch-names))
|
|
||||||
(not (member def (magit-list-local-branch-names)))
|
|
||||||
def)))
|
|
||||||
choice)
|
|
||||||
(if (eq magit-branch-read-upstream-first 'fallback)
|
|
||||||
(list choice
|
|
||||||
(magit-read-starting-point prompt choice default-start))
|
|
||||||
(user-error "Not a valid starting-point: %s" choice))))
|
|
||||||
(let ((branch (magit-read-string-ns (concat prompt " named"))))
|
|
||||||
(list branch (magit-read-starting-point prompt branch default-start)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-spinout (branch &optional from)
|
|
||||||
"Create new branch from the unpushed commits.
|
|
||||||
Like `magit-branch-spinoff' but remain on the current branch.
|
|
||||||
If there are any uncommitted changes, then behave exactly like
|
|
||||||
`magit-branch-spinoff'."
|
|
||||||
(interactive (list (magit-read-string-ns "Spin out branch")
|
|
||||||
(car (last (magit-region-values 'commit)))))
|
|
||||||
(magit--branch-spinoff branch from nil))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-spinoff (branch &optional from)
|
|
||||||
"Create new branch from the unpushed commits.
|
|
||||||
|
|
||||||
Create and checkout a new branch starting at and tracking the
|
|
||||||
current branch. That branch in turn is reset to the last commit
|
|
||||||
it shares with its upstream. If the current branch has no
|
|
||||||
upstream or no unpushed commits, then the new branch is created
|
|
||||||
anyway and the previously current branch is not touched.
|
|
||||||
|
|
||||||
This is useful to create a feature branch after work has already
|
|
||||||
began on the old branch (likely but not necessarily \"master\").
|
|
||||||
|
|
||||||
If the current branch is a member of the value of option
|
|
||||||
`magit-branch-prefer-remote-upstream' (which see), then the
|
|
||||||
current branch will be used as the starting point as usual, but
|
|
||||||
the upstream of the starting-point may be used as the upstream
|
|
||||||
of the new branch, instead of the starting-point itself.
|
|
||||||
|
|
||||||
If optional FROM is non-nil, then the source branch is reset
|
|
||||||
to `FROM~', instead of to the last commit it shares with its
|
|
||||||
upstream. Interactively, FROM is only ever non-nil, if the
|
|
||||||
region selects some commits, and among those commits, FROM is
|
|
||||||
the commit that is the fewest commits ahead of the source
|
|
||||||
branch.
|
|
||||||
|
|
||||||
The commit at the other end of the selection actually does not
|
|
||||||
matter, all commits between FROM and `HEAD' are moved to the new
|
|
||||||
branch. If FROM is not reachable from `HEAD' or is reachable
|
|
||||||
from the source branch's upstream, then an error is raised."
|
|
||||||
(interactive (list (magit-read-string-ns "Spin off branch")
|
|
||||||
(car (last (magit-region-values 'commit)))))
|
|
||||||
(magit--branch-spinoff branch from t))
|
|
||||||
|
|
||||||
(defun magit--branch-spinoff (branch from checkout)
|
|
||||||
(when (magit-branch-p branch)
|
|
||||||
(user-error "Cannot spin off %s. It already exists" branch))
|
|
||||||
(when (and (not checkout)
|
|
||||||
(magit-anything-modified-p))
|
|
||||||
(message "Staying on HEAD due to uncommitted changes")
|
|
||||||
(setq checkout t))
|
|
||||||
(if-let ((current (magit-get-current-branch)))
|
|
||||||
(let ((tracked (magit-get-upstream-branch current))
|
|
||||||
base)
|
|
||||||
(when from
|
|
||||||
(unless (magit-rev-ancestor-p from current)
|
|
||||||
(user-error "Cannot spin off %s. %s is not reachable from %s"
|
|
||||||
branch from current))
|
|
||||||
(when (and tracked
|
|
||||||
(magit-rev-ancestor-p from tracked))
|
|
||||||
(user-error "Cannot spin off %s. %s is ancestor of upstream %s"
|
|
||||||
branch from tracked)))
|
|
||||||
(let ((magit-process-raise-error t))
|
|
||||||
(if checkout
|
|
||||||
(magit-call-git "checkout" "-b" branch current)
|
|
||||||
(magit-call-git "branch" branch current)))
|
|
||||||
(--when-let (magit-get-indirect-upstream-branch current)
|
|
||||||
(magit-call-git "branch" "--set-upstream-to" it branch))
|
|
||||||
(when (and tracked
|
|
||||||
(setq base
|
|
||||||
(if from
|
|
||||||
(concat from "^")
|
|
||||||
(magit-git-string "merge-base" current tracked)))
|
|
||||||
(not (magit-rev-eq base current)))
|
|
||||||
(if checkout
|
|
||||||
(magit-call-git "update-ref" "-m"
|
|
||||||
(format "reset: moving to %s" base)
|
|
||||||
(concat "refs/heads/" current) base)
|
|
||||||
(magit-call-git "reset" "--hard" base))))
|
|
||||||
(if checkout
|
|
||||||
(magit-call-git "checkout" "-b" branch)
|
|
||||||
(magit-call-git "branch" branch)))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-reset (branch to &optional set-upstream)
|
|
||||||
"Reset a branch to the tip of another branch or any other commit.
|
|
||||||
|
|
||||||
When the branch being reset is the current branch, then do a
|
|
||||||
hard reset. If there are any uncommitted changes, then the user
|
|
||||||
has to confirm the reset because those changes would be lost.
|
|
||||||
|
|
||||||
This is useful when you have started work on a feature branch but
|
|
||||||
realize it's all crap and want to start over.
|
|
||||||
|
|
||||||
When resetting to another branch and a prefix argument is used,
|
|
||||||
then also set the target branch as the upstream of the branch
|
|
||||||
that is being reset."
|
|
||||||
(interactive
|
|
||||||
(let* ((atpoint (magit-local-branch-at-point))
|
|
||||||
(branch (magit-read-local-branch "Reset branch" atpoint)))
|
|
||||||
(list branch
|
|
||||||
(magit-completing-read (format "Reset %s to" branch)
|
|
||||||
(delete branch (magit-list-branch-names))
|
|
||||||
nil nil nil 'magit-revision-history
|
|
||||||
(or (and (not (equal branch atpoint)) atpoint)
|
|
||||||
(magit-get-upstream-branch branch)))
|
|
||||||
current-prefix-arg)))
|
|
||||||
(let ((inhibit-magit-refresh t))
|
|
||||||
(if (equal branch (magit-get-current-branch))
|
|
||||||
(if (and (magit-anything-modified-p)
|
|
||||||
(not (yes-or-no-p
|
|
||||||
"Uncommitted changes will be lost. Proceed? ")))
|
|
||||||
(user-error "Abort")
|
|
||||||
(magit-reset-hard to))
|
|
||||||
(magit-call-git "update-ref"
|
|
||||||
"-m" (format "reset: moving to %s" to)
|
|
||||||
(magit-git-string "rev-parse" "--symbolic-full-name"
|
|
||||||
branch)
|
|
||||||
to))
|
|
||||||
(when (and set-upstream (magit-branch-p to))
|
|
||||||
(magit-set-upstream-branch branch to)
|
|
||||||
(magit-branch-maybe-adjust-upstream branch to)))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-delete (branches &optional force)
|
|
||||||
"Delete one or multiple branches.
|
|
||||||
If the region marks multiple branches, then offer to delete
|
|
||||||
those, otherwise prompt for a single branch to be deleted,
|
|
||||||
defaulting to the branch at point."
|
|
||||||
;; One would expect this to be a command as simple as, for example,
|
|
||||||
;; `magit-branch-rename'; but it turns out everyone wants to squeeze
|
|
||||||
;; a bit of extra functionality into this one, including myself.
|
|
||||||
(interactive
|
|
||||||
(let ((branches (magit-region-values 'branch t))
|
|
||||||
(force current-prefix-arg))
|
|
||||||
(if (> (length branches) 1)
|
|
||||||
(magit-confirm t nil "Delete %i branches" nil branches)
|
|
||||||
(setq branches
|
|
||||||
(list (magit-read-branch-prefer-other
|
|
||||||
(if force "Force delete branch" "Delete branch")))))
|
|
||||||
(unless force
|
|
||||||
(when-let ((unmerged (-remove #'magit-branch-merged-p branches)))
|
|
||||||
(if (magit-confirm 'delete-unmerged-branch
|
|
||||||
"Delete unmerged branch %s"
|
|
||||||
"Delete %i unmerged branches"
|
|
||||||
'noabort unmerged)
|
|
||||||
(setq force branches)
|
|
||||||
(or (setq branches (-difference branches unmerged))
|
|
||||||
(user-error "Abort")))))
|
|
||||||
(list branches force)))
|
|
||||||
(let* ((refs (mapcar #'magit-ref-fullname branches))
|
|
||||||
(ambiguous (--remove it refs)))
|
|
||||||
(when ambiguous
|
|
||||||
(user-error
|
|
||||||
"%s ambiguous. Please cleanup using git directly."
|
|
||||||
(let ((len (length ambiguous)))
|
|
||||||
(cond
|
|
||||||
((= len 1)
|
|
||||||
(format "%s is" (-first #'magit-ref-ambiguous-p branches)))
|
|
||||||
((= len (length refs))
|
|
||||||
(format "These %s names are" len))
|
|
||||||
(t
|
|
||||||
(format "%s of these names are" len))))))
|
|
||||||
(cond
|
|
||||||
((string-match "^refs/remotes/\\([^/]+\\)" (car refs))
|
|
||||||
(let* ((remote (match-string 1 (car refs)))
|
|
||||||
(offset (1+ (length remote))))
|
|
||||||
;; Assume the branches actually still exists on the remote.
|
|
||||||
(magit-run-git-async
|
|
||||||
"push" remote (--map (concat ":" (substring it offset)) branches))
|
|
||||||
;; If that is not the case, then this deletes the tracking branches.
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(apply-partially 'magit-delete-remote-branch-sentinel remote refs))))
|
|
||||||
((> (length branches) 1)
|
|
||||||
(setq branches (delete (magit-get-current-branch) branches))
|
|
||||||
(mapc 'magit-branch-maybe-delete-pr-remote branches)
|
|
||||||
(mapc 'magit-branch-unset-pushRemote branches)
|
|
||||||
(magit-run-git "branch" (if force "-D" "-d") branches))
|
|
||||||
(t ; And now for something completely different.
|
|
||||||
(let* ((branch (car branches))
|
|
||||||
(prompt (format "Branch %s is checked out. " branch)))
|
|
||||||
(when (equal branch (magit-get-current-branch))
|
|
||||||
(pcase (if (or (equal branch "master")
|
|
||||||
(not (magit-rev-verify "master")))
|
|
||||||
(magit-read-char-case prompt nil
|
|
||||||
(?d "[d]etach HEAD & delete" 'detach)
|
|
||||||
(?a "[a]bort" 'abort))
|
|
||||||
(magit-read-char-case prompt nil
|
|
||||||
(?d "[d]etach HEAD & delete" 'detach)
|
|
||||||
(?c "[c]heckout master & delete" 'master)
|
|
||||||
(?a "[a]bort" 'abort)))
|
|
||||||
(`detach (unless (or (equal force '(4))
|
|
||||||
(member branch force)
|
|
||||||
(magit-branch-merged-p branch t))
|
|
||||||
(magit-confirm 'delete-unmerged-branch
|
|
||||||
"Delete unmerged branch %s" ""
|
|
||||||
nil (list branch)))
|
|
||||||
(magit-call-git "checkout" "--detach"))
|
|
||||||
(`master (unless (or (equal force '(4))
|
|
||||||
(member branch force)
|
|
||||||
(magit-branch-merged-p branch "master"))
|
|
||||||
(magit-confirm 'delete-unmerged-branch
|
|
||||||
"Delete unmerged branch %s" ""
|
|
||||||
nil (list branch)))
|
|
||||||
(magit-call-git "checkout" "master"))
|
|
||||||
(`abort (user-error "Abort")))
|
|
||||||
(setq force t))
|
|
||||||
(magit-branch-maybe-delete-pr-remote branch)
|
|
||||||
(magit-branch-unset-pushRemote branch)
|
|
||||||
(magit-run-git "branch" (if force "-D" "-d") branch))))))
|
|
||||||
|
|
||||||
(put 'magit-branch-delete 'interactive-only t)
|
|
||||||
|
|
||||||
(defun magit-branch-maybe-delete-pr-remote (branch)
|
|
||||||
(when-let ((remote (magit-get "branch" branch "pullRequestRemote")))
|
|
||||||
(let* ((variable (format "remote.%s.fetch" remote))
|
|
||||||
(refspecs (magit-get-all variable)))
|
|
||||||
(unless (member (format "+refs/heads/*:refs/remotes/%s/*" remote)
|
|
||||||
refspecs)
|
|
||||||
(let ((refspec
|
|
||||||
(if (equal (magit-get "branch" branch "pushRemote") remote)
|
|
||||||
(format "+refs/heads/%s:refs/remotes/%s/%s"
|
|
||||||
branch remote branch)
|
|
||||||
(let ((merge (magit-get "branch" branch "merge")))
|
|
||||||
(and merge
|
|
||||||
(string-prefix-p "refs/heads/" merge)
|
|
||||||
(setq merge (substring merge 11))
|
|
||||||
(format "+refs/heads/%s:refs/remotes/%s/%s"
|
|
||||||
merge remote merge))))))
|
|
||||||
(when (member refspec refspecs)
|
|
||||||
(if (and (= (length refspecs) 1)
|
|
||||||
(magit-confirm 'delete-pr-remote
|
|
||||||
(format "Also delete remote %s (%s)" remote
|
|
||||||
"no pull-request branch remains")
|
|
||||||
nil t))
|
|
||||||
(magit-call-git "remote" "rm" remote)
|
|
||||||
(magit-call-git "config" "--unset-all" variable
|
|
||||||
(format "^%s$" (regexp-quote refspec))))))))))
|
|
||||||
|
|
||||||
(defun magit-branch-unset-pushRemote (branch)
|
|
||||||
(magit-set nil "branch" branch "pushRemote"))
|
|
||||||
|
|
||||||
(defun magit-delete-remote-branch-sentinel (remote refs process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (= (process-exit-status process) 1)
|
|
||||||
(if-let ((on-remote (--map (concat "refs/remotes/" remote "/" it)
|
|
||||||
(magit-remote-list-branches remote)))
|
|
||||||
(rest (--filter (and (not (member it on-remote))
|
|
||||||
(magit-ref-exists-p it))
|
|
||||||
refs)))
|
|
||||||
(progn
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(setq magit-this-error nil)
|
|
||||||
(message "Some remote branches no longer exist. %s"
|
|
||||||
"Deleting just the local tracking refs instead...")
|
|
||||||
(dolist (ref rest)
|
|
||||||
(magit-call-git "update-ref" "-d" ref))
|
|
||||||
(magit-refresh)
|
|
||||||
(message "Deleting local remote-tracking refs...done"))
|
|
||||||
(magit-process-sentinel process event))
|
|
||||||
(magit-process-sentinel process event))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-rename (old new &optional force)
|
|
||||||
"Rename the branch named OLD to NEW.
|
|
||||||
|
|
||||||
With a prefix argument FORCE, rename even if a branch named NEW
|
|
||||||
already exists.
|
|
||||||
|
|
||||||
If `branch.OLD.pushRemote' is set, then unset it. Depending on
|
|
||||||
the value of `magit-branch-rename-push-target' (which see) maybe
|
|
||||||
set `branch.NEW.pushRemote' and maybe rename the push-target on
|
|
||||||
the remote."
|
|
||||||
(interactive
|
|
||||||
(let ((branch (magit-read-local-branch "Rename branch")))
|
|
||||||
(list branch
|
|
||||||
(magit-read-string-ns (format "Rename branch '%s' to" branch)
|
|
||||||
nil 'magit-revision-history)
|
|
||||||
current-prefix-arg)))
|
|
||||||
(when (string-match "\\`heads/\\(.+\\)" old)
|
|
||||||
(setq old (match-string 1 old)))
|
|
||||||
(when (equal old new)
|
|
||||||
(user-error "Old and new branch names are the same"))
|
|
||||||
(magit-call-git "branch" (if force "-M" "-m") old new)
|
|
||||||
(when magit-branch-rename-push-target
|
|
||||||
(let ((remote (magit-get-push-remote old))
|
|
||||||
(old-specific (magit-get "branch" old "pushRemote"))
|
|
||||||
(new-specific (magit-get "branch" new "pushRemote")))
|
|
||||||
(when (and old-specific (or force (not new-specific)))
|
|
||||||
;; Keep the target setting branch specific, even if that is
|
|
||||||
;; redundant. But if a branch by the same name existed before
|
|
||||||
;; and the rename isn't forced, then do not change a leftover
|
|
||||||
;; setting. Such a leftover setting may or may not conform to
|
|
||||||
;; what we expect here...
|
|
||||||
(magit-set old-specific "branch" new "pushRemote"))
|
|
||||||
(when (and (equal (magit-get-push-remote new) remote)
|
|
||||||
;; ...and if it does not, then we must abort.
|
|
||||||
(not (eq magit-branch-rename-push-target 'local-only))
|
|
||||||
(or (not (memq magit-branch-rename-push-target
|
|
||||||
'(forge-only github-only)))
|
|
||||||
(and (require (quote forge) nil t)
|
|
||||||
(fboundp 'forge--forge-remote-p)
|
|
||||||
(forge--forge-remote-p remote))))
|
|
||||||
(let ((old-target (magit-get-push-branch old t))
|
|
||||||
(new-target (magit-get-push-branch new t))
|
|
||||||
(remote (magit-get-push-remote new)))
|
|
||||||
(when (and old-target
|
|
||||||
(not new-target)
|
|
||||||
(magit-y-or-n-p (format "Also rename %S to %S on \"%s\""
|
|
||||||
old new remote)))
|
|
||||||
;; Rename on (i.e. within) the remote, but only if the
|
|
||||||
;; destination ref doesn't exist yet. If that ref already
|
|
||||||
;; exists, then it probably is of some value and we better
|
|
||||||
;; not touch it. Ignore what the local ref points at,
|
|
||||||
;; i.e. if the local and the remote ref didn't point at
|
|
||||||
;; the same commit before the rename then keep it that way.
|
|
||||||
(magit-call-git "push" "-v" remote
|
|
||||||
(format "%s:refs/heads/%s" old-target new)
|
|
||||||
(format ":refs/heads/%s" old)))))))
|
|
||||||
(magit-branch-unset-pushRemote old)
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-shelve (branch)
|
|
||||||
"Shelve a BRANCH.
|
|
||||||
Rename \"refs/heads/BRANCH\" to \"refs/shelved/BRANCH\",
|
|
||||||
and also rename the respective reflog file."
|
|
||||||
(interactive (list (magit-read-other-local-branch "Shelve branch")))
|
|
||||||
(let ((old (concat "refs/heads/" branch))
|
|
||||||
(new (concat "refs/shelved/" branch)))
|
|
||||||
(magit-git "update-ref" new old "")
|
|
||||||
(magit--rename-reflog-file old new)
|
|
||||||
(magit-branch-unset-pushRemote branch)
|
|
||||||
(magit-run-git "branch" "-D" branch)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-branch-unshelve (branch)
|
|
||||||
"Unshelve a BRANCH
|
|
||||||
Rename \"refs/shelved/BRANCH\" to \"refs/heads/BRANCH\",
|
|
||||||
and also rename the respective reflog file."
|
|
||||||
(interactive
|
|
||||||
(list (magit-completing-read
|
|
||||||
"Unshelve branch"
|
|
||||||
(--map (substring it 8)
|
|
||||||
(magit-list-refnames "refs/shelved"))
|
|
||||||
nil t)))
|
|
||||||
(let ((old (concat "refs/shelved/" branch))
|
|
||||||
(new (concat "refs/heads/" branch)))
|
|
||||||
(magit-git "update-ref" new old "")
|
|
||||||
(magit--rename-reflog-file old new)
|
|
||||||
(magit-run-git "update-ref" "-d" old)))
|
|
||||||
|
|
||||||
(defun magit--rename-reflog-file (old new)
|
|
||||||
(let ((old (magit-git-dir (concat "logs/" old)))
|
|
||||||
(new (magit-git-dir (concat "logs/" new))))
|
|
||||||
(when (file-exists-p old)
|
|
||||||
(make-directory (file-name-directory new) t)
|
|
||||||
(rename-file old new t))))
|
|
||||||
|
|
||||||
;;; Configure
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-branch-configure "magit-branch" nil t)
|
|
||||||
(define-transient-command magit-branch-configure (branch)
|
|
||||||
"Configure a branch."
|
|
||||||
:man-page "git-branch"
|
|
||||||
[:description
|
|
||||||
(lambda ()
|
|
||||||
(concat
|
|
||||||
(propertize "Configure " 'face 'transient-heading)
|
|
||||||
(propertize (oref transient--prefix scope) 'face 'magit-branch-local)))
|
|
||||||
("d" magit-branch.<branch>.description)
|
|
||||||
("u" magit-branch.<branch>.merge/remote)
|
|
||||||
("r" magit-branch.<branch>.rebase)
|
|
||||||
("p" magit-branch.<branch>.pushRemote)]
|
|
||||||
["Configure repository defaults"
|
|
||||||
("R" magit-pull.rebase)
|
|
||||||
("P" magit-remote.pushDefault)]
|
|
||||||
["Configure branch creation"
|
|
||||||
("a m" magit-branch.autoSetupMerge)
|
|
||||||
("a r" magit-branch.autoSetupRebase)]
|
|
||||||
(interactive
|
|
||||||
(list (or (and (not current-prefix-arg)
|
|
||||||
(not (and magit-branch-direct-configure
|
|
||||||
(eq current-transient-command 'magit-branch)))
|
|
||||||
(magit-get-current-branch))
|
|
||||||
(magit--read-branch-scope))))
|
|
||||||
(transient-setup 'magit-branch-configure nil nil :scope branch))
|
|
||||||
|
|
||||||
(defun magit--read-branch-scope (&optional obj)
|
|
||||||
(magit-read-local-branch
|
|
||||||
(if obj
|
|
||||||
(format "Set %s for branch"
|
|
||||||
(format (oref obj variable) "<name>"))
|
|
||||||
"Configure branch")))
|
|
||||||
|
|
||||||
(define-suffix-command magit-branch.<branch>.description (branch)
|
|
||||||
"Edit the description of BRANCH."
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:transient nil
|
|
||||||
:variable "branch.%s.description"
|
|
||||||
(interactive (list (oref current-transient-prefix scope)))
|
|
||||||
(magit-run-git-with-editor "branch" "--edit-description" branch))
|
|
||||||
|
|
||||||
(add-hook 'find-file-hook 'magit-branch-description-check-buffers)
|
|
||||||
|
|
||||||
(defun magit-branch-description-check-buffers ()
|
|
||||||
(and buffer-file-name
|
|
||||||
(string-match-p "/\\(BRANCH\\|EDIT\\)_DESCRIPTION\\'" buffer-file-name)))
|
|
||||||
|
|
||||||
(defclass magit--git-branch:upstream (magit--git-variable)
|
|
||||||
((format :initform " %k %m %M\n %r %R")))
|
|
||||||
|
|
||||||
(define-infix-command magit-branch.<branch>.merge/remote ()
|
|
||||||
:class 'magit--git-branch:upstream)
|
|
||||||
|
|
||||||
(cl-defmethod transient-init-value ((obj magit--git-branch:upstream))
|
|
||||||
(when-let ((branch (oref transient--prefix scope))
|
|
||||||
(remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge")))
|
|
||||||
(oset obj value (list remote merge))))
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-read ((obj magit--git-branch:upstream))
|
|
||||||
(if (oref obj value)
|
|
||||||
(oset obj value nil)
|
|
||||||
(magit-read-upstream-branch (oref transient--prefix scope) "Upstream")))
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-set ((obj magit--git-branch:upstream) refname)
|
|
||||||
(magit-set-upstream-branch (oref transient--prefix scope) refname)
|
|
||||||
(oset obj value
|
|
||||||
(let ((branch (oref transient--prefix scope)))
|
|
||||||
(when-let ((r (magit-get "branch" branch "remote"))
|
|
||||||
(m (magit-get "branch" branch "merge")))
|
|
||||||
(list r m))))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
(cl-defmethod transient-format ((obj magit--git-branch:upstream))
|
|
||||||
(let ((branch (oref transient--prefix scope)))
|
|
||||||
(format-spec
|
|
||||||
(oref obj format)
|
|
||||||
`((?k . ,(transient-format-key obj))
|
|
||||||
(?r . ,(format "branch.%s.remote" branch))
|
|
||||||
(?m . ,(format "branch.%s.merge" branch))
|
|
||||||
(?R . ,(transient-format-value obj #'car))
|
|
||||||
(?M . ,(transient-format-value obj #'cadr))))))
|
|
||||||
|
|
||||||
(cl-defmethod transient-format-value ((obj magit--git-branch:upstream) key)
|
|
||||||
(if-let ((value (funcall key (oref obj value))))
|
|
||||||
(propertize value 'face 'transient-argument)
|
|
||||||
(propertize "unset" 'face 'transient-inactive-argument)))
|
|
||||||
|
|
||||||
(define-infix-command magit-branch.<branch>.rebase ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:scope 'magit--read-branch-scope
|
|
||||||
:variable "branch.%s.rebase"
|
|
||||||
:fallback "pull.rebase"
|
|
||||||
:choices '("true" "false")
|
|
||||||
:default "false")
|
|
||||||
|
|
||||||
(define-infix-command magit-branch.<branch>.pushRemote ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:scope 'magit--read-branch-scope
|
|
||||||
:variable "branch.%s.pushRemote"
|
|
||||||
:fallback "remote.pushDefault"
|
|
||||||
:choices 'magit-list-remotes)
|
|
||||||
|
|
||||||
(define-infix-command magit-pull.rebase ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:variable "pull.rebase"
|
|
||||||
:choices '("true" "false")
|
|
||||||
:default "false")
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.pushDefault ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:variable "remote.pushDefault"
|
|
||||||
:choices 'magit-list-remotes)
|
|
||||||
|
|
||||||
(define-infix-command magit-branch.autoSetupMerge ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:variable "branch.autoSetupMerge"
|
|
||||||
:choices '("always" "true" "false")
|
|
||||||
:default "true")
|
|
||||||
|
|
||||||
(define-infix-command magit-branch.autoSetupRebase ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:variable "branch.autoSetupRebase"
|
|
||||||
:choices '("always" "local" "remote" "never")
|
|
||||||
:default "never")
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-branch)
|
|
||||||
;;; magit-branch.el ends here
|
|
Binary file not shown.
|
@ -1,267 +0,0 @@
|
||||||
;;; magit-clone.el --- clone a repository -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements clone commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-clone-set-remote-head nil
|
|
||||||
"Whether cloning creates the symbolic-ref `<remote>/HEAD'."
|
|
||||||
:package-version '(magit . "2.4.2")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-clone-set-remote.pushDefault 'ask
|
|
||||||
"Whether to set the value of `remote.pushDefault' after cloning.
|
|
||||||
|
|
||||||
If t, then set without asking. If nil, then don't set. If
|
|
||||||
`ask', then ask."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "set" t)
|
|
||||||
(const :tag "ask" ask)
|
|
||||||
(const :tag "don't set" nil)))
|
|
||||||
|
|
||||||
(defcustom magit-clone-default-directory nil
|
|
||||||
"Default directory to use when `magit-clone' reads destination.
|
|
||||||
If nil (the default), then use the value of `default-directory'.
|
|
||||||
If a directory, then use that. If a function, then call that
|
|
||||||
with the remote url as only argument and use the returned value."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "value of default-directory")
|
|
||||||
(directory :tag "constant directory")
|
|
||||||
(function :tag "function's value")))
|
|
||||||
|
|
||||||
(defcustom magit-clone-always-transient nil
|
|
||||||
"Whether `magit-clone' always acts as a transient prefix command.
|
|
||||||
If nil, then a prefix argument has to be used to show the transient
|
|
||||||
popup instead of invoking the default suffix `magit-clone-regular'
|
|
||||||
directly."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-clone-name-alist
|
|
||||||
'(("\\`\\(?:github:\\|gh:\\)?\\([^:]+\\)\\'" "github.com" "github.user")
|
|
||||||
("\\`\\(?:gitlab:\\|gl:\\)\\([^:]+\\)\\'" "gitlab.com" "gitlab.user"))
|
|
||||||
"Alist mapping repository names to repository urls.
|
|
||||||
|
|
||||||
Each element has the form (REGEXP HOSTNAME USER). When the user
|
|
||||||
enters a name when a cloning command asks for a name or url, then
|
|
||||||
that is looked up in this list. The first element whose REGEXP
|
|
||||||
matches is used.
|
|
||||||
|
|
||||||
The format specified by option `magit-clone-url-format' is used
|
|
||||||
to turn the name into an url, using HOSTNAME and the repository
|
|
||||||
name. If the provided name contains a slash, then that is used.
|
|
||||||
Otherwise if the name omits the owner of the repository, then the
|
|
||||||
default user specified in the matched entry is used.
|
|
||||||
|
|
||||||
If USER contains a dot, then it is treated as a Git variable and
|
|
||||||
the value of that is used as the username. Otherwise it is used
|
|
||||||
as the username itself."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(repeat (list regexp
|
|
||||||
(string :tag "hostname")
|
|
||||||
(string :tag "user name or git variable"))))
|
|
||||||
|
|
||||||
(defcustom magit-clone-url-format "git@%h:%n.git"
|
|
||||||
"Format used when turning repository names into urls.
|
|
||||||
%h is the hostname and %n is the repository name, including
|
|
||||||
the name of the owner. Also see `magit-clone-name-alist'."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'regexp)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-clone "magit-clone" nil t)
|
|
||||||
(define-transient-command magit-clone (&optional transient)
|
|
||||||
"Clone a repository."
|
|
||||||
:man-page "git-clone"
|
|
||||||
["Fetch arguments"
|
|
||||||
("-B" "Clone a single branch" "--single-branch")
|
|
||||||
("-n" "Do not clone tags" "--no-tags")
|
|
||||||
("-S" "Clones submodules" "--recurse-submodules" :level 6)
|
|
||||||
("-l" "Do not optimize" "--no-local" :level 7)]
|
|
||||||
["Setup arguments"
|
|
||||||
("-o" "Set name of remote" ("-o" "--origin="))
|
|
||||||
("-b" "Set HEAD branch" ("-b" "--branch="))
|
|
||||||
("-g" "Separate git directory" "--separate-git-dir="
|
|
||||||
transient-read-directory :level 7)
|
|
||||||
("-t" "Use template directory" "--template="
|
|
||||||
transient-read-existing-directory :level 6)]
|
|
||||||
["Local sharing arguments"
|
|
||||||
("-s" "Share objects" ("-s" "--shared" :level 7))
|
|
||||||
("-h" "Do not use hardlinks" "--no-hardlinks")]
|
|
||||||
["Clone"
|
|
||||||
("C" "regular" magit-clone-regular)
|
|
||||||
("s" "shallow" magit-clone-shallow)
|
|
||||||
("d" "shallow since date" magit-clone-shallow-since :level 7)
|
|
||||||
("e" "shallow excluding" magit-clone-shallow-exclude :level 7)
|
|
||||||
("b" "bare" magit-clone-bare)
|
|
||||||
("m" "mirror" magit-clone-mirror)]
|
|
||||||
(interactive (list (or magit-clone-always-transient current-prefix-arg)))
|
|
||||||
(if transient
|
|
||||||
(transient-setup #'magit-clone)
|
|
||||||
(call-interactively #'magit-clone-regular)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-regular (repository directory args)
|
|
||||||
"Create a clone of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository."
|
|
||||||
(interactive (magit-clone-read-args))
|
|
||||||
(magit-clone-internal repository directory args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-shallow (repository directory args depth)
|
|
||||||
"Create a shallow clone of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository.
|
|
||||||
With a prefix argument read the DEPTH of the clone;
|
|
||||||
otherwise use 1."
|
|
||||||
(interactive (append (magit-clone-read-args)
|
|
||||||
(list (if current-prefix-arg
|
|
||||||
(read-number "Depth: " 1)
|
|
||||||
1))))
|
|
||||||
(magit-clone-internal repository directory
|
|
||||||
(cons (format "--depth=%s" depth) args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-shallow-since (repository directory args date)
|
|
||||||
"Create a shallow clone of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository.
|
|
||||||
Exclude commits before DATE, which is read from the
|
|
||||||
user."
|
|
||||||
(interactive (append (magit-clone-read-args)
|
|
||||||
(list (transient-read-date "Exclude commits before: "
|
|
||||||
nil nil))))
|
|
||||||
(magit-clone-internal repository directory
|
|
||||||
(cons (format "--shallow-since=%s" date) args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-shallow-exclude (repository directory args exclude)
|
|
||||||
"Create a shallow clone of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository.
|
|
||||||
Exclude commits reachable from EXCLUDE, which is a
|
|
||||||
branch or tag read from the user."
|
|
||||||
(interactive (append (magit-clone-read-args)
|
|
||||||
(list (read-string "Exclude commits reachable from: "))))
|
|
||||||
(magit-clone-internal repository directory
|
|
||||||
(cons (format "--shallow-exclude=%s" exclude) args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-bare (repository directory args)
|
|
||||||
"Create a bare clone of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository."
|
|
||||||
(interactive (magit-clone-read-args))
|
|
||||||
(magit-clone-internal repository directory (cons "--bare" args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clone-mirror (repository directory args)
|
|
||||||
"Create a mirror of REPOSITORY in DIRECTORY.
|
|
||||||
Then show the status buffer for the new repository."
|
|
||||||
(interactive (magit-clone-read-args))
|
|
||||||
(magit-clone-internal repository directory (cons "--mirror" args)))
|
|
||||||
|
|
||||||
(defun magit-clone-internal (repository directory args)
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(setq directory (file-name-as-directory (expand-file-name directory)))
|
|
||||||
(magit-run-git-async "clone" args "--" repository
|
|
||||||
(magit-convert-filename-for-git directory))
|
|
||||||
;; Don't refresh the buffer we're calling from.
|
|
||||||
(process-put magit-this-process 'inhibit-refresh t)
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(let ((magit-process-raise-error t))
|
|
||||||
(magit-process-sentinel process event)))
|
|
||||||
(when (and (eq (process-status process) 'exit)
|
|
||||||
(= (process-exit-status process) 0))
|
|
||||||
(unless (memq (car args) '("--bare" "--mirror"))
|
|
||||||
(let ((default-directory directory))
|
|
||||||
(when (or (eq magit-clone-set-remote.pushDefault t)
|
|
||||||
(and magit-clone-set-remote.pushDefault
|
|
||||||
(y-or-n-p "Set `remote.pushDefault' to \"origin\"? ")))
|
|
||||||
(setf (magit-get "remote.pushDefault") "origin"))
|
|
||||||
(unless magit-clone-set-remote-head
|
|
||||||
(magit-remote-unset-head "origin"))))
|
|
||||||
(with-current-buffer (process-get process 'command-buf)
|
|
||||||
(magit-status-setup-buffer directory))))))
|
|
||||||
|
|
||||||
(defun magit-clone-read-args ()
|
|
||||||
(let ((repo (magit-clone-read-repository)))
|
|
||||||
(list repo
|
|
||||||
(read-directory-name
|
|
||||||
"Clone to: "
|
|
||||||
(if (functionp magit-clone-default-directory)
|
|
||||||
(funcall magit-clone-default-directory repo)
|
|
||||||
magit-clone-default-directory)
|
|
||||||
nil nil
|
|
||||||
(and (string-match "\\([^/:]+?\\)\\(/?\\.git\\)?$" repo)
|
|
||||||
(match-string 1 repo)))
|
|
||||||
(transient-args 'magit-clone))))
|
|
||||||
|
|
||||||
(defun magit-clone-read-repository ()
|
|
||||||
(magit-read-char-case "Clone from " nil
|
|
||||||
(?u "[u]rl or name"
|
|
||||||
(let ((str (magit-read-string-ns "Clone from url or name")))
|
|
||||||
(if (string-match-p "\\(://\\|@\\)" str)
|
|
||||||
str
|
|
||||||
(magit-clone--name-to-url str))))
|
|
||||||
(?p "[p]ath"
|
|
||||||
(read-directory-name "Clone repository: "))
|
|
||||||
(?l "or [l]ocal url"
|
|
||||||
(concat "file://" (read-directory-name "Clone repository: file://")))))
|
|
||||||
|
|
||||||
(defun magit-clone--name-to-url (name)
|
|
||||||
(or (-some
|
|
||||||
(pcase-lambda (`(,re ,host ,user))
|
|
||||||
(and (string-match re name)
|
|
||||||
(let ((repo (match-string 1 name)))
|
|
||||||
(format-spec
|
|
||||||
magit-clone-url-format
|
|
||||||
`((?h . ,host)
|
|
||||||
(?n . ,(if (string-match-p "/" repo)
|
|
||||||
repo
|
|
||||||
(if (string-match-p "\\." user)
|
|
||||||
(if-let ((user (magit-get user)))
|
|
||||||
(concat user "/" repo)
|
|
||||||
(user-error
|
|
||||||
"Set %S or specify owner explicitly" user))
|
|
||||||
(concat user "/" repo)))))))))
|
|
||||||
magit-clone-name-alist)
|
|
||||||
(user-error "Not an url and no matching entry in `%s'"
|
|
||||||
'magit-clone-name-alist)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-clone)
|
|
||||||
;;; magit-clone.el ends here
|
|
Binary file not shown.
|
@ -1,570 +0,0 @@
|
||||||
;;; magit-commit.el --- create Git commits -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements commands for creating Git commits. These
|
|
||||||
;; commands just initiate the commit, support for writing the commit
|
|
||||||
;; messages is implemented in `git-commit.el'.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'magit-sequence)
|
|
||||||
|
|
||||||
(eval-when-compile (require 'epa)) ; for `epa-protocol'
|
|
||||||
(eval-when-compile (require 'epg))
|
|
||||||
(eval-when-compile (require 'subr-x))
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-commit-ask-to-stage 'verbose
|
|
||||||
"Whether to ask to stage all unstaged changes when committing and nothing is staged."
|
|
||||||
:package-version '(magit . "2.3.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "Ask" t)
|
|
||||||
(const :tag "Ask showing diff" verbose)
|
|
||||||
(const :tag "Stage without confirmation" stage)
|
|
||||||
(const :tag "Don't ask" nil)))
|
|
||||||
|
|
||||||
(defcustom magit-commit-show-diff t
|
|
||||||
"Whether the relevant diff is automatically shown when committing."
|
|
||||||
:package-version '(magit . "2.3.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-commit-extend-override-date t
|
|
||||||
"Whether using `magit-commit-extend' changes the committer date."
|
|
||||||
:package-version '(magit . "2.3.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-commit-reword-override-date t
|
|
||||||
"Whether using `magit-commit-reword' changes the committer date."
|
|
||||||
:package-version '(magit . "2.3.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-commit-squash-confirm t
|
|
||||||
"Whether the commit targeted by squash and fixup has to be confirmed.
|
|
||||||
When non-nil then the commit at point (if any) is used as default
|
|
||||||
choice, otherwise it has to be confirmed. This option only
|
|
||||||
affects `magit-commit-squash' and `magit-commit-fixup'. The
|
|
||||||
\"instant\" variants always require confirmation because making
|
|
||||||
an error while using those is harder to recover from."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-post-commit-hook nil
|
|
||||||
"Hook run after creating a commit without the user editing a message.
|
|
||||||
|
|
||||||
This hook is run by `magit-refresh' if `this-command' is a member
|
|
||||||
of `magit-post-stage-hook-commands'. This only includes commands
|
|
||||||
named `magit-commit-*' that do *not* require that the user edits
|
|
||||||
the commit message in a buffer and then finishes by pressing
|
|
||||||
\\<with-editor-mode-map>\\[with-editor-finish].
|
|
||||||
|
|
||||||
Also see `git-commit-post-finish-hook'."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defvar magit-post-commit-hook-commands
|
|
||||||
'(magit-commit-extend
|
|
||||||
magit-commit-fixup
|
|
||||||
magit-commit-augment
|
|
||||||
magit-commit-instant-fixup
|
|
||||||
magit-commit-instant-squash))
|
|
||||||
|
|
||||||
;;; Popup
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-commit "magit-commit" nil t)
|
|
||||||
(define-transient-command magit-commit ()
|
|
||||||
"Create a new commit or replace an existing commit."
|
|
||||||
:info-manual "(magit)Initiating a Commit"
|
|
||||||
:man-page "git-commit"
|
|
||||||
["Arguments"
|
|
||||||
("-a" "Stage all modified and deleted files" ("-a" "--all"))
|
|
||||||
("-e" "Allow empty commit" "--allow-empty")
|
|
||||||
("-v" "Show diff of changes to be committed" ("-v" "--verbose"))
|
|
||||||
("-n" "Disable hooks" ("-n" "--no-verify"))
|
|
||||||
("-R" "Claim authorship and reset author date" "--reset-author")
|
|
||||||
(magit:--author :description "Override the author")
|
|
||||||
(7 "-D" "Override the author date" "--date=" transient-read-date)
|
|
||||||
("-s" "Add Signed-off-by line" ("-s" "--signoff"))
|
|
||||||
(5 magit:--gpg-sign)
|
|
||||||
(magit-commit:--reuse-message)]
|
|
||||||
[["Create"
|
|
||||||
("c" "Commit" magit-commit-create)]
|
|
||||||
["Edit HEAD"
|
|
||||||
("e" "Extend" magit-commit-extend)
|
|
||||||
("w" "Reword" magit-commit-reword)
|
|
||||||
("a" "Amend" magit-commit-amend)
|
|
||||||
(6 "n" "Reshelve" magit-commit-reshelve)]
|
|
||||||
["Edit"
|
|
||||||
("f" "Fixup" magit-commit-fixup)
|
|
||||||
("s" "Squash" magit-commit-squash)
|
|
||||||
("A" "Augment" magit-commit-augment)
|
|
||||||
(6 "x" "Absorb changes" magit-commit-absorb)]
|
|
||||||
[""
|
|
||||||
("F" "Instant fixup" magit-commit-instant-fixup)
|
|
||||||
("S" "Instant squash" magit-commit-instant-squash)]]
|
|
||||||
(interactive)
|
|
||||||
(if-let ((buffer (magit-commit-message-buffer)))
|
|
||||||
(switch-to-buffer buffer)
|
|
||||||
(transient-setup 'magit-commit)))
|
|
||||||
|
|
||||||
(defun magit-commit-arguments nil
|
|
||||||
(transient-args 'magit-commit))
|
|
||||||
|
|
||||||
(define-infix-argument magit:--gpg-sign ()
|
|
||||||
:description "Sign using gpg"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-S"
|
|
||||||
:argument "--gpg-sign="
|
|
||||||
:allow-empty t
|
|
||||||
:reader 'magit-read-gpg-secret-key)
|
|
||||||
|
|
||||||
(defvar magit-gpg-secret-key-hist nil)
|
|
||||||
|
|
||||||
(defun magit-read-gpg-secret-key (prompt &optional initial-input history)
|
|
||||||
(require 'epa)
|
|
||||||
(let* ((keys (mapcar
|
|
||||||
(lambda (obj)
|
|
||||||
(let ((key (epg-sub-key-id (car (epg-key-sub-key-list obj))))
|
|
||||||
(author
|
|
||||||
(when-let ((id-obj (car (epg-key-user-id-list obj))))
|
|
||||||
(let ((id-str (epg-user-id-string id-obj)))
|
|
||||||
(if (stringp id-str)
|
|
||||||
id-str
|
|
||||||
(epg-decode-dn id-obj))))))
|
|
||||||
(propertize key 'display (concat key " " author))))
|
|
||||||
(epg-list-keys (epg-make-context epa-protocol) nil t)))
|
|
||||||
(choice (completing-read prompt keys nil nil nil
|
|
||||||
history nil initial-input)))
|
|
||||||
(set-text-properties 0 (length choice) nil choice)
|
|
||||||
choice))
|
|
||||||
|
|
||||||
(define-infix-argument magit-commit:--reuse-message ()
|
|
||||||
:description "Reuse commit message"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-C"
|
|
||||||
:argument "--reuse-message="
|
|
||||||
:reader 'magit-read-reuse-message
|
|
||||||
:history-key 'magit-revision-history)
|
|
||||||
|
|
||||||
(defun magit-read-reuse-message (prompt &optional default history)
|
|
||||||
(magit-completing-read prompt (magit-list-refnames)
|
|
||||||
nil nil nil history
|
|
||||||
(or default
|
|
||||||
(and (magit-rev-verify "ORIG_HEAD")
|
|
||||||
"ORIG_HEAD"))))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-create (&optional args)
|
|
||||||
"Create a new commit on `HEAD'.
|
|
||||||
With a prefix argument, amend to the commit at `HEAD' instead.
|
|
||||||
\n(git commit [--amend] ARGS)"
|
|
||||||
(interactive (if current-prefix-arg
|
|
||||||
(list (cons "--amend" (magit-commit-arguments)))
|
|
||||||
(list (magit-commit-arguments))))
|
|
||||||
(when (member "--all" args)
|
|
||||||
(setq this-command 'magit-commit-all))
|
|
||||||
(when (setq args (magit-commit-assert args))
|
|
||||||
(let ((default-directory (magit-toplevel)))
|
|
||||||
(magit-run-git-with-editor "commit" args))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-amend (&optional args)
|
|
||||||
"Amend the last commit.
|
|
||||||
\n(git commit --amend ARGS)"
|
|
||||||
(interactive (list (magit-commit-arguments)))
|
|
||||||
(magit-commit-amend-assert)
|
|
||||||
(magit-run-git-with-editor "commit" "--amend" args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-extend (&optional args override-date)
|
|
||||||
"Amend the last commit, without editing the message.
|
|
||||||
|
|
||||||
With a prefix argument keep the committer date, otherwise change
|
|
||||||
it. The option `magit-commit-extend-override-date' can be used
|
|
||||||
to inverse the meaning of the prefix argument. \n(git commit
|
|
||||||
--amend --no-edit)"
|
|
||||||
(interactive (list (magit-commit-arguments)
|
|
||||||
(if current-prefix-arg
|
|
||||||
(not magit-commit-extend-override-date)
|
|
||||||
magit-commit-extend-override-date)))
|
|
||||||
(when (setq args (magit-commit-assert args (not override-date)))
|
|
||||||
(magit-commit-amend-assert)
|
|
||||||
(let ((process-environment process-environment))
|
|
||||||
(unless override-date
|
|
||||||
(push (magit-rev-format "GIT_COMMITTER_DATE=%cD") process-environment))
|
|
||||||
(magit-run-git-with-editor "commit" "--amend" "--no-edit" args))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-reword (&optional args override-date)
|
|
||||||
"Reword the last commit, ignoring staged changes.
|
|
||||||
|
|
||||||
With a prefix argument keep the committer date, otherwise change
|
|
||||||
it. The option `magit-commit-reword-override-date' can be used
|
|
||||||
to inverse the meaning of the prefix argument.
|
|
||||||
|
|
||||||
Non-interactively respect the optional OVERRIDE-DATE argument
|
|
||||||
and ignore the option.
|
|
||||||
\n(git commit --amend --only)"
|
|
||||||
(interactive (list (magit-commit-arguments)
|
|
||||||
(if current-prefix-arg
|
|
||||||
(not magit-commit-reword-override-date)
|
|
||||||
magit-commit-reword-override-date)))
|
|
||||||
(magit-commit-amend-assert)
|
|
||||||
(let ((process-environment process-environment))
|
|
||||||
(unless override-date
|
|
||||||
(push (magit-rev-format "GIT_COMMITTER_DATE=%cD") process-environment))
|
|
||||||
(cl-pushnew "--allow-empty" args :test #'equal)
|
|
||||||
(magit-run-git-with-editor "commit" "--amend" "--only" args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-fixup (&optional commit args)
|
|
||||||
"Create a fixup commit.
|
|
||||||
|
|
||||||
With a prefix argument the target COMMIT has to be confirmed.
|
|
||||||
Otherwise the commit at point may be used without confirmation
|
|
||||||
depending on the value of option `magit-commit-squash-confirm'."
|
|
||||||
(interactive (list (magit-commit-at-point)
|
|
||||||
(magit-commit-arguments)))
|
|
||||||
(magit-commit-squash-internal "--fixup" commit args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-squash (&optional commit args)
|
|
||||||
"Create a squash commit, without editing the squash message.
|
|
||||||
|
|
||||||
With a prefix argument the target COMMIT has to be confirmed.
|
|
||||||
Otherwise the commit at point may be used without confirmation
|
|
||||||
depending on the value of option `magit-commit-squash-confirm'."
|
|
||||||
(interactive (list (magit-commit-at-point)
|
|
||||||
(magit-commit-arguments)))
|
|
||||||
(magit-commit-squash-internal "--squash" commit args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-augment (&optional commit args)
|
|
||||||
"Create a squash commit, editing the squash message.
|
|
||||||
|
|
||||||
With a prefix argument the target COMMIT has to be confirmed.
|
|
||||||
Otherwise the commit at point may be used without confirmation
|
|
||||||
depending on the value of option `magit-commit-squash-confirm'."
|
|
||||||
(interactive (list (magit-commit-at-point)
|
|
||||||
(magit-commit-arguments)))
|
|
||||||
(magit-commit-squash-internal "--squash" commit args nil t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-instant-fixup (&optional commit args)
|
|
||||||
"Create a fixup commit targeting COMMIT and instantly rebase."
|
|
||||||
(interactive (list (magit-commit-at-point)
|
|
||||||
(magit-commit-arguments)))
|
|
||||||
(magit-commit-squash-internal "--fixup" commit args t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-instant-squash (&optional commit args)
|
|
||||||
"Create a squash commit targeting COMMIT and instantly rebase."
|
|
||||||
(interactive (list (magit-commit-at-point)
|
|
||||||
(magit-commit-arguments)))
|
|
||||||
(magit-commit-squash-internal "--squash" commit args t))
|
|
||||||
|
|
||||||
(defun magit-commit-squash-internal
|
|
||||||
(option commit &optional args rebase edit confirmed)
|
|
||||||
(when-let ((args (magit-commit-assert args t)))
|
|
||||||
(when commit
|
|
||||||
(when (and rebase (not (magit-rev-ancestor-p commit "HEAD")))
|
|
||||||
(magit-read-char-case
|
|
||||||
(format "%s isn't an ancestor of HEAD. " commit) nil
|
|
||||||
(?c "[c]reate without rebasing" (setq rebase nil))
|
|
||||||
(?s "[s]elect other" (setq commit nil))
|
|
||||||
(?a "[a]bort" (user-error "Quit")))))
|
|
||||||
(when commit
|
|
||||||
(setq commit (magit-rebase-interactive-assert commit t)))
|
|
||||||
(if (and commit
|
|
||||||
(or confirmed
|
|
||||||
(not (or rebase
|
|
||||||
current-prefix-arg
|
|
||||||
magit-commit-squash-confirm))))
|
|
||||||
(let ((magit-commit-show-diff nil))
|
|
||||||
(push (concat option "=" commit) args)
|
|
||||||
(unless edit
|
|
||||||
(push "--no-edit" args))
|
|
||||||
(if rebase
|
|
||||||
(magit-with-editor
|
|
||||||
(magit-call-git
|
|
||||||
"commit" "--no-gpg-sign"
|
|
||||||
(-remove-first
|
|
||||||
(apply-partially #'string-match-p "\\`--gpg-sign=")
|
|
||||||
args)))
|
|
||||||
(magit-run-git-with-editor "commit" args))
|
|
||||||
t) ; The commit was created; used by below lambda.
|
|
||||||
(magit-log-select
|
|
||||||
(lambda (commit)
|
|
||||||
(when (and (magit-commit-squash-internal option commit args
|
|
||||||
rebase edit t)
|
|
||||||
rebase)
|
|
||||||
(magit-commit-amend-assert commit)
|
|
||||||
(magit-rebase-interactive-1 commit
|
|
||||||
(list "--autosquash" "--autostash" "--keep-empty")
|
|
||||||
"" "true" nil t)))
|
|
||||||
(format "Type %%p on a commit to %s into it,"
|
|
||||||
(substring option 2))
|
|
||||||
nil nil nil commit)
|
|
||||||
(when magit-commit-show-diff
|
|
||||||
(let ((magit-display-buffer-noselect t))
|
|
||||||
(apply #'magit-diff-staged nil (magit-diff-arguments)))))))
|
|
||||||
|
|
||||||
(defun magit-commit-amend-assert (&optional commit)
|
|
||||||
(--when-let (magit-list-publishing-branches commit)
|
|
||||||
(let ((m1 "This commit has already been published to ")
|
|
||||||
(m2 ".\nDo you really want to modify it"))
|
|
||||||
(magit-confirm 'amend-published
|
|
||||||
(concat m1 "%s" m2)
|
|
||||||
(concat m1 "%i public branches" m2)
|
|
||||||
nil it))))
|
|
||||||
|
|
||||||
(defun magit-commit-assert (args &optional strict)
|
|
||||||
(cond
|
|
||||||
((or (magit-anything-staged-p)
|
|
||||||
(and (magit-anything-unstaged-p)
|
|
||||||
;; ^ Everything of nothing is still nothing.
|
|
||||||
(member "--all" args))
|
|
||||||
(and (not strict)
|
|
||||||
;; ^ For amend variants that don't make sense otherwise.
|
|
||||||
(or (member "--amend" args)
|
|
||||||
(member "--allow-empty" args))))
|
|
||||||
(or args (list "--")))
|
|
||||||
((and (magit-rebase-in-progress-p)
|
|
||||||
(not (magit-anything-unstaged-p))
|
|
||||||
(y-or-n-p "Nothing staged. Continue in-progress rebase? "))
|
|
||||||
(setq this-command 'magit-rebase-continue)
|
|
||||||
(magit-run-git-sequencer "rebase" "--continue")
|
|
||||||
nil)
|
|
||||||
((and (file-exists-p (magit-git-dir "MERGE_MSG"))
|
|
||||||
(not (magit-anything-unstaged-p)))
|
|
||||||
(or args (list "--")))
|
|
||||||
((not (magit-anything-unstaged-p))
|
|
||||||
(user-error "Nothing staged (or unstaged)"))
|
|
||||||
(magit-commit-ask-to-stage
|
|
||||||
(when (eq magit-commit-ask-to-stage 'verbose)
|
|
||||||
(magit-diff-unstaged))
|
|
||||||
(prog1 (when (or (eq magit-commit-ask-to-stage 'stage)
|
|
||||||
(y-or-n-p "Nothing staged. Stage and commit all unstaged changes? "))
|
|
||||||
(magit-run-git "add" "-u" ".")
|
|
||||||
(or args (list "--")))
|
|
||||||
(when (and (eq magit-commit-ask-to-stage 'verbose)
|
|
||||||
(derived-mode-p 'magit-diff-mode))
|
|
||||||
(magit-mode-bury-buffer))))
|
|
||||||
(t
|
|
||||||
(user-error "Nothing staged"))))
|
|
||||||
|
|
||||||
(defvar magit--reshelve-history nil)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-commit-reshelve (date)
|
|
||||||
"Change the committer date and possibly the author date of `HEAD'.
|
|
||||||
|
|
||||||
If you are the author of `HEAD', then both dates are changed,
|
|
||||||
otherwise only the committer date. The current time is used
|
|
||||||
as the initial minibuffer input and the original author (if
|
|
||||||
that is you) or committer date is available as the previous
|
|
||||||
history element."
|
|
||||||
(interactive
|
|
||||||
(let ((author-p (magit-rev-author-p "HEAD")))
|
|
||||||
(push (magit-rev-format (if author-p "%ad" "%cd") "HEAD"
|
|
||||||
(concat "--date=format:%F %T %z"))
|
|
||||||
magit--reshelve-history)
|
|
||||||
(list (read-string (if author-p
|
|
||||||
"Change author and committer dates to: "
|
|
||||||
"Change committer date to: ")
|
|
||||||
(cons (format-time-string "%F %T %z") 17)
|
|
||||||
'magit--reshelve-history))))
|
|
||||||
(let ((process-environment process-environment))
|
|
||||||
(push (concat "GIT_COMMITTER_DATE=" date) process-environment)
|
|
||||||
(magit-run-git "commit" "--amend" "--no-edit"
|
|
||||||
(and (magit-rev-author-p "HEAD")
|
|
||||||
(concat "--date=" date)))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-commit-absorb "magit-commit" nil t)
|
|
||||||
(define-transient-command magit-commit-absorb (phase commit args)
|
|
||||||
"Spread unstaged changes across recent commits.
|
|
||||||
With a prefix argument use a transient command to select infix
|
|
||||||
arguments. This command requires the git-autofixup script, which
|
|
||||||
is available from https://github.com/torbiak/git-autofixup."
|
|
||||||
["Arguments"
|
|
||||||
(magit-autofixup:--context)
|
|
||||||
(magit-autofixup:--strict)]
|
|
||||||
["Actions"
|
|
||||||
("x" "Absorb" magit-commit-absorb)]
|
|
||||||
(interactive (if current-prefix-arg
|
|
||||||
(list 'transient nil nil)
|
|
||||||
(list 'select
|
|
||||||
(magit-get-upstream-branch)
|
|
||||||
(transient-args 'magit-commit-absorb))))
|
|
||||||
(if (eq phase 'transient)
|
|
||||||
(transient-setup 'magit-commit-absorb)
|
|
||||||
(unless (executable-find "git-autofixup")
|
|
||||||
(user-error "This command requires the git-autofixup script, which %s"
|
|
||||||
"is available from https://github.com/torbiak/git-autofixup"))
|
|
||||||
(when (magit-anything-staged-p)
|
|
||||||
(user-error "Cannot absorb when there are staged changes"))
|
|
||||||
(unless (magit-anything-unstaged-p)
|
|
||||||
(user-error "There are no unstaged changes that could be absorbed"))
|
|
||||||
(when commit
|
|
||||||
(setq commit (magit-rebase-interactive-assert commit t)))
|
|
||||||
(if (and commit (eq phase 'run))
|
|
||||||
(progn (magit-run-git-async "autofixup" "-vv" args commit) t)
|
|
||||||
(magit-log-select
|
|
||||||
(lambda (commit)
|
|
||||||
(with-no-warnings ; about non-interactive use
|
|
||||||
(magit-commit-absorb 'run commit args)))
|
|
||||||
nil nil nil nil commit))))
|
|
||||||
|
|
||||||
(define-infix-argument magit-autofixup:--context ()
|
|
||||||
:description "Diff context lines"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-c"
|
|
||||||
:argument "--context="
|
|
||||||
:reader 'transient-read-number-N0)
|
|
||||||
|
|
||||||
(define-infix-argument magit-autofixup:--strict ()
|
|
||||||
:description "Strictness"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-s"
|
|
||||||
:argument "--strict="
|
|
||||||
:reader 'transient-read-number-N0)
|
|
||||||
|
|
||||||
;;; Pending Diff
|
|
||||||
|
|
||||||
(defun magit-commit-diff ()
|
|
||||||
(when (and git-commit-mode magit-commit-show-diff)
|
|
||||||
(when-let ((diff-buffer (magit-get-mode-buffer 'magit-diff-mode)))
|
|
||||||
;; This window just started displaying the commit message
|
|
||||||
;; buffer. Without this that buffer would immediately be
|
|
||||||
;; replaced with the diff buffer. See #2632.
|
|
||||||
(unrecord-window-buffer nil diff-buffer))
|
|
||||||
(condition-case nil
|
|
||||||
(let ((args (car (magit-diff-arguments)))
|
|
||||||
(magit-inhibit-save-previous-winconf 'unset)
|
|
||||||
(magit-display-buffer-noselect t)
|
|
||||||
(inhibit-quit nil))
|
|
||||||
(message "Diffing changes to be committed (C-g to abort diffing)")
|
|
||||||
(cl-case last-command
|
|
||||||
(magit-commit
|
|
||||||
(magit-diff-staged nil args))
|
|
||||||
(magit-commit-all
|
|
||||||
(magit-diff-working-tree nil args))
|
|
||||||
((magit-commit-amend
|
|
||||||
magit-commit-reword
|
|
||||||
magit-rebase-reword-commit)
|
|
||||||
(magit-diff-while-amending args))
|
|
||||||
(t (if (magit-anything-staged-p)
|
|
||||||
(magit-diff-staged nil args)
|
|
||||||
(magit-diff-while-amending args)))))
|
|
||||||
(quit))))
|
|
||||||
|
|
||||||
;; Mention `magit-diff-while-committing' because that's
|
|
||||||
;; always what I search for when I try to find this line.
|
|
||||||
(add-hook 'server-switch-hook 'magit-commit-diff)
|
|
||||||
|
|
||||||
(add-to-list 'with-editor-server-window-alist
|
|
||||||
(cons git-commit-filename-regexp 'switch-to-buffer))
|
|
||||||
|
|
||||||
;;; Message Utilities
|
|
||||||
|
|
||||||
(defun magit-commit-message-buffer ()
|
|
||||||
(let* ((find-file-visit-truename t) ; git uses truename of COMMIT_EDITMSG
|
|
||||||
(topdir (magit-toplevel)))
|
|
||||||
(--first (equal topdir (with-current-buffer it
|
|
||||||
(and git-commit-mode (magit-toplevel))))
|
|
||||||
(append (buffer-list (selected-frame))
|
|
||||||
(buffer-list)))))
|
|
||||||
|
|
||||||
(defvar magit-commit-add-log-insert-function 'magit-commit-add-log-insert
|
|
||||||
"Used by `magit-commit-add-log' to insert a single entry.")
|
|
||||||
|
|
||||||
(defun magit-commit-add-log ()
|
|
||||||
"Add a stub for the current change into the commit message buffer.
|
|
||||||
If no commit is in progress, then initiate it. Use the function
|
|
||||||
specified by variable `magit-commit-add-log-insert-function' to
|
|
||||||
actually insert the entry."
|
|
||||||
(interactive)
|
|
||||||
(pcase-let* ((hunk (and (magit-section-match 'hunk)
|
|
||||||
(magit-current-section)))
|
|
||||||
(log (magit-commit-message-buffer))
|
|
||||||
(`(,buf ,pos) (magit-diff-visit-file--noselect)))
|
|
||||||
(unless log
|
|
||||||
(unless (magit-commit-assert nil)
|
|
||||||
(user-error "Abort"))
|
|
||||||
(magit-commit-create)
|
|
||||||
(while (not (setq log (magit-commit-message-buffer)))
|
|
||||||
(sit-for 0.01)))
|
|
||||||
(magit--with-temp-position buf pos
|
|
||||||
(funcall magit-commit-add-log-insert-function log
|
|
||||||
(magit-file-relative-name)
|
|
||||||
(and hunk (add-log-current-defun))))))
|
|
||||||
|
|
||||||
(defun magit-commit-add-log-insert (buffer file defun)
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(undo-boundary)
|
|
||||||
(goto-char (point-max))
|
|
||||||
(while (re-search-backward (concat "^" comment-start) nil t))
|
|
||||||
(save-restriction
|
|
||||||
(narrow-to-region (point-min) (point))
|
|
||||||
(cond ((re-search-backward (format "* %s\\(?: (\\([^)]+\\))\\)?: " file)
|
|
||||||
nil t)
|
|
||||||
(when (equal (match-string 1) defun)
|
|
||||||
(setq defun nil))
|
|
||||||
(re-search-forward ": "))
|
|
||||||
(t
|
|
||||||
(when (re-search-backward "^[\\*(].+\n" nil t)
|
|
||||||
(goto-char (match-end 0)))
|
|
||||||
(while (re-search-forward "^[^\\*\n].*\n" nil t))
|
|
||||||
(if defun
|
|
||||||
(progn (insert (format "* %s (%s): \n" file defun))
|
|
||||||
(setq defun nil))
|
|
||||||
(insert (format "* %s: \n" file)))
|
|
||||||
(backward-char)
|
|
||||||
(unless (looking-at "\n[\n\\']")
|
|
||||||
(insert ?\n)
|
|
||||||
(backward-char))))
|
|
||||||
(when defun
|
|
||||||
(forward-line)
|
|
||||||
(let ((limit (save-excursion
|
|
||||||
(and (re-search-forward "^\\*" nil t)
|
|
||||||
(point)))))
|
|
||||||
(unless (or (looking-back (format "(%s): " defun)
|
|
||||||
(line-beginning-position))
|
|
||||||
(re-search-forward (format "^(%s): " defun) limit t))
|
|
||||||
(while (re-search-forward "^[^\\*\n].*\n" limit t))
|
|
||||||
(insert (format "(%s): \n" defun))
|
|
||||||
(backward-char)))))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-commit)
|
|
||||||
;;; magit-commit.el ends here
|
|
Binary file not shown.
|
@ -1,139 +0,0 @@
|
||||||
;;; magit-core.el --- core functionality -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library requires several other libraries, so that yet other
|
|
||||||
;; libraries can just require this one, instead of having to require
|
|
||||||
;; all the other ones. In other words this separates the low-level
|
|
||||||
;; stuff from the rest. It also defines some Custom groups.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit-utils)
|
|
||||||
(require 'magit-section)
|
|
||||||
(require 'magit-git)
|
|
||||||
(require 'magit-mode)
|
|
||||||
(require 'magit-margin)
|
|
||||||
(require 'magit-process)
|
|
||||||
(require 'magit-transient)
|
|
||||||
(require 'magit-autorevert)
|
|
||||||
|
|
||||||
(when (magit--libgit-available-p)
|
|
||||||
(condition-case err
|
|
||||||
(require 'magit-libgit)
|
|
||||||
(error
|
|
||||||
(setq magit-inhibit-libgit 'error)
|
|
||||||
(message "Error while loading `magit-libgit': %S" err)
|
|
||||||
(message "That is not fatal. The `libegit2' module just won't be used."))))
|
|
||||||
|
|
||||||
(defgroup magit nil
|
|
||||||
"Controlling Git from Emacs."
|
|
||||||
:link '(url-link "https://magit.vc")
|
|
||||||
:link '(info-link "(magit)FAQ")
|
|
||||||
:link '(info-link "(magit)")
|
|
||||||
:group 'tools)
|
|
||||||
|
|
||||||
(defgroup magit-essentials nil
|
|
||||||
"Options that every Magit user should briefly think about.
|
|
||||||
|
|
||||||
Each of these options falls into one or more of these categories:
|
|
||||||
|
|
||||||
* Options that affect Magit's behavior in fundamental ways.
|
|
||||||
* Options that affect safety.
|
|
||||||
* Options that affect performance.
|
|
||||||
* Options that are of a personal nature."
|
|
||||||
:link '(info-link "(magit)Essential Settings")
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(defgroup magit-miscellaneous nil
|
|
||||||
"Miscellaneous Magit options."
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(defgroup magit-commands nil
|
|
||||||
"Options controlling behavior of certain commands."
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(defgroup magit-git-arguments nil
|
|
||||||
"Options controlling what arguments are passed to Git.
|
|
||||||
|
|
||||||
Most of these options can be set using the respective popup,
|
|
||||||
and it is recommended that you do that because then you can
|
|
||||||
be certain that Magit supports the arguments that you select.
|
|
||||||
|
|
||||||
An option `magit-NAME-argument' specifies the arguments that
|
|
||||||
are enabled by default by the popup `magit-NAME-popup'."
|
|
||||||
:link '(info-link "(magit-popup)Customizing Existing Popups")
|
|
||||||
:link '(info-link "(magit-popup)Usage")
|
|
||||||
:group 'magit-commands)
|
|
||||||
|
|
||||||
(defgroup magit-modes nil
|
|
||||||
"Modes used or provided by Magit."
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(defgroup magit-buffers nil
|
|
||||||
"Options concerning Magit buffers."
|
|
||||||
:link '(info-link "(magit)Modes and Buffers")
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(defgroup magit-refresh nil
|
|
||||||
"Options controlling how Magit buffers are refreshed."
|
|
||||||
:link '(info-link "(magit)Automatic Refreshing of Magit Buffers")
|
|
||||||
:group 'magit
|
|
||||||
:group 'magit-buffers)
|
|
||||||
|
|
||||||
(defgroup magit-faces nil
|
|
||||||
"Faces used by Magit."
|
|
||||||
:group 'magit
|
|
||||||
:group 'faces)
|
|
||||||
|
|
||||||
(defgroup magit-extensions nil
|
|
||||||
"Extensions to Magit."
|
|
||||||
:group 'magit)
|
|
||||||
|
|
||||||
(custom-add-to-group 'magit-modes 'git-commit 'custom-group)
|
|
||||||
(custom-add-to-group 'magit-faces 'git-commit-faces 'custom-group)
|
|
||||||
(custom-add-to-group 'magit-modes 'git-rebase 'custom-group)
|
|
||||||
(custom-add-to-group 'magit-faces 'git-rebase-faces 'custom-group)
|
|
||||||
(custom-add-to-group 'magit-process 'with-editor 'custom-group)
|
|
||||||
|
|
||||||
(defgroup magit-related nil
|
|
||||||
"Options that are relevant to Magit but that are defined elsewhere."
|
|
||||||
:link '(custom-group-link vc)
|
|
||||||
:link '(custom-group-link smerge)
|
|
||||||
:link '(custom-group-link ediff)
|
|
||||||
:link '(custom-group-link auto-revert)
|
|
||||||
:group 'magit
|
|
||||||
:group 'magit-extensions
|
|
||||||
:group 'magit-essentials)
|
|
||||||
|
|
||||||
(custom-add-to-group 'magit-related 'auto-revert-check-vc-info 'custom-variable)
|
|
||||||
(custom-add-to-group 'magit-auto-revert 'auto-revert-check-vc-info 'custom-variable)
|
|
||||||
|
|
||||||
(custom-add-to-group 'magit-related 'ediff-window-setup-function 'custom-variable)
|
|
||||||
(custom-add-to-group 'magit-related 'smerge-refine-ignore-whitespace 'custom-variable)
|
|
||||||
(custom-add-to-group 'magit-related 'vc-follow-symlinks 'custom-variable)
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-core)
|
|
||||||
;;; magit-core.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,511 +0,0 @@
|
||||||
;;; magit-ediff.el --- Ediff extension for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library provides basic support for Ediff.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
(require 'ediff)
|
|
||||||
(require 'smerge-mode)
|
|
||||||
|
|
||||||
(defvar smerge-ediff-buf)
|
|
||||||
(defvar smerge-ediff-windows)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-ediff nil
|
|
||||||
"Ediff support for Magit."
|
|
||||||
:link '(info-link "(magit)Ediffing")
|
|
||||||
:group 'magit-extensions)
|
|
||||||
|
|
||||||
(defcustom magit-ediff-quit-hook
|
|
||||||
'(magit-ediff-cleanup-auxiliary-buffers
|
|
||||||
magit-ediff-restore-previous-winconf)
|
|
||||||
"Hooks to run after finishing Ediff, when that was invoked using Magit.
|
|
||||||
The hooks are run in the Ediff control buffer. This is similar
|
|
||||||
to `ediff-quit-hook' but takes the needs of Magit into account.
|
|
||||||
The `ediff-quit-hook' is ignored by Ediff sessions which were
|
|
||||||
invoked using Magit."
|
|
||||||
:package-version '(magit . "2.2.0")
|
|
||||||
:group 'magit-ediff
|
|
||||||
:type 'hook
|
|
||||||
:get 'magit-hook-custom-get
|
|
||||||
:options '(magit-ediff-cleanup-auxiliary-buffers
|
|
||||||
magit-ediff-restore-previous-winconf))
|
|
||||||
|
|
||||||
(defcustom magit-ediff-dwim-show-on-hunks nil
|
|
||||||
"Whether `magit-ediff-dwim' runs show variants on hunks.
|
|
||||||
If non-nil, `magit-ediff-show-staged' or
|
|
||||||
`magit-ediff-show-unstaged' are called based on what section the
|
|
||||||
hunk is in. Otherwise, `magit-ediff-dwim' runs
|
|
||||||
`magit-ediff-stage' when point is on an uncommitted hunk."
|
|
||||||
:package-version '(magit . "2.2.0")
|
|
||||||
:group 'magit-ediff
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-ediff-show-stash-with-index t
|
|
||||||
"Whether `magit-ediff-show-stash' shows the state of the index.
|
|
||||||
|
|
||||||
If non-nil, use a third Ediff buffer to distinguish which changes
|
|
||||||
in the stash were staged. In cases where the stash contains no
|
|
||||||
staged changes, fall back to a two-buffer Ediff.
|
|
||||||
|
|
||||||
More specifically, a stash is a merge commit, stash@{N}, with
|
|
||||||
potentially three parents.
|
|
||||||
|
|
||||||
* stash@{N}^1 represents the `HEAD' commit at the time the stash
|
|
||||||
was created.
|
|
||||||
|
|
||||||
* stash@{N}^2 records any changes that were staged when the stash
|
|
||||||
was made.
|
|
||||||
|
|
||||||
* stash@{N}^3, if it exists, contains files that were untracked
|
|
||||||
when stashing.
|
|
||||||
|
|
||||||
If this option is non-nil, `magit-ediff-show-stash' will run
|
|
||||||
Ediff on a file using three buffers: one for stash@{N}, another
|
|
||||||
for stash@{N}^1, and a third for stash@{N}^2.
|
|
||||||
|
|
||||||
Otherwise, Ediff uses two buffers, comparing
|
|
||||||
stash@{N}^1..stash@{N}. Along with any unstaged changes, changes
|
|
||||||
in the index commit, stash@{N}^2, will be shown in this
|
|
||||||
comparison unless they conflicted with changes in the working
|
|
||||||
tree at the time of stashing."
|
|
||||||
:package-version '(magit . "2.6.0")
|
|
||||||
:group 'magit-ediff
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
(defvar magit-ediff-previous-winconf nil)
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-ediff "magit-ediff" nil)
|
|
||||||
(define-transient-command magit-ediff ()
|
|
||||||
"Show differences using the Ediff package."
|
|
||||||
:info-manual "(ediff)"
|
|
||||||
["Ediff"
|
|
||||||
[("E" "Dwim" magit-ediff-dwim)
|
|
||||||
("s" "Stage" magit-ediff-stage)
|
|
||||||
("m" "Resolve" magit-ediff-resolve)]
|
|
||||||
[("u" "Show unstaged" magit-ediff-show-unstaged)
|
|
||||||
("i" "Show staged" magit-ediff-show-staged)
|
|
||||||
("w" "Show worktree" magit-ediff-show-working-tree)]
|
|
||||||
[("c" "Show commit" magit-ediff-show-commit)
|
|
||||||
("r" "Show range" magit-ediff-compare)
|
|
||||||
("z" "Show stash" magit-ediff-show-stash)]])
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-resolve (file)
|
|
||||||
"Resolve outstanding conflicts in FILE using Ediff.
|
|
||||||
FILE has to be relative to the top directory of the repository.
|
|
||||||
|
|
||||||
In the rare event that you want to manually resolve all
|
|
||||||
conflicts, including those already resolved by Git, use
|
|
||||||
`ediff-merge-revisions-with-ancestor'."
|
|
||||||
(interactive
|
|
||||||
(let ((current (magit-current-file))
|
|
||||||
(unmerged (magit-unmerged-files)))
|
|
||||||
(unless unmerged
|
|
||||||
(user-error "There are no unresolved conflicts"))
|
|
||||||
(list (magit-completing-read "Resolve file" unmerged nil t nil nil
|
|
||||||
(car (member current unmerged))))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(with-current-buffer (find-file-noselect file)
|
|
||||||
(smerge-ediff)
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
(let ((bufC ediff-buffer-C)
|
|
||||||
(bufS smerge-ediff-buf))
|
|
||||||
(with-current-buffer bufS
|
|
||||||
(when (yes-or-no-p (format "Conflict resolution finished; save %s? "
|
|
||||||
buffer-file-name))
|
|
||||||
(erase-buffer)
|
|
||||||
(insert-buffer-substring bufC)
|
|
||||||
(save-buffer))))
|
|
||||||
(when (buffer-live-p ediff-buffer-A) (kill-buffer ediff-buffer-A))
|
|
||||||
(when (buffer-live-p ediff-buffer-B) (kill-buffer ediff-buffer-B))
|
|
||||||
(when (buffer-live-p ediff-buffer-C) (kill-buffer ediff-buffer-C))
|
|
||||||
(when (buffer-live-p ediff-ancestor-buffer)
|
|
||||||
(kill-buffer ediff-ancestor-buffer))
|
|
||||||
(let ((magit-ediff-previous-winconf smerge-ediff-windows))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-stage (file)
|
|
||||||
"Stage and unstage changes to FILE using Ediff.
|
|
||||||
FILE has to be relative to the top directory of the repository."
|
|
||||||
(interactive
|
|
||||||
(let ((files (magit-tracked-files)))
|
|
||||||
(list (magit-completing-read "Selectively stage file" files nil t nil nil
|
|
||||||
(car (member (magit-current-file) files))))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let* ((conf (current-window-configuration))
|
|
||||||
(bufA (magit-get-revision-buffer "HEAD" file))
|
|
||||||
(bufB (magit-get-revision-buffer "{index}" file))
|
|
||||||
(bufBrw (and bufB (with-current-buffer bufB (not buffer-read-only))))
|
|
||||||
(bufC (get-file-buffer file))
|
|
||||||
(fileBufC (or bufC (find-file-noselect file)))
|
|
||||||
(coding-system-for-read
|
|
||||||
(with-current-buffer fileBufC buffer-file-coding-system)))
|
|
||||||
(ediff-buffers3
|
|
||||||
(or bufA (magit-find-file-noselect "HEAD" file))
|
|
||||||
(with-current-buffer (magit-find-file-index-noselect file t)
|
|
||||||
(setq buffer-read-only nil)
|
|
||||||
(current-buffer))
|
|
||||||
fileBufC
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
(and (buffer-live-p ediff-buffer-B)
|
|
||||||
(buffer-modified-p ediff-buffer-B)
|
|
||||||
(with-current-buffer ediff-buffer-B
|
|
||||||
(magit-update-index)))
|
|
||||||
(and (buffer-live-p ediff-buffer-C)
|
|
||||||
(buffer-modified-p ediff-buffer-C)
|
|
||||||
(with-current-buffer ediff-buffer-C
|
|
||||||
(when (y-or-n-p
|
|
||||||
(format "Save file %s? " buffer-file-name))
|
|
||||||
(save-buffer))))
|
|
||||||
,@(unless bufA '((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(if bufB
|
|
||||||
(unless bufBrw '((with-current-buffer ediff-buffer-B
|
|
||||||
(setq buffer-read-only t))))
|
|
||||||
'((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
,@(unless bufC '((ediff-kill-buffer-carefully ediff-buffer-C)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-buffers3))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-compare (revA revB fileA fileB)
|
|
||||||
"Compare REVA:FILEA with REVB:FILEB using Ediff.
|
|
||||||
|
|
||||||
FILEA and FILEB have to be relative to the top directory of the
|
|
||||||
repository. If REVA or REVB is nil, then this stands for the
|
|
||||||
working tree state.
|
|
||||||
|
|
||||||
If the region is active, use the revisions on the first and last
|
|
||||||
line of the region. With a prefix argument, instead of diffing
|
|
||||||
the revisions, choose a revision to view changes along, starting
|
|
||||||
at the common ancestor of both revisions (i.e., use a \"...\"
|
|
||||||
range)."
|
|
||||||
(interactive
|
|
||||||
(pcase-let ((`(,revA ,revB) (magit-ediff-compare--read-revisions
|
|
||||||
nil current-prefix-arg)))
|
|
||||||
(nconc (list revA revB)
|
|
||||||
(magit-ediff-read-files revA revB))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((conf (current-window-configuration))
|
|
||||||
(bufA (if revA
|
|
||||||
(magit-get-revision-buffer revA fileA)
|
|
||||||
(get-file-buffer fileA)))
|
|
||||||
(bufB (if revB
|
|
||||||
(magit-get-revision-buffer revB fileB)
|
|
||||||
(get-file-buffer fileB))))
|
|
||||||
(ediff-buffers
|
|
||||||
(or bufA (if revA
|
|
||||||
(magit-find-file-noselect revA fileA)
|
|
||||||
(find-file-noselect fileA)))
|
|
||||||
(or bufB (if revB
|
|
||||||
(magit-find-file-noselect revB fileB)
|
|
||||||
(find-file-noselect fileB)))
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
,@(unless bufA '((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(unless bufB '((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-revision))))
|
|
||||||
|
|
||||||
(defun magit-ediff-compare--read-revisions (&optional arg mbase)
|
|
||||||
(let ((input (or arg (magit-diff-read-range-or-commit
|
|
||||||
"Compare range or commit"
|
|
||||||
nil mbase))))
|
|
||||||
(--if-let (magit-split-range input)
|
|
||||||
(-cons-to-list it)
|
|
||||||
(list input nil))))
|
|
||||||
|
|
||||||
(defun magit-ediff-read-files (revA revB &optional fileB)
|
|
||||||
"Read file in REVB, return it and the corresponding file in REVA.
|
|
||||||
When FILEB is non-nil, use this as REVB's file instead of
|
|
||||||
prompting for it."
|
|
||||||
(unless fileB
|
|
||||||
(setq fileB (magit-read-file-choice
|
|
||||||
(format "File to compare between %s and %s"
|
|
||||||
revA (or revB "the working tree"))
|
|
||||||
(magit-changed-files revA revB)
|
|
||||||
(format "No changed files between %s and %s"
|
|
||||||
revA (or revB "the working tree")))))
|
|
||||||
(list (or (car (member fileB (magit-revision-files revA)))
|
|
||||||
(cdr (assoc fileB (magit-renamed-files revB revA)))
|
|
||||||
(magit-read-file-choice
|
|
||||||
(format "File in %s to compare with %s in %s"
|
|
||||||
revA fileB (or revB "the working tree"))
|
|
||||||
(magit-changed-files revB revA)
|
|
||||||
(format "No files have changed between %s and %s"
|
|
||||||
revA revB)))
|
|
||||||
fileB))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-dwim ()
|
|
||||||
"Compare, stage, or resolve using Ediff.
|
|
||||||
This command tries to guess what file, and what commit or range
|
|
||||||
the user wants to compare, stage, or resolve using Ediff. It
|
|
||||||
might only be able to guess either the file, or range or commit,
|
|
||||||
in which case the user is asked about the other. It might not
|
|
||||||
always guess right, in which case the appropriate `magit-ediff-*'
|
|
||||||
command has to be used explicitly. If it cannot read the user's
|
|
||||||
mind at all, then it asks the user for a command to run."
|
|
||||||
(interactive)
|
|
||||||
(magit-section-case
|
|
||||||
(hunk (save-excursion
|
|
||||||
(goto-char (oref (oref it parent) start))
|
|
||||||
(magit-ediff-dwim)))
|
|
||||||
(t
|
|
||||||
(let ((range (magit-diff--dwim))
|
|
||||||
(file (magit-current-file))
|
|
||||||
command revA revB)
|
|
||||||
(pcase range
|
|
||||||
((and (guard (not magit-ediff-dwim-show-on-hunks))
|
|
||||||
(or `unstaged `staged))
|
|
||||||
(setq command (if (magit-anything-unmerged-p)
|
|
||||||
#'magit-ediff-resolve
|
|
||||||
#'magit-ediff-stage)))
|
|
||||||
(`unstaged (setq command #'magit-ediff-show-unstaged))
|
|
||||||
(`staged (setq command #'magit-ediff-show-staged))
|
|
||||||
(`(commit . ,value)
|
|
||||||
(setq command #'magit-ediff-show-commit)
|
|
||||||
(setq revB value))
|
|
||||||
(`(stash . ,value)
|
|
||||||
(setq command #'magit-ediff-show-stash)
|
|
||||||
(setq revB value))
|
|
||||||
((pred stringp)
|
|
||||||
(pcase-let ((`(,a ,b) (magit-ediff-compare--read-revisions range)))
|
|
||||||
(setq command #'magit-ediff-compare)
|
|
||||||
(setq revA a)
|
|
||||||
(setq revB b)))
|
|
||||||
(_
|
|
||||||
(when (derived-mode-p 'magit-diff-mode)
|
|
||||||
(pcase (magit-diff-type)
|
|
||||||
(`committed (pcase-let ((`(,a ,b)
|
|
||||||
(magit-ediff-compare--read-revisions
|
|
||||||
magit-buffer-range)))
|
|
||||||
(setq revA a)
|
|
||||||
(setq revB b)))
|
|
||||||
((guard (not magit-ediff-dwim-show-on-hunks))
|
|
||||||
(setq command #'magit-ediff-stage))
|
|
||||||
(`unstaged (setq command #'magit-ediff-show-unstaged))
|
|
||||||
(`staged (setq command #'magit-ediff-show-staged))
|
|
||||||
(`undefined (setq command nil))
|
|
||||||
(_ (setq command nil))))))
|
|
||||||
(cond ((not command)
|
|
||||||
(call-interactively
|
|
||||||
(magit-read-char-case
|
|
||||||
"Failed to read your mind; do you want to " t
|
|
||||||
(?c "[c]ommit" 'magit-ediff-show-commit)
|
|
||||||
(?r "[r]ange" 'magit-ediff-compare)
|
|
||||||
(?s "[s]tage" 'magit-ediff-stage)
|
|
||||||
(?v "resol[v]e" 'magit-ediff-resolve))))
|
|
||||||
((eq command 'magit-ediff-compare)
|
|
||||||
(apply 'magit-ediff-compare revA revB
|
|
||||||
(magit-ediff-read-files revA revB file)))
|
|
||||||
((eq command 'magit-ediff-show-commit)
|
|
||||||
(magit-ediff-show-commit revB))
|
|
||||||
((eq command 'magit-ediff-show-stash)
|
|
||||||
(magit-ediff-show-stash revB))
|
|
||||||
(file
|
|
||||||
(funcall command file))
|
|
||||||
(t
|
|
||||||
(call-interactively command)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-show-staged (file)
|
|
||||||
"Show staged changes using Ediff.
|
|
||||||
|
|
||||||
This only allows looking at the changes; to stage, unstage,
|
|
||||||
and discard changes using Ediff, use `magit-ediff-stage'.
|
|
||||||
|
|
||||||
FILE must be relative to the top directory of the repository."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Show staged changes for file"
|
|
||||||
(magit-staged-files)
|
|
||||||
"No staged files")))
|
|
||||||
(let ((conf (current-window-configuration))
|
|
||||||
(bufA (magit-get-revision-buffer "HEAD" file))
|
|
||||||
(bufB (get-buffer (concat file ".~{index}~"))))
|
|
||||||
(ediff-buffers
|
|
||||||
(or bufA (magit-find-file-noselect "HEAD" file))
|
|
||||||
(or bufB (magit-find-file-index-noselect file t))
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
,@(unless bufA '((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(unless bufB '((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-buffers)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-show-unstaged (file)
|
|
||||||
"Show unstaged changes using Ediff.
|
|
||||||
|
|
||||||
This only allows looking at the changes; to stage, unstage,
|
|
||||||
and discard changes using Ediff, use `magit-ediff-stage'.
|
|
||||||
|
|
||||||
FILE must be relative to the top directory of the repository."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Show unstaged changes for file"
|
|
||||||
(magit-unstaged-files)
|
|
||||||
"No unstaged files")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((conf (current-window-configuration))
|
|
||||||
(bufA (get-buffer (concat file ".~{index}~")))
|
|
||||||
(bufB (get-file-buffer file)))
|
|
||||||
(ediff-buffers
|
|
||||||
(or bufA (magit-find-file-index-noselect file t))
|
|
||||||
(or bufB (find-file-noselect file))
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
,@(unless bufA '((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(unless bufB '((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-buffers))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-show-working-tree (file)
|
|
||||||
"Show changes between `HEAD' and working tree using Ediff.
|
|
||||||
FILE must be relative to the top directory of the repository."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Show changes in file"
|
|
||||||
(magit-changed-files "HEAD")
|
|
||||||
"No changed files")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((conf (current-window-configuration))
|
|
||||||
(bufA (magit-get-revision-buffer "HEAD" file))
|
|
||||||
(bufB (get-file-buffer file)))
|
|
||||||
(ediff-buffers
|
|
||||||
(or bufA (magit-find-file-noselect "HEAD" file))
|
|
||||||
(or bufB (find-file-noselect file))
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
,@(unless bufA '((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(unless bufB '((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-buffers))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-show-commit (commit)
|
|
||||||
"Show changes introduced by COMMIT using Ediff."
|
|
||||||
(interactive (list (magit-read-branch-or-commit "Revision")))
|
|
||||||
(let ((revA (concat commit "^"))
|
|
||||||
(revB commit))
|
|
||||||
(apply #'magit-ediff-compare
|
|
||||||
revA revB
|
|
||||||
(magit-ediff-read-files revA revB (magit-current-file)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-ediff-show-stash (stash)
|
|
||||||
"Show changes introduced by STASH using Ediff.
|
|
||||||
`magit-ediff-show-stash-with-index' controls whether a
|
|
||||||
three-buffer Ediff is used in order to distinguish changes in the
|
|
||||||
stash that were staged."
|
|
||||||
(interactive (list (magit-read-stash "Stash")))
|
|
||||||
(pcase-let* ((revA (concat stash "^1"))
|
|
||||||
(revB (concat stash "^2"))
|
|
||||||
(revC stash)
|
|
||||||
(`(,fileA ,fileC) (magit-ediff-read-files revA revC))
|
|
||||||
(fileB fileC))
|
|
||||||
(if (and magit-ediff-show-stash-with-index
|
|
||||||
(member fileA (magit-changed-files revB revA)))
|
|
||||||
(let ((conf (current-window-configuration))
|
|
||||||
(bufA (magit-get-revision-buffer revA fileA))
|
|
||||||
(bufB (magit-get-revision-buffer revB fileB))
|
|
||||||
(bufC (magit-get-revision-buffer revC fileC)))
|
|
||||||
(ediff-buffers3
|
|
||||||
(or bufA (magit-find-file-noselect revA fileA))
|
|
||||||
(or bufB (magit-find-file-noselect revB fileB))
|
|
||||||
(or bufC (magit-find-file-noselect revC fileC))
|
|
||||||
`((lambda ()
|
|
||||||
(setq-local
|
|
||||||
ediff-quit-hook
|
|
||||||
(lambda ()
|
|
||||||
,@(unless bufA
|
|
||||||
'((ediff-kill-buffer-carefully ediff-buffer-A)))
|
|
||||||
,@(unless bufB
|
|
||||||
'((ediff-kill-buffer-carefully ediff-buffer-B)))
|
|
||||||
,@(unless bufC
|
|
||||||
'((ediff-kill-buffer-carefully ediff-buffer-C)))
|
|
||||||
(let ((magit-ediff-previous-winconf ,conf))
|
|
||||||
(run-hooks 'magit-ediff-quit-hook))))))
|
|
||||||
'ediff-buffers3))
|
|
||||||
(magit-ediff-compare revA revC fileA fileC))))
|
|
||||||
|
|
||||||
(defun magit-ediff-cleanup-auxiliary-buffers ()
|
|
||||||
(let* ((ctl-buf ediff-control-buffer)
|
|
||||||
(ctl-win (ediff-get-visible-buffer-window ctl-buf))
|
|
||||||
(ctl-frm ediff-control-frame)
|
|
||||||
(main-frame (cond ((window-live-p ediff-window-A)
|
|
||||||
(window-frame ediff-window-A))
|
|
||||||
((window-live-p ediff-window-B)
|
|
||||||
(window-frame ediff-window-B)))))
|
|
||||||
(ediff-kill-buffer-carefully ediff-diff-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-custom-diff-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-fine-diff-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-tmp-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-error-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-msg-buffer)
|
|
||||||
(ediff-kill-buffer-carefully ediff-debug-buffer)
|
|
||||||
(when (boundp 'ediff-patch-diagnostics)
|
|
||||||
(ediff-kill-buffer-carefully ediff-patch-diagnostics))
|
|
||||||
(cond ((and (ediff-window-display-p)
|
|
||||||
(frame-live-p ctl-frm))
|
|
||||||
(delete-frame ctl-frm))
|
|
||||||
((window-live-p ctl-win)
|
|
||||||
(delete-window ctl-win)))
|
|
||||||
(unless (ediff-multiframe-setup-p)
|
|
||||||
(ediff-kill-bottom-toolbar))
|
|
||||||
(ediff-kill-buffer-carefully ctl-buf)
|
|
||||||
(when (frame-live-p main-frame)
|
|
||||||
(select-frame main-frame))))
|
|
||||||
|
|
||||||
(defun magit-ediff-restore-previous-winconf ()
|
|
||||||
(set-window-configuration magit-ediff-previous-winconf))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-ediff)
|
|
||||||
;;; magit-ediff.el ends here
|
|
Binary file not shown.
|
@ -1,649 +0,0 @@
|
||||||
;;; magit-extras.el --- additional functionality for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Additional functionality for Magit.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
(declare-function dired-read-shell-command "dired-aux" (prompt arg files))
|
|
||||||
|
|
||||||
(defvar ido-exit)
|
|
||||||
(defvar ido-fallback)
|
|
||||||
|
|
||||||
(defgroup magit-extras nil
|
|
||||||
"Additional functionality for Magit."
|
|
||||||
:group 'magit-extensions)
|
|
||||||
|
|
||||||
;;; External Tools
|
|
||||||
|
|
||||||
(defcustom magit-gitk-executable
|
|
||||||
(or (and (eq system-type 'windows-nt)
|
|
||||||
(let ((exe (magit-git-string
|
|
||||||
"-c" "alias.X=!x() { which \"$1\" | cygpath -mf -; }; x"
|
|
||||||
"X" "gitk.exe")))
|
|
||||||
(and exe (file-executable-p exe) exe)))
|
|
||||||
(executable-find "gitk") "gitk")
|
|
||||||
"The Gitk executable."
|
|
||||||
:group 'magit-extras
|
|
||||||
:set-after '(magit-git-executable)
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-run-git-gui ()
|
|
||||||
"Run `git gui' for the current git repository."
|
|
||||||
(interactive)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-process-file magit-git-executable nil 0 nil "gui")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-run-git-gui-blame (commit filename &optional linenum)
|
|
||||||
"Run `git gui blame' on the given FILENAME and COMMIT.
|
|
||||||
Interactively run it for the current file and the `HEAD', with a
|
|
||||||
prefix or when the current file cannot be determined let the user
|
|
||||||
choose. When the current buffer is visiting FILENAME instruct
|
|
||||||
blame to center around the line point is on."
|
|
||||||
(interactive
|
|
||||||
(let (revision filename)
|
|
||||||
(when (or current-prefix-arg
|
|
||||||
(not (setq revision "HEAD"
|
|
||||||
filename (magit-file-relative-name nil 'tracked))))
|
|
||||||
(setq revision (magit-read-branch-or-commit "Blame from revision"))
|
|
||||||
(setq filename (magit-read-file-from-rev revision "Blame file")))
|
|
||||||
(list revision filename
|
|
||||||
(and (equal filename
|
|
||||||
(ignore-errors
|
|
||||||
(magit-file-relative-name buffer-file-name)))
|
|
||||||
(line-number-at-pos)))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(apply #'magit-process-file magit-git-executable nil 0 nil "gui" "blame"
|
|
||||||
`(,@(and linenum (list (format "--line=%d" linenum)))
|
|
||||||
,commit
|
|
||||||
,filename))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-run-gitk ()
|
|
||||||
"Run `gitk' in the current repository."
|
|
||||||
(interactive)
|
|
||||||
(magit-process-file magit-gitk-executable nil 0))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-run-gitk-branches ()
|
|
||||||
"Run `gitk --branches' in the current repository."
|
|
||||||
(interactive)
|
|
||||||
(magit-process-file magit-gitk-executable nil 0 nil "--branches"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-run-gitk-all ()
|
|
||||||
"Run `gitk --all' in the current repository."
|
|
||||||
(interactive)
|
|
||||||
(magit-process-file magit-gitk-executable nil 0 nil "--all"))
|
|
||||||
|
|
||||||
;;; Emacs Tools
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun ido-enter-magit-status ()
|
|
||||||
"Drop into `magit-status' from file switching.
|
|
||||||
|
|
||||||
This command does not work in Emacs 26.1.
|
|
||||||
See https://github.com/magit/magit/issues/3634
|
|
||||||
and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=31707.
|
|
||||||
|
|
||||||
To make this command available use something like:
|
|
||||||
|
|
||||||
(add-hook \\='ido-setup-hook
|
|
||||||
(lambda ()
|
|
||||||
(define-key ido-completion-map
|
|
||||||
(kbd \"C-x g\") \\='ido-enter-magit-status)))
|
|
||||||
|
|
||||||
Starting with Emacs 25.1 the Ido keymaps are defined just once
|
|
||||||
instead of every time Ido is invoked, so now you can modify it
|
|
||||||
like pretty much every other keymap:
|
|
||||||
|
|
||||||
(define-key ido-common-completion-map
|
|
||||||
(kbd \"C-x g\") \\='ido-enter-magit-status)"
|
|
||||||
(interactive)
|
|
||||||
(setq ido-exit 'fallback)
|
|
||||||
(setq ido-fallback 'magit-status) ; for Emacs >= 26.2
|
|
||||||
(with-no-warnings (setq fallback 'magit-status)) ; for Emacs 25
|
|
||||||
(exit-minibuffer))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-dired-jump (&optional other-window)
|
|
||||||
"Visit file at point using Dired.
|
|
||||||
With a prefix argument, visit in another window. If there
|
|
||||||
is no file at point, then instead visit `default-directory'."
|
|
||||||
(interactive "P")
|
|
||||||
(dired-jump other-window
|
|
||||||
(when-let ((file (magit-file-at-point)))
|
|
||||||
(expand-file-name (if (file-directory-p file)
|
|
||||||
(file-name-as-directory file)
|
|
||||||
file)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-dired-log (&optional follow)
|
|
||||||
"Show log for all marked files, or the current file."
|
|
||||||
(interactive "P")
|
|
||||||
(if-let ((topdir (magit-toplevel default-directory)))
|
|
||||||
(let ((args (car (magit-log-arguments)))
|
|
||||||
(files (dired-get-marked-files nil nil #'magit-file-tracked-p)))
|
|
||||||
(unless files
|
|
||||||
(user-error "No marked file is being tracked by Git"))
|
|
||||||
(when (and follow
|
|
||||||
(not (member "--follow" args))
|
|
||||||
(not (cdr files)))
|
|
||||||
(push "--follow" args))
|
|
||||||
(magit-log-setup-buffer
|
|
||||||
(list (or (magit-get-current-branch) "HEAD"))
|
|
||||||
args
|
|
||||||
(let ((default-directory topdir))
|
|
||||||
(mapcar #'file-relative-name files))
|
|
||||||
magit-log-buffer-file-locked))
|
|
||||||
(magit--not-inside-repository-error)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-do-async-shell-command (file)
|
|
||||||
"Open FILE with `dired-do-async-shell-command'.
|
|
||||||
Interactively, open the file at point."
|
|
||||||
(interactive (list (or (magit-file-at-point)
|
|
||||||
(completing-read "Act on file: "
|
|
||||||
(magit-list-files)))))
|
|
||||||
(require 'dired-aux)
|
|
||||||
(dired-do-async-shell-command
|
|
||||||
(dired-read-shell-command "& on %s: " current-prefix-arg (list file))
|
|
||||||
nil (list file)))
|
|
||||||
|
|
||||||
;;; Shift Selection
|
|
||||||
|
|
||||||
(defun magit--turn-on-shift-select-mode-p ()
|
|
||||||
(and shift-select-mode
|
|
||||||
this-command-keys-shift-translated
|
|
||||||
(not mark-active)
|
|
||||||
(not (eq (car-safe transient-mark-mode) 'only))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-previous-line (&optional arg try-vscroll)
|
|
||||||
"Like `previous-line' but with Magit-specific shift-selection.
|
|
||||||
|
|
||||||
Magit's selection mechanism is based on the region but selects an
|
|
||||||
area that is larger than the region. This causes `previous-line'
|
|
||||||
when invoked while holding the shift key to move up one line and
|
|
||||||
thereby select two lines. When invoked inside a hunk body this
|
|
||||||
command does not move point on the first invocation and thereby
|
|
||||||
it only selects a single line. Which inconsistency you prefer
|
|
||||||
is a matter of preference."
|
|
||||||
(declare (interactive-only
|
|
||||||
"use `forward-line' with negative argument instead."))
|
|
||||||
(interactive "p\np")
|
|
||||||
(unless arg (setq arg 1))
|
|
||||||
(let ((stay (or (magit-diff-inside-hunk-body-p)
|
|
||||||
(magit-section-position-in-heading-p))))
|
|
||||||
(if (and stay (= arg 1) (magit--turn-on-shift-select-mode-p))
|
|
||||||
(push-mark nil nil t)
|
|
||||||
(with-no-warnings
|
|
||||||
(handle-shift-selection)
|
|
||||||
(previous-line (if stay (max (1- arg) 1) arg) try-vscroll)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-next-line (&optional arg try-vscroll)
|
|
||||||
"Like `next-line' but with Magit-specific shift-selection.
|
|
||||||
|
|
||||||
Magit's selection mechanism is based on the region but selects
|
|
||||||
an area that is larger than the region. This causes `next-line'
|
|
||||||
when invoked while holding the shift key to move down one line
|
|
||||||
and thereby select two lines. When invoked inside a hunk body
|
|
||||||
this command does not move point on the first invocation and
|
|
||||||
thereby it only selects a single line. Which inconsistency you
|
|
||||||
prefer is a matter of preference."
|
|
||||||
(declare (interactive-only forward-line))
|
|
||||||
(interactive "p\np")
|
|
||||||
(unless arg (setq arg 1))
|
|
||||||
(let ((stay (or (magit-diff-inside-hunk-body-p)
|
|
||||||
(magit-section-position-in-heading-p))))
|
|
||||||
(if (and stay (= arg 1) (magit--turn-on-shift-select-mode-p))
|
|
||||||
(push-mark nil nil t)
|
|
||||||
(with-no-warnings
|
|
||||||
(handle-shift-selection)
|
|
||||||
(next-line (if stay (max (1- arg) 1) arg) try-vscroll)))))
|
|
||||||
|
|
||||||
;;; Clean
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-clean (&optional arg)
|
|
||||||
"Remove untracked files from the working tree.
|
|
||||||
With a prefix argument also remove ignored files,
|
|
||||||
with two prefix arguments remove ignored files only.
|
|
||||||
\n(git clean -f -d [-x|-X])"
|
|
||||||
(interactive "p")
|
|
||||||
(when (yes-or-no-p (format "Remove %s files? "
|
|
||||||
(pcase arg
|
|
||||||
(1 "untracked")
|
|
||||||
(4 "untracked and ignored")
|
|
||||||
(_ "ignored"))))
|
|
||||||
(magit-wip-commit-before-change)
|
|
||||||
(magit-run-git "clean" "-f" "-d" (pcase arg (4 "-x") (16 "-X")))))
|
|
||||||
|
|
||||||
(put 'magit-clean 'disabled t)
|
|
||||||
|
|
||||||
;;; ChangeLog
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-add-change-log-entry (&optional whoami file-name other-window)
|
|
||||||
"Find change log file and add date entry and item for current change.
|
|
||||||
This differs from `add-change-log-entry' (which see) in that
|
|
||||||
it acts on the current hunk in a Magit buffer instead of on
|
|
||||||
a position in a file-visiting buffer."
|
|
||||||
(interactive (list current-prefix-arg
|
|
||||||
(prompt-for-change-log-name)))
|
|
||||||
(pcase-let ((`(,buf ,pos) (magit-diff-visit-file--noselect)))
|
|
||||||
(magit--with-temp-position buf pos
|
|
||||||
(add-change-log-entry whoami file-name other-window))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-add-change-log-entry-other-window (&optional whoami file-name)
|
|
||||||
"Find change log file in other window and add entry and item.
|
|
||||||
This differs from `add-change-log-entry-other-window' (which see)
|
|
||||||
in that it acts on the current hunk in a Magit buffer instead of
|
|
||||||
on a position in a file-visiting buffer."
|
|
||||||
(interactive (and current-prefix-arg
|
|
||||||
(list current-prefix-arg
|
|
||||||
(prompt-for-change-log-name))))
|
|
||||||
(magit-add-change-log-entry whoami file-name t))
|
|
||||||
|
|
||||||
;;; Edit Line Commit
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-edit-line-commit (&optional type)
|
|
||||||
"Edit the commit that added the current line.
|
|
||||||
|
|
||||||
With a prefix argument edit the commit that removes the line,
|
|
||||||
if any. The commit is determined using `git blame' and made
|
|
||||||
editable using `git rebase --interactive' if it is reachable
|
|
||||||
from `HEAD', or by checking out the commit (or a branch that
|
|
||||||
points at it) otherwise."
|
|
||||||
(interactive (list (and current-prefix-arg 'removal)))
|
|
||||||
(let* ((chunk (magit-current-blame-chunk (or type 'addition)))
|
|
||||||
(rev (oref chunk orig-rev)))
|
|
||||||
(if (equal rev "0000000000000000000000000000000000000000")
|
|
||||||
(message "This line has not been committed yet")
|
|
||||||
(let ((rebase (magit-rev-ancestor-p rev "HEAD"))
|
|
||||||
(file (expand-file-name (oref chunk orig-file)
|
|
||||||
(magit-toplevel))))
|
|
||||||
(if rebase
|
|
||||||
(let ((magit--rebase-published-symbol 'edit-published))
|
|
||||||
(magit-rebase-edit-commit rev (magit-rebase-arguments)))
|
|
||||||
(magit-checkout (or (magit-rev-branch rev) rev)))
|
|
||||||
(unless (and buffer-file-name
|
|
||||||
(file-equal-p file buffer-file-name))
|
|
||||||
(let ((blame-type (and magit-blame-mode magit-blame-type)))
|
|
||||||
(if rebase
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(magit-sequencer-process-sentinel process event)
|
|
||||||
(when (eq (process-status process) 'exit)
|
|
||||||
(find-file file)
|
|
||||||
(when blame-type
|
|
||||||
(magit-blame--pre-blame-setup blame-type)
|
|
||||||
(magit-blame--run (magit-blame-arguments))))))
|
|
||||||
(find-file file)
|
|
||||||
(when blame-type
|
|
||||||
(magit-blame--pre-blame-setup blame-type)
|
|
||||||
(magit-blame--run (magit-blame-arguments))))))))))
|
|
||||||
|
|
||||||
(put 'magit-edit-line-commit 'disabled t)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-diff-edit-hunk-commit (file)
|
|
||||||
"From a hunk, edit the respective commit and visit the file.
|
|
||||||
|
|
||||||
First visit the file being modified by the hunk at the correct
|
|
||||||
location using `magit-diff-visit-file'. This actually visits a
|
|
||||||
blob. When point is on a diff header, not within an individual
|
|
||||||
hunk, then this visits the blob the first hunk is about.
|
|
||||||
|
|
||||||
Then invoke `magit-edit-line-commit', which uses an interactive
|
|
||||||
rebase to make the commit editable, or if that is not possible
|
|
||||||
because the commit is not reachable from `HEAD' by checking out
|
|
||||||
that commit directly. This also causes the actual worktree file
|
|
||||||
to be visited.
|
|
||||||
|
|
||||||
Neither the blob nor the file buffer are killed when finishing
|
|
||||||
the rebase. If that is undesirable, then it might be better to
|
|
||||||
use `magit-rebase-edit-command' instead of this command."
|
|
||||||
(interactive (list (magit-file-at-point t t)))
|
|
||||||
(let ((magit-diff-visit-previous-blob nil))
|
|
||||||
(with-current-buffer
|
|
||||||
(magit-diff-visit-file--internal file nil #'pop-to-buffer-same-window)
|
|
||||||
(magit-edit-line-commit))))
|
|
||||||
|
|
||||||
(put 'magit-diff-edit-hunk-commit 'disabled t)
|
|
||||||
|
|
||||||
;;; Reshelve
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reshelve-since (rev)
|
|
||||||
"Change the author and committer dates of the commits since REV.
|
|
||||||
|
|
||||||
Ask the user for the first reachable commit whose dates should
|
|
||||||
be changed. Then read the new date for that commit. The initial
|
|
||||||
minibuffer input and the previous history element offer good
|
|
||||||
values. The next commit will be created one minute later and so
|
|
||||||
on.
|
|
||||||
|
|
||||||
This command is only intended for interactive use and should only
|
|
||||||
be used on highly rearranged and unpublished history."
|
|
||||||
(interactive (list nil))
|
|
||||||
(cond
|
|
||||||
((not rev)
|
|
||||||
(let ((backup (concat "refs/original/refs/heads/"
|
|
||||||
(magit-get-current-branch))))
|
|
||||||
(when (and (magit-ref-p backup)
|
|
||||||
(not (magit-y-or-n-p
|
|
||||||
"Backup ref %s already exists. Override? " backup)))
|
|
||||||
(user-error "Abort")))
|
|
||||||
(magit-log-select 'magit-reshelve-since
|
|
||||||
"Type %p on a commit to reshelve it and the commits above it,"))
|
|
||||||
(t
|
|
||||||
(cl-flet ((adjust (time offset)
|
|
||||||
(format-time-string
|
|
||||||
"%F %T %z"
|
|
||||||
(+ (floor time)
|
|
||||||
(* offset 60)
|
|
||||||
(- (car (decode-time time)))))))
|
|
||||||
(let* ((start (concat rev "^"))
|
|
||||||
(range (concat start ".." (magit-get-current-branch)))
|
|
||||||
(time-rev (adjust (float-time (string-to-number
|
|
||||||
(magit-rev-format "%at" start)))
|
|
||||||
1))
|
|
||||||
(time-now (adjust (float-time)
|
|
||||||
(- (string-to-number
|
|
||||||
(magit-git-string "rev-list" "--count"
|
|
||||||
range))))))
|
|
||||||
(push time-rev magit--reshelve-history)
|
|
||||||
(let ((date (floor
|
|
||||||
(float-time
|
|
||||||
(date-to-time
|
|
||||||
(read-string "Date for first commit: "
|
|
||||||
time-now 'magit--reshelve-history))))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async
|
|
||||||
"filter-branch" "--force" "--env-filter"
|
|
||||||
(format "case $GIT_COMMIT in %s\nesac"
|
|
||||||
(mapconcat (lambda (rev)
|
|
||||||
(prog1 (format "%s) \
|
|
||||||
export GIT_AUTHOR_DATE=\"%s\"; \
|
|
||||||
export GIT_COMMITTER_DATE=\"%s\";;" rev date date)
|
|
||||||
(cl-incf date 60)))
|
|
||||||
(magit-git-lines "rev-list" "--reverse"
|
|
||||||
range)
|
|
||||||
" "))
|
|
||||||
range "--")
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (> (process-exit-status process) 0)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(magit-run-git "update-ref" "-d"
|
|
||||||
(concat "refs/original/refs/heads/"
|
|
||||||
(magit-get-current-branch))))))))))))))
|
|
||||||
|
|
||||||
;;; Revision Stack
|
|
||||||
|
|
||||||
(defvar magit-revision-stack nil)
|
|
||||||
|
|
||||||
(defcustom magit-pop-revision-stack-format
|
|
||||||
'("[%N: %h] " "%N: %H\n %s\n" "\\[\\([0-9]+\\)[]:]")
|
|
||||||
"Control how `magit-pop-revision-stack' inserts a revision.
|
|
||||||
|
|
||||||
The command `magit-pop-revision-stack' inserts a representation
|
|
||||||
of the revision last pushed to the `magit-revision-stack' into
|
|
||||||
the current buffer. It inserts text at point and/or near the end
|
|
||||||
of the buffer, and removes the consumed revision from the stack.
|
|
||||||
|
|
||||||
The entries on the stack have the format (HASH TOPLEVEL) and this
|
|
||||||
option has the format (POINT-FORMAT EOB-FORMAT INDEX-REGEXP), all
|
|
||||||
of which may be nil or a string (though either one of EOB-FORMAT
|
|
||||||
or POINT-FORMAT should be a string, and if INDEX-REGEXP is
|
|
||||||
non-nil, then the two formats should be too).
|
|
||||||
|
|
||||||
First INDEX-REGEXP is used to find the previously inserted entry,
|
|
||||||
by searching backward from point. The first submatch must match
|
|
||||||
the index number. That number is incremented by one, and becomes
|
|
||||||
the index number of the entry to be inserted. If you don't want
|
|
||||||
to number the inserted revisions, then use nil for INDEX-REGEXP.
|
|
||||||
|
|
||||||
If INDEX-REGEXP is non-nil, then both POINT-FORMAT and EOB-FORMAT
|
|
||||||
should contain \"%N\", which is replaced with the number that was
|
|
||||||
determined in the previous step.
|
|
||||||
|
|
||||||
Both formats, if non-nil and after removing %N, are then expanded
|
|
||||||
using `git show --format=FORMAT ...' inside TOPLEVEL.
|
|
||||||
|
|
||||||
The expansion of POINT-FORMAT is inserted at point, and the
|
|
||||||
expansion of EOB-FORMAT is inserted at the end of the buffer (if
|
|
||||||
the buffer ends with a comment, then it is inserted right before
|
|
||||||
that)."
|
|
||||||
:package-version '(magit . "2.3.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(list (choice (string :tag "Insert at point format")
|
|
||||||
(cons (string :tag "Insert at point format")
|
|
||||||
(repeat (string :tag "Argument to git show")))
|
|
||||||
(const :tag "Don't insert at point" nil))
|
|
||||||
(choice (string :tag "Insert at eob format")
|
|
||||||
(cons (string :tag "Insert at eob format")
|
|
||||||
(repeat (string :tag "Argument to git show")))
|
|
||||||
(const :tag "Don't insert at eob" nil))
|
|
||||||
(choice (regexp :tag "Find index regexp")
|
|
||||||
(const :tag "Don't number entries" nil))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-pop-revision-stack (rev toplevel)
|
|
||||||
"Insert a representation of a revision into the current buffer.
|
|
||||||
|
|
||||||
Pop a revision from the `magit-revision-stack' and insert it into
|
|
||||||
the current buffer according to `magit-pop-revision-stack-format'.
|
|
||||||
Revisions can be put on the stack using `magit-copy-section-value'
|
|
||||||
and `magit-copy-buffer-revision'.
|
|
||||||
|
|
||||||
If the stack is empty or with a prefix argument, instead read a
|
|
||||||
revision in the minibuffer. By using the minibuffer history this
|
|
||||||
allows selecting an item which was popped earlier or to insert an
|
|
||||||
arbitrary reference or revision without first pushing it onto the
|
|
||||||
stack.
|
|
||||||
|
|
||||||
When reading the revision from the minibuffer, then it might not
|
|
||||||
be possible to guess the correct repository. When this command
|
|
||||||
is called inside a repository (e.g. while composing a commit
|
|
||||||
message), then that repository is used. Otherwise (e.g. while
|
|
||||||
composing an email) then the repository recorded for the top
|
|
||||||
element of the stack is used (even though we insert another
|
|
||||||
revision). If not called inside a repository and with an empty
|
|
||||||
stack, or with two prefix arguments, then read the repository in
|
|
||||||
the minibuffer too."
|
|
||||||
(interactive
|
|
||||||
(if (or current-prefix-arg (not magit-revision-stack))
|
|
||||||
(let ((default-directory
|
|
||||||
(or (and (not (= (prefix-numeric-value current-prefix-arg) 16))
|
|
||||||
(or (magit-toplevel)
|
|
||||||
(cadr (car magit-revision-stack))))
|
|
||||||
(magit-read-repository))))
|
|
||||||
(list (magit-read-branch-or-commit "Insert revision")
|
|
||||||
default-directory))
|
|
||||||
(push (caar magit-revision-stack) magit-revision-history)
|
|
||||||
(pop magit-revision-stack)))
|
|
||||||
(if rev
|
|
||||||
(pcase-let ((`(,pnt-format ,eob-format ,idx-format)
|
|
||||||
magit-pop-revision-stack-format))
|
|
||||||
(let ((default-directory toplevel)
|
|
||||||
(idx (and idx-format
|
|
||||||
(save-excursion
|
|
||||||
(if (re-search-backward idx-format nil t)
|
|
||||||
(number-to-string
|
|
||||||
(1+ (string-to-number (match-string 1))))
|
|
||||||
"1"))))
|
|
||||||
pnt-args eob-args)
|
|
||||||
(when (listp pnt-format)
|
|
||||||
(setq pnt-args (cdr pnt-format))
|
|
||||||
(setq pnt-format (car pnt-format)))
|
|
||||||
(when (listp eob-format)
|
|
||||||
(setq eob-args (cdr eob-format))
|
|
||||||
(setq eob-format (car eob-format)))
|
|
||||||
(when pnt-format
|
|
||||||
(when idx-format
|
|
||||||
(setq pnt-format
|
|
||||||
(replace-regexp-in-string "%N" idx pnt-format t t)))
|
|
||||||
(magit-rev-insert-format pnt-format rev pnt-args)
|
|
||||||
(backward-delete-char 1))
|
|
||||||
(when eob-format
|
|
||||||
(when idx-format
|
|
||||||
(setq eob-format
|
|
||||||
(replace-regexp-in-string "%N" idx eob-format t t)))
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (point-max))
|
|
||||||
(skip-syntax-backward ">s-")
|
|
||||||
(beginning-of-line)
|
|
||||||
(if (and comment-start (looking-at comment-start))
|
|
||||||
(while (looking-at comment-start)
|
|
||||||
(forward-line -1))
|
|
||||||
(forward-line)
|
|
||||||
(unless (= (current-column) 0)
|
|
||||||
(insert ?\n)))
|
|
||||||
(insert ?\n)
|
|
||||||
(magit-rev-insert-format eob-format rev eob-args)
|
|
||||||
(backward-delete-char 1)))))
|
|
||||||
(user-error "Revision stack is empty")))
|
|
||||||
|
|
||||||
(define-key git-commit-mode-map
|
|
||||||
(kbd "C-c C-w") 'magit-pop-revision-stack)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-copy-section-value ()
|
|
||||||
"Save the value of the current section for later use.
|
|
||||||
|
|
||||||
Save the section value to the `kill-ring', and, provided that
|
|
||||||
the current section is a commit, branch, or tag section, push
|
|
||||||
the (referenced) revision to the `magit-revision-stack' for use
|
|
||||||
with `magit-pop-revision-stack'.
|
|
||||||
|
|
||||||
When the current section is a branch or a tag, and a prefix
|
|
||||||
argument is used, then save the revision at its tip to the
|
|
||||||
`kill-ring' instead of the reference name.
|
|
||||||
|
|
||||||
When the region is active, then save that to the `kill-ring',
|
|
||||||
like `kill-ring-save' would, instead of behaving as described
|
|
||||||
above. If a prefix argument is used and the region is within a
|
|
||||||
hunk, strip the outer diff marker column."
|
|
||||||
(interactive)
|
|
||||||
(cond
|
|
||||||
((and current-prefix-arg
|
|
||||||
(magit-section-internal-region-p)
|
|
||||||
(magit-section-match 'hunk))
|
|
||||||
(deactivate-mark)
|
|
||||||
(kill-new (replace-regexp-in-string
|
|
||||||
"^[ \\+\\-]" ""
|
|
||||||
(buffer-substring-no-properties
|
|
||||||
(region-beginning) (region-end)))))
|
|
||||||
((use-region-p)
|
|
||||||
(call-interactively #'copy-region-as-kill))
|
|
||||||
(t
|
|
||||||
(when-let ((section (magit-current-section))
|
|
||||||
(value (oref section value)))
|
|
||||||
(magit-section-case
|
|
||||||
((branch commit module-commit tag)
|
|
||||||
(let ((default-directory default-directory) ref)
|
|
||||||
(magit-section-case
|
|
||||||
((branch tag)
|
|
||||||
(setq ref value))
|
|
||||||
(module-commit
|
|
||||||
(setq default-directory
|
|
||||||
(file-name-as-directory
|
|
||||||
(expand-file-name (magit-section-parent-value section)
|
|
||||||
(magit-toplevel))))))
|
|
||||||
(setq value (magit-rev-parse value))
|
|
||||||
(push (list value default-directory) magit-revision-stack)
|
|
||||||
(kill-new (message "%s" (or (and current-prefix-arg ref)
|
|
||||||
value)))))
|
|
||||||
(t (kill-new (message "%s" value))))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-copy-buffer-revision ()
|
|
||||||
"Save the revision of the current buffer for later use.
|
|
||||||
|
|
||||||
Save the revision shown in the current buffer to the `kill-ring'
|
|
||||||
and push it to the `magit-revision-stack'.
|
|
||||||
|
|
||||||
This command is mainly intended for use in `magit-revision-mode'
|
|
||||||
buffers, the only buffers where it is always unambiguous exactly
|
|
||||||
which revision should be saved.
|
|
||||||
|
|
||||||
Most other Magit buffers usually show more than one revision, in
|
|
||||||
some way or another, so this command has to select one of them,
|
|
||||||
and that choice might not always be the one you think would have
|
|
||||||
been the best pick.
|
|
||||||
|
|
||||||
In such buffers it is often more useful to save the value of
|
|
||||||
the current section instead, using `magit-copy-section-value'.
|
|
||||||
|
|
||||||
When the region is active, then save that to the `kill-ring',
|
|
||||||
like `kill-ring-save' would, instead of behaving as described
|
|
||||||
above."
|
|
||||||
(interactive)
|
|
||||||
(if (use-region-p)
|
|
||||||
(call-interactively #'copy-region-as-kill)
|
|
||||||
(when-let ((rev (or magit-buffer-revision
|
|
||||||
(cl-case major-mode
|
|
||||||
(magit-diff-mode
|
|
||||||
(if (string-match "\\.\\.\\.?\\(.+\\)"
|
|
||||||
magit-buffer-range)
|
|
||||||
(match-string 1 magit-buffer-range)
|
|
||||||
magit-buffer-range))
|
|
||||||
(magit-status-mode "HEAD")))))
|
|
||||||
(when (magit-commit-p rev)
|
|
||||||
(setq rev (magit-rev-parse rev))
|
|
||||||
(push (list rev default-directory) magit-revision-stack)
|
|
||||||
(kill-new (message "%s" rev))))))
|
|
||||||
|
|
||||||
;;; Miscellaneous
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-abort-dwim ()
|
|
||||||
"Abort current operation.
|
|
||||||
Depending on the context, this will abort a merge, a rebase, a
|
|
||||||
patch application, a cherry-pick, a revert, or a bisect."
|
|
||||||
(interactive)
|
|
||||||
(cond ((magit-merge-in-progress-p) (magit-merge-abort))
|
|
||||||
((magit-rebase-in-progress-p) (magit-rebase-abort))
|
|
||||||
((magit-am-in-progress-p) (magit-am-abort))
|
|
||||||
((magit-sequencer-in-progress-p) (magit-sequencer-abort))
|
|
||||||
((magit-bisect-in-progress-p) (magit-bisect-reset))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-extras)
|
|
||||||
;;; magit-extras.el ends here
|
|
Binary file not shown.
|
@ -1,186 +0,0 @@
|
||||||
;;; magit-fetch.el --- download objects and refs -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements fetch commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-fetch-modules-jobs 4
|
|
||||||
"Number of submodules to fetch in parallel.
|
|
||||||
Ignored for Git versions before v2.8.0."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "one at a time" nil) number))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-fetch "magit-fetch" nil t)
|
|
||||||
(define-transient-command magit-fetch ()
|
|
||||||
"Fetch from another repository."
|
|
||||||
:man-page "git-fetch"
|
|
||||||
["Arguments"
|
|
||||||
("-p" "Prune deleted branches" ("-p" "--prune"))
|
|
||||||
("-t" "Fetch all tags" ("-t" "--tags"))]
|
|
||||||
["Fetch from"
|
|
||||||
("p" magit-fetch-from-pushremote)
|
|
||||||
("u" magit-fetch-from-upstream)
|
|
||||||
("e" "elsewhere" magit-fetch-other)
|
|
||||||
("a" "all remotes" magit-fetch-all)]
|
|
||||||
["Fetch"
|
|
||||||
("o" "another branch" magit-fetch-branch)
|
|
||||||
("r" "explicit refspec" magit-fetch-refspec)
|
|
||||||
("m" "submodules" magit-fetch-modules)]
|
|
||||||
["Configure"
|
|
||||||
("C" "variables..." magit-branch-configure)])
|
|
||||||
|
|
||||||
(defun magit-fetch-arguments ()
|
|
||||||
(transient-args 'magit-fetch))
|
|
||||||
|
|
||||||
(defun magit-git-fetch (remote args)
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "fetch" remote args))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-fetch-from-pushremote "magit-fetch" nil t)
|
|
||||||
(define-suffix-command magit-fetch-from-pushremote (args)
|
|
||||||
"Fetch from the current push-remote.
|
|
||||||
|
|
||||||
When the push-remote is not configured, then read the push-remote
|
|
||||||
from the user, set it, and then fetch from it. With a prefix
|
|
||||||
argument the push-remote can be changed before fetching from it."
|
|
||||||
:description 'magit-fetch--pushremote-description
|
|
||||||
(interactive (list (magit-fetch-arguments)))
|
|
||||||
(let ((remote (magit-get-push-remote)))
|
|
||||||
(when (or current-prefix-arg
|
|
||||||
(not (member remote (magit-list-remotes))))
|
|
||||||
(let ((var (magit--push-remote-variable)))
|
|
||||||
(setq remote
|
|
||||||
(magit-read-remote (format "Set %s and fetch from there" var)))
|
|
||||||
(magit-set remote var)))
|
|
||||||
(magit-git-fetch remote args)))
|
|
||||||
|
|
||||||
(defun magit-fetch--pushremote-description ()
|
|
||||||
(let* ((branch (magit-get-current-branch))
|
|
||||||
(remote (magit-get-push-remote branch))
|
|
||||||
(v (magit--push-remote-variable branch t)))
|
|
||||||
(cond
|
|
||||||
((member remote (magit-list-remotes)) remote)
|
|
||||||
(remote
|
|
||||||
(format "%s, replacing invalid" v))
|
|
||||||
(t
|
|
||||||
(format "%s, setting that" v)))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-fetch-from-upstream "magit-fetch" nil t)
|
|
||||||
(define-suffix-command magit-fetch-from-upstream (remote args)
|
|
||||||
"Fetch from the \"current\" remote, usually the upstream.
|
|
||||||
|
|
||||||
If the upstream is configured for the current branch and names
|
|
||||||
an existing remote, then use that. Otherwise try to use another
|
|
||||||
remote: If only a single remote is configured, then use that.
|
|
||||||
Otherwise if a remote named \"origin\" exists, then use that.
|
|
||||||
|
|
||||||
If no remote can be determined, then this command is not available
|
|
||||||
from the `magit-fetch' transient prefix and invoking it directly
|
|
||||||
results in an error."
|
|
||||||
:if (lambda () (magit-get-current-remote t))
|
|
||||||
:description (lambda () (magit-get-current-remote t))
|
|
||||||
(interactive (list (magit-get-current-remote t)
|
|
||||||
(magit-fetch-arguments)))
|
|
||||||
(unless remote
|
|
||||||
(error "The \"current\" remote could not be determined"))
|
|
||||||
(magit-git-fetch remote args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-other (remote args)
|
|
||||||
"Fetch from another repository."
|
|
||||||
(interactive (list (magit-read-remote "Fetch remote")
|
|
||||||
(magit-fetch-arguments)))
|
|
||||||
(magit-git-fetch remote args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-branch (remote branch args)
|
|
||||||
"Fetch a BRANCH from a REMOTE."
|
|
||||||
(interactive
|
|
||||||
(let ((remote (magit-read-remote-or-url "Fetch from remote or url")))
|
|
||||||
(list remote
|
|
||||||
(magit-read-remote-branch "Fetch branch" remote)
|
|
||||||
(magit-fetch-arguments))))
|
|
||||||
(magit-git-fetch remote (cons branch args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-refspec (remote refspec args)
|
|
||||||
"Fetch a REFSPEC from a REMOTE."
|
|
||||||
(interactive
|
|
||||||
(let ((remote (magit-read-remote-or-url "Fetch from remote or url")))
|
|
||||||
(list remote
|
|
||||||
(magit-read-refspec "Fetch using refspec" remote)
|
|
||||||
(magit-fetch-arguments))))
|
|
||||||
(magit-git-fetch remote (cons refspec args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-all (args)
|
|
||||||
"Fetch from all remotes."
|
|
||||||
(interactive (list (magit-fetch-arguments)))
|
|
||||||
(magit-git-fetch nil (cons "--all" args)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-all-prune ()
|
|
||||||
"Fetch from all remotes, and prune.
|
|
||||||
Prune remote tracking branches for branches that have been
|
|
||||||
removed on the respective remote."
|
|
||||||
(interactive)
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "remote" "update" "--prune"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-all-no-prune ()
|
|
||||||
"Fetch from all remotes."
|
|
||||||
(interactive)
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "remote" "update"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-fetch-modules (&optional all)
|
|
||||||
"Fetch all submodules.
|
|
||||||
|
|
||||||
Option `magit-fetch-modules-jobs' controls how many submodules
|
|
||||||
are being fetched in parallel. Also fetch the super-repository,
|
|
||||||
because `git-fetch' does not support not doing that. With a
|
|
||||||
prefix argument fetch all remotes."
|
|
||||||
(interactive "P")
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async
|
|
||||||
"fetch" "--verbose" "--recurse-submodules"
|
|
||||||
(and magit-fetch-modules-jobs
|
|
||||||
(version<= "2.8.0" (magit-git-version))
|
|
||||||
(list "-j" (number-to-string magit-fetch-modules-jobs)))
|
|
||||||
(and all "--all"))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-fetch)
|
|
||||||
;;; magit-fetch.el ends here
|
|
Binary file not shown.
|
@ -1,558 +0,0 @@
|
||||||
;;; magit-files.el --- finding files -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for finding blobs, staged files,
|
|
||||||
;; and Git configuration files. It also implements modes useful in
|
|
||||||
;; buffers visiting files and blobs, and the commands used by those
|
|
||||||
;; modes.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Find Blob
|
|
||||||
|
|
||||||
(defvar magit-find-file-hook nil)
|
|
||||||
(add-hook 'magit-find-file-hook #'magit-blob-mode)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-find-file (rev file)
|
|
||||||
"View FILE from REV.
|
|
||||||
Switch to a buffer visiting blob REV:FILE, creating one if none
|
|
||||||
already exists. If prior to calling this command the current
|
|
||||||
buffer and/or cursor position is about the same file, then go
|
|
||||||
to the line and column corresponding to that location."
|
|
||||||
(interactive (magit-find-file-read-args "Find file"))
|
|
||||||
(magit-find-file--internal rev file #'pop-to-buffer-same-window))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-find-file-other-window (rev file)
|
|
||||||
"View FILE from REV, in another window.
|
|
||||||
Switch to a buffer visiting blob REV:FILE, creating one if none
|
|
||||||
already exists. If prior to calling this command the current
|
|
||||||
buffer and/or cursor position is about the same file, then go to
|
|
||||||
the line and column corresponding to that location."
|
|
||||||
(interactive (magit-find-file-read-args "Find file in other window"))
|
|
||||||
(magit-find-file--internal rev file #'switch-to-buffer-other-window))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-find-file-other-frame (rev file)
|
|
||||||
"View FILE from REV, in another frame.
|
|
||||||
Switch to a buffer visiting blob REV:FILE, creating one if none
|
|
||||||
already exists. If prior to calling this command the current
|
|
||||||
buffer and/or cursor position is about the same file, then go to
|
|
||||||
the line and column corresponding to that location."
|
|
||||||
(interactive (magit-find-file-read-args "Find file in other frame"))
|
|
||||||
(magit-find-file--internal rev file #'switch-to-buffer-other-frame))
|
|
||||||
|
|
||||||
(defun magit-find-file-read-args (prompt)
|
|
||||||
(let ((pseudo-revs '("{worktree}" "{index}")))
|
|
||||||
(if-let ((rev (magit-completing-read "Find file from revision"
|
|
||||||
(append pseudo-revs
|
|
||||||
(magit-list-refnames nil t))
|
|
||||||
nil nil nil 'magit-revision-history
|
|
||||||
(or (magit-branch-or-commit-at-point)
|
|
||||||
(magit-get-current-branch)))))
|
|
||||||
(list rev (magit-read-file-from-rev (if (member rev pseudo-revs)
|
|
||||||
"HEAD"
|
|
||||||
rev)
|
|
||||||
prompt))
|
|
||||||
(user-error "Nothing selected"))))
|
|
||||||
|
|
||||||
(defun magit-find-file--internal (rev file fn)
|
|
||||||
(let ((buf (magit-find-file-noselect rev file))
|
|
||||||
line col)
|
|
||||||
(when-let ((visited-file (magit-file-relative-name)))
|
|
||||||
(setq line (line-number-at-pos))
|
|
||||||
(setq col (current-column))
|
|
||||||
(cond
|
|
||||||
((not (equal visited-file file)))
|
|
||||||
((equal magit-buffer-revision rev))
|
|
||||||
((equal rev "{worktree}")
|
|
||||||
(setq line (magit-diff-visit--offset file magit-buffer-revision line)))
|
|
||||||
((equal rev "{index}")
|
|
||||||
(setq line (magit-diff-visit--offset file nil line)))
|
|
||||||
(magit-buffer-revision
|
|
||||||
(setq line (magit-diff-visit--offset
|
|
||||||
file (concat magit-buffer-revision ".." rev) line)))
|
|
||||||
(t
|
|
||||||
(setq line (magit-diff-visit--offset file (list "-R" rev) line)))))
|
|
||||||
(funcall fn buf)
|
|
||||||
(when line
|
|
||||||
(with-current-buffer buf
|
|
||||||
(widen)
|
|
||||||
(goto-char (point-min))
|
|
||||||
(forward-line (1- line))
|
|
||||||
(move-to-column col)))
|
|
||||||
buf))
|
|
||||||
|
|
||||||
(defun magit-find-file-noselect (rev file)
|
|
||||||
"Read FILE from REV into a buffer and return the buffer.
|
|
||||||
REV is a revision or one of \"{worktree}\" or \"{index}\".
|
|
||||||
FILE must be relative to the top directory of the repository."
|
|
||||||
(magit-find-file-noselect-1 rev file))
|
|
||||||
|
|
||||||
(defun magit-find-file-noselect-1 (rev file &optional revert)
|
|
||||||
"Read FILE from REV into a buffer and return the buffer.
|
|
||||||
REV is a revision or one of \"{worktree}\" or \"{index}\".
|
|
||||||
FILE must be relative to the top directory of the repository.
|
|
||||||
Non-nil REVERT means to revert the buffer. If `ask-revert',
|
|
||||||
then only after asking. A non-nil value for REVERT is ignored if REV is
|
|
||||||
\"{worktree}\"."
|
|
||||||
(if (equal rev "{worktree}")
|
|
||||||
(find-file-noselect (expand-file-name file (magit-toplevel)))
|
|
||||||
(let ((topdir (magit-toplevel)))
|
|
||||||
(when (file-name-absolute-p file)
|
|
||||||
(setq file (file-relative-name file topdir)))
|
|
||||||
(with-current-buffer (magit-get-revision-buffer-create rev file)
|
|
||||||
(when (or (not magit-buffer-file-name)
|
|
||||||
(if (eq revert 'ask-revert)
|
|
||||||
(y-or-n-p (format "%s already exists; revert it? "
|
|
||||||
(buffer-name))))
|
|
||||||
revert)
|
|
||||||
(setq magit-buffer-revision
|
|
||||||
(if (equal rev "{index}")
|
|
||||||
"{index}"
|
|
||||||
(magit-rev-format "%H" rev)))
|
|
||||||
(setq magit-buffer-refname rev)
|
|
||||||
(setq magit-buffer-file-name (expand-file-name file topdir))
|
|
||||||
(setq default-directory
|
|
||||||
(let ((dir (file-name-directory magit-buffer-file-name)))
|
|
||||||
(if (file-exists-p dir) dir topdir)))
|
|
||||||
(setq-local revert-buffer-function #'magit-revert-rev-file-buffer)
|
|
||||||
(revert-buffer t t)
|
|
||||||
(run-hooks (if (equal rev "{index}")
|
|
||||||
'magit-find-index-hook
|
|
||||||
'magit-find-file-hook)))
|
|
||||||
(current-buffer)))))
|
|
||||||
|
|
||||||
(defun magit-get-revision-buffer-create (rev file)
|
|
||||||
(magit-get-revision-buffer rev file t))
|
|
||||||
|
|
||||||
(defun magit-get-revision-buffer (rev file &optional create)
|
|
||||||
(funcall (if create 'get-buffer-create 'get-buffer)
|
|
||||||
(format "%s.~%s~" file (subst-char-in-string ?/ ?_ rev))))
|
|
||||||
|
|
||||||
(defun magit-revert-rev-file-buffer (_ignore-auto noconfirm)
|
|
||||||
(when (or noconfirm
|
|
||||||
(and (not (buffer-modified-p))
|
|
||||||
(catch 'found
|
|
||||||
(dolist (regexp revert-without-query)
|
|
||||||
(when (string-match regexp magit-buffer-file-name)
|
|
||||||
(throw 'found t)))))
|
|
||||||
(yes-or-no-p (format "Revert buffer from Git %s? "
|
|
||||||
(if (equal magit-buffer-refname "{index}")
|
|
||||||
"index"
|
|
||||||
(concat "revision " magit-buffer-refname)))))
|
|
||||||
(let* ((inhibit-read-only t)
|
|
||||||
(default-directory (magit-toplevel))
|
|
||||||
(file (file-relative-name magit-buffer-file-name))
|
|
||||||
(coding-system-for-read (or coding-system-for-read 'undecided)))
|
|
||||||
(erase-buffer)
|
|
||||||
(magit-git-insert "cat-file" "-p"
|
|
||||||
(if (equal magit-buffer-refname "{index}")
|
|
||||||
(concat ":" file)
|
|
||||||
(concat magit-buffer-refname ":" file)))
|
|
||||||
(setq buffer-file-coding-system last-coding-system-used))
|
|
||||||
(let ((buffer-file-name magit-buffer-file-name)
|
|
||||||
(after-change-major-mode-hook
|
|
||||||
(remq 'global-diff-hl-mode-enable-in-buffers
|
|
||||||
after-change-major-mode-hook)))
|
|
||||||
(normal-mode t))
|
|
||||||
(setq buffer-read-only t)
|
|
||||||
(set-buffer-modified-p nil)
|
|
||||||
(goto-char (point-min))))
|
|
||||||
|
|
||||||
;;; Find Index
|
|
||||||
|
|
||||||
(defvar magit-find-index-hook nil)
|
|
||||||
|
|
||||||
(defun magit-find-file-index-noselect (file &optional revert)
|
|
||||||
"Read FILE from the index into a buffer and return the buffer.
|
|
||||||
FILE must to be relative to the top directory of the repository."
|
|
||||||
(magit-find-file-noselect-1 "{index}" file (or revert 'ask-revert)))
|
|
||||||
|
|
||||||
(defun magit-update-index ()
|
|
||||||
"Update the index with the contents of the current buffer.
|
|
||||||
The current buffer has to be visiting a file in the index, which
|
|
||||||
is done using `magit-find-index-noselect'."
|
|
||||||
(interactive)
|
|
||||||
(let ((file (magit-file-relative-name)))
|
|
||||||
(unless (equal magit-buffer-refname "{index}")
|
|
||||||
(user-error "%s isn't visiting the index" file))
|
|
||||||
(if (y-or-n-p (format "Update index with contents of %s" (buffer-name)))
|
|
||||||
(let ((index (make-temp-file "index"))
|
|
||||||
(buffer (current-buffer)))
|
|
||||||
(when magit-wip-before-change-mode
|
|
||||||
(magit-wip-commit-before-change (list file) " before un-/stage"))
|
|
||||||
(let ((coding-system-for-write buffer-file-coding-system))
|
|
||||||
(with-temp-file index
|
|
||||||
(insert-buffer-substring buffer)))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-call-git "update-index" "--cacheinfo"
|
|
||||||
(substring (magit-git-string "ls-files" "-s" file)
|
|
||||||
0 6)
|
|
||||||
(magit-git-string "hash-object" "-t" "blob" "-w"
|
|
||||||
(concat "--path=" file)
|
|
||||||
"--" index)
|
|
||||||
file))
|
|
||||||
(set-buffer-modified-p nil)
|
|
||||||
(when magit-wip-after-apply-mode
|
|
||||||
(magit-wip-commit-after-apply (list file) " after un-/stage")))
|
|
||||||
(message "Abort")))
|
|
||||||
(--when-let (magit-get-mode-buffer 'magit-status-mode)
|
|
||||||
(with-current-buffer it (magit-refresh)))
|
|
||||||
t)
|
|
||||||
|
|
||||||
;;; Find Config File
|
|
||||||
|
|
||||||
(defun magit-find-git-config-file (filename &optional wildcards)
|
|
||||||
"Edit a file located in the current repository's git directory.
|
|
||||||
|
|
||||||
When \".git\", located at the root of the working tree, is a
|
|
||||||
regular file, then that makes it cumbersome to open a file
|
|
||||||
located in the actual git directory.
|
|
||||||
|
|
||||||
This command is like `find-file', except that it temporarily
|
|
||||||
binds `default-directory' to the actual git directory, while
|
|
||||||
reading the FILENAME."
|
|
||||||
(interactive
|
|
||||||
(let ((default-directory (magit-git-dir)))
|
|
||||||
(find-file-read-args "Find file: "
|
|
||||||
(confirm-nonexistent-file-or-buffer))))
|
|
||||||
(find-file filename wildcards))
|
|
||||||
|
|
||||||
(defun magit-find-git-config-file-other-window (filename &optional wildcards)
|
|
||||||
"Edit a file located in the current repository's git directory, in another window.
|
|
||||||
|
|
||||||
When \".git\", located at the root of the working tree, is a
|
|
||||||
regular file, then that makes it cumbersome to open a file
|
|
||||||
located in the actual git directory.
|
|
||||||
|
|
||||||
This command is like `find-file-other-window', except that it
|
|
||||||
temporarily binds `default-directory' to the actual git
|
|
||||||
directory, while reading the FILENAME."
|
|
||||||
(interactive
|
|
||||||
(let ((default-directory (magit-git-dir)))
|
|
||||||
(find-file-read-args "Find file in other window: "
|
|
||||||
(confirm-nonexistent-file-or-buffer))))
|
|
||||||
(find-file-other-window filename wildcards))
|
|
||||||
|
|
||||||
(defun magit-find-git-config-file-other-frame (filename &optional wildcards)
|
|
||||||
"Edit a file located in the current repository's git directory, in another frame.
|
|
||||||
|
|
||||||
When \".git\", located at the root of the working tree, is a
|
|
||||||
regular file, then that makes it cumbersome to open a file
|
|
||||||
located in the actual git directory.
|
|
||||||
|
|
||||||
This command is like `find-file-other-frame', except that it
|
|
||||||
temporarily binds `default-directory' to the actual git
|
|
||||||
directory, while reading the FILENAME."
|
|
||||||
(interactive
|
|
||||||
(let ((default-directory (magit-git-dir)))
|
|
||||||
(find-file-read-args "Find file in other frame: "
|
|
||||||
(confirm-nonexistent-file-or-buffer))))
|
|
||||||
(find-file-other-frame filename wildcards))
|
|
||||||
|
|
||||||
;;; File Mode
|
|
||||||
|
|
||||||
(defvar magit-file-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map "\C-xg" 'magit-status)
|
|
||||||
(define-key map "\C-x\M-g" 'magit-dispatch)
|
|
||||||
(define-key map "\C-c\M-g" 'magit-file-dispatch)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-file-mode'.")
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-file-dispatch "magit" nil t)
|
|
||||||
(define-transient-command magit-file-dispatch ()
|
|
||||||
"Invoke a Magit command that acts on the visited file."
|
|
||||||
:info-manual "(magit) Minor Mode for Buffers Visiting Files"
|
|
||||||
["Actions"
|
|
||||||
[("s" "Stage" magit-stage-file)
|
|
||||||
("u" "Unstage" magit-unstage-file)
|
|
||||||
("c" "Commit" magit-commit)
|
|
||||||
("e" "Edit line" magit-edit-line-commit)]
|
|
||||||
[("D" "Diff..." magit-diff)
|
|
||||||
("d" "Diff" magit-diff-buffer-file)
|
|
||||||
("g" "Status" magit-status-here)]
|
|
||||||
[("L" "Log..." magit-log)
|
|
||||||
("l" "Log" magit-log-buffer-file)
|
|
||||||
("t" "Trace" magit-log-trace-definition)]
|
|
||||||
[("B" "Blame..." magit-blame)
|
|
||||||
("b" "Blame" magit-blame-addition)
|
|
||||||
("r" "...removal" magit-blame-removal)
|
|
||||||
("f" "...reverse" magit-blame-reverse)
|
|
||||||
("m" "Blame echo" magit-blame-echo)
|
|
||||||
("q" "Quit blame" magit-blame-quit)]
|
|
||||||
[("p" "Prev blob" magit-blob-previous)
|
|
||||||
("n" "Next blob" magit-blob-next)
|
|
||||||
("v" "Goto blob" magit-find-file)
|
|
||||||
("V" "Goto file" magit-blob-visit-file)]
|
|
||||||
[(5 "C-c r" "Rename file" magit-file-rename)
|
|
||||||
(5 "C-c d" "Delete file" magit-file-delete)
|
|
||||||
(5 "C-c u" "Untrack file" magit-file-untrack)
|
|
||||||
(5 "C-c c" "Checkout file" magit-file-checkout)]])
|
|
||||||
|
|
||||||
(defvar magit-file-mode-lighter "")
|
|
||||||
|
|
||||||
(define-minor-mode magit-file-mode
|
|
||||||
"Enable some Magit features in a file-visiting buffer.
|
|
||||||
|
|
||||||
Currently this only adds the following key bindings.
|
|
||||||
\n\\{magit-file-mode-map}"
|
|
||||||
:package-version '(magit . "2.2.0")
|
|
||||||
:lighter magit-file-mode-lighter
|
|
||||||
:keymap magit-file-mode-map)
|
|
||||||
|
|
||||||
(defun magit-file-mode-turn-on ()
|
|
||||||
(and buffer-file-name
|
|
||||||
(magit-inside-worktree-p t)
|
|
||||||
(magit-file-mode)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-globalized-minor-mode global-magit-file-mode
|
|
||||||
magit-file-mode magit-file-mode-turn-on
|
|
||||||
:package-version '(magit . "2.13.0")
|
|
||||||
:link '(info-link "(magit)Minor Mode for Buffers Visiting Files")
|
|
||||||
:group 'magit-essentials
|
|
||||||
:group 'magit-modes
|
|
||||||
:init-value t)
|
|
||||||
;; Unfortunately `:init-value t' only sets the value of the mode
|
|
||||||
;; variable but does not cause the mode function to be called, and we
|
|
||||||
;; cannot use `:initialize' to call that explicitly because the option
|
|
||||||
;; is defined before the functions, so we have to do it here.
|
|
||||||
(cl-eval-when (load eval)
|
|
||||||
(when global-magit-file-mode
|
|
||||||
(global-magit-file-mode 1)))
|
|
||||||
|
|
||||||
;;; Blob Mode
|
|
||||||
|
|
||||||
(defvar magit-blob-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(cond ((featurep 'jkl)
|
|
||||||
(define-key map "i" 'magit-blob-previous)
|
|
||||||
(define-key map "k" 'magit-blob-next)
|
|
||||||
(define-key map "j" 'magit-blame-addition)
|
|
||||||
(define-key map "l" 'magit-blame-removal)
|
|
||||||
(define-key map "f" 'magit-blame-reverse))
|
|
||||||
(t
|
|
||||||
(define-key map "p" 'magit-blob-previous)
|
|
||||||
(define-key map "n" 'magit-blob-next)
|
|
||||||
(define-key map "b" 'magit-blame-addition)
|
|
||||||
(define-key map "r" 'magit-blame-removal)
|
|
||||||
(define-key map "f" 'magit-blame-reverse)))
|
|
||||||
(define-key map "q" 'magit-kill-this-buffer)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-blob-mode'.")
|
|
||||||
|
|
||||||
(define-minor-mode magit-blob-mode
|
|
||||||
"Enable some Magit features in blob-visiting buffers.
|
|
||||||
|
|
||||||
Currently this only adds the following key bindings.
|
|
||||||
\n\\{magit-blob-mode-map}"
|
|
||||||
:package-version '(magit . "2.3.0"))
|
|
||||||
|
|
||||||
(defun magit-blob-next ()
|
|
||||||
"Visit the next blob which modified the current file."
|
|
||||||
(interactive)
|
|
||||||
(if magit-buffer-file-name
|
|
||||||
(magit-blob-visit (or (magit-blob-successor magit-buffer-revision
|
|
||||||
magit-buffer-file-name)
|
|
||||||
magit-buffer-file-name))
|
|
||||||
(if (buffer-file-name (buffer-base-buffer))
|
|
||||||
(user-error "You have reached the end of time")
|
|
||||||
(user-error "Buffer isn't visiting a file or blob"))))
|
|
||||||
|
|
||||||
(defun magit-blob-previous ()
|
|
||||||
"Visit the previous blob which modified the current file."
|
|
||||||
(interactive)
|
|
||||||
(if-let ((file (or magit-buffer-file-name
|
|
||||||
(buffer-file-name (buffer-base-buffer)))))
|
|
||||||
(--if-let (magit-blob-ancestor magit-buffer-revision file)
|
|
||||||
(magit-blob-visit it)
|
|
||||||
(user-error "You have reached the beginning of time"))
|
|
||||||
(user-error "Buffer isn't visiting a file or blob")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-blob-visit-file ()
|
|
||||||
"View the file from the worktree corresponding to the current blob.
|
|
||||||
When visiting a blob or the version from the index, then go to
|
|
||||||
the same location in the respective file in the working tree."
|
|
||||||
(interactive)
|
|
||||||
(if-let ((file (magit-file-relative-name)))
|
|
||||||
(magit-find-file--internal "{worktree}" file #'pop-to-buffer-same-window)
|
|
||||||
(user-error "Not visiting a blob")))
|
|
||||||
|
|
||||||
(defun magit-blob-visit (blob-or-file)
|
|
||||||
(if (stringp blob-or-file)
|
|
||||||
(find-file blob-or-file)
|
|
||||||
(pcase-let ((`(,rev ,file) blob-or-file))
|
|
||||||
(magit-find-file rev file)
|
|
||||||
(apply #'message "%s (%s %s ago)"
|
|
||||||
(magit-rev-format "%s" rev)
|
|
||||||
(magit--age (magit-rev-format "%ct" rev))))))
|
|
||||||
|
|
||||||
(defun magit-blob-ancestor (rev file)
|
|
||||||
(let ((lines (magit-with-toplevel
|
|
||||||
(magit-git-lines "log" "-2" "--format=%H" "--name-only"
|
|
||||||
"--follow" (or rev "HEAD") "--" file))))
|
|
||||||
(if rev (cddr lines) (butlast lines 2))))
|
|
||||||
|
|
||||||
(defun magit-blob-successor (rev file)
|
|
||||||
(let ((lines (magit-with-toplevel
|
|
||||||
(magit-git-lines "log" "--format=%H" "--name-only" "--follow"
|
|
||||||
"HEAD" "--" file))))
|
|
||||||
(catch 'found
|
|
||||||
(while lines
|
|
||||||
(if (equal (nth 2 lines) rev)
|
|
||||||
(throw 'found (list (nth 0 lines) (nth 1 lines)))
|
|
||||||
(setq lines (nthcdr 2 lines)))))))
|
|
||||||
|
|
||||||
;;; File Commands
|
|
||||||
|
|
||||||
(defun magit-file-rename (file newname)
|
|
||||||
"Rename the FILE to NEWNAME.
|
|
||||||
If FILE isn't tracked in Git, fallback to using `rename-file'."
|
|
||||||
(interactive
|
|
||||||
(let* ((file (magit-read-file "Rename file"))
|
|
||||||
(dir (file-name-directory file))
|
|
||||||
(newname (read-file-name (format "Rename %s to file: " file)
|
|
||||||
(and dir (expand-file-name dir)))))
|
|
||||||
(list (expand-file-name file (magit-toplevel))
|
|
||||||
(expand-file-name newname))))
|
|
||||||
(let ((oldbuf (get-file-buffer file)))
|
|
||||||
(when (and oldbuf (buffer-modified-p oldbuf))
|
|
||||||
(user-error "Save %s before moving it" file))
|
|
||||||
(when (file-exists-p newname)
|
|
||||||
(user-error "%s already exists" newname))
|
|
||||||
(if (magit-file-tracked-p (magit-convert-filename-for-git file))
|
|
||||||
(magit-call-git "mv"
|
|
||||||
(magit-convert-filename-for-git file)
|
|
||||||
(magit-convert-filename-for-git newname))
|
|
||||||
(rename-file file newname current-prefix-arg))
|
|
||||||
(when oldbuf
|
|
||||||
(with-current-buffer oldbuf
|
|
||||||
(let ((buffer-read-only buffer-read-only))
|
|
||||||
(set-visited-file-name newname nil t))
|
|
||||||
(if (fboundp 'vc-refresh-state)
|
|
||||||
(vc-refresh-state)
|
|
||||||
(with-no-warnings
|
|
||||||
(vc-find-file-hook))))))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
(defun magit-file-untrack (files &optional force)
|
|
||||||
"Untrack the selected FILES or one file read in the minibuffer.
|
|
||||||
|
|
||||||
With a prefix argument FORCE do so even when the files have
|
|
||||||
staged as well as unstaged changes."
|
|
||||||
(interactive (list (or (--if-let (magit-region-values 'file t)
|
|
||||||
(progn
|
|
||||||
(unless (magit-file-tracked-p (car it))
|
|
||||||
(user-error "Already untracked"))
|
|
||||||
(magit-confirm-files 'untrack it "Untrack"))
|
|
||||||
(list (magit-read-tracked-file "Untrack file"))))
|
|
||||||
current-prefix-arg))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "rm" "--cached" (and force "--force") "--" files)))
|
|
||||||
|
|
||||||
(defun magit-file-delete (files &optional force)
|
|
||||||
"Delete the selected FILES or one file read in the minibuffer.
|
|
||||||
|
|
||||||
With a prefix argument FORCE do so even when the files have
|
|
||||||
uncommitted changes. When the files aren't being tracked in
|
|
||||||
Git, then fallback to using `delete-file'."
|
|
||||||
(interactive (list (--if-let (magit-region-values 'file t)
|
|
||||||
(magit-confirm-files 'delete it "Delete")
|
|
||||||
(list (magit-read-file "Delete file")))
|
|
||||||
current-prefix-arg))
|
|
||||||
(if (magit-file-tracked-p (car files))
|
|
||||||
(magit-call-git "rm" (and force "--force") "--" files)
|
|
||||||
(let ((topdir (magit-toplevel)))
|
|
||||||
(dolist (file files)
|
|
||||||
(delete-file (expand-file-name file topdir) t))))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-file-checkout (rev file)
|
|
||||||
"Checkout FILE from REV."
|
|
||||||
(interactive
|
|
||||||
(let ((rev (magit-read-branch-or-commit
|
|
||||||
"Checkout from revision" magit-buffer-revision)))
|
|
||||||
(list rev (magit-read-file-from-rev rev "Checkout file"))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "checkout" rev "--" file)))
|
|
||||||
|
|
||||||
;;; Read File
|
|
||||||
|
|
||||||
(defvar magit-read-file-hist nil)
|
|
||||||
|
|
||||||
(defun magit-read-file-from-rev (rev prompt &optional default)
|
|
||||||
(let ((files (magit-revision-files rev)))
|
|
||||||
(magit-completing-read
|
|
||||||
prompt files nil t nil 'magit-read-file-hist
|
|
||||||
(car (member (or default (magit-current-file)) files)))))
|
|
||||||
|
|
||||||
(defun magit-read-file (prompt &optional tracked-only)
|
|
||||||
(let ((choices (nconc (magit-list-files)
|
|
||||||
(unless tracked-only (magit-untracked-files)))))
|
|
||||||
(magit-completing-read
|
|
||||||
prompt choices nil t nil nil
|
|
||||||
(car (member (or (magit-section-value-if '(file submodule))
|
|
||||||
(magit-file-relative-name nil tracked-only))
|
|
||||||
choices)))))
|
|
||||||
|
|
||||||
(defun magit-read-tracked-file (prompt)
|
|
||||||
(magit-read-file prompt t))
|
|
||||||
|
|
||||||
(defun magit-read-file-choice (prompt files &optional error default)
|
|
||||||
"Read file from FILES.
|
|
||||||
|
|
||||||
If FILES has only one member, return that instead of prompting.
|
|
||||||
If FILES has no members, give a user error. ERROR can be given
|
|
||||||
to provide a more informative error.
|
|
||||||
|
|
||||||
If DEFAULT is non-nil, use this as the default value instead of
|
|
||||||
`magit-current-file'."
|
|
||||||
(pcase (length files)
|
|
||||||
(0 (user-error (or error "No file choices")))
|
|
||||||
(1 (car files))
|
|
||||||
(_ (magit-completing-read
|
|
||||||
prompt files nil t nil 'magit-read-file-hist
|
|
||||||
(car (member (or default (magit-current-file)) files))))))
|
|
||||||
|
|
||||||
(defun magit-read-changed-file (rev-or-range prompt &optional default)
|
|
||||||
(magit-read-file-choice
|
|
||||||
prompt
|
|
||||||
(magit-changed-files rev-or-range)
|
|
||||||
default
|
|
||||||
(concat "No file changed in " rev-or-range)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-files)
|
|
||||||
;;; magit-files.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,197 +0,0 @@
|
||||||
;;; magit-gitignore.el --- intentionally untracked files -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements gitignore commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Transient
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-gitignore "magit-gitignore" nil t)
|
|
||||||
(define-transient-command magit-gitignore ()
|
|
||||||
"Instruct Git to ignore a file or pattern."
|
|
||||||
:man-page "gitignore"
|
|
||||||
["Gitignore"
|
|
||||||
("t" "shared at toplevel (.gitignore)"
|
|
||||||
magit-gitignore-in-topdir)
|
|
||||||
("s" "shared in subdirectory (path/to/.gitignore)"
|
|
||||||
magit-gitignore-in-subdir)
|
|
||||||
("p" "privately (.git/info/exclude)"
|
|
||||||
magit-gitignore-in-gitdir)
|
|
||||||
("g" magit-gitignore-on-system
|
|
||||||
:if (lambda () (magit-get "core.excludesfile"))
|
|
||||||
:description (lambda ()
|
|
||||||
(format "privately for all repositories (%s)"
|
|
||||||
(magit-get "core.excludesfile"))))]
|
|
||||||
["Skip worktree"
|
|
||||||
(7 "w" "do skip worktree" magit-skip-worktree)
|
|
||||||
(7 "W" "do not skip worktree" magit-no-skip-worktree)]
|
|
||||||
["Assume unchanged"
|
|
||||||
(7 "u" "do assume unchanged" magit-assume-unchanged)
|
|
||||||
(7 "U" "do not assume unchanged" magit-no-assume-unchanged)])
|
|
||||||
|
|
||||||
;;; Gitignore Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-gitignore-in-topdir (rule)
|
|
||||||
"Add the Git ignore RULE to the top-level \".gitignore\" file.
|
|
||||||
Since this file is tracked, it is shared with other clones of the
|
|
||||||
repository. Also stage the file."
|
|
||||||
(interactive (list (magit-gitignore-read-pattern)))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit--gitignore rule ".gitignore")
|
|
||||||
(magit-run-git "add" ".gitignore")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-gitignore-in-subdir (rule directory)
|
|
||||||
"Add the Git ignore RULE to a \".gitignore\" file.
|
|
||||||
Prompted the user for a directory and add the rule to the
|
|
||||||
\".gitignore\" file in that directory. Since such files are
|
|
||||||
tracked, they are shared with other clones of the repository.
|
|
||||||
Also stage the file."
|
|
||||||
(interactive (list (magit-gitignore-read-pattern)
|
|
||||||
(read-directory-name "Limit rule to files in: ")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((file (expand-file-name ".gitignore" directory)))
|
|
||||||
(magit--gitignore rule file)
|
|
||||||
(magit-run-git "add" file))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-gitignore-in-gitdir (rule)
|
|
||||||
"Add the Git ignore RULE to \"$GIT_DIR/info/exclude\".
|
|
||||||
Rules in that file only affects this clone of the repository."
|
|
||||||
(interactive (list (magit-gitignore-read-pattern)))
|
|
||||||
(magit--gitignore rule (magit-git-dir "info/exclude"))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-gitignore-on-system (rule)
|
|
||||||
"Add the Git ignore RULE to the file specified by `core.excludesFile'.
|
|
||||||
Rules that are defined in that file affect all local repositories."
|
|
||||||
(interactive (list (magit-gitignore-read-pattern)))
|
|
||||||
(magit--gitignore rule
|
|
||||||
(or (magit-get "core.excludesFile")
|
|
||||||
(error "Variable `core.excludesFile' isn't set")))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
(defun magit--gitignore (rule file)
|
|
||||||
(when-let ((directory (file-name-directory file)))
|
|
||||||
(make-directory directory t))
|
|
||||||
(with-temp-buffer
|
|
||||||
(when (file-exists-p file)
|
|
||||||
(insert-file-contents file))
|
|
||||||
(goto-char (point-max))
|
|
||||||
(unless (bolp)
|
|
||||||
(insert "\n"))
|
|
||||||
(insert (replace-regexp-in-string "\\(\\\\*\\)" "\\1\\1" rule))
|
|
||||||
(insert "\n")
|
|
||||||
(write-region nil nil file)))
|
|
||||||
|
|
||||||
(defun magit-gitignore-read-pattern ()
|
|
||||||
(let* ((default (magit-current-file))
|
|
||||||
(base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base))
|
|
||||||
(choices
|
|
||||||
(delete-dups
|
|
||||||
(--mapcat
|
|
||||||
(cons (concat "/" it)
|
|
||||||
(when-let ((ext (file-name-extension it)))
|
|
||||||
(list (concat "/" (file-name-directory it) "*." ext)
|
|
||||||
(concat "*." ext))))
|
|
||||||
(sort (nconc
|
|
||||||
(magit-untracked-files nil base)
|
|
||||||
;; The untracked section of the status buffer lists
|
|
||||||
;; directories containing only untracked files.
|
|
||||||
;; Add those as candidates.
|
|
||||||
(-filter #'directory-name-p
|
|
||||||
(magit-list-files
|
|
||||||
"--other" "--exclude-standard" "--directory"
|
|
||||||
"--no-empty-directory" "--" base)))
|
|
||||||
#'string-lessp)))))
|
|
||||||
(when default
|
|
||||||
(setq default (concat "/" default))
|
|
||||||
(unless (member default choices)
|
|
||||||
(setq default (concat "*." (file-name-extension default)))
|
|
||||||
(unless (member default choices)
|
|
||||||
(setq default nil))))
|
|
||||||
(magit-completing-read "File or pattern to ignore"
|
|
||||||
choices nil nil nil nil default)))
|
|
||||||
|
|
||||||
;;; Skip Worktree Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-skip-worktree (file)
|
|
||||||
"Call \"git update-index --skip-worktree -- FILE\"."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Skip worktree for"
|
|
||||||
(magit-with-toplevel
|
|
||||||
(cl-set-difference
|
|
||||||
(magit-list-files)
|
|
||||||
(magit-skip-worktree-files))))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "update-index" "--skip-worktree" "--" file)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-no-skip-worktree (file)
|
|
||||||
"Call \"git update-index --no-skip-worktree -- FILE\"."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Do not skip worktree for"
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-skip-worktree-files)))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "update-index" "--no-skip-worktree" "--" file)))
|
|
||||||
|
|
||||||
;;; Assume Unchanged Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-assume-unchanged (file)
|
|
||||||
"Call \"git update-index --assume-unchanged -- FILE\"."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Assume file to be unchanged"
|
|
||||||
(magit-with-toplevel
|
|
||||||
(cl-set-difference
|
|
||||||
(magit-list-files)
|
|
||||||
(magit-assume-unchanged-files))))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "update-index" "--assume-unchanged" "--" file)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-no-assume-unchanged (file)
|
|
||||||
"Call \"git update-index --no-assume-unchanged -- FILE\"."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-file-choice "Do not assume file to be unchanged"
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-assume-unchanged-files)))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git "update-index" "--no-assume-unchanged" "--" file)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-gitignore)
|
|
||||||
;;; magit-gitignore.el ends here
|
|
Binary file not shown.
|
@ -1,245 +0,0 @@
|
||||||
;;; magit-imenu.el --- Integrate Imenu in magit major modes -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Damien Cassou <damien@cassou.me>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Emacs' major modes can facilitate navigation in their buffers by
|
|
||||||
;; supporting Imenu. In such major modes, launching Imenu (M-x imenu)
|
|
||||||
;; makes Emacs display a list of items (e.g., function definitions in
|
|
||||||
;; a programming major mode). Selecting an item from this list moves
|
|
||||||
;; point to this item.
|
|
||||||
|
|
||||||
;; magit-imenu.el adds Imenu support to every major mode in Magit.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'git-rebase)
|
|
||||||
|
|
||||||
;;; Core
|
|
||||||
|
|
||||||
(defun magit-imenu--index-function (entry-types menu-types)
|
|
||||||
"Return an alist of imenu entries in current buffer.
|
|
||||||
|
|
||||||
ENTRY-TYPES is a list of section types to be selected through
|
|
||||||
`imenu'.
|
|
||||||
|
|
||||||
MENU-TYPES is a list of section types containing elements of
|
|
||||||
ENTRY-TYPES. Elements of MENU-TYPES are are used to categories
|
|
||||||
elements of ENTRY-TYPES.
|
|
||||||
|
|
||||||
This function is used as a helper for functions set as
|
|
||||||
`imenu-create-index-function'."
|
|
||||||
(let ((entries (make-hash-table :test 'equal)))
|
|
||||||
(goto-char (point-max))
|
|
||||||
(while (magit-section--backward-find
|
|
||||||
(lambda ()
|
|
||||||
(let* ((section (magit-current-section))
|
|
||||||
(type (oref section type))
|
|
||||||
(parent (oref section parent))
|
|
||||||
(parent-type (oref parent type)))
|
|
||||||
(and (-contains-p entry-types type)
|
|
||||||
(-contains-p menu-types parent-type)))))
|
|
||||||
(let* ((section (magit-current-section))
|
|
||||||
(name (buffer-substring-no-properties
|
|
||||||
(line-beginning-position)
|
|
||||||
(line-end-position)))
|
|
||||||
(parent (oref section parent))
|
|
||||||
(parent-title (buffer-substring-no-properties
|
|
||||||
(oref parent start)
|
|
||||||
(1- (oref parent content)))))
|
|
||||||
(puthash parent-title
|
|
||||||
(cons (cons name (point))
|
|
||||||
(gethash parent-title entries (list)))
|
|
||||||
entries)))
|
|
||||||
(mapcar (lambda (menu-title)
|
|
||||||
(cons menu-title (gethash menu-title entries)))
|
|
||||||
(hash-table-keys entries))))
|
|
||||||
|
|
||||||
;;; Log mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--log-prev-index-position-function ()
|
|
||||||
"Move point to previous line in current buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(magit-section--backward-find
|
|
||||||
(lambda ()
|
|
||||||
(-contains-p '(commit stash)
|
|
||||||
(oref (magit-current-section) type)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--log-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(save-match-data
|
|
||||||
(looking-at "\\([^ ]+\\)[ *|]+\\(.+\\)$")
|
|
||||||
(format "%s: %s"
|
|
||||||
(match-string-no-properties 1)
|
|
||||||
(match-string-no-properties 2))))
|
|
||||||
|
|
||||||
;;; Diff mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--diff-prev-index-position-function ()
|
|
||||||
"Move point to previous file line in current buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(magit-section--backward-find
|
|
||||||
(lambda ()
|
|
||||||
(let ((section (magit-current-section)))
|
|
||||||
(and (magit-file-section-p section)
|
|
||||||
(not (equal (oref (oref section parent) type)
|
|
||||||
'diffstat)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--diff-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(buffer-substring-no-properties (line-beginning-position)
|
|
||||||
(line-end-position)))
|
|
||||||
|
|
||||||
;;; Status mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--status-create-index-function ()
|
|
||||||
"Return an alist of all imenu entries in current buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-create-index-function'."
|
|
||||||
(magit-imenu--index-function
|
|
||||||
'(file commit stash)
|
|
||||||
'(unpushed unstaged unpulled untracked staged stashes)))
|
|
||||||
|
|
||||||
;;;; Refs mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--refs-create-index-function ()
|
|
||||||
"Return an alist of all imenu entries in current buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-create-index-function'."
|
|
||||||
(magit-imenu--index-function
|
|
||||||
'(branch commit tag)
|
|
||||||
'(local remote tags)))
|
|
||||||
|
|
||||||
;;;; Cherry mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--cherry-create-index-function ()
|
|
||||||
"Return an alist of all imenu entries in current buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-create-index-function'."
|
|
||||||
(magit-imenu--index-function
|
|
||||||
'(commit)
|
|
||||||
'(cherries)))
|
|
||||||
|
|
||||||
;;;; Submodule list mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--submodule-prev-index-position-function ()
|
|
||||||
"Move point to previous line in magit-submodule-list buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(unless (bobp)
|
|
||||||
(forward-line -1)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--submodule-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(elt (tabulated-list-get-entry) 0))
|
|
||||||
|
|
||||||
;;;; Repolist mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--repolist-prev-index-position-function ()
|
|
||||||
"Move point to previous line in magit-repolist buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(unless (bobp)
|
|
||||||
(forward-line -1)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--repolist-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(let ((entry (tabulated-list-get-entry)))
|
|
||||||
(format "%s (%s)"
|
|
||||||
(elt entry 0)
|
|
||||||
(elt entry (1- (length entry))))))
|
|
||||||
|
|
||||||
;;;; Process mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--process-prev-index-position-function ()
|
|
||||||
"Move point to previous process in magit-process buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(magit-section--backward-find
|
|
||||||
(lambda ()
|
|
||||||
(eq (oref (magit-current-section) type) 'process))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--process-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(buffer-substring-no-properties (line-beginning-position)
|
|
||||||
(line-end-position)))
|
|
||||||
|
|
||||||
;;;; Rebase mode
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--rebase-prev-index-position-function ()
|
|
||||||
"Move point to previous commit in git-rebase buffer.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-prev-index-position-function'."
|
|
||||||
(catch 'found
|
|
||||||
(while (not (bobp))
|
|
||||||
(git-rebase-backward-line)
|
|
||||||
(when (git-rebase-line-p)
|
|
||||||
(throw 'found t)))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-imenu--rebase-extract-index-name-function ()
|
|
||||||
"Return imenu name for line at point.
|
|
||||||
This function is used as a value for
|
|
||||||
`imenu-extract-index-name-function'. Point should be at the
|
|
||||||
beginning of the line."
|
|
||||||
(buffer-substring-no-properties (line-beginning-position)
|
|
||||||
(line-end-position)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-imenu)
|
|
||||||
;;; magit-imenu.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,241 +0,0 @@
|
||||||
;;; magit-margin.el --- margins in Magit buffers -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for showing additional information
|
|
||||||
;; in the margins of Magit buffers. Currently this is only used for
|
|
||||||
;; commits, for which the committer date or age, and optionally the
|
|
||||||
;; author name are shown.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'dash)
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit-section)
|
|
||||||
(require 'magit-transient)
|
|
||||||
(require 'magit-mode)
|
|
||||||
|
|
||||||
(defgroup magit-margin nil
|
|
||||||
"Information Magit displays in the margin.
|
|
||||||
|
|
||||||
You can change the STYLE and AUTHOR-WIDTH of all `magit-*-margin'
|
|
||||||
options to the same values by customizing `magit-log-margin'
|
|
||||||
*before* `magit' is loaded. If you do that, then the respective
|
|
||||||
values for the other options will default to what you have set
|
|
||||||
for that variable. Likewise if you set `magit-log-margin's INIT
|
|
||||||
to nil, then that is used in the default of all other options. But
|
|
||||||
setting it to t, i.e. re-enforcing the default for that option,
|
|
||||||
does not carry to other options."
|
|
||||||
:link '(info-link "(magit)Log Margin")
|
|
||||||
:group 'magit-log)
|
|
||||||
|
|
||||||
(defvar-local magit-buffer-margin nil)
|
|
||||||
(put 'magit-buffer-margin 'permanent-local t)
|
|
||||||
|
|
||||||
(defvar-local magit-set-buffer-margin-refresh nil)
|
|
||||||
|
|
||||||
(defvar magit--age-spec)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
(define-transient-command magit-margin-settings ()
|
|
||||||
"Change what information is displayed in the margin."
|
|
||||||
:info-manual "(magit) Log Margin"
|
|
||||||
["Margin"
|
|
||||||
("L" "Toggle visibility" magit-toggle-margin)
|
|
||||||
("l" "Cycle style" magit-cycle-margin-style)
|
|
||||||
("d" "Toggle details" magit-toggle-margin-details)
|
|
||||||
("v" "Change verbosity" magit-refs-set-show-commit-count
|
|
||||||
:if-derived magit-refs-mode)])
|
|
||||||
|
|
||||||
(defun magit-toggle-margin ()
|
|
||||||
"Show or hide the Magit margin."
|
|
||||||
(interactive)
|
|
||||||
(unless (magit-margin-option)
|
|
||||||
(user-error "Magit margin isn't supported in this buffer"))
|
|
||||||
(setcar magit-buffer-margin (not (magit-buffer-margin-p)))
|
|
||||||
(magit-set-buffer-margin))
|
|
||||||
|
|
||||||
(defun magit-cycle-margin-style ()
|
|
||||||
"Cycle style used for the Magit margin."
|
|
||||||
(interactive)
|
|
||||||
(unless (magit-margin-option)
|
|
||||||
(user-error "Magit margin isn't supported in this buffer"))
|
|
||||||
;; This is only suitable for commit margins (there are not others).
|
|
||||||
(setf (cadr magit-buffer-margin)
|
|
||||||
(pcase (cadr magit-buffer-margin)
|
|
||||||
(`age 'age-abbreviated)
|
|
||||||
(`age-abbreviated
|
|
||||||
(let ((default (cadr (symbol-value (magit-margin-option)))))
|
|
||||||
(if (stringp default) default "%Y-%m-%d %H:%M ")))
|
|
||||||
(_ 'age)))
|
|
||||||
(magit-set-buffer-margin nil t))
|
|
||||||
|
|
||||||
(defun magit-toggle-margin-details ()
|
|
||||||
"Show or hide details in the Magit margin."
|
|
||||||
(interactive)
|
|
||||||
(unless (magit-margin-option)
|
|
||||||
(user-error "Magit margin isn't supported in this buffer"))
|
|
||||||
(setf (nth 3 magit-buffer-margin)
|
|
||||||
(not (nth 3 magit-buffer-margin)))
|
|
||||||
(magit-set-buffer-margin nil t))
|
|
||||||
|
|
||||||
;;; Core
|
|
||||||
|
|
||||||
(defun magit-buffer-margin-p ()
|
|
||||||
(car magit-buffer-margin))
|
|
||||||
|
|
||||||
(defun magit-margin-option ()
|
|
||||||
(pcase major-mode
|
|
||||||
(`magit-cherry-mode 'magit-cherry-margin)
|
|
||||||
(`magit-log-mode 'magit-log-margin)
|
|
||||||
(`magit-log-select-mode 'magit-log-select-margin)
|
|
||||||
(`magit-reflog-mode 'magit-reflog-margin)
|
|
||||||
(`magit-refs-mode 'magit-refs-margin)
|
|
||||||
(`magit-stashes-mode 'magit-stashes-margin)
|
|
||||||
(`magit-status-mode 'magit-status-margin)
|
|
||||||
(`forge-notifications-mode 'magit-status-margin)))
|
|
||||||
|
|
||||||
(defun magit-set-buffer-margin (&optional reset refresh)
|
|
||||||
(when-let ((option (magit-margin-option)))
|
|
||||||
(let* ((default (symbol-value option))
|
|
||||||
(default-width (nth 2 default)))
|
|
||||||
(when (or reset (not magit-buffer-margin))
|
|
||||||
(setq magit-buffer-margin (copy-sequence default)))
|
|
||||||
(pcase-let ((`(,enable ,style ,_width ,details ,details-width)
|
|
||||||
magit-buffer-margin))
|
|
||||||
(when (functionp default-width)
|
|
||||||
(setf (nth 2 magit-buffer-margin)
|
|
||||||
(funcall default-width style details details-width)))
|
|
||||||
(dolist (window (get-buffer-window-list nil nil 0))
|
|
||||||
(with-selected-window window
|
|
||||||
(magit-set-window-margin window)
|
|
||||||
(if enable
|
|
||||||
(add-hook 'window-configuration-change-hook
|
|
||||||
'magit-set-window-margin nil t)
|
|
||||||
(remove-hook 'window-configuration-change-hook
|
|
||||||
'magit-set-window-margin t))))
|
|
||||||
(when (and enable (or refresh magit-set-buffer-margin-refresh))
|
|
||||||
(magit-refresh-buffer))))))
|
|
||||||
|
|
||||||
(defun magit-set-window-margin (&optional window)
|
|
||||||
(when (or window (setq window (get-buffer-window)))
|
|
||||||
(with-selected-window window
|
|
||||||
(set-window-margins
|
|
||||||
nil (car (window-margins))
|
|
||||||
(and (magit-buffer-margin-p)
|
|
||||||
(nth 2 magit-buffer-margin))))))
|
|
||||||
|
|
||||||
(defun magit-make-margin-overlay (&optional string previous-line)
|
|
||||||
(if previous-line
|
|
||||||
(save-excursion
|
|
||||||
(forward-line -1)
|
|
||||||
(magit-make-margin-overlay string))
|
|
||||||
;; Don't put the overlay on the complete line to work around #1880.
|
|
||||||
(let ((o (make-overlay (1+ (line-beginning-position))
|
|
||||||
(line-end-position)
|
|
||||||
nil t)))
|
|
||||||
(overlay-put o 'evaporate t)
|
|
||||||
(overlay-put o 'before-string
|
|
||||||
(propertize "o" 'display
|
|
||||||
(list (list 'margin 'right-margin)
|
|
||||||
(or string " ")))))))
|
|
||||||
|
|
||||||
(defun magit-maybe-make-margin-overlay ()
|
|
||||||
(when (or (magit-section-match
|
|
||||||
'(unpulled unpushed recent stashes local cherries)
|
|
||||||
magit-insert-section--current)
|
|
||||||
(and (eq major-mode 'magit-refs-mode)
|
|
||||||
(magit-section-match
|
|
||||||
'(remote commit tags)
|
|
||||||
magit-insert-section--current)))
|
|
||||||
(magit-make-margin-overlay nil t)))
|
|
||||||
|
|
||||||
;;; Custom Support
|
|
||||||
|
|
||||||
(defun magit-margin-set-variable (mode symbol value)
|
|
||||||
(set-default symbol value)
|
|
||||||
(message "Updating margins in %s buffers..." mode)
|
|
||||||
(dolist (buffer (buffer-list))
|
|
||||||
(with-current-buffer buffer
|
|
||||||
(when (eq major-mode mode)
|
|
||||||
(magit-set-buffer-margin t)
|
|
||||||
(magit-refresh))))
|
|
||||||
(message "Updating margins in %s buffers...done" mode))
|
|
||||||
|
|
||||||
(defconst magit-log-margin--custom-type
|
|
||||||
'(list (boolean :tag "Show margin initially")
|
|
||||||
(choice :tag "Show committer"
|
|
||||||
(string :tag "date using time-format" "%Y-%m-%d %H:%M ")
|
|
||||||
(const :tag "date's age" age)
|
|
||||||
(const :tag "date's age (abbreviated)" age-abbreviated))
|
|
||||||
(const :tag "Calculate width using magit-log-margin-width"
|
|
||||||
magit-log-margin-width)
|
|
||||||
(boolean :tag "Show author name by default")
|
|
||||||
(integer :tag "Show author name using width")))
|
|
||||||
|
|
||||||
;;; Time Utilities
|
|
||||||
|
|
||||||
(defvar magit--age-spec
|
|
||||||
`((?Y "year" "years" ,(round (* 60 60 24 365.2425)))
|
|
||||||
(?M "month" "months" ,(round (* 60 60 24 30.436875)))
|
|
||||||
(?w "week" "weeks" ,(* 60 60 24 7))
|
|
||||||
(?d "day" "days" ,(* 60 60 24))
|
|
||||||
(?h "hour" "hours" ,(* 60 60))
|
|
||||||
(?m "minute" "minutes" 60)
|
|
||||||
(?s "second" "seconds" 1))
|
|
||||||
"Time units used when formatting relative commit ages.
|
|
||||||
|
|
||||||
The value is a list of time units, beginning with the longest.
|
|
||||||
Each element has the form (CHAR UNIT UNITS SECONDS). UNIT is the
|
|
||||||
time unit, UNITS is the plural of that unit. CHAR is a character
|
|
||||||
abbreviation. And SECONDS is the number of seconds in one UNIT.
|
|
||||||
|
|
||||||
This is defined as a variable to make it possible to use time
|
|
||||||
units for a language other than English. It is not defined
|
|
||||||
as an option, because most other parts of Magit are always in
|
|
||||||
English.")
|
|
||||||
|
|
||||||
(defun magit--age (date &optional abbreviate)
|
|
||||||
(cl-labels ((fn (age spec)
|
|
||||||
(pcase-let ((`(,char ,unit ,units ,weight) (car spec)))
|
|
||||||
(let ((cnt (round (/ age weight 1.0))))
|
|
||||||
(if (or (not (cdr spec))
|
|
||||||
(>= (/ age weight) 1))
|
|
||||||
(list cnt (cond (abbreviate char)
|
|
||||||
((= cnt 1) unit)
|
|
||||||
(t units)))
|
|
||||||
(fn age (cdr spec)))))))
|
|
||||||
(fn (abs (- (float-time)
|
|
||||||
(if (stringp date)
|
|
||||||
(string-to-number date)
|
|
||||||
date)))
|
|
||||||
magit--age-spec)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-margin)
|
|
||||||
;;; magit-margin.el ends here
|
|
Binary file not shown.
|
@ -1,302 +0,0 @@
|
||||||
;;; magit-merge.el --- merge functionality -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements merge commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'magit-diff)
|
|
||||||
|
|
||||||
(declare-function magit-git-push "magit-push" (branch target args))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-merge "magit" nil t)
|
|
||||||
(define-transient-command magit-merge ()
|
|
||||||
"Merge branches."
|
|
||||||
:man-page "git-merge"
|
|
||||||
:incompatible '(("--ff-only" "--no-ff"))
|
|
||||||
["Arguments"
|
|
||||||
:if-not magit-merge-in-progress-p
|
|
||||||
("-f" "Fast-forward only" "--ff-only")
|
|
||||||
("-n" "No fast-forward" "--no-ff")
|
|
||||||
(magit-merge:--strategy)
|
|
||||||
(5 magit-diff:--diff-algorithm :argument "--Xdiff-algorithm=")
|
|
||||||
(5 magit:--gpg-sign)]
|
|
||||||
["Actions"
|
|
||||||
:if-not magit-merge-in-progress-p
|
|
||||||
[("m" "Merge" magit-merge-plain)
|
|
||||||
("e" "Merge and edit message" magit-merge-editmsg)
|
|
||||||
("n" "Merge but don't commit" magit-merge-nocommit)
|
|
||||||
("a" "Absorb" magit-merge-absorb)]
|
|
||||||
[("p" "Preview merge" magit-merge-preview)
|
|
||||||
""
|
|
||||||
("s" "Squash merge" magit-merge-squash)
|
|
||||||
("i" "Merge into" magit-merge-into)]]
|
|
||||||
["Actions"
|
|
||||||
:if magit-merge-in-progress-p
|
|
||||||
("m" "Commit merge" magit-commit-create)
|
|
||||||
("a" "Abort merge" magit-merge-abort)])
|
|
||||||
|
|
||||||
(defun magit-merge-arguments ()
|
|
||||||
(transient-args 'magit-merge))
|
|
||||||
|
|
||||||
(define-infix-argument magit-merge:--strategy ()
|
|
||||||
:description "Strategy"
|
|
||||||
:class 'transient-option
|
|
||||||
;; key for merge: "-s"
|
|
||||||
;; key for cherry-pick and revert: "=s"
|
|
||||||
;; shortarg for merge: "-s"
|
|
||||||
;; shortarg for cherry-pick and revert: none
|
|
||||||
:key "-s"
|
|
||||||
:argument "--strategy="
|
|
||||||
:choices '("resolve" "recursive" "octopus" "ours" "subtree"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-plain (rev &optional args nocommit)
|
|
||||||
"Merge commit REV into the current branch; using default message.
|
|
||||||
|
|
||||||
Unless there are conflicts or a prefix argument is used create a
|
|
||||||
merge commit using a generic commit message and without letting
|
|
||||||
the user inspect the result. With a prefix argument pretend the
|
|
||||||
merge failed to give the user the opportunity to inspect the
|
|
||||||
merge.
|
|
||||||
|
|
||||||
\(git merge --no-edit|--no-commit [ARGS] REV)"
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Merge")
|
|
||||||
(magit-merge-arguments)
|
|
||||||
current-prefix-arg))
|
|
||||||
(magit-merge-assert)
|
|
||||||
(magit-run-git-async "merge" (if nocommit "--no-commit" "--no-edit") args rev))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-editmsg (rev &optional args)
|
|
||||||
"Merge commit REV into the current branch; and edit message.
|
|
||||||
Perform the merge and prepare a commit message but let the user
|
|
||||||
edit it.
|
|
||||||
\n(git merge --edit --no-ff [ARGS] REV)"
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Merge")
|
|
||||||
(magit-merge-arguments)))
|
|
||||||
(magit-merge-assert)
|
|
||||||
(cl-pushnew "--no-ff" args :test #'equal)
|
|
||||||
(apply #'magit-run-git-with-editor "merge" "--edit"
|
|
||||||
(append (delete "--ff-only" args)
|
|
||||||
(list rev))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-nocommit (rev &optional args)
|
|
||||||
"Merge commit REV into the current branch; pretending it failed.
|
|
||||||
Pretend the merge failed to give the user the opportunity to
|
|
||||||
inspect the merge and change the commit message.
|
|
||||||
\n(git merge --no-commit --no-ff [ARGS] REV)"
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Merge")
|
|
||||||
(magit-merge-arguments)))
|
|
||||||
(magit-merge-assert)
|
|
||||||
(cl-pushnew "--no-ff" args :test #'equal)
|
|
||||||
(magit-run-git-async "merge" "--no-commit" args rev))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-into (branch &optional args)
|
|
||||||
"Merge the current branch into BRANCH and remove the former.
|
|
||||||
|
|
||||||
Before merging, force push the source branch to its push-remote,
|
|
||||||
provided the respective remote branch already exists, ensuring
|
|
||||||
that the respective pull-request (if any) won't get stuck on some
|
|
||||||
obsolete version of the commits that are being merged. Finally
|
|
||||||
if `forge-branch-pullreq' was used to create the merged branch,
|
|
||||||
branch, then also remove the respective remote branch."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-other-local-branch
|
|
||||||
(format "Merge `%s' into" (magit-get-current-branch))
|
|
||||||
nil
|
|
||||||
(when-let ((upstream (magit-get-upstream-branch))
|
|
||||||
(upstream (cdr (magit-split-branch-name upstream))))
|
|
||||||
(and (magit-branch-p upstream) upstream)))
|
|
||||||
(magit-merge-arguments)))
|
|
||||||
(let ((current (magit-get-current-branch)))
|
|
||||||
(when (zerop (magit-call-git "checkout" branch))
|
|
||||||
(magit--merge-absorb current args))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-absorb (branch &optional args)
|
|
||||||
"Merge BRANCH into the current branch and remove the former.
|
|
||||||
|
|
||||||
Before merging, force push the source branch to its push-remote,
|
|
||||||
provided the respective remote branch already exists, ensuring
|
|
||||||
that the respective pull-request (if any) won't get stuck on some
|
|
||||||
obsolete version of the commits that are being merged. Finally
|
|
||||||
if `forge-branch-pullreq' was used to create the merged branch,
|
|
||||||
then also remove the respective remote branch."
|
|
||||||
(interactive (list (magit-read-other-local-branch "Absorb branch")
|
|
||||||
(magit-merge-arguments)))
|
|
||||||
(magit--merge-absorb branch args))
|
|
||||||
|
|
||||||
(defun magit--merge-absorb (branch args)
|
|
||||||
(when (equal branch "master")
|
|
||||||
(unless (yes-or-no-p
|
|
||||||
"Do you really want to merge `master' into another branch? ")
|
|
||||||
(user-error "Abort")))
|
|
||||||
(if-let ((target (magit-get-push-branch branch t)))
|
|
||||||
(progn
|
|
||||||
(magit-git-push branch target (list "--force-with-lease"))
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (not (zerop (process-exit-status process)))
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(magit--merge-absorb-1 branch args))))))
|
|
||||||
(magit--merge-absorb-1 branch args)))
|
|
||||||
|
|
||||||
(defun magit--merge-absorb-1 (branch args)
|
|
||||||
(if-let ((pr (magit-get "branch" branch "pullRequest")))
|
|
||||||
(magit-run-git-async
|
|
||||||
"merge" args "-m"
|
|
||||||
(format "Merge branch '%s'%s [%s]"
|
|
||||||
branch
|
|
||||||
(let ((current (magit-get-current-branch)))
|
|
||||||
(if (equal current "master") "" (format " into %s" current)))
|
|
||||||
pr)
|
|
||||||
branch)
|
|
||||||
(magit-run-git-async "merge" args "--no-edit" branch))
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (> (process-exit-status process) 0)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(magit-branch-maybe-delete-pr-remote branch)
|
|
||||||
(magit-branch-unset-pushRemote branch)
|
|
||||||
(magit-run-git "branch" "-D" branch))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-squash (rev)
|
|
||||||
"Squash commit REV into the current branch; don't create a commit.
|
|
||||||
\n(git merge --squash REV)"
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Squash")))
|
|
||||||
(magit-merge-assert)
|
|
||||||
(magit-run-git-async "merge" "--squash" rev))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-preview (rev)
|
|
||||||
"Preview result of merging REV into the current branch."
|
|
||||||
(interactive (list (magit-read-other-branch-or-commit "Preview merge")))
|
|
||||||
(magit-merge-preview-setup-buffer rev))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-merge-abort ()
|
|
||||||
"Abort the current merge operation.
|
|
||||||
\n(git merge --abort)"
|
|
||||||
(interactive)
|
|
||||||
(unless (file-exists-p (magit-git-dir "MERGE_HEAD"))
|
|
||||||
(user-error "No merge in progress"))
|
|
||||||
(magit-confirm 'abort-merge)
|
|
||||||
(magit-run-git-async "merge" "--abort"))
|
|
||||||
|
|
||||||
(defun magit-checkout-stage (file arg)
|
|
||||||
"During a conflict checkout and stage side, or restore conflict."
|
|
||||||
(interactive
|
|
||||||
(let ((file (magit-completing-read "Checkout file"
|
|
||||||
(magit-tracked-files) nil nil nil
|
|
||||||
'magit-read-file-hist
|
|
||||||
(magit-current-file))))
|
|
||||||
(cond ((member file (magit-unmerged-files))
|
|
||||||
(list file (magit-checkout-read-stage file)))
|
|
||||||
((yes-or-no-p (format "Restore conflicts in %s? " file))
|
|
||||||
(list file "--merge"))
|
|
||||||
(t
|
|
||||||
(user-error "Quit")))))
|
|
||||||
(pcase (cons arg (cddr (car (magit-file-status file))))
|
|
||||||
((or `("--ours" ?D ,_)
|
|
||||||
`("--theirs" ,_ ?D))
|
|
||||||
(magit-run-git "rm" "--" file))
|
|
||||||
(_ (if (equal arg "--merge")
|
|
||||||
;; This fails if the file was deleted on one
|
|
||||||
;; side. And we cannot do anything about it.
|
|
||||||
(magit-run-git "checkout" "--merge" "--" file)
|
|
||||||
(magit-call-git "checkout" arg "--" file)
|
|
||||||
(magit-run-git "add" "-u" "--" file)))))
|
|
||||||
|
|
||||||
;;; Utilities
|
|
||||||
|
|
||||||
(defun magit-merge-in-progress-p ()
|
|
||||||
(file-exists-p (magit-git-dir "MERGE_HEAD")))
|
|
||||||
|
|
||||||
(defun magit--merge-range (&optional head)
|
|
||||||
(unless head
|
|
||||||
(setq head (magit-get-shortname
|
|
||||||
(car (magit-file-lines (magit-git-dir "MERGE_HEAD"))))))
|
|
||||||
(and head
|
|
||||||
(concat (magit-git-string "merge-base" "--octopus" "HEAD" head)
|
|
||||||
".." head)))
|
|
||||||
|
|
||||||
(defun magit-merge-assert ()
|
|
||||||
(or (not (magit-anything-modified-p t))
|
|
||||||
(magit-confirm 'merge-dirty
|
|
||||||
"Merging with dirty worktree is risky. Continue")))
|
|
||||||
|
|
||||||
(defun magit-checkout-read-stage (file)
|
|
||||||
(magit-read-char-case (format "For %s checkout: " file) t
|
|
||||||
(?o "[o]ur stage" "--ours")
|
|
||||||
(?t "[t]heir stage" "--theirs")
|
|
||||||
(?c "[c]onflict" "--merge")))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
(defvar magit-unmerged-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-diff-dwim)
|
|
||||||
map)
|
|
||||||
"Keymap for `unmerged' sections.")
|
|
||||||
|
|
||||||
(defun magit-insert-merge-log ()
|
|
||||||
"Insert section for the on-going merge.
|
|
||||||
Display the heads that are being merged.
|
|
||||||
If no merge is in progress, do nothing."
|
|
||||||
(when (magit-merge-in-progress-p)
|
|
||||||
(let* ((heads (mapcar #'magit-get-shortname
|
|
||||||
(magit-file-lines (magit-git-dir "MERGE_HEAD"))))
|
|
||||||
(range (magit--merge-range (car heads))))
|
|
||||||
(magit-insert-section (unmerged range)
|
|
||||||
(magit-insert-heading
|
|
||||||
(format "Merging %s:" (mapconcat #'identity heads ", ")))
|
|
||||||
(magit-insert-log
|
|
||||||
range
|
|
||||||
(let ((args magit-buffer-log-args))
|
|
||||||
(unless (member "--decorate=full" magit-buffer-log-args)
|
|
||||||
(push "--decorate=full" args))
|
|
||||||
args))))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-merge)
|
|
||||||
;;; magit-merge.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,200 +0,0 @@
|
||||||
;;; magit-notes.el --- notes support -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for `git-notes'.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-notes "magit" nil t)
|
|
||||||
(define-transient-command magit-notes ()
|
|
||||||
"Edit notes attached to commits."
|
|
||||||
:man-page "git-notes"
|
|
||||||
["Configure local settings"
|
|
||||||
("c" magit-core.notesRef)
|
|
||||||
("d" magit-notes.displayRef)]
|
|
||||||
["Configure global settings"
|
|
||||||
("C" magit-global-core.notesRef)
|
|
||||||
("D" magit-global-notes.displayRef)]
|
|
||||||
["Arguments for prune"
|
|
||||||
:if-not magit-notes-merging-p
|
|
||||||
("-n" "Dry run" ("-n" "--dry-run"))]
|
|
||||||
["Arguments for edit and remove"
|
|
||||||
:if-not magit-notes-merging-p
|
|
||||||
(magit-notes:--ref)]
|
|
||||||
["Arguments for merge"
|
|
||||||
:if-not magit-notes-merging-p
|
|
||||||
(magit-notes:--strategy)]
|
|
||||||
["Actions"
|
|
||||||
:if-not magit-notes-merging-p
|
|
||||||
("T" "Edit" magit-notes-edit)
|
|
||||||
("r" "Remove" magit-notes-remove)
|
|
||||||
("m" "Merge" magit-notes-merge)
|
|
||||||
("p" "Prune" magit-notes-prune)]
|
|
||||||
["Actions"
|
|
||||||
:if magit-notes-merging-p
|
|
||||||
("c" "Commit merge" magit-notes-merge-commit)
|
|
||||||
("a" "Abort merge" magit-notes-merge-abort)])
|
|
||||||
|
|
||||||
(defun magit-notes-merging-p ()
|
|
||||||
(let ((dir (magit-git-dir "NOTES_MERGE_WORKTREE")))
|
|
||||||
(and (file-directory-p dir)
|
|
||||||
(directory-files dir nil "^[^.]"))))
|
|
||||||
|
|
||||||
(define-infix-command magit-core.notesRef ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:variable "core.notesRef"
|
|
||||||
:reader 'magit-notes-read-ref
|
|
||||||
:prompt "Set local core.notesRef")
|
|
||||||
|
|
||||||
(define-infix-command magit-notes.displayRef ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:variable "notes.displayRef"
|
|
||||||
:multi-value t
|
|
||||||
:reader 'magit-notes-read-refs
|
|
||||||
:prompt "Set local notes.displayRef")
|
|
||||||
|
|
||||||
(define-infix-command magit-global-core.notesRef ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:variable "core.notesRef"
|
|
||||||
:reader 'magit-notes-read-ref
|
|
||||||
:prompt "Set global core.notesRef")
|
|
||||||
|
|
||||||
(define-infix-command magit-global-notes.displayRef ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:variable "notes.displayRef"
|
|
||||||
:multi-value t
|
|
||||||
:reader 'magit-notes-read-refs
|
|
||||||
:prompt "Set global notes.displayRef")
|
|
||||||
|
|
||||||
(define-infix-argument magit-notes:--ref ()
|
|
||||||
:description "Merge strategy"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "-r"
|
|
||||||
:argument "--ref="
|
|
||||||
:reader 'magit-notes-read-ref)
|
|
||||||
|
|
||||||
(define-infix-argument magit-notes:--strategy ()
|
|
||||||
:description "Merge strategy"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-s"
|
|
||||||
:argument "--strategy="
|
|
||||||
:choices '("manual" "ours" "theirs" "union" "cat_sort_uniq"))
|
|
||||||
|
|
||||||
(defun magit-notes-edit (commit &optional ref)
|
|
||||||
"Edit the note attached to COMMIT.
|
|
||||||
REF is the notes ref used to store the notes.
|
|
||||||
|
|
||||||
Interactively or when optional REF is nil use the value of Git
|
|
||||||
variable `core.notesRef' or \"refs/notes/commits\" if that is
|
|
||||||
undefined."
|
|
||||||
(interactive (magit-notes-read-args "Edit notes"))
|
|
||||||
(magit-run-git-with-editor "notes" (and ref (concat "--ref=" ref))
|
|
||||||
"edit" commit))
|
|
||||||
|
|
||||||
(defun magit-notes-remove (commit &optional ref)
|
|
||||||
"Remove the note attached to COMMIT.
|
|
||||||
REF is the notes ref from which the note is removed.
|
|
||||||
|
|
||||||
Interactively or when optional REF is nil use the value of Git
|
|
||||||
variable `core.notesRef' or \"refs/notes/commits\" if that is
|
|
||||||
undefined."
|
|
||||||
(interactive (magit-notes-read-args "Remove notes"))
|
|
||||||
(magit-run-git-with-editor "notes" (and ref (concat "--ref=" ref))
|
|
||||||
"remove" commit))
|
|
||||||
|
|
||||||
(defun magit-notes-merge (ref)
|
|
||||||
"Merge the notes ref REF into the current notes ref.
|
|
||||||
|
|
||||||
The current notes ref is the value of Git variable
|
|
||||||
`core.notesRef' or \"refs/notes/commits\" if that is undefined.
|
|
||||||
|
|
||||||
When there are conflicts, then they have to be resolved in the
|
|
||||||
temporary worktree \".git/NOTES_MERGE_WORKTREE\". When
|
|
||||||
done use `magit-notes-merge-commit' to finish. To abort
|
|
||||||
use `magit-notes-merge-abort'."
|
|
||||||
(interactive (list (magit-read-string-ns "Merge reference")))
|
|
||||||
(magit-run-git-with-editor "notes" "merge" ref))
|
|
||||||
|
|
||||||
(defun magit-notes-merge-commit ()
|
|
||||||
"Commit the current notes ref merge.
|
|
||||||
Also see `magit-notes-merge'."
|
|
||||||
(interactive)
|
|
||||||
(magit-run-git-with-editor "notes" "merge" "--commit"))
|
|
||||||
|
|
||||||
(defun magit-notes-merge-abort ()
|
|
||||||
"Abort the current notes ref merge.
|
|
||||||
Also see `magit-notes-merge'."
|
|
||||||
(interactive)
|
|
||||||
(magit-run-git-with-editor "notes" "merge" "--abort"))
|
|
||||||
|
|
||||||
(defun magit-notes-prune (&optional dry-run)
|
|
||||||
"Remove notes about unreachable commits."
|
|
||||||
(interactive (list (and (member "--dry-run" (transient-args 'magit-notes)) t)))
|
|
||||||
(when dry-run
|
|
||||||
(magit-process-buffer))
|
|
||||||
(magit-run-git-with-editor "notes" "prune" (and dry-run "--dry-run")))
|
|
||||||
|
|
||||||
;;; Readers
|
|
||||||
|
|
||||||
(defun magit-notes-read-ref (prompt _initial-input history)
|
|
||||||
(--when-let (magit-completing-read
|
|
||||||
prompt (magit-list-notes-refnames) nil nil
|
|
||||||
(--when-let (magit-get "core.notesRef")
|
|
||||||
(if (string-prefix-p "refs/notes/" it)
|
|
||||||
(substring it 11)
|
|
||||||
it))
|
|
||||||
history)
|
|
||||||
(if (string-prefix-p "refs/" it)
|
|
||||||
it
|
|
||||||
(concat "refs/notes/" it))))
|
|
||||||
|
|
||||||
(defun magit-notes-read-refs (prompt)
|
|
||||||
(mapcar (lambda (ref)
|
|
||||||
(if (string-prefix-p "refs/" ref)
|
|
||||||
ref
|
|
||||||
(concat "refs/notes/" ref)))
|
|
||||||
(completing-read-multiple
|
|
||||||
(concat prompt ": ")
|
|
||||||
(magit-list-notes-refnames) nil nil
|
|
||||||
(mapconcat (lambda (ref)
|
|
||||||
(if (string-prefix-p "refs/notes/" ref)
|
|
||||||
(substring ref 11)
|
|
||||||
ref))
|
|
||||||
(magit-get-all "notes.displayRef")
|
|
||||||
","))))
|
|
||||||
|
|
||||||
(defun magit-notes-read-args (prompt)
|
|
||||||
(list (magit-read-branch-or-commit prompt (magit-stash-at-point))
|
|
||||||
(--when-let (--first (string-match "^--ref=\\(.+\\)" it)
|
|
||||||
(transient-args 'magit-notes))
|
|
||||||
(match-string 1 it))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-notes)
|
|
||||||
;;; magit-notes.el ends here
|
|
Binary file not shown.
|
@ -1,106 +0,0 @@
|
||||||
;;; magit-obsolete.el --- obsolete definitions -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library defines aliases for obsolete variables and functions.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Obsolete since v2.91.0
|
|
||||||
|
|
||||||
(define-obsolete-function-alias 'magit-diff-visit-file-worktree
|
|
||||||
'magit-diff-visit-worktree-file "Magit 2.91.0")
|
|
||||||
|
|
||||||
(define-obsolete-function-alias 'magit-status-internal
|
|
||||||
'magit-status-setup-buffer "Magit 2.91.0")
|
|
||||||
|
|
||||||
(define-obsolete-variable-alias 'magit-mode-setup-hook
|
|
||||||
'magit-setup-buffer-hook "Magit 2.91.0")
|
|
||||||
|
|
||||||
(define-obsolete-variable-alias 'magit-branch-popup-show-variables
|
|
||||||
'magit-branch-direct-configure "Magit 2.91.0")
|
|
||||||
|
|
||||||
(define-obsolete-function-alias 'magit-dispatch-popup
|
|
||||||
'magit-dispatch "Magit 2.91.0")
|
|
||||||
|
|
||||||
(define-obsolete-function-alias 'magit-repolist-column-dirty
|
|
||||||
'magit-repolist-column-flag "Magit 2.91.0")
|
|
||||||
|
|
||||||
(defun magit--magit-popup-warning ()
|
|
||||||
(display-warning 'magit "\
|
|
||||||
Magit no longer uses Magit-Popup.
|
|
||||||
It now uses Transient.
|
|
||||||
See https://emacsair.me/2019/02/14/transient-0.1.
|
|
||||||
|
|
||||||
However your configuration and/or some third-party package that
|
|
||||||
you use still depends on the `magit-popup' package. But because
|
|
||||||
`magit' no longer depends on that, `package' has removed it from
|
|
||||||
your system.
|
|
||||||
|
|
||||||
If some package that you use still depends on `magit-popup' but
|
|
||||||
does not declare it as a dependency, then please contact its
|
|
||||||
maintainer about that and install `magit-popup' explicitly.
|
|
||||||
|
|
||||||
If you yourself use functions that are defined in `magit-popup'
|
|
||||||
in your configuration, then the next step depends on what you use
|
|
||||||
that for.
|
|
||||||
|
|
||||||
* If you use `magit-popup' to define your own popups but do not
|
|
||||||
modify any of Magit's old popups, then you have to install
|
|
||||||
`magit-popup' explicitly. (You can also migrate to Transient,
|
|
||||||
but there is no need to rush that.)
|
|
||||||
|
|
||||||
* If you add additional arguments and/or actions to Magit's popups,
|
|
||||||
then you have to port that to modify the new \"transients\" instead.
|
|
||||||
See https://github.com/magit/magit/wiki/\
|
|
||||||
Converting-popup-modifications-to-transient-modifications
|
|
||||||
|
|
||||||
To find installed packages that still use `magit-popup' you can
|
|
||||||
use e.g. \"M-x rgrep RET magit-popup RET RET ~/.emacs.d/ RET\"."))
|
|
||||||
(cl-eval-when (eval load)
|
|
||||||
(unless (require 'magit-popup nil t)
|
|
||||||
(defun magit-define-popup-switch (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-option (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-variable (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-action (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-sequence-action (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-key (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-define-popup-keys-deferred (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-change-popup-key (&rest _)
|
|
||||||
(magit--magit-popup-warning))
|
|
||||||
(defun magit-remove-popup-key (&rest _)
|
|
||||||
(magit--magit-popup-warning))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-obsolete)
|
|
||||||
;;; magit-obsolete.el ends here
|
|
Binary file not shown.
|
@ -1,267 +0,0 @@
|
||||||
;;; magit-patch.el --- creating and applying patches -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements patch commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-patch-save-arguments '(exclude "--stat")
|
|
||||||
"Control arguments used by the command `magit-patch-save'.
|
|
||||||
|
|
||||||
`magit-patch-save' (which see) saves a diff for the changes
|
|
||||||
shown in the current buffer in a patch file. It may use the
|
|
||||||
same arguments as used in the buffer or a subset thereof, or
|
|
||||||
a constant list of arguments, depending on this option and
|
|
||||||
the prefix argument."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-diff
|
|
||||||
:type '(choice (const :tag "use buffer arguments" buffer)
|
|
||||||
(cons :tag "use buffer arguments except"
|
|
||||||
(const :format "" exclude)
|
|
||||||
(repeat :format "%v%i\n"
|
|
||||||
(string :tag "Argument")))
|
|
||||||
(repeat :tag "use constant arguments"
|
|
||||||
(string :tag "Argument"))))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-patch "magit-patch" nil t)
|
|
||||||
(define-transient-command magit-patch ()
|
|
||||||
"Create or apply patches."
|
|
||||||
["Actions"
|
|
||||||
("c" "Create patches" magit-patch-create)
|
|
||||||
("a" "Apply patch" magit-patch-apply)
|
|
||||||
("s" "Save diff as patch" magit-patch-save)
|
|
||||||
("r" "Request pull" magit-request-pull)])
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-patch-create "magit-patch" nil t)
|
|
||||||
(define-transient-command magit-patch-create (range args files)
|
|
||||||
"Create patches for the commits in RANGE.
|
|
||||||
When a single commit is given for RANGE, create a patch for the
|
|
||||||
changes introduced by that commit (unlike 'git format-patch'
|
|
||||||
which creates patches for all commits that are reachable from
|
|
||||||
`HEAD' but not from the specified commit)."
|
|
||||||
:man-page "git-format-patch"
|
|
||||||
["Mail arguments"
|
|
||||||
(magit-format-patch:--in-reply-to)
|
|
||||||
(magit-format-patch:--thread)
|
|
||||||
(magit-format-patch:--reroll-count)
|
|
||||||
(magit-format-patch:--subject-prefix)
|
|
||||||
("C-m l " "Add cover letter" "--cover-letter")
|
|
||||||
(magit-format-patch:--from)
|
|
||||||
(magit-format-patch:--to)
|
|
||||||
(magit-format-patch:--cc)
|
|
||||||
(magit-format-patch:--output-directory)]
|
|
||||||
["Diff arguments"
|
|
||||||
(magit-diff:-U)
|
|
||||||
(magit-diff:-M)
|
|
||||||
(magit-diff:-C)
|
|
||||||
(magit-diff:--diff-algorithm)
|
|
||||||
(magit:--)
|
|
||||||
(7 "-b" "Ignore whitespace changes" ("-b" "--ignore-space-change"))
|
|
||||||
(7 "-w" "Ignore all whitespace" ("-w" "--ignore-all-space"))]
|
|
||||||
["Actions"
|
|
||||||
("c" "Create patches" magit-patch-create)]
|
|
||||||
(interactive
|
|
||||||
(if (not (eq current-transient-command 'magit-patch-create))
|
|
||||||
(list nil nil nil)
|
|
||||||
(cons (if-let ((revs (magit-region-values 'commit t)))
|
|
||||||
(concat (car (last revs)) "^.." (car revs))
|
|
||||||
(let ((range (magit-read-range-or-commit
|
|
||||||
"Format range or commit")))
|
|
||||||
(if (string-match-p "\\.\\." range)
|
|
||||||
range
|
|
||||||
(format "%s~..%s" range range))))
|
|
||||||
(let ((args (transient-args 'magit-patch-create)))
|
|
||||||
(list (-filter #'stringp args)
|
|
||||||
(cdr (assoc "--" args)))))))
|
|
||||||
(if (not range)
|
|
||||||
(transient-setup 'magit-patch-create)
|
|
||||||
(magit-run-git "format-patch" range args "--" files)
|
|
||||||
(when (member "--cover-letter" args)
|
|
||||||
(save-match-data
|
|
||||||
(find-file
|
|
||||||
(expand-file-name
|
|
||||||
(concat (--some (and (string-match "\\`--reroll-count=\\(.+\\)" it)
|
|
||||||
(format "v%s-" (match-string 1 it)))
|
|
||||||
args)
|
|
||||||
"0000-cover-letter.patch")
|
|
||||||
(let ((topdir (magit-toplevel)))
|
|
||||||
(or (--some (and (string-match "\\`--output-directory=\\(.+\\)" it)
|
|
||||||
(expand-file-name (match-string 1 it) topdir))
|
|
||||||
args)
|
|
||||||
topdir))))))))
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--in-reply-to ()
|
|
||||||
:description "In reply to"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m r "
|
|
||||||
:argument "--in-reply-to=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--thread ()
|
|
||||||
:description "Thread style"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m s "
|
|
||||||
:argument "--thread=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--reroll-count ()
|
|
||||||
:description "Reroll count"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m v "
|
|
||||||
:shortarg "-v"
|
|
||||||
:argument "--reroll-count="
|
|
||||||
:reader 'transient-read-number-N+)
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--subject-prefix ()
|
|
||||||
:description "Subject Prefix"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m p "
|
|
||||||
:argument "--subject-prefix=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--from ()
|
|
||||||
:description "From"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m C-f"
|
|
||||||
:argument "--from="
|
|
||||||
:reader 'magit-transient-read-person)
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--to ()
|
|
||||||
:description "To"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m C-t"
|
|
||||||
:argument "--to="
|
|
||||||
:reader 'magit-transient-read-person)
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--cc ()
|
|
||||||
:description "CC"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m C-c"
|
|
||||||
:argument "--cc="
|
|
||||||
:reader 'magit-transient-read-person)
|
|
||||||
|
|
||||||
(define-infix-argument magit-format-patch:--output-directory ()
|
|
||||||
:description "Output directory"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "C-m o "
|
|
||||||
:shortarg "-o"
|
|
||||||
:argument "--output-directory="
|
|
||||||
:reader 'transient-read-existing-directory)
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-patch-apply "magit-patch" nil t)
|
|
||||||
(define-transient-command magit-patch-apply (file &rest args)
|
|
||||||
"Apply the patch file FILE."
|
|
||||||
:man-page "git-apply"
|
|
||||||
["Arguments"
|
|
||||||
("-i" "Also apply to index" "--index")
|
|
||||||
("-c" "Only apply to index" "--cached")
|
|
||||||
("-3" "Fall back on 3way merge" ("-3" "--3way"))]
|
|
||||||
["Actions"
|
|
||||||
("a" "Apply patch" magit-patch-apply)]
|
|
||||||
(interactive
|
|
||||||
(if (not (eq current-transient-command 'magit-patch-apply))
|
|
||||||
(list nil)
|
|
||||||
(list (expand-file-name
|
|
||||||
(read-file-name "Apply patch: "
|
|
||||||
default-directory nil nil
|
|
||||||
(when-let ((file (magit-file-at-point)))
|
|
||||||
(file-relative-name file))))
|
|
||||||
(transient-args 'magit-patch-apply))))
|
|
||||||
(if (not file)
|
|
||||||
(transient-setup 'magit-patch-apply)
|
|
||||||
(magit-run-git "apply" args "--" (magit-convert-filename-for-git file))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-patch-save (file &optional arg)
|
|
||||||
"Write current diff into patch FILE.
|
|
||||||
|
|
||||||
What arguments are used to create the patch depends on the value
|
|
||||||
of `magit-patch-save-arguments' and whether a prefix argument is
|
|
||||||
used.
|
|
||||||
|
|
||||||
If the value is the symbol `buffer', then use the same arguments
|
|
||||||
as the buffer. With a prefix argument use no arguments.
|
|
||||||
|
|
||||||
If the value is a list beginning with the symbol `exclude', then
|
|
||||||
use the same arguments as the buffer except for those matched by
|
|
||||||
entries in the cdr of the list. The comparison is done using
|
|
||||||
`string-prefix-p'. With a prefix argument use the same arguments
|
|
||||||
as the buffer.
|
|
||||||
|
|
||||||
If the value is a list of strings (including the empty list),
|
|
||||||
then use those arguments. With a prefix argument use the same
|
|
||||||
arguments as the buffer.
|
|
||||||
|
|
||||||
Of course the arguments that are required to actually show the
|
|
||||||
same differences as those shown in the buffer are always used."
|
|
||||||
(interactive (list (read-file-name "Write patch file: " default-directory)
|
|
||||||
current-prefix-arg))
|
|
||||||
(unless (derived-mode-p 'magit-diff-mode)
|
|
||||||
(user-error "Only diff buffers can be saved as patches"))
|
|
||||||
(let ((rev magit-buffer-range)
|
|
||||||
(typearg magit-buffer-typearg)
|
|
||||||
(args magit-buffer-diff-args)
|
|
||||||
(files magit-buffer-diff-files))
|
|
||||||
(cond ((eq magit-patch-save-arguments 'buffer)
|
|
||||||
(when arg
|
|
||||||
(setq args nil)))
|
|
||||||
((eq (car-safe magit-patch-save-arguments) 'exclude)
|
|
||||||
(unless arg
|
|
||||||
(setq args (-difference args (cdr magit-patch-save-arguments)))))
|
|
||||||
((not arg)
|
|
||||||
(setq args magit-patch-save-arguments)))
|
|
||||||
(with-temp-file file
|
|
||||||
(magit-git-insert "diff" rev "-p" typearg args "--" files)))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-request-pull (url start end)
|
|
||||||
"Request upstream to pull from you public repository.
|
|
||||||
|
|
||||||
URL is the url of your publicly accessible repository.
|
|
||||||
START is a commit that already is in the upstream repository.
|
|
||||||
END is the last commit, usually a branch name, which upstream
|
|
||||||
is asked to pull. START has to be reachable from that commit."
|
|
||||||
(interactive
|
|
||||||
(list (magit-get "remote" (magit-read-remote "Remote") "url")
|
|
||||||
(magit-read-branch-or-commit "Start" (magit-get-upstream-branch))
|
|
||||||
(magit-read-branch-or-commit "End")))
|
|
||||||
(let ((dir default-directory))
|
|
||||||
;; mu4e changes default-directory
|
|
||||||
(compose-mail)
|
|
||||||
(setq default-directory dir))
|
|
||||||
(message-goto-body)
|
|
||||||
(magit-git-insert "request-pull" start url end)
|
|
||||||
(set-buffer-modified-p nil))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-patch)
|
|
||||||
;;; magit-patch.el ends here
|
|
Binary file not shown.
|
@ -1,12 +0,0 @@
|
||||||
(define-package "magit" "20191120.1637" "A Git porcelain inside Emacs."
|
|
||||||
'((emacs "25.1")
|
|
||||||
(async "20180527")
|
|
||||||
(dash "20180910")
|
|
||||||
(git-commit "20181104")
|
|
||||||
(transient "20190812")
|
|
||||||
(with-editor "20181103"))
|
|
||||||
:keywords
|
|
||||||
'("git" "tools" "vc"))
|
|
||||||
;; Local Variables:
|
|
||||||
;; no-byte-compile: t
|
|
||||||
;; End:
|
|
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,163 +0,0 @@
|
||||||
;;; magit-pull.el --- update local objects and refs -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements pull commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-pull-or-fetch nil
|
|
||||||
"Whether `magit-pull' also offers some fetch suffixes."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-pull "magit-pull" nil t)
|
|
||||||
(define-transient-command magit-pull ()
|
|
||||||
"Pull from another repository."
|
|
||||||
:man-page "git-pull"
|
|
||||||
[:description
|
|
||||||
(lambda () (if magit-pull-or-fetch "Pull arguments" "Arguments"))
|
|
||||||
("-r" "Rebase local commits" ("-r" "--rebase"))]
|
|
||||||
[:description
|
|
||||||
(lambda ()
|
|
||||||
(if-let ((branch (magit-get-current-branch)))
|
|
||||||
(concat
|
|
||||||
(propertize "Pull into " 'face 'transient-heading)
|
|
||||||
(propertize branch 'face 'magit-branch-local)
|
|
||||||
(propertize " from" 'face 'transient-heading))
|
|
||||||
(propertize "Pull from" 'face 'transient-heading)))
|
|
||||||
("p" magit-pull-from-pushremote)
|
|
||||||
("u" magit-pull-from-upstream)
|
|
||||||
("e" "elsewhere" magit-pull-branch)]
|
|
||||||
["Fetch from"
|
|
||||||
:if-non-nil magit-pull-or-fetch
|
|
||||||
("f" "remotes" magit-fetch-all-no-prune)
|
|
||||||
("F" "remotes and prune" magit-fetch-all-prune)]
|
|
||||||
["Fetch"
|
|
||||||
:if-non-nil magit-pull-or-fetch
|
|
||||||
("o" "another branch" magit-fetch-branch)
|
|
||||||
("s" "explicit refspec" magit-fetch-refspec)
|
|
||||||
("m" "submodules" magit-fetch-modules)]
|
|
||||||
["Configure"
|
|
||||||
("r" magit-branch.<branch>.rebase :if magit-get-current-branch)
|
|
||||||
("C" "variables..." magit-branch-configure)]
|
|
||||||
(interactive)
|
|
||||||
(transient-setup 'magit-pull nil nil :scope (magit-get-current-branch)))
|
|
||||||
|
|
||||||
(defun magit-pull-arguments ()
|
|
||||||
(transient-args 'magit-pull))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-pull-from-pushremote "magit-pull" nil t)
|
|
||||||
(define-suffix-command magit-pull-from-pushremote (args)
|
|
||||||
"Pull from the push-remote of the current branch.
|
|
||||||
|
|
||||||
When the push-remote is not configured, then read the push-remote
|
|
||||||
from the user, set it, and then pull from it. With a prefix
|
|
||||||
argument the push-remote can be changed before pulling from it."
|
|
||||||
:if 'magit-get-current-branch
|
|
||||||
:description 'magit-pull--pushbranch-description
|
|
||||||
(interactive (list (magit-pull-arguments)))
|
|
||||||
(pcase-let ((`(,branch ,remote)
|
|
||||||
(magit--select-push-remote "pull from there")))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "pull" args remote branch)))
|
|
||||||
|
|
||||||
(defun magit-pull--pushbranch-description ()
|
|
||||||
;; Also used by `magit-rebase-onto-pushremote'.
|
|
||||||
(let* ((branch (magit-get-current-branch))
|
|
||||||
(target (magit-get-push-branch branch t))
|
|
||||||
(remote (magit-get-push-remote branch))
|
|
||||||
(v (magit--push-remote-variable branch t)))
|
|
||||||
(cond
|
|
||||||
(target)
|
|
||||||
((member remote (magit-list-remotes))
|
|
||||||
(format "%s, replacing non-existent" v))
|
|
||||||
(remote
|
|
||||||
(format "%s, replacing invalid" v))
|
|
||||||
(t
|
|
||||||
(format "%s, setting that" v)))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-pull-from-upstream "magit-pull" nil t)
|
|
||||||
(define-suffix-command magit-pull-from-upstream (args)
|
|
||||||
"Pull from the upstream of the current branch.
|
|
||||||
|
|
||||||
With a prefix argument or when the upstream is either not
|
|
||||||
configured or unusable, then let the user first configure
|
|
||||||
the upstream."
|
|
||||||
:if 'magit-get-current-branch
|
|
||||||
:description 'magit-pull--upstream-description
|
|
||||||
(interactive (list (magit-pull-arguments)))
|
|
||||||
(let* ((branch (or (magit-get-current-branch)
|
|
||||||
(user-error "No branch is checked out")))
|
|
||||||
(remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge")))
|
|
||||||
(when (or current-prefix-arg
|
|
||||||
(not (or (magit-get-upstream-branch branch)
|
|
||||||
(magit--unnamed-upstream-p remote merge))))
|
|
||||||
(magit-set-upstream-branch
|
|
||||||
branch (magit-read-upstream-branch
|
|
||||||
branch (format "Set upstream of %s and pull from there" branch)))
|
|
||||||
(setq remote (magit-get "branch" branch "remote"))
|
|
||||||
(setq merge (magit-get "branch" branch "merge")))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-with-editor "pull" args remote merge)))
|
|
||||||
|
|
||||||
(defun magit-pull--upstream-description ()
|
|
||||||
(when-let ((branch (magit-get-current-branch)))
|
|
||||||
(or (magit-get-upstream-branch branch)
|
|
||||||
(let ((remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge"))
|
|
||||||
(u (magit--propertize-face "@{upstream}" 'bold)))
|
|
||||||
(cond
|
|
||||||
((magit--unnamed-upstream-p remote merge)
|
|
||||||
(format "%s of %s"
|
|
||||||
(magit--propertize-face merge 'magit-branch-remote)
|
|
||||||
(magit--propertize-face remote 'bold)))
|
|
||||||
((magit--valid-upstream-p remote merge)
|
|
||||||
(concat u ", replacing non-existent"))
|
|
||||||
((or remote merge)
|
|
||||||
(concat u ", replacing invalid"))
|
|
||||||
(t
|
|
||||||
(concat u ", setting that")))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-pull-branch (source args)
|
|
||||||
"Pull from a branch read in the minibuffer."
|
|
||||||
(interactive (list (magit-read-remote-branch "Pull" nil nil nil t)
|
|
||||||
(magit-pull-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(pcase-let ((`(,remote . ,branch)
|
|
||||||
(magit-get-tracked source)))
|
|
||||||
(magit-run-git-with-editor "pull" args remote branch)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-pull)
|
|
||||||
;;; magit-pull.el ends here
|
|
Binary file not shown.
|
@ -1,319 +0,0 @@
|
||||||
;;; magit-push.el --- update remote objects and refs -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements push commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-push "magit-push" nil t)
|
|
||||||
(define-transient-command magit-push ()
|
|
||||||
"Push to another repository."
|
|
||||||
:man-page "git-push"
|
|
||||||
["Arguments"
|
|
||||||
("-f" "Force with lease" (nil "--force-with-lease"))
|
|
||||||
("-F" "Force" ("-f" "--force"))
|
|
||||||
("-h" "Disable hooks" "--no-verify")
|
|
||||||
("-n" "Dry run" ("-n" "--dry-run"))
|
|
||||||
(5 "-u" "Set upstream" "--set-upstream")
|
|
||||||
(7 "-t" "Follow tags" "--follow-tags")]
|
|
||||||
[:if magit-get-current-branch
|
|
||||||
:description (lambda ()
|
|
||||||
(format (propertize "Push %s to" 'face 'transient-heading)
|
|
||||||
(propertize (magit-get-current-branch)
|
|
||||||
'face 'magit-branch-local)))
|
|
||||||
("p" magit-push-current-to-pushremote)
|
|
||||||
("u" magit-push-current-to-upstream)
|
|
||||||
("e" "elsewhere" magit-push-current)]
|
|
||||||
["Push"
|
|
||||||
[("o" "another branch" magit-push-other)
|
|
||||||
("r" "explicit refspecs" magit-push-refspecs)
|
|
||||||
("m" "matching branches" magit-push-matching)]
|
|
||||||
[("T" "a tag" magit-push-tag)
|
|
||||||
("t" "all tags" magit-push-tags)]]
|
|
||||||
["Configure"
|
|
||||||
("C" "Set variables..." magit-branch-configure)])
|
|
||||||
|
|
||||||
(defun magit-push-arguments ()
|
|
||||||
(transient-args 'magit-push))
|
|
||||||
|
|
||||||
(defun magit-git-push (branch target args)
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
;; If the remote branch already exists, then we do not have to
|
|
||||||
;; qualify the target, which we prefer to avoid doing because
|
|
||||||
;; using the default namespace is wrong in obscure cases.
|
|
||||||
(pcase-let ((namespace (if (magit-get-tracked target) "" "refs/heads/"))
|
|
||||||
(`(,remote . ,target)
|
|
||||||
(magit-split-branch-name target)))
|
|
||||||
(magit-run-git-async "push" "-v" args remote
|
|
||||||
(format "%s:%s%s" branch namespace target))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-push-current-to-pushremote "magit-push" nil t)
|
|
||||||
(define-suffix-command magit-push-current-to-pushremote (args)
|
|
||||||
"Push the current branch to its push-remote.
|
|
||||||
|
|
||||||
When the push-remote is not configured, then read the push-remote
|
|
||||||
from the user, set it, and then push to it. With a prefix
|
|
||||||
argument the push-remote can be changed before pushed to it."
|
|
||||||
:if 'magit-get-current-branch
|
|
||||||
:description 'magit-push--pushbranch-description
|
|
||||||
(interactive (list (magit-push-arguments)))
|
|
||||||
(pcase-let ((`(,branch ,remote)
|
|
||||||
(magit--select-push-remote "push there")))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args remote
|
|
||||||
(format "refs/heads/%s:refs/heads/%s"
|
|
||||||
branch branch)))) ; see #3847 and #3872
|
|
||||||
|
|
||||||
(defun magit-push--pushbranch-description ()
|
|
||||||
(let* ((branch (magit-get-current-branch))
|
|
||||||
(target (magit-get-push-branch branch t))
|
|
||||||
(remote (magit-get-push-remote branch))
|
|
||||||
(v (magit--push-remote-variable branch t)))
|
|
||||||
(cond
|
|
||||||
(target)
|
|
||||||
((member remote (magit-list-remotes))
|
|
||||||
(format "%s, creating it"
|
|
||||||
(magit--propertize-face (concat remote "/" branch)
|
|
||||||
'magit-branch-remote)))
|
|
||||||
(remote
|
|
||||||
(format "%s, replacing invalid" v))
|
|
||||||
(t
|
|
||||||
(format "%s, setting that" v)))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-push-current-to-upstream "magit-push" nil t)
|
|
||||||
(define-suffix-command magit-push-current-to-upstream (args)
|
|
||||||
"Push the current branch to its upstream branch.
|
|
||||||
|
|
||||||
With a prefix argument or when the upstream is either not
|
|
||||||
configured or unusable, then let the user first configure
|
|
||||||
the upstream."
|
|
||||||
:if 'magit-get-current-branch
|
|
||||||
:description 'magit-push--upstream-description
|
|
||||||
(interactive (list (magit-push-arguments)))
|
|
||||||
(let* ((branch (or (magit-get-current-branch)
|
|
||||||
(user-error "No branch is checked out")))
|
|
||||||
(remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge")))
|
|
||||||
(when (or current-prefix-arg
|
|
||||||
(not (or (magit-get-upstream-branch branch)
|
|
||||||
(magit--unnamed-upstream-p remote merge)
|
|
||||||
(magit--valid-upstream-p remote merge))))
|
|
||||||
(let* ((branches (-union (--map (concat it "/" branch)
|
|
||||||
(magit-list-remotes))
|
|
||||||
(magit-list-remote-branch-names)))
|
|
||||||
(upstream (magit-completing-read
|
|
||||||
(format "Set upstream of %s and push there" branch)
|
|
||||||
branches nil nil nil 'magit-revision-history
|
|
||||||
(or (car (member (magit-remote-branch-at-point) branches))
|
|
||||||
(car (member "origin/master" branches)))))
|
|
||||||
(upstream (or (magit-get-tracked upstream)
|
|
||||||
(magit-split-branch-name upstream))))
|
|
||||||
(setq remote (car upstream))
|
|
||||||
(setq merge (cdr upstream))
|
|
||||||
(unless (string-prefix-p "refs/" merge)
|
|
||||||
;; User selected a non-existent remote-tracking branch.
|
|
||||||
;; It is very likely, but not certain, that this is the
|
|
||||||
;; correct thing to do. It is even more likely that it
|
|
||||||
;; is what the user wants to happen.
|
|
||||||
(setq merge (concat "refs/heads/" merge))))
|
|
||||||
(cl-pushnew "--set-upstream" args :test #'equal))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args remote (concat branch ":" merge))))
|
|
||||||
|
|
||||||
(defun magit-push--upstream-description ()
|
|
||||||
(when-let ((branch (magit-get-current-branch)))
|
|
||||||
(or (magit-get-upstream-branch branch)
|
|
||||||
(let ((remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge"))
|
|
||||||
(u (magit--propertize-face "@{upstream}" 'bold)))
|
|
||||||
(cond
|
|
||||||
((magit--unnamed-upstream-p remote merge)
|
|
||||||
(format "%s as %s"
|
|
||||||
(magit--propertize-face remote 'bold)
|
|
||||||
(magit--propertize-face merge 'magit-branch-remote)))
|
|
||||||
((magit--valid-upstream-p remote merge)
|
|
||||||
(format "%s creating %s"
|
|
||||||
(magit--propertize-face remote 'magit-branch-remote)
|
|
||||||
(magit--propertize-face merge 'magit-branch-remote)))
|
|
||||||
((or remote merge)
|
|
||||||
(concat u ", creating it and replacing invalid"))
|
|
||||||
(t
|
|
||||||
(concat u ", creating it")))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-current (target args)
|
|
||||||
"Push the current branch to a branch read in the minibuffer."
|
|
||||||
(interactive
|
|
||||||
(--if-let (magit-get-current-branch)
|
|
||||||
(list (magit-read-remote-branch (format "Push %s to" it)
|
|
||||||
nil nil it 'confirm)
|
|
||||||
(magit-push-arguments))
|
|
||||||
(user-error "No branch is checked out")))
|
|
||||||
(magit-git-push (magit-get-current-branch) target args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-other (source target args)
|
|
||||||
"Push an arbitrary branch or commit somewhere.
|
|
||||||
Both the source and the target are read in the minibuffer."
|
|
||||||
(interactive
|
|
||||||
(let ((source (magit-read-local-branch-or-commit "Push")))
|
|
||||||
(list source
|
|
||||||
(magit-read-remote-branch
|
|
||||||
(format "Push %s to" source) nil
|
|
||||||
(if (magit-local-branch-p source)
|
|
||||||
(or (magit-get-push-branch source)
|
|
||||||
(magit-get-upstream-branch source))
|
|
||||||
(and (magit-rev-ancestor-p source "HEAD")
|
|
||||||
(or (magit-get-push-branch)
|
|
||||||
(magit-get-upstream-branch))))
|
|
||||||
source 'confirm)
|
|
||||||
(magit-push-arguments))))
|
|
||||||
(magit-git-push source target args))
|
|
||||||
|
|
||||||
(defvar magit-push-refspecs-history nil)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-refspecs (remote refspecs args)
|
|
||||||
"Push one or multiple REFSPECS to a REMOTE.
|
|
||||||
Both the REMOTE and the REFSPECS are read in the minibuffer. To
|
|
||||||
use multiple REFSPECS, separate them with commas. Completion is
|
|
||||||
only available for the part before the colon, or when no colon
|
|
||||||
is used."
|
|
||||||
(interactive
|
|
||||||
(list (magit-read-remote "Push to remote")
|
|
||||||
(split-string (magit-completing-read-multiple
|
|
||||||
"Push refspec,s"
|
|
||||||
(cons "HEAD" (magit-list-local-branch-names))
|
|
||||||
nil nil 'magit-push-refspecs-history)
|
|
||||||
crm-default-separator t)
|
|
||||||
(magit-push-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args remote refspecs))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-matching (remote &optional args)
|
|
||||||
"Push all matching branches to another repository.
|
|
||||||
If multiple remotes exist, then read one from the user.
|
|
||||||
If just one exists, use that without requiring confirmation."
|
|
||||||
(interactive (list (magit-read-remote "Push matching branches to" nil t)
|
|
||||||
(magit-push-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args remote ":"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-tags (remote &optional args)
|
|
||||||
"Push all tags to another repository.
|
|
||||||
If only one remote exists, then push to that. Otherwise prompt
|
|
||||||
for a remote, offering the remote configured for the current
|
|
||||||
branch as default."
|
|
||||||
(interactive (list (magit-read-remote "Push tags to remote" nil t)
|
|
||||||
(magit-push-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" remote "--tags" args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-tag (tag remote &optional args)
|
|
||||||
"Push a tag to another repository."
|
|
||||||
(interactive
|
|
||||||
(let ((tag (magit-read-tag "Push tag")))
|
|
||||||
(list tag (magit-read-remote (format "Push %s to remote" tag) nil t)
|
|
||||||
(magit-push-arguments))))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" remote tag args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-implicitly (args)
|
|
||||||
"Push somewhere without using an explicit refspec.
|
|
||||||
|
|
||||||
This command simply runs \"git push -v [ARGS]\". ARGS are the
|
|
||||||
arguments specified in the popup buffer. No explicit refspec
|
|
||||||
arguments are used. Instead the behavior depends on at least
|
|
||||||
these Git variables: `push.default', `remote.pushDefault',
|
|
||||||
`branch.<branch>.pushRemote', `branch.<branch>.remote',
|
|
||||||
`branch.<branch>.merge', and `remote.<remote>.push'.
|
|
||||||
|
|
||||||
The function `magit-push-implicitly--desc' attempts to predict
|
|
||||||
what this command will do. The value it returns is displayed in
|
|
||||||
the popup buffer."
|
|
||||||
(interactive (list (magit-push-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args))
|
|
||||||
|
|
||||||
(defun magit-push-implicitly--desc ()
|
|
||||||
(let ((default (magit-get "push.default")))
|
|
||||||
(unless (equal default "nothing")
|
|
||||||
(or (when-let ((remote (or (magit-get-remote)
|
|
||||||
(magit-remote-p "origin")))
|
|
||||||
(refspec (magit-get "remote" remote "push")))
|
|
||||||
(format "%s using %s"
|
|
||||||
(magit--propertize-face remote 'magit-branch-remote)
|
|
||||||
(magit--propertize-face refspec 'bold)))
|
|
||||||
(--when-let (and (not (magit-get-push-branch))
|
|
||||||
(magit-get-upstream-branch))
|
|
||||||
(format "%s aka %s\n"
|
|
||||||
(magit-branch-set-face it)
|
|
||||||
(magit--propertize-face "@{upstream}" 'bold)))
|
|
||||||
(--when-let (magit-get-push-branch)
|
|
||||||
(format "%s aka %s\n"
|
|
||||||
(magit-branch-set-face it)
|
|
||||||
(magit--propertize-face "pushRemote" 'bold)))
|
|
||||||
(--when-let (magit-get-@{push}-branch)
|
|
||||||
(format "%s aka %s\n"
|
|
||||||
(magit-branch-set-face it)
|
|
||||||
(magit--propertize-face "@{push}" 'bold)))
|
|
||||||
(format "using %s (%s is %s)\n"
|
|
||||||
(magit--propertize-face "git push" 'bold)
|
|
||||||
(magit--propertize-face "push.default" 'bold)
|
|
||||||
(magit--propertize-face default 'bold))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-push-to-remote (remote args)
|
|
||||||
"Push to REMOTE without using an explicit refspec.
|
|
||||||
The REMOTE is read in the minibuffer.
|
|
||||||
|
|
||||||
This command simply runs \"git push -v [ARGS] REMOTE\". ARGS
|
|
||||||
are the arguments specified in the popup buffer. No refspec
|
|
||||||
arguments are used. Instead the behavior depends on at least
|
|
||||||
these Git variables: `push.default', `remote.pushDefault',
|
|
||||||
`branch.<branch>.pushRemote', `branch.<branch>.remote',
|
|
||||||
`branch.<branch>.merge', and `remote.<remote>.push'."
|
|
||||||
(interactive (list (magit-read-remote "Push to remote")
|
|
||||||
(magit-push-arguments)))
|
|
||||||
(run-hooks 'magit-credential-hook)
|
|
||||||
(magit-run-git-async "push" "-v" args remote))
|
|
||||||
|
|
||||||
(defun magit-push-to-remote--desc ()
|
|
||||||
(format "using %s\n" (magit--propertize-face "git push <remote>" 'bold)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-push)
|
|
||||||
;;; magit-push.el ends here
|
|
Binary file not shown.
|
@ -1,213 +0,0 @@
|
||||||
;;; magit-reflog.el --- inspect ref history -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for looking at Git reflogs.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit-core)
|
|
||||||
(require 'magit-log)
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-reflog-limit 256
|
|
||||||
"Maximal number of entries initially shown in reflog buffers.
|
|
||||||
The limit in the current buffer can be changed using \"+\"
|
|
||||||
and \"-\"."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-git-arguments
|
|
||||||
:type 'number)
|
|
||||||
|
|
||||||
(defcustom magit-reflog-margin
|
|
||||||
(list (nth 0 magit-log-margin)
|
|
||||||
(nth 1 magit-log-margin)
|
|
||||||
'magit-log-margin-width nil
|
|
||||||
(nth 4 magit-log-margin))
|
|
||||||
"Format of the margin in `magit-reflog-mode' buffers.
|
|
||||||
|
|
||||||
The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).
|
|
||||||
|
|
||||||
If INIT is non-nil, then the margin is shown initially.
|
|
||||||
STYLE controls how to format the author or committer date.
|
|
||||||
It can be one of `age' (to show the age of the commit),
|
|
||||||
`age-abbreviated' (to abbreviate the time unit to a character),
|
|
||||||
or a string (suitable for `format-time-string') to show the
|
|
||||||
actual date. Option `magit-log-margin-show-committer-date'
|
|
||||||
controls which date is being displayed.
|
|
||||||
WIDTH controls the width of the margin. This exists for forward
|
|
||||||
compatibility and currently the value should not be changed.
|
|
||||||
AUTHOR controls whether the name of the author is also shown by
|
|
||||||
default.
|
|
||||||
AUTHOR-WIDTH has to be an integer. When the name of the author
|
|
||||||
is shown, then this specifies how much space is used to do so."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-log
|
|
||||||
:group 'magit-margin
|
|
||||||
:type magit-log-margin--custom-type
|
|
||||||
:initialize 'magit-custom-initialize-reset
|
|
||||||
:set-after '(magit-log-margin)
|
|
||||||
:set (apply-partially #'magit-margin-set-variable 'magit-reflog-mode))
|
|
||||||
|
|
||||||
;;; Faces
|
|
||||||
|
|
||||||
(defface magit-reflog-commit '((t :foreground "green"))
|
|
||||||
"Face for commit commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-amend '((t :foreground "magenta"))
|
|
||||||
"Face for amend commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-merge '((t :foreground "green"))
|
|
||||||
"Face for merge, checkout and branch commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-checkout '((t :foreground "blue"))
|
|
||||||
"Face for checkout commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-reset '((t :foreground "red"))
|
|
||||||
"Face for reset commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-rebase '((t :foreground "magenta"))
|
|
||||||
"Face for rebase commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-cherry-pick '((t :foreground "green"))
|
|
||||||
"Face for cherry-pick commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-remote '((t :foreground "cyan"))
|
|
||||||
"Face for pull and clone commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-reflog-other '((t :foreground "cyan"))
|
|
||||||
"Face for other commands in reflogs."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reflog-current ()
|
|
||||||
"Display the reflog of the current branch.
|
|
||||||
If `HEAD' is detached, then show the reflog for that instead."
|
|
||||||
(interactive)
|
|
||||||
(magit-reflog-setup-buffer (or (magit-get-current-branch) "HEAD")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reflog-other (ref)
|
|
||||||
"Display the reflog of a branch or another ref."
|
|
||||||
(interactive (list (magit-read-local-branch-or-ref "Show reflog for")))
|
|
||||||
(magit-reflog-setup-buffer ref))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reflog-head ()
|
|
||||||
"Display the `HEAD' reflog."
|
|
||||||
(interactive)
|
|
||||||
(magit-reflog-setup-buffer "HEAD"))
|
|
||||||
|
|
||||||
;;; Mode
|
|
||||||
|
|
||||||
(defvar magit-reflog-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map magit-log-mode-map)
|
|
||||||
(define-key map "\C-c\C-n" 'undefined)
|
|
||||||
(define-key map "L" 'magit-margin-settings)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-reflog-mode'.")
|
|
||||||
|
|
||||||
(define-derived-mode magit-reflog-mode magit-mode "Magit Reflog"
|
|
||||||
"Mode for looking at Git reflog.
|
|
||||||
|
|
||||||
This mode is documented in info node `(magit)Reflog'.
|
|
||||||
|
|
||||||
\\<magit-mode-map>\
|
|
||||||
Type \\[magit-refresh] to refresh the current buffer.
|
|
||||||
Type \\[magit-visit-thing] or \\[magit-diff-show-or-scroll-up] \
|
|
||||||
to visit the commit at point.
|
|
||||||
|
|
||||||
Type \\[magit-cherry-pick] to apply the commit at point.
|
|
||||||
Type \\[magit-reset] to reset `HEAD' to the commit at point.
|
|
||||||
|
|
||||||
\\{magit-reflog-mode-map}"
|
|
||||||
:group 'magit-log
|
|
||||||
(hack-dir-local-variables-non-file-buffer))
|
|
||||||
|
|
||||||
(defun magit-reflog-setup-buffer (ref)
|
|
||||||
(require 'magit)
|
|
||||||
(magit-setup-buffer #'magit-reflog-mode nil
|
|
||||||
(magit-buffer-refname ref)
|
|
||||||
(magit-buffer-log-args (list (format "-n%s" magit-reflog-limit)))))
|
|
||||||
|
|
||||||
(defun magit-reflog-refresh-buffer ()
|
|
||||||
(magit-set-header-line-format (concat "Reflog for " magit-buffer-refname))
|
|
||||||
(magit-insert-section (reflogbuf)
|
|
||||||
(magit-git-wash (apply-partially 'magit-log-wash-log 'reflog)
|
|
||||||
"reflog" "show" "--format=%h%x00%aN%x00%gd%x00%gs" "--date=raw"
|
|
||||||
magit-buffer-log-args magit-buffer-refname "--")))
|
|
||||||
|
|
||||||
(cl-defmethod magit-buffer-value (&context (major-mode magit-reflog-mode))
|
|
||||||
magit-buffer-refname)
|
|
||||||
|
|
||||||
(defvar magit-reflog-labels
|
|
||||||
'(("commit" . magit-reflog-commit)
|
|
||||||
("amend" . magit-reflog-amend)
|
|
||||||
("merge" . magit-reflog-merge)
|
|
||||||
("checkout" . magit-reflog-checkout)
|
|
||||||
("branch" . magit-reflog-checkout)
|
|
||||||
("reset" . magit-reflog-reset)
|
|
||||||
("rebase" . magit-reflog-rebase)
|
|
||||||
("cherry-pick" . magit-reflog-cherry-pick)
|
|
||||||
("initial" . magit-reflog-commit)
|
|
||||||
("pull" . magit-reflog-remote)
|
|
||||||
("clone" . magit-reflog-remote)
|
|
||||||
("autosave" . magit-reflog-commit)
|
|
||||||
("restart" . magit-reflog-reset)))
|
|
||||||
|
|
||||||
(defun magit-reflog-format-subject (subject)
|
|
||||||
(let* ((match (string-match magit-reflog-subject-re subject))
|
|
||||||
(command (and match (match-string 1 subject)))
|
|
||||||
(option (and match (match-string 2 subject)))
|
|
||||||
(type (and match (match-string 3 subject)))
|
|
||||||
(label (if (string= command "commit")
|
|
||||||
(or type command)
|
|
||||||
command))
|
|
||||||
(text (if (string= command "commit")
|
|
||||||
label
|
|
||||||
(mapconcat #'identity
|
|
||||||
(delq nil (list command option type))
|
|
||||||
" "))))
|
|
||||||
(format "%-16s "
|
|
||||||
(magit--propertize-face
|
|
||||||
text (or (cdr (assoc label magit-reflog-labels))
|
|
||||||
'magit-reflog-other)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-reflog)
|
|
||||||
;;; magit-reflog.el ends here
|
|
Binary file not shown.
|
@ -1,757 +0,0 @@
|
||||||
;;; magit-refs.el --- listing references -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for listing references in a buffer.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-refs nil
|
|
||||||
"Inspect and manipulate Git branches and tags."
|
|
||||||
:link '(info-link "(magit)References Buffer")
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
(defcustom magit-refs-mode-hook nil
|
|
||||||
"Hook run after entering Magit-Refs mode."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom magit-refs-sections-hook
|
|
||||||
'(magit-insert-error-header
|
|
||||||
magit-insert-branch-description
|
|
||||||
magit-insert-local-branches
|
|
||||||
magit-insert-remote-branches
|
|
||||||
magit-insert-tags)
|
|
||||||
"Hook run to insert sections into a references buffer."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom magit-refs-show-commit-count nil
|
|
||||||
"Whether to show commit counts in Magit-Refs mode buffers.
|
|
||||||
|
|
||||||
all Show counts for branches and tags.
|
|
||||||
branch Show counts for branches only.
|
|
||||||
nil Never show counts.
|
|
||||||
|
|
||||||
To change the value in an existing buffer use the command
|
|
||||||
`magit-refs-show-commit-count'"
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:safe (lambda (val) (memq val '(all branch nil)))
|
|
||||||
:type '(choice (const all :tag "For branches and tags")
|
|
||||||
(const branch :tag "For branches only")
|
|
||||||
(const nil :tag "Never")))
|
|
||||||
(put 'magit-refs-show-commit-count 'safe-local-variable 'symbolp)
|
|
||||||
(put 'magit-refs-show-commit-count 'permanent-local t)
|
|
||||||
|
|
||||||
(defcustom magit-refs-pad-commit-counts nil
|
|
||||||
"Whether to pad all counts on all sides in `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
If this is nil, then some commit counts are displayed right next
|
|
||||||
to one of the branches that appear next to the count, without any
|
|
||||||
space in between. This might look bad if the branch name faces
|
|
||||||
look too similar to `magit-dimmed'.
|
|
||||||
|
|
||||||
If this is non-nil, then spaces are placed on both sides of all
|
|
||||||
commit counts."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defvar magit-refs-show-push-remote nil
|
|
||||||
"Whether to show the push-remotes of local branches.
|
|
||||||
Also show the commits that the local branch is ahead and behind
|
|
||||||
the push-target. Unfortunately there is a bug in Git that makes
|
|
||||||
this useless (the commits ahead and behind the upstream are
|
|
||||||
shown), so this isn't enabled yet.")
|
|
||||||
|
|
||||||
(defcustom magit-refs-show-remote-prefix nil
|
|
||||||
"Whether to show the remote prefix in lists of remote branches.
|
|
||||||
|
|
||||||
This is redundant because the name of the remote is already shown
|
|
||||||
in the heading preceding the list of its branches."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-refs-margin
|
|
||||||
(list nil
|
|
||||||
(nth 1 magit-log-margin)
|
|
||||||
'magit-log-margin-width nil
|
|
||||||
(nth 4 magit-log-margin))
|
|
||||||
"Format of the margin in `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).
|
|
||||||
|
|
||||||
If INIT is non-nil, then the margin is shown initially.
|
|
||||||
STYLE controls how to format the author or committer date.
|
|
||||||
It can be one of `age' (to show the age of the commit),
|
|
||||||
`age-abbreviated' (to abbreviate the time unit to a character),
|
|
||||||
or a string (suitable for `format-time-string') to show the
|
|
||||||
actual date. Option `magit-log-margin-show-committer-date'
|
|
||||||
controls which date is being displayed.
|
|
||||||
WIDTH controls the width of the margin. This exists for forward
|
|
||||||
compatibility and currently the value should not be changed.
|
|
||||||
AUTHOR controls whether the name of the author is also shown by
|
|
||||||
default.
|
|
||||||
AUTHOR-WIDTH has to be an integer. When the name of the author
|
|
||||||
is shown, then this specifies how much space is used to do so."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:group 'magit-margin
|
|
||||||
:safe (lambda (val) (memq val '(all branch nil)))
|
|
||||||
:type magit-log-margin--custom-type
|
|
||||||
:initialize 'magit-custom-initialize-reset
|
|
||||||
:set-after '(magit-log-margin)
|
|
||||||
:set (apply-partially #'magit-margin-set-variable 'magit-refs-mode))
|
|
||||||
|
|
||||||
(defcustom magit-refs-margin-for-tags nil
|
|
||||||
"Whether to show information about tags in the margin.
|
|
||||||
|
|
||||||
This is disabled by default because it is slow if there are many
|
|
||||||
tags."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:group 'magit-margin
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-refs-primary-column-width (cons 16 32)
|
|
||||||
"Width of the focus column in `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
The primary column is the column that contains the name of the
|
|
||||||
branch that the current row is about.
|
|
||||||
|
|
||||||
If this is an integer, then the column is that many columns wide.
|
|
||||||
Otherwise it has to be a cons-cell of two integers. The first
|
|
||||||
specifies the minimal width, the second the maximal width. In that
|
|
||||||
case the actual width is determined using the length of the names
|
|
||||||
of the shown local branches. (Remote branches and tags are not
|
|
||||||
taken into account when calculating to optimal width.)"
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type '(choice (integer :tag "Constant wide")
|
|
||||||
(cons :tag "Wide constrains"
|
|
||||||
(integer :tag "Minimum")
|
|
||||||
(integer :tag "Maximum"))))
|
|
||||||
|
|
||||||
(defcustom magit-refs-focus-column-width 5
|
|
||||||
"Width of the focus column in `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
The focus column is the first column, which marks one
|
|
||||||
branch (usually the current branch) as the focused branch using
|
|
||||||
\"*\" or \"@\". For each other reference, this column optionally
|
|
||||||
shows how many commits it is ahead of the focused branch and \"<\", or
|
|
||||||
if it isn't ahead then the commits it is behind and \">\", or if it
|
|
||||||
isn't behind either, then a \"=\".
|
|
||||||
|
|
||||||
This column may also display only \"*\" or \"@\" for the focused
|
|
||||||
branch, in which case this option is ignored. Use \"L v\" to
|
|
||||||
change the verbosity of this column."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type 'integer)
|
|
||||||
|
|
||||||
(defcustom magit-refs-filter-alist nil
|
|
||||||
"Alist controlling which refs are omitted from `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
The purpose of this option is to forgo displaying certain refs
|
|
||||||
based on their name. If you want to not display any refs of a
|
|
||||||
certain type, then you should remove the appropriate function
|
|
||||||
from `magit-refs-sections-hook' instead.
|
|
||||||
|
|
||||||
All keys are tried in order until one matches. Then its value
|
|
||||||
is used and subsequent elements are ignored. If the value is
|
|
||||||
non-nil, then the reference is displayed, otherwise it is not.
|
|
||||||
If no element matches, then the reference is displayed.
|
|
||||||
|
|
||||||
A key can either be a regular expression that the refname has to
|
|
||||||
match, or a function that takes the refname as only argument and
|
|
||||||
returns a boolean. A remote branch such as \"origin/master\" is
|
|
||||||
displayed as just \"master\", however for this comparison the
|
|
||||||
former is used."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:type '(alist :key-type (choice :tag "Key" regexp function)
|
|
||||||
:value-type (boolean :tag "Value"
|
|
||||||
:on "show (non-nil)"
|
|
||||||
:off "omit (nil)")))
|
|
||||||
|
|
||||||
(defcustom magit-visit-ref-behavior nil
|
|
||||||
"Control how `magit-visit-ref' behaves in `magit-refs-mode' buffers.
|
|
||||||
|
|
||||||
By default `magit-visit-ref' behaves like `magit-show-commit',
|
|
||||||
in all buffers, including `magit-refs-mode' buffers. When the
|
|
||||||
type of the section at point is `commit' then \"RET\" is bound to
|
|
||||||
`magit-show-commit', and when the type is either `branch' or
|
|
||||||
`tag' then it is bound to `magit-visit-ref'.
|
|
||||||
|
|
||||||
\"RET\" is one of Magit's most essential keys and at least by
|
|
||||||
default it should behave consistently across all of Magit,
|
|
||||||
especially because users quickly learn that it does something
|
|
||||||
very harmless; it shows more information about the thing at point
|
|
||||||
in another buffer.
|
|
||||||
|
|
||||||
However \"RET\" used to behave differently in `magit-refs-mode'
|
|
||||||
buffers, doing surprising things, some of which cannot really be
|
|
||||||
described as \"visit this thing\". If you have grown accustomed
|
|
||||||
to such inconsistent, but to you useful, behavior, then you can
|
|
||||||
restore that by adding one or more of the below symbols to the
|
|
||||||
value of this option. But keep in mind that by doing so you
|
|
||||||
don't only introduce inconsistencies, you also lose some
|
|
||||||
functionality and might have to resort to `M-x magit-show-commit'
|
|
||||||
to get it back.
|
|
||||||
|
|
||||||
`magit-visit-ref' looks for these symbols in the order in which
|
|
||||||
they are described here. If the presence of a symbol applies to
|
|
||||||
the current situation, then the symbols that follow do not affect
|
|
||||||
the outcome.
|
|
||||||
|
|
||||||
`focus-on-ref'
|
|
||||||
|
|
||||||
With a prefix argument update the buffer to show commit counts
|
|
||||||
and lists of cherry commits relative to the reference at point
|
|
||||||
instead of relative to the current buffer or `HEAD'.
|
|
||||||
|
|
||||||
Instead of adding this symbol, consider pressing \"C-u y o RET\".
|
|
||||||
|
|
||||||
`create-branch'
|
|
||||||
|
|
||||||
If point is on a remote branch, then create a new local branch
|
|
||||||
with the same name, use the remote branch as its upstream, and
|
|
||||||
then check out the local branch.
|
|
||||||
|
|
||||||
Instead of adding this symbol, consider pressing \"b c RET RET\",
|
|
||||||
like you would do in other buffers.
|
|
||||||
|
|
||||||
`checkout-any'
|
|
||||||
|
|
||||||
Check out the reference at point. If that reference is a tag
|
|
||||||
or a remote branch, then this results in a detached `HEAD'.
|
|
||||||
|
|
||||||
Instead of adding this symbol, consider pressing \"b b RET\",
|
|
||||||
like you would do in other buffers.
|
|
||||||
|
|
||||||
`checkout-branch'
|
|
||||||
|
|
||||||
Check out the local branch at point.
|
|
||||||
|
|
||||||
Instead of adding this symbol, consider pressing \"b b RET\",
|
|
||||||
like you would do in other buffers."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-refs
|
|
||||||
:group 'magit-commands
|
|
||||||
:options '(focus-on-ref create-branch checkout-any checkout-branch)
|
|
||||||
:type '(list :convert-widget custom-hook-convert-widget))
|
|
||||||
|
|
||||||
;;; Mode
|
|
||||||
|
|
||||||
(defvar magit-refs-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map magit-mode-map)
|
|
||||||
(define-key map "\C-y" 'magit-refs-set-show-commit-count)
|
|
||||||
(define-key map "L" 'magit-margin-settings)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-refs-mode'.")
|
|
||||||
|
|
||||||
(define-derived-mode magit-refs-mode magit-mode "Magit Refs"
|
|
||||||
"Mode which lists and compares references.
|
|
||||||
|
|
||||||
This mode is documented in info node `(magit)References Buffer'.
|
|
||||||
|
|
||||||
\\<magit-mode-map>\
|
|
||||||
Type \\[magit-refresh] to refresh the current buffer.
|
|
||||||
Type \\[magit-section-toggle] to expand or hide the section at point.
|
|
||||||
Type \\[magit-visit-thing] or \\[magit-diff-show-or-scroll-up] \
|
|
||||||
to visit the commit or branch at point.
|
|
||||||
|
|
||||||
Type \\[magit-branch] to see available branch commands.
|
|
||||||
Type \\[magit-merge] to merge the branch or commit at point.
|
|
||||||
Type \\[magit-cherry-pick] to apply the commit at point.
|
|
||||||
Type \\[magit-reset] to reset `HEAD' to the commit at point.
|
|
||||||
|
|
||||||
\\{magit-refs-mode-map}"
|
|
||||||
:group 'magit-refs
|
|
||||||
(hack-dir-local-variables-non-file-buffer)
|
|
||||||
(setq imenu-create-index-function
|
|
||||||
#'magit-imenu--refs-create-index-function))
|
|
||||||
|
|
||||||
(defun magit-refs-setup-buffer (ref args)
|
|
||||||
(magit-setup-buffer #'magit-refs-mode nil
|
|
||||||
(magit-buffer-upstream ref)
|
|
||||||
(magit-buffer-arguments args)))
|
|
||||||
|
|
||||||
(defun magit-refs-refresh-buffer ()
|
|
||||||
(setq magit-set-buffer-margin-refresh (not (magit-buffer-margin-p)))
|
|
||||||
(unless (magit-rev-verify magit-buffer-upstream)
|
|
||||||
(setq magit-refs-show-commit-count nil))
|
|
||||||
(magit-set-header-line-format
|
|
||||||
(format "%s %s" magit-buffer-upstream
|
|
||||||
(mapconcat #'identity magit-buffer-arguments " ")))
|
|
||||||
(magit-insert-section (branchbuf)
|
|
||||||
(magit-run-section-hook 'magit-refs-sections-hook))
|
|
||||||
(add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache))
|
|
||||||
|
|
||||||
(cl-defmethod magit-buffer-value (&context (major-mode magit-refs-mode))
|
|
||||||
(cons magit-buffer-upstream magit-buffer-arguments))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-show-refs "magit-refs" nil t)
|
|
||||||
(define-transient-command magit-show-refs (&optional transient)
|
|
||||||
"List and compare references in a dedicated buffer."
|
|
||||||
:man-page "git-branch"
|
|
||||||
:value 'magit-show-refs-arguments
|
|
||||||
["Arguments"
|
|
||||||
(magit-for-each-ref:--contains)
|
|
||||||
("=m" "Merged" "--merged=" magit-transient-read-revision)
|
|
||||||
("-m" "Merged to HEAD" "--merged")
|
|
||||||
("-M" "Merged to master" "--merged=master")
|
|
||||||
("=n" "Not merged" "--no-merged=" magit-transient-read-revision)
|
|
||||||
("-n" "Not merged to HEAD" "--no-merged")
|
|
||||||
("-N" "Not merged to master" "--no-merged=master")
|
|
||||||
(magit-for-each-ref:--sort)]
|
|
||||||
["Actions"
|
|
||||||
("y" "Show refs, comparing them with HEAD" magit-show-refs-head)
|
|
||||||
("c" "Show refs, comparing them with current branch" magit-show-refs-current)
|
|
||||||
("o" "Show refs, comparing them with other branch" magit-show-refs-other)]
|
|
||||||
(interactive (list (or (derived-mode-p 'magit-refs-mode)
|
|
||||||
current-prefix-arg)))
|
|
||||||
(if transient
|
|
||||||
(transient-setup 'magit-show-refs)
|
|
||||||
(magit-refs-setup-buffer "HEAD" (magit-show-refs-arguments))))
|
|
||||||
|
|
||||||
(defun magit-show-refs-arguments ()
|
|
||||||
(let (args)
|
|
||||||
(cond
|
|
||||||
((eq current-transient-command 'magit-show-refs)
|
|
||||||
(setq args (transient-args 'magit-show-refs)))
|
|
||||||
((eq major-mode 'magit-show-refs-mode)
|
|
||||||
(setq args magit-buffer-arguments))
|
|
||||||
((and (memq magit-prefix-use-buffer-arguments '(always selected))
|
|
||||||
(when-let ((buffer (magit-get-mode-buffer
|
|
||||||
'magit-refs-mode nil
|
|
||||||
(or (eq magit-prefix-use-buffer-arguments
|
|
||||||
'selected)
|
|
||||||
'all))))
|
|
||||||
(setq args (buffer-local-value 'magit-buffer-arguments buffer))
|
|
||||||
t)))
|
|
||||||
(t
|
|
||||||
(setq args (alist-get 'magit-show-refs transient-values))))
|
|
||||||
args))
|
|
||||||
|
|
||||||
(define-infix-argument magit-for-each-ref:--contains ()
|
|
||||||
:description "Contains"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "-c"
|
|
||||||
:argument "--contains="
|
|
||||||
:reader 'magit-transient-read-revision)
|
|
||||||
|
|
||||||
(define-infix-argument magit-for-each-ref:--sort ()
|
|
||||||
:description "Sort"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "-s"
|
|
||||||
:argument "--sort="
|
|
||||||
:reader 'magit-read-ref-sort)
|
|
||||||
|
|
||||||
(defun magit-read-ref-sort (prompt initial-input _history)
|
|
||||||
(magit-completing-read prompt
|
|
||||||
'("-committerdate" "-authordate"
|
|
||||||
"committerdate" "authordate")
|
|
||||||
nil nil initial-input))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-show-refs-head (&optional args)
|
|
||||||
"List and compare references in a dedicated buffer.
|
|
||||||
Compared with `HEAD'."
|
|
||||||
(interactive (list (magit-show-refs-arguments)))
|
|
||||||
(magit-refs-setup-buffer "HEAD" args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-show-refs-current (&optional args)
|
|
||||||
"List and compare references in a dedicated buffer.
|
|
||||||
Compare with the current branch or `HEAD' if it is detached."
|
|
||||||
(interactive (list (magit-show-refs-arguments)))
|
|
||||||
(magit-refs-setup-buffer (magit-get-current-branch) args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-show-refs-other (&optional ref args)
|
|
||||||
"List and compare references in a dedicated buffer.
|
|
||||||
Compared with a branch read from the user."
|
|
||||||
(interactive (list (magit-read-other-branch "Compare with")
|
|
||||||
(magit-show-refs-arguments)))
|
|
||||||
(magit-refs-setup-buffer ref args))
|
|
||||||
|
|
||||||
(defun magit-refs-set-show-commit-count ()
|
|
||||||
"Change for which refs the commit count is shown."
|
|
||||||
(interactive)
|
|
||||||
(setq-local magit-refs-show-commit-count
|
|
||||||
(magit-read-char-case "Show commit counts for " nil
|
|
||||||
(?a "[a]ll refs" 'all)
|
|
||||||
(?b "[b]ranches only" t)
|
|
||||||
(?n "[n]othing" nil)))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
(defun magit-visit-ref ()
|
|
||||||
"Visit the reference or revision at point in another buffer.
|
|
||||||
If there is no revision at point or with a prefix argument prompt
|
|
||||||
for a revision.
|
|
||||||
|
|
||||||
This command behaves just like `magit-show-commit', except if
|
|
||||||
point is on a reference in a `magit-refs-mode' buffer (a buffer
|
|
||||||
listing branches and tags), in which case the behavior may be
|
|
||||||
different, but only if you have customized the option
|
|
||||||
`magit-visit-ref-behavior' (which see)."
|
|
||||||
(interactive)
|
|
||||||
(if (and (derived-mode-p 'magit-refs-mode)
|
|
||||||
(magit-section-match '(branch tag)))
|
|
||||||
(let ((ref (oref (magit-current-section) value)))
|
|
||||||
(cond (current-prefix-arg
|
|
||||||
(cond ((memq 'focus-on-ref magit-visit-ref-behavior)
|
|
||||||
(magit-refs-setup-buffer ref (magit-show-refs-arguments)))
|
|
||||||
(magit-visit-ref-behavior
|
|
||||||
;; Don't prompt for commit to visit.
|
|
||||||
(let ((current-prefix-arg nil))
|
|
||||||
(call-interactively #'magit-show-commit)))))
|
|
||||||
((and (memq 'create-branch magit-visit-ref-behavior)
|
|
||||||
(magit-section-match [branch remote]))
|
|
||||||
(let ((branch (cdr (magit-split-branch-name ref))))
|
|
||||||
(if (magit-branch-p branch)
|
|
||||||
(if (magit-rev-eq branch ref)
|
|
||||||
(magit-call-git "checkout" branch)
|
|
||||||
(setq branch (propertize branch 'face 'magit-branch-local))
|
|
||||||
(setq ref (propertize ref 'face 'magit-branch-remote))
|
|
||||||
(pcase (prog1 (read-char-choice (format (propertize "\
|
|
||||||
Branch %s already exists.
|
|
||||||
[c]heckout %s as-is
|
|
||||||
[r]reset %s to %s and checkout %s
|
|
||||||
[a]bort " 'face 'minibuffer-prompt) branch branch branch ref branch)
|
|
||||||
'(?c ?r ?a))
|
|
||||||
(message "")) ; otherwise prompt sticks
|
|
||||||
(?c (magit-call-git "checkout" branch))
|
|
||||||
(?r (magit-call-git "checkout" "-B" branch ref))
|
|
||||||
(?a (user-error "Abort"))))
|
|
||||||
(magit-call-git "checkout" "-b" branch ref))
|
|
||||||
(setq magit-buffer-upstream branch)
|
|
||||||
(magit-refresh)))
|
|
||||||
((or (memq 'checkout-any magit-visit-ref-behavior)
|
|
||||||
(and (memq 'checkout-branch magit-visit-ref-behavior)
|
|
||||||
(magit-section-match [branch local])))
|
|
||||||
(magit-call-git "checkout" ref)
|
|
||||||
(setq magit-buffer-upstream ref)
|
|
||||||
(magit-refresh))
|
|
||||||
(t
|
|
||||||
(call-interactively #'magit-show-commit))))
|
|
||||||
(call-interactively #'magit-show-commit)))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
(defvar magit-remote-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-remote-remove)
|
|
||||||
(define-key map "R" 'magit-remote-rename)
|
|
||||||
map)
|
|
||||||
"Keymap for `remote' sections.")
|
|
||||||
|
|
||||||
(defvar magit-branch-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-visit-ref)
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-branch-delete)
|
|
||||||
(define-key map "R" 'magit-branch-rename)
|
|
||||||
map)
|
|
||||||
"Keymap for `branch' sections.")
|
|
||||||
|
|
||||||
(defvar magit-tag-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-visit-ref)
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-tag-delete)
|
|
||||||
map)
|
|
||||||
"Keymap for `tag' sections.")
|
|
||||||
|
|
||||||
(defun magit-insert-branch-description ()
|
|
||||||
"Insert header containing the description of the current branch.
|
|
||||||
Insert a header line with the name and description of the
|
|
||||||
current branch. The description is taken from the Git variable
|
|
||||||
`branch.<NAME>.description'; if that is undefined then no header
|
|
||||||
line is inserted at all."
|
|
||||||
(when-let ((branch (magit-get-current-branch))
|
|
||||||
(desc (magit-get "branch" branch "description"))
|
|
||||||
(desc (split-string desc "\n")))
|
|
||||||
(when (equal (car (last desc)) "")
|
|
||||||
(setq desc (butlast desc)))
|
|
||||||
(magit-insert-section (branchdesc branch t)
|
|
||||||
(magit-insert-heading branch ": " (car desc))
|
|
||||||
(when (cdr desc)
|
|
||||||
(insert (mapconcat 'identity (cdr desc) "\n"))
|
|
||||||
(insert "\n\n")))))
|
|
||||||
|
|
||||||
(defun magit-insert-tags ()
|
|
||||||
"Insert sections showing all tags."
|
|
||||||
(when-let ((tags (magit-git-lines "tag" "--list" "-n" magit-buffer-arguments)))
|
|
||||||
(let ((_head (magit-rev-parse "HEAD")))
|
|
||||||
(magit-insert-section (tags)
|
|
||||||
(magit-insert-heading "Tags:")
|
|
||||||
(dolist (tag tags)
|
|
||||||
(string-match "^\\([^ \t]+\\)[ \t]+\\([^ \t\n].*\\)?" tag)
|
|
||||||
(let ((tag (match-string 1 tag))
|
|
||||||
(msg (match-string 2 tag)))
|
|
||||||
(when (magit-refs--insert-refname-p tag)
|
|
||||||
(magit-insert-section (tag tag t)
|
|
||||||
(magit-insert-heading
|
|
||||||
(magit-refs--format-focus-column tag 'tag)
|
|
||||||
(propertize tag 'font-lock-face 'magit-tag)
|
|
||||||
(make-string (max 1 (- magit-refs-primary-column-width
|
|
||||||
(length tag)))
|
|
||||||
?\s)
|
|
||||||
(and msg (magit-log-propertize-keywords nil msg)))
|
|
||||||
(when (and magit-refs-margin-for-tags (magit-buffer-margin-p))
|
|
||||||
(magit-refs--format-margin tag))
|
|
||||||
(magit-refs--insert-cherry-commits tag)))))
|
|
||||||
(insert ?\n)
|
|
||||||
(magit-make-margin-overlay nil t)))))
|
|
||||||
|
|
||||||
(defun magit-insert-remote-branches ()
|
|
||||||
"Insert sections showing all remote-tracking branches."
|
|
||||||
(dolist (remote (magit-list-remotes))
|
|
||||||
(magit-insert-section (remote remote)
|
|
||||||
(magit-insert-heading
|
|
||||||
(let ((pull (magit-get "remote" remote "url"))
|
|
||||||
(push (magit-get "remote" remote "pushurl")))
|
|
||||||
(format (propertize "Remote %s (%s):"
|
|
||||||
'font-lock-face 'magit-section-heading)
|
|
||||||
(propertize remote 'font-lock-face 'magit-branch-remote)
|
|
||||||
(concat pull (and pull push ", ") push))))
|
|
||||||
(let (head)
|
|
||||||
(dolist (line (magit-git-lines "for-each-ref" "--format=\
|
|
||||||
%(symref:short)%00%(refname:short)%00%(refname)%00%(subject)"
|
|
||||||
(concat "refs/remotes/" remote)
|
|
||||||
magit-buffer-arguments))
|
|
||||||
(pcase-let ((`(,head-branch ,branch ,ref ,msg)
|
|
||||||
(-replace "" nil (split-string line "\0"))))
|
|
||||||
(if head-branch
|
|
||||||
(progn (cl-assert (equal branch (concat remote "/HEAD")))
|
|
||||||
(setq head head-branch))
|
|
||||||
(when (magit-refs--insert-refname-p branch)
|
|
||||||
(magit-insert-section (branch branch t)
|
|
||||||
(let ((headp (equal branch head))
|
|
||||||
(abbrev (if magit-refs-show-remote-prefix
|
|
||||||
branch
|
|
||||||
(substring branch (1+ (length remote))))))
|
|
||||||
(magit-insert-heading
|
|
||||||
(magit-refs--format-focus-column branch)
|
|
||||||
(magit-refs--propertize-branch
|
|
||||||
abbrev ref (and headp 'magit-branch-remote-head))
|
|
||||||
(make-string (max 1 (- magit-refs-primary-column-width
|
|
||||||
(length abbrev)))
|
|
||||||
?\s)
|
|
||||||
(and msg (magit-log-propertize-keywords nil msg))))
|
|
||||||
(when (magit-buffer-margin-p)
|
|
||||||
(magit-refs--format-margin branch))
|
|
||||||
(magit-refs--insert-cherry-commits branch)))))))
|
|
||||||
(insert ?\n)
|
|
||||||
(magit-make-margin-overlay nil t))))
|
|
||||||
|
|
||||||
(defun magit-insert-local-branches ()
|
|
||||||
"Insert sections showing all local branches."
|
|
||||||
(magit-insert-section (local nil)
|
|
||||||
(magit-insert-heading "Branches:")
|
|
||||||
(dolist (line (magit-refs--format-local-branches))
|
|
||||||
(pcase-let ((`(,branch . ,strings) line))
|
|
||||||
(magit-insert-section
|
|
||||||
((eval (if branch 'branch 'commit))
|
|
||||||
(or branch (magit-rev-parse "HEAD"))
|
|
||||||
t)
|
|
||||||
(apply #'magit-insert-heading strings)
|
|
||||||
(when (magit-buffer-margin-p)
|
|
||||||
(magit-refs--format-margin branch))
|
|
||||||
(magit-refs--insert-cherry-commits branch))))
|
|
||||||
(insert ?\n)
|
|
||||||
(magit-make-margin-overlay nil t)))
|
|
||||||
|
|
||||||
(defun magit-refs--format-local-branches ()
|
|
||||||
(let ((lines (-keep 'magit-refs--format-local-branch
|
|
||||||
(magit-git-lines
|
|
||||||
"for-each-ref"
|
|
||||||
(concat "--format=\
|
|
||||||
%(HEAD)%00%(refname:short)%00%(refname)%00\
|
|
||||||
%(upstream:short)%00%(upstream)%00%(upstream:track)%00"
|
|
||||||
(if magit-refs-show-push-remote "\
|
|
||||||
%(push:remotename)%00%(push)%00%(push:track)%00%(subject)"
|
|
||||||
"%00%00%00%(subject)"))
|
|
||||||
"refs/heads"
|
|
||||||
magit-buffer-arguments))))
|
|
||||||
(unless (magit-get-current-branch)
|
|
||||||
(push (magit-refs--format-local-branch
|
|
||||||
(concat "*\0\0\0\0\0\0\0\0" (magit-rev-format "%s")))
|
|
||||||
lines))
|
|
||||||
(setq-local magit-refs-primary-column-width
|
|
||||||
(let ((def (default-value 'magit-refs-primary-column-width)))
|
|
||||||
(if (atom def)
|
|
||||||
def
|
|
||||||
(pcase-let ((`(,min . ,max) def))
|
|
||||||
(min max (apply #'max min (mapcar #'car lines)))))))
|
|
||||||
(mapcar (pcase-lambda (`(,_ ,branch ,focus ,branch-desc ,u:ahead ,p:ahead
|
|
||||||
,u:behind ,upstream ,p:behind ,push ,msg))
|
|
||||||
(list branch focus branch-desc u:ahead p:ahead
|
|
||||||
(make-string (max 1 (- magit-refs-primary-column-width
|
|
||||||
(length (concat branch-desc
|
|
||||||
u:ahead
|
|
||||||
p:ahead
|
|
||||||
u:behind))))
|
|
||||||
?\s)
|
|
||||||
u:behind upstream p:behind push
|
|
||||||
msg))
|
|
||||||
lines)))
|
|
||||||
|
|
||||||
(defun magit-refs--format-local-branch (line)
|
|
||||||
(pcase-let ((`(,head ,branch ,ref ,upstream ,u:ref ,u:track
|
|
||||||
,push ,p:ref ,p:track ,msg)
|
|
||||||
(-replace "" nil (split-string line "\0"))))
|
|
||||||
(when (or (not branch)
|
|
||||||
(magit-refs--insert-refname-p branch))
|
|
||||||
(let* ((headp (equal head "*"))
|
|
||||||
(pushp (and push
|
|
||||||
magit-refs-show-push-remote
|
|
||||||
(magit-rev-verify p:ref)
|
|
||||||
(not (equal p:ref u:ref))))
|
|
||||||
(branch-desc
|
|
||||||
(if branch
|
|
||||||
(magit-refs--propertize-branch
|
|
||||||
branch ref (and headp 'magit-branch-current))
|
|
||||||
(magit--propertize-face "(detached)"
|
|
||||||
'font-lock-warning-face)))
|
|
||||||
(u:ahead (and u:track
|
|
||||||
(string-match "ahead \\([0-9]+\\)" u:track)
|
|
||||||
(magit--propertize-face
|
|
||||||
(concat (and magit-refs-pad-commit-counts " ")
|
|
||||||
(match-string 1 u:track)
|
|
||||||
">")
|
|
||||||
'magit-dimmed)))
|
|
||||||
(u:behind (and u:track
|
|
||||||
(string-match "behind \\([0-9]+\\)" u:track)
|
|
||||||
(magit--propertize-face
|
|
||||||
(concat "<"
|
|
||||||
(match-string 1 u:track)
|
|
||||||
(and magit-refs-pad-commit-counts " "))
|
|
||||||
'magit-dimmed)))
|
|
||||||
(p:ahead (and pushp p:track
|
|
||||||
(string-match "ahead \\([0-9]+\\)" p:track)
|
|
||||||
(magit--propertize-face
|
|
||||||
(concat (match-string 1 p:track)
|
|
||||||
">"
|
|
||||||
(and magit-refs-pad-commit-counts " "))
|
|
||||||
'magit-branch-remote)))
|
|
||||||
(p:behind (and pushp p:track
|
|
||||||
(string-match "behind \\([0-9]+\\)" p:track)
|
|
||||||
(magit--propertize-face
|
|
||||||
(concat "<"
|
|
||||||
(match-string 1 p:track)
|
|
||||||
(and magit-refs-pad-commit-counts " "))
|
|
||||||
'magit-dimmed))))
|
|
||||||
(list (1+ (length (concat branch-desc u:ahead p:ahead u:behind)))
|
|
||||||
branch
|
|
||||||
(magit-refs--format-focus-column branch headp)
|
|
||||||
branch-desc u:ahead p:ahead u:behind
|
|
||||||
(and upstream
|
|
||||||
(concat (if (equal u:track "[gone]")
|
|
||||||
(magit--propertize-face upstream 'error)
|
|
||||||
(magit-refs--propertize-branch upstream u:ref))
|
|
||||||
" "))
|
|
||||||
(and pushp
|
|
||||||
(concat p:behind
|
|
||||||
(magit--propertize-face
|
|
||||||
push 'magit-branch-remote)
|
|
||||||
" "))
|
|
||||||
(and msg (magit-log-propertize-keywords nil msg)))))))
|
|
||||||
|
|
||||||
(defun magit-refs--format-focus-column (ref &optional type)
|
|
||||||
(let ((focus magit-buffer-upstream)
|
|
||||||
(width (if magit-refs-show-commit-count
|
|
||||||
magit-refs-focus-column-width
|
|
||||||
1)))
|
|
||||||
(format
|
|
||||||
(format "%%%ss " width)
|
|
||||||
(cond ((or (equal ref focus)
|
|
||||||
(and (eq type t)
|
|
||||||
(equal focus "HEAD")))
|
|
||||||
(magit--propertize-face (concat (if (equal focus "HEAD") "@" "*")
|
|
||||||
(make-string (1- width) ?\s))
|
|
||||||
'magit-section-heading))
|
|
||||||
((if (eq type 'tag)
|
|
||||||
(eq magit-refs-show-commit-count 'all)
|
|
||||||
magit-refs-show-commit-count)
|
|
||||||
(pcase-let ((`(,behind ,ahead)
|
|
||||||
(magit-rev-diff-count magit-buffer-upstream ref)))
|
|
||||||
(magit--propertize-face
|
|
||||||
(cond ((> ahead 0) (concat "<" (number-to-string ahead)))
|
|
||||||
((> behind 0) (concat (number-to-string behind) ">"))
|
|
||||||
(t "="))
|
|
||||||
'magit-dimmed)))
|
|
||||||
(t "")))))
|
|
||||||
|
|
||||||
(defun magit-refs--propertize-branch (branch ref &optional head-face)
|
|
||||||
(let ((face (cdr (cl-find-if (pcase-lambda (`(,re . ,_))
|
|
||||||
(string-match-p re ref))
|
|
||||||
magit-ref-namespaces))))
|
|
||||||
(magit--propertize-face
|
|
||||||
branch (if head-face (list face head-face) face))))
|
|
||||||
|
|
||||||
(defun magit-refs--insert-refname-p (refname)
|
|
||||||
(--if-let (-first (pcase-lambda (`(,key . ,_))
|
|
||||||
(if (functionp key)
|
|
||||||
(funcall key refname)
|
|
||||||
(string-match-p key refname)))
|
|
||||||
magit-refs-filter-alist)
|
|
||||||
(cdr it)
|
|
||||||
t))
|
|
||||||
|
|
||||||
(defun magit-refs--insert-cherry-commits (ref)
|
|
||||||
(magit-insert-section-body
|
|
||||||
(let ((start (point))
|
|
||||||
(magit-insert-section--current nil))
|
|
||||||
(magit-git-wash (apply-partially 'magit-log-wash-log 'cherry)
|
|
||||||
"cherry" "-v" (magit-abbrev-arg) magit-buffer-upstream ref)
|
|
||||||
(if (= (point) start)
|
|
||||||
(message "No cherries for %s" ref)
|
|
||||||
(magit-make-margin-overlay nil t)))))
|
|
||||||
|
|
||||||
(defun magit-refs--format-margin (commit)
|
|
||||||
(save-excursion
|
|
||||||
(goto-char (line-beginning-position 0))
|
|
||||||
(let ((line (magit-rev-format "%ct%cN" commit)))
|
|
||||||
(magit-log-format-margin commit
|
|
||||||
(substring line 10)
|
|
||||||
(substring line 0 10)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-refs)
|
|
||||||
;;; magit-refs.el ends here
|
|
Binary file not shown.
|
@ -1,341 +0,0 @@
|
||||||
;;; magit-remote.el --- transfer Git commits -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements remote commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-remote-add-set-remote.pushDefault 'ask-if-unset
|
|
||||||
"Whether to set the value of `remote.pushDefault' after adding a remote.
|
|
||||||
|
|
||||||
If `ask', then always ask. If `ask-if-unset', then ask, but only
|
|
||||||
if the variable isn't set already. If nil, then don't ever set.
|
|
||||||
If the value is a string, then set without asking, provided that
|
|
||||||
the name of the added remote is equal to that string and the
|
|
||||||
variable isn't already set."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type '(choice (const :tag "ask if unset" ask-if-unset)
|
|
||||||
(const :tag "always ask" ask)
|
|
||||||
(string :tag "set if named")
|
|
||||||
(const :tag "don't set")))
|
|
||||||
|
|
||||||
(defcustom magit-remote-direct-configure t
|
|
||||||
"Whether the command `magit-remote' shows Git variables.
|
|
||||||
When set to nil, no variables are displayed by this transient
|
|
||||||
command, instead the sub-transient `magit-remote-configure'
|
|
||||||
has to be used to view and change remote related variables."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-prefer-push-default nil
|
|
||||||
"Whether to prefer `remote.pushDefault' over per-branch variables."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-remote "magit-remote" nil t)
|
|
||||||
(define-transient-command magit-remote (remote)
|
|
||||||
"Add, configure or remove a remote."
|
|
||||||
:man-page "git-remote"
|
|
||||||
:value '("-f")
|
|
||||||
["Variables"
|
|
||||||
:if (lambda ()
|
|
||||||
(and magit-remote-direct-configure
|
|
||||||
(oref transient--prefix scope)))
|
|
||||||
("u" magit-remote.<remote>.url)
|
|
||||||
("U" magit-remote.<remote>.fetch)
|
|
||||||
("s" magit-remote.<remote>.pushurl)
|
|
||||||
("S" magit-remote.<remote>.push)
|
|
||||||
("O" magit-remote.<remote>.tagopt)]
|
|
||||||
["Arguments for add"
|
|
||||||
("-f" "Fetch after add" "-f")]
|
|
||||||
["Actions"
|
|
||||||
[("a" "Add" magit-remote-add)
|
|
||||||
("r" "Rename" magit-remote-rename)
|
|
||||||
("k" "Remove" magit-remote-remove)]
|
|
||||||
[("C" "Configure..." magit-remote-configure)
|
|
||||||
("p" "Prune stale branches" magit-remote-prune)
|
|
||||||
("P" "Prune stale refspecs" magit-remote-prune-refspecs)]]
|
|
||||||
(interactive (list (magit-get-current-remote)))
|
|
||||||
(transient-setup 'magit-remote nil nil :scope remote))
|
|
||||||
|
|
||||||
(defun magit-read-url (prompt &optional initial-input)
|
|
||||||
(let ((url (magit-read-string-ns prompt initial-input)))
|
|
||||||
(if (string-prefix-p "~" url)
|
|
||||||
(expand-file-name url)
|
|
||||||
url)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-add (remote url &optional args)
|
|
||||||
"Add a remote named REMOTE and fetch it."
|
|
||||||
(interactive (list (magit-read-string-ns "Remote name")
|
|
||||||
(magit-read-url "Remote url")
|
|
||||||
(transient-args 'magit-remote)))
|
|
||||||
(if (pcase (list magit-remote-add-set-remote.pushDefault
|
|
||||||
(magit-get "remote.pushDefault"))
|
|
||||||
(`(,(pred stringp) ,_) t)
|
|
||||||
((or `(ask ,_) `(ask-if-unset nil))
|
|
||||||
(y-or-n-p (format "Set `remote.pushDefault' to \"%s\"? " remote))))
|
|
||||||
(progn (magit-call-git "remote" "add" args remote url)
|
|
||||||
(setf (magit-get "remote.pushDefault") remote)
|
|
||||||
(magit-refresh))
|
|
||||||
(magit-run-git-async "remote" "add" args remote url)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-rename (old new)
|
|
||||||
"Rename the remote named OLD to NEW."
|
|
||||||
(interactive
|
|
||||||
(let ((remote (magit-read-remote "Rename remote")))
|
|
||||||
(list remote (magit-read-string-ns (format "Rename %s to" remote)))))
|
|
||||||
(unless (string= old new)
|
|
||||||
(magit-call-git "remote" "rename" old new)
|
|
||||||
(magit-remote--cleanup-push-variables old new)
|
|
||||||
(magit-refresh)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-remove (remote)
|
|
||||||
"Delete the remote named REMOTE."
|
|
||||||
(interactive (list (magit-read-remote "Delete remote")))
|
|
||||||
(magit-call-git "remote" "rm" remote)
|
|
||||||
(magit-remote--cleanup-push-variables remote)
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
(defun magit-remote--cleanup-push-variables (remote &optional new-name)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(when (equal (magit-get "remote.pushDefault") remote)
|
|
||||||
(magit-set new-name "remote.pushDefault"))
|
|
||||||
(dolist (var (magit-git-lines "config" "--name-only"
|
|
||||||
"--get-regexp" "^branch\.[^.]*\.pushRemote"
|
|
||||||
(format "^%s$" remote)))
|
|
||||||
(magit-call-git "config" (and (not new-name) "--unset") var new-name))))
|
|
||||||
|
|
||||||
(defconst magit--refspec-re "\\`\\(\\+\\)?\\([^:]+\\):\\(.*\\)\\'")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-prune (remote)
|
|
||||||
"Remove stale remote-tracking branches for REMOTE."
|
|
||||||
(interactive (list (magit-read-remote "Prune stale branches of remote")))
|
|
||||||
(magit-run-git-async "remote" "prune" remote))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-prune-refspecs (remote)
|
|
||||||
"Remove stale refspecs for REMOTE.
|
|
||||||
|
|
||||||
A refspec is stale if there no longer exists at least one branch
|
|
||||||
on the remote that would be fetched due to that refspec. A stale
|
|
||||||
refspec is problematic because its existence causes Git to refuse
|
|
||||||
to fetch according to the remaining non-stale refspecs.
|
|
||||||
|
|
||||||
If only stale refspecs remain, then offer to either delete the
|
|
||||||
remote or to replace the stale refspecs with the default refspec.
|
|
||||||
|
|
||||||
Also remove the remote-tracking branches that were created due to
|
|
||||||
the now stale refspecs. Other stale branches are not removed."
|
|
||||||
(interactive (list (magit-read-remote "Prune refspecs of remote")))
|
|
||||||
(let* ((tracking-refs (magit-list-remote-branches remote))
|
|
||||||
(remote-refs (magit-remote-list-refs remote))
|
|
||||||
(variable (format "remote.%s.fetch" remote))
|
|
||||||
(refspecs (magit-get-all variable))
|
|
||||||
stale)
|
|
||||||
(dolist (refspec refspecs)
|
|
||||||
(when (string-match magit--refspec-re refspec)
|
|
||||||
(let ((theirs (match-string 2 refspec))
|
|
||||||
(ours (match-string 3 refspec)))
|
|
||||||
(unless (if (string-match "\\*" theirs)
|
|
||||||
(let ((re (replace-match ".*" t t theirs)))
|
|
||||||
(--some (string-match-p re it) remote-refs))
|
|
||||||
(member theirs remote-refs))
|
|
||||||
(push (cons refspec
|
|
||||||
(if (string-match "\\*" ours)
|
|
||||||
(let ((re (replace-match ".*" t t ours)))
|
|
||||||
(--filter (string-match-p re it) tracking-refs))
|
|
||||||
(list (car (member ours tracking-refs)))))
|
|
||||||
stale)))))
|
|
||||||
(if (not stale)
|
|
||||||
(message "No stale refspecs for remote %S" remote)
|
|
||||||
(if (= (length stale)
|
|
||||||
(length refspecs))
|
|
||||||
(magit-read-char-case
|
|
||||||
(format "All of %s's refspecs are stale. " remote) nil
|
|
||||||
(?s "replace with [d]efault refspec"
|
|
||||||
(magit-set-all
|
|
||||||
(list (format "+refs/heads/*:refs/remotes/%s/*" remote))
|
|
||||||
variable))
|
|
||||||
(?r "[r]emove remote"
|
|
||||||
(magit-call-git "remote" "rm" remote))
|
|
||||||
(?a "or [a]abort"
|
|
||||||
(user-error "Abort")))
|
|
||||||
(if (if (= (length stale) 1)
|
|
||||||
(pcase-let ((`(,refspec . ,refs) (car stale)))
|
|
||||||
(magit-confirm 'prune-stale-refspecs
|
|
||||||
(format "Prune stale refspec %s and branch %%s" refspec)
|
|
||||||
(format "Prune stale refspec %s and %%i branches" refspec)
|
|
||||||
nil refs))
|
|
||||||
(magit-confirm 'prune-stale-refspecs nil
|
|
||||||
(format "Prune %%i stale refspecs and %i branches"
|
|
||||||
(length (cl-mapcan (lambda (s) (copy-sequence (cdr s)))
|
|
||||||
stale)))
|
|
||||||
nil
|
|
||||||
(mapcar (pcase-lambda (`(,refspec . ,refs))
|
|
||||||
(concat refspec "\n"
|
|
||||||
(mapconcat (lambda (b) (concat " " b))
|
|
||||||
refs "\n")))
|
|
||||||
stale)))
|
|
||||||
(pcase-dolist (`(,refspec . ,refs) stale)
|
|
||||||
(magit-call-git "config" "--unset" variable
|
|
||||||
(regexp-quote refspec))
|
|
||||||
(magit--log-action
|
|
||||||
(lambda (refs)
|
|
||||||
(format "Deleting %i branches" (length refs)))
|
|
||||||
(lambda (ref)
|
|
||||||
(format "Deleting branch %s (was %s)" ref
|
|
||||||
(magit-rev-parse "--short" ref)))
|
|
||||||
refs)
|
|
||||||
(dolist (ref refs)
|
|
||||||
(magit-call-git "update-ref" "-d" ref)))
|
|
||||||
(user-error "Abort")))
|
|
||||||
(magit-refresh))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-set-head (remote &optional branch)
|
|
||||||
"Set the local representation of REMOTE's default branch.
|
|
||||||
Query REMOTE and set the symbolic-ref refs/remotes/<remote>/HEAD
|
|
||||||
accordingly. With a prefix argument query for the branch to be
|
|
||||||
used, which allows you to select an incorrect value if you fancy
|
|
||||||
doing that."
|
|
||||||
(interactive
|
|
||||||
(let ((remote (magit-read-remote "Set HEAD for remote")))
|
|
||||||
(list remote
|
|
||||||
(and current-prefix-arg
|
|
||||||
(magit-read-remote-branch (format "Set %s/HEAD to" remote)
|
|
||||||
remote nil nil t)))))
|
|
||||||
(magit-run-git "remote" "set-head" remote (or branch "--auto")))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-remote-unset-head (remote)
|
|
||||||
"Unset the local representation of REMOTE's default branch.
|
|
||||||
Delete the symbolic-ref \"refs/remotes/<remote>/HEAD\"."
|
|
||||||
(interactive (list (magit-read-remote "Unset HEAD for remote")))
|
|
||||||
(magit-run-git "remote" "set-head" remote "--delete"))
|
|
||||||
|
|
||||||
;;; Configure
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-remote-configure "magit-remote" nil t)
|
|
||||||
(define-transient-command magit-remote-configure (remote)
|
|
||||||
"Configure a remote."
|
|
||||||
:man-page "git-remote"
|
|
||||||
[:description
|
|
||||||
(lambda ()
|
|
||||||
(concat
|
|
||||||
(propertize "Configure " 'face 'transient-heading)
|
|
||||||
(propertize (oref transient--prefix scope) 'face 'magit-branch-remote)))
|
|
||||||
("u" magit-remote.<remote>.url)
|
|
||||||
("U" magit-remote.<remote>.fetch)
|
|
||||||
("s" magit-remote.<remote>.pushurl)
|
|
||||||
("S" magit-remote.<remote>.push)
|
|
||||||
("O" magit-remote.<remote>.tagopt)]
|
|
||||||
(interactive
|
|
||||||
(list (or (and (not current-prefix-arg)
|
|
||||||
(not (and magit-remote-direct-configure
|
|
||||||
(eq current-transient-command 'magit-remote)))
|
|
||||||
(magit-get-current-remote))
|
|
||||||
(magit--read-remote-scope))))
|
|
||||||
(transient-setup 'magit-remote-configure nil nil :scope remote))
|
|
||||||
|
|
||||||
(defun magit--read-remote-scope (&optional obj)
|
|
||||||
(magit-read-remote
|
|
||||||
(if obj
|
|
||||||
(format "Set %s for remote"
|
|
||||||
(format (oref obj variable) "<name>"))
|
|
||||||
"Configure remote")))
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.<remote>.url ()
|
|
||||||
:class 'magit--git-variable:urls
|
|
||||||
:scope 'magit--read-remote-scope
|
|
||||||
:variable "remote.%s.url"
|
|
||||||
:multi-value t
|
|
||||||
:history-key 'magit-remote.<remote>.*url)
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.<remote>.fetch ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:scope 'magit--read-remote-scope
|
|
||||||
:variable "remote.%s.fetch"
|
|
||||||
:multi-value t)
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.<remote>.pushurl ()
|
|
||||||
:class 'magit--git-variable:urls
|
|
||||||
:scope 'magit--read-remote-scope
|
|
||||||
:variable "remote.%s.pushurl"
|
|
||||||
:multi-value t
|
|
||||||
:history-key 'magit-remote.<remote>.*url
|
|
||||||
:seturl-arg "--push")
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.<remote>.push ()
|
|
||||||
:class 'magit--git-variable
|
|
||||||
:scope 'magit--read-remote-scope
|
|
||||||
:variable "remote.%s.push")
|
|
||||||
|
|
||||||
(define-infix-command magit-remote.<remote>.tagopt ()
|
|
||||||
:class 'magit--git-variable:choices
|
|
||||||
:scope 'magit--read-remote-scope
|
|
||||||
:variable "remote.%s.tagOpt"
|
|
||||||
:choices '("--no-tags" "--tags"))
|
|
||||||
|
|
||||||
;;; Transfer Utilities
|
|
||||||
|
|
||||||
(defun magit--push-remote-variable (&optional branch short)
|
|
||||||
(unless branch
|
|
||||||
(setq branch (magit-get-current-branch)))
|
|
||||||
(magit--propertize-face
|
|
||||||
(if (or (not branch) magit-prefer-push-default)
|
|
||||||
(if short "pushDefault" "remote.pushDefault")
|
|
||||||
(if short "pushRemote" (format "branch.%s.pushRemote" branch)))
|
|
||||||
'bold))
|
|
||||||
|
|
||||||
(defun magit--select-push-remote (prompt-suffix)
|
|
||||||
(let* ((branch (or (magit-get-current-branch)
|
|
||||||
(user-error "No branch is checked out")))
|
|
||||||
(remote (magit-get-push-remote branch)))
|
|
||||||
(when (or current-prefix-arg
|
|
||||||
(not remote)
|
|
||||||
(not (member remote (magit-list-remotes))))
|
|
||||||
(setq remote
|
|
||||||
(magit-read-remote (format "Set %s and %s"
|
|
||||||
(magit--push-remote-variable)
|
|
||||||
prompt-suffix)))
|
|
||||||
(setf (magit-get (magit--push-remote-variable branch)) remote))
|
|
||||||
(list branch remote)))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-remote)
|
|
||||||
;;; magit-remote.el ends here
|
|
Binary file not shown.
|
@ -1,339 +0,0 @@
|
||||||
;;; magit-repos.el --- listing repositories -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for listing repositories. This
|
|
||||||
;; includes getting a Lisp list of known repositories as well as a
|
|
||||||
;; mode for listing repositories in a buffer.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit-core)
|
|
||||||
|
|
||||||
(declare-function magit-status-setup-buffer "magit-status" (directory))
|
|
||||||
|
|
||||||
(defvar x-stretch-cursor)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-repository-directories nil
|
|
||||||
"List of directories that are or contain Git repositories.
|
|
||||||
|
|
||||||
Each element has the form (DIRECTORY . DEPTH). DIRECTORY has
|
|
||||||
to be a directory or a directory file-name, a string. DEPTH,
|
|
||||||
an integer, specifies the maximum depth to look for Git
|
|
||||||
repositories. If it is 0, then only add DIRECTORY itself.
|
|
||||||
|
|
||||||
This option controls which repositories are being listed by
|
|
||||||
`magit-list-repositories'. It also affects `magit-status'
|
|
||||||
\(which see) in potentially surprising ways."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-essentials
|
|
||||||
:type '(repeat (cons directory (integer :tag "Depth"))))
|
|
||||||
|
|
||||||
(defgroup magit-repolist nil
|
|
||||||
"List repositories in a buffer."
|
|
||||||
:link '(info-link "(magit)Repository List")
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
(defcustom magit-repolist-mode-hook '(hl-line-mode)
|
|
||||||
"Hook run after entering Magit-Repolist mode."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-repolist
|
|
||||||
:type 'hook
|
|
||||||
:get 'magit-hook-custom-get
|
|
||||||
:options '(hl-line-mode))
|
|
||||||
|
|
||||||
(defcustom magit-repolist-columns
|
|
||||||
'(("Name" 25 magit-repolist-column-ident nil)
|
|
||||||
("Version" 25 magit-repolist-column-version nil)
|
|
||||||
("B<U" 3 magit-repolist-column-unpulled-from-upstream
|
|
||||||
((:right-align t)
|
|
||||||
(:help-echo "Upstream changes not in branch")))
|
|
||||||
("B>U" 3 magit-repolist-column-unpushed-to-upstream
|
|
||||||
((:right-align t)
|
|
||||||
(:help-echo "Local changes not in upstream")))
|
|
||||||
("Path" 99 magit-repolist-column-path nil))
|
|
||||||
"List of columns displayed by `magit-list-repositories'.
|
|
||||||
|
|
||||||
Each element has the form (HEADER WIDTH FORMAT PROPS).
|
|
||||||
|
|
||||||
HEADER is the string displayed in the header. WIDTH is the width
|
|
||||||
of the column. FORMAT is a function that is called with one
|
|
||||||
argument, the repository identification (usually its basename),
|
|
||||||
and with `default-directory' bound to the toplevel of its working
|
|
||||||
tree. It has to return a string to be inserted or nil. PROPS is
|
|
||||||
an alist that supports the keys `:right-align' and `:pad-right'.
|
|
||||||
Some entries also use `:help-echo', but `tabulated-list' does not
|
|
||||||
actually support that yet."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-repolist
|
|
||||||
:type `(repeat (list :tag "Column"
|
|
||||||
(string :tag "Header Label")
|
|
||||||
(integer :tag "Column Width")
|
|
||||||
(function :tag "Inserter Function")
|
|
||||||
(repeat :tag "Properties"
|
|
||||||
(list (choice :tag "Property"
|
|
||||||
(const :right-align)
|
|
||||||
(const :pad-right)
|
|
||||||
(symbol))
|
|
||||||
(sexp :tag "Value"))))))
|
|
||||||
|
|
||||||
(defcustom magit-repolist-column-flag-alist
|
|
||||||
'((magit-untracked-files . "N")
|
|
||||||
(magit-unstaged-files . "U")
|
|
||||||
(magit-staged-files . "S"))
|
|
||||||
"Association list of predicates and flags for `magit-repolist-column-flag'.
|
|
||||||
|
|
||||||
Each element is of the form (FUNCTION . FLAG). Each FUNCTION is
|
|
||||||
called with no arguments, with `default-directory' bound to the
|
|
||||||
top level of a repository working tree, until one of them returns
|
|
||||||
a non-nil value. FLAG corresponding to that function is returned
|
|
||||||
as the value of `magit-repolist-column-flag'."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-repolist
|
|
||||||
:type '(alist :key-type (function :tag "Predicate Function")
|
|
||||||
:value-type (string :tag "Flag")))
|
|
||||||
|
|
||||||
;;; List Repositories
|
|
||||||
;;;; Command
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-list-repositories ()
|
|
||||||
"Display a list of repositories.
|
|
||||||
|
|
||||||
Use the options `magit-repository-directories' to control which
|
|
||||||
repositories are displayed."
|
|
||||||
(interactive)
|
|
||||||
(if magit-repository-directories
|
|
||||||
(with-current-buffer (get-buffer-create "*Magit Repositories*")
|
|
||||||
(magit-repolist-mode)
|
|
||||||
(magit-repolist-refresh)
|
|
||||||
(tabulated-list-print)
|
|
||||||
(switch-to-buffer (current-buffer)))
|
|
||||||
(message "You need to customize `magit-repository-directories' %s"
|
|
||||||
"before you can list repositories")))
|
|
||||||
|
|
||||||
;;;; Mode
|
|
||||||
|
|
||||||
(defvar magit-repolist-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map tabulated-list-mode-map)
|
|
||||||
(define-key map (if (featurep 'jkl) [return] (kbd "C-m"))
|
|
||||||
'magit-repolist-status)
|
|
||||||
map)
|
|
||||||
"Local keymap for Magit-Repolist mode buffers.")
|
|
||||||
|
|
||||||
(defun magit-repolist-status (&optional _button)
|
|
||||||
"Show the status for the repository at point."
|
|
||||||
(interactive)
|
|
||||||
(--if-let (tabulated-list-get-id)
|
|
||||||
(magit-status-setup-buffer (expand-file-name it))
|
|
||||||
(user-error "There is no repository at point")))
|
|
||||||
|
|
||||||
(define-derived-mode magit-repolist-mode tabulated-list-mode "Repos"
|
|
||||||
"Major mode for browsing a list of Git repositories."
|
|
||||||
(setq-local x-stretch-cursor nil)
|
|
||||||
(setq tabulated-list-padding 0)
|
|
||||||
(setq tabulated-list-sort-key (cons "Path" nil))
|
|
||||||
(setq tabulated-list-format
|
|
||||||
(vconcat (mapcar (pcase-lambda (`(,title ,width ,_fn ,props))
|
|
||||||
(nconc (list title width t)
|
|
||||||
(-flatten props)))
|
|
||||||
magit-repolist-columns)))
|
|
||||||
(tabulated-list-init-header)
|
|
||||||
(add-hook 'tabulated-list-revert-hook 'magit-repolist-refresh nil t)
|
|
||||||
(setq imenu-prev-index-position-function
|
|
||||||
'magit-imenu--repolist-prev-index-position-function)
|
|
||||||
(setq imenu-extract-index-name-function
|
|
||||||
'magit-imenu--repolist-extract-index-name-function))
|
|
||||||
|
|
||||||
(defun magit-repolist-refresh ()
|
|
||||||
(setq tabulated-list-entries
|
|
||||||
(mapcar (pcase-lambda (`(,id . ,path))
|
|
||||||
(let ((default-directory path))
|
|
||||||
(list path
|
|
||||||
(vconcat (--map (or (funcall (nth 2 it) id) "")
|
|
||||||
magit-repolist-columns)))))
|
|
||||||
(magit-list-repos-uniquify
|
|
||||||
(--map (cons (file-name-nondirectory (directory-file-name it))
|
|
||||||
it)
|
|
||||||
(magit-list-repos))))))
|
|
||||||
|
|
||||||
;;;; Columns
|
|
||||||
|
|
||||||
(defun magit-repolist-column-ident (id)
|
|
||||||
"Insert the identification of the repository.
|
|
||||||
Usually this is just its basename."
|
|
||||||
id)
|
|
||||||
|
|
||||||
(defun magit-repolist-column-path (_id)
|
|
||||||
"Insert the absolute path of the repository."
|
|
||||||
(abbreviate-file-name default-directory))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-version (_id)
|
|
||||||
"Insert a description of the repository's `HEAD' revision."
|
|
||||||
(when-let ((v (or (magit-git-string "describe" "--tags" "--dirty")
|
|
||||||
;; If there are no tags, use the date in MELPA format.
|
|
||||||
(magit-git-string "show" "--no-patch" "--format=%cd-g%h"
|
|
||||||
"--date=format:%Y%m%d.%H%M"))))
|
|
||||||
(save-match-data
|
|
||||||
(when (string-match "-dirty\\'" v)
|
|
||||||
(magit--put-face (1+ (match-beginning 0)) (length v) 'error v))
|
|
||||||
(if (and v (string-match "\\`[0-9]" v))
|
|
||||||
(concat " " v)
|
|
||||||
v))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-branch (_id)
|
|
||||||
"Insert the current branch."
|
|
||||||
(magit-get-current-branch))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-upstream (_id)
|
|
||||||
"Insert the upstream branch of the current branch."
|
|
||||||
(magit-get-upstream-branch))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-flag (_id)
|
|
||||||
"Insert a flag as specified by `magit-repolist-column-flag-alist'.
|
|
||||||
|
|
||||||
By default this indicates whether there are uncommitted changes.
|
|
||||||
- N if there is at least one untracked file.
|
|
||||||
- U if there is at least one unstaged file.
|
|
||||||
- S if there is at least one staged file.
|
|
||||||
Only one letter is shown, the first that applies."
|
|
||||||
(-some (pcase-lambda (`(,fun . ,flag))
|
|
||||||
(and (funcall fun) flag))
|
|
||||||
magit-repolist-column-flag-alist))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-unpulled-from-upstream (_id)
|
|
||||||
"Insert number of upstream commits not in the current branch."
|
|
||||||
(--when-let (magit-get-upstream-branch)
|
|
||||||
(let ((n (cadr (magit-rev-diff-count "HEAD" it))))
|
|
||||||
(magit--propertize-face
|
|
||||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-unpulled-from-pushremote (_id)
|
|
||||||
"Insert number of commits in the push branch but not the current branch."
|
|
||||||
(--when-let (magit-get-push-branch nil t)
|
|
||||||
(let ((n (cadr (magit-rev-diff-count "HEAD" it))))
|
|
||||||
(magit--propertize-face
|
|
||||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-unpushed-to-upstream (_id)
|
|
||||||
"Insert number of commits in the current branch but not its upstream."
|
|
||||||
(--when-let (magit-get-upstream-branch)
|
|
||||||
(let ((n (car (magit-rev-diff-count "HEAD" it))))
|
|
||||||
(magit--propertize-face
|
|
||||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-unpushed-to-pushremote (_id)
|
|
||||||
"Insert number of commits in the current branch but not its push branch."
|
|
||||||
(--when-let (magit-get-push-branch nil t)
|
|
||||||
(let ((n (car (magit-rev-diff-count "HEAD" it))))
|
|
||||||
(magit--propertize-face
|
|
||||||
(number-to-string n) (if (> n 0) 'bold 'shadow)))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-branches (_id)
|
|
||||||
"Insert number of branches."
|
|
||||||
(let ((n (length (magit-list-local-branches))))
|
|
||||||
(magit--propertize-face (number-to-string n) (if (> n 1) 'bold 'shadow))))
|
|
||||||
|
|
||||||
(defun magit-repolist-column-stashes (_id)
|
|
||||||
"Insert number of stashes."
|
|
||||||
(let ((n (length (magit-list-stashes))))
|
|
||||||
(magit--propertize-face (number-to-string n) (if (> n 0) 'bold 'shadow))))
|
|
||||||
|
|
||||||
;;; Read Repository
|
|
||||||
|
|
||||||
(defun magit-read-repository (&optional read-directory-name)
|
|
||||||
"Read a Git repository in the minibuffer, with completion.
|
|
||||||
|
|
||||||
The completion choices are the basenames of top-levels of
|
|
||||||
repositories found in the directories specified by option
|
|
||||||
`magit-repository-directories'. In case of name conflicts
|
|
||||||
the basenames are prefixed with the name of the respective
|
|
||||||
parent directories. The returned value is the actual path
|
|
||||||
to the selected repository.
|
|
||||||
|
|
||||||
If READ-DIRECTORY-NAME is non-nil or no repositories can be
|
|
||||||
found based on the value of `magit-repository-directories',
|
|
||||||
then read an arbitrary directory using `read-directory-name'
|
|
||||||
instead."
|
|
||||||
(if-let ((repos (and (not read-directory-name)
|
|
||||||
magit-repository-directories
|
|
||||||
(magit-repos-alist))))
|
|
||||||
(let ((reply (magit-completing-read "Git repository" repos)))
|
|
||||||
(file-name-as-directory
|
|
||||||
(or (cdr (assoc reply repos))
|
|
||||||
(if (file-directory-p reply)
|
|
||||||
(expand-file-name reply)
|
|
||||||
(user-error "Not a repository or a directory: %s" reply)))))
|
|
||||||
(file-name-as-directory
|
|
||||||
(read-directory-name "Git repository: "
|
|
||||||
(or (magit-toplevel) default-directory)))))
|
|
||||||
|
|
||||||
(defun magit-list-repos ()
|
|
||||||
(cl-mapcan (pcase-lambda (`(,dir . ,depth))
|
|
||||||
(magit-list-repos-1 dir depth))
|
|
||||||
magit-repository-directories))
|
|
||||||
|
|
||||||
(defun magit-list-repos-1 (directory depth)
|
|
||||||
(cond ((file-readable-p (expand-file-name ".git" directory))
|
|
||||||
(list (file-name-as-directory directory)))
|
|
||||||
((and (> depth 0) (magit-file-accessible-directory-p directory))
|
|
||||||
(--mapcat (and (file-directory-p it)
|
|
||||||
(magit-list-repos-1 it (1- depth)))
|
|
||||||
(directory-files directory t
|
|
||||||
directory-files-no-dot-files-regexp t)))))
|
|
||||||
|
|
||||||
(defun magit-list-repos-uniquify (alist)
|
|
||||||
(let (result (dict (make-hash-table :test 'equal)))
|
|
||||||
(dolist (a (delete-dups alist))
|
|
||||||
(puthash (car a) (cons (cdr a) (gethash (car a) dict)) dict))
|
|
||||||
(maphash
|
|
||||||
(lambda (key value)
|
|
||||||
(if (= (length value) 1)
|
|
||||||
(push (cons key (car value)) result)
|
|
||||||
(setq result
|
|
||||||
(append result
|
|
||||||
(magit-list-repos-uniquify
|
|
||||||
(--map (cons (concat
|
|
||||||
key "\\"
|
|
||||||
(file-name-nondirectory
|
|
||||||
(directory-file-name
|
|
||||||
(substring it 0 (- (1+ (length key)))))))
|
|
||||||
it)
|
|
||||||
value))))))
|
|
||||||
dict)
|
|
||||||
result))
|
|
||||||
|
|
||||||
(defun magit-repos-alist ()
|
|
||||||
(magit-list-repos-uniquify
|
|
||||||
(--map (cons (file-name-nondirectory (directory-file-name it)) it)
|
|
||||||
(magit-list-repos))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-repos)
|
|
||||||
;;; magit-repos.el ends here
|
|
Binary file not shown.
|
@ -1,127 +0,0 @@
|
||||||
;;; magit-reset.el --- reset fuctionality -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements reset commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-reset "magit" nil t)
|
|
||||||
(define-transient-command magit-reset ()
|
|
||||||
"Reset the `HEAD', index and/or worktree to a previous state."
|
|
||||||
:man-page "git-reset"
|
|
||||||
["Reset"
|
|
||||||
("m" "mixed (HEAD and index)" magit-reset-mixed)
|
|
||||||
("s" "soft (HEAD only)" magit-reset-soft)
|
|
||||||
("h" "hard (HEAD, index and files)" magit-reset-hard)
|
|
||||||
("i" "index (only)" magit-reset-index)
|
|
||||||
("w" "worktree (only)" magit-reset-worktree)
|
|
||||||
""
|
|
||||||
("f" "a file" magit-file-checkout)])
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-mixed (commit)
|
|
||||||
"Reset the `HEAD' and index to COMMIT, but not the working tree.
|
|
||||||
\n(git reset --mixed COMMIT)"
|
|
||||||
(interactive (list (magit-reset-read-branch-or-commit "Reset %s to")))
|
|
||||||
(magit-reset-internal "--mixed" commit))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-soft (commit)
|
|
||||||
"Reset the `HEAD' to COMMIT, but not the index and working tree.
|
|
||||||
\n(git reset --soft REVISION)"
|
|
||||||
(interactive (list (magit-reset-read-branch-or-commit "Soft reset %s to")))
|
|
||||||
(magit-reset-internal "--soft" commit))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-hard (commit)
|
|
||||||
"Reset the `HEAD', index, and working tree to COMMIT.
|
|
||||||
\n(git reset --hard REVISION)"
|
|
||||||
(interactive (list (magit-reset-read-branch-or-commit
|
|
||||||
(concat (magit--propertize-face "Hard" 'bold)
|
|
||||||
" reset %s to"))))
|
|
||||||
(magit-reset-internal "--hard" commit))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-index (commit)
|
|
||||||
"Reset the index to COMMIT.
|
|
||||||
Keep the `HEAD' and working tree as-is, so if COMMIT refers to the
|
|
||||||
head this effectively unstages all changes.
|
|
||||||
\n(git reset COMMIT .)"
|
|
||||||
(interactive (list (magit-read-branch-or-commit "Reset index to")))
|
|
||||||
(magit-reset-internal nil commit "."))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-worktree (commit)
|
|
||||||
"Reset the worktree to COMMIT.
|
|
||||||
Keep the `HEAD' and index as-is."
|
|
||||||
(interactive (list (magit-read-branch-or-commit "Reset worktree to")))
|
|
||||||
(magit-wip-commit-before-change nil " before reset")
|
|
||||||
(magit-with-temp-index commit nil
|
|
||||||
(magit-call-git "checkout-index" "--all" "--force"))
|
|
||||||
(magit-wip-commit-after-apply nil " after reset")
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-reset-quickly (commit &optional hard)
|
|
||||||
"Reset the `HEAD' and index to COMMIT, and possibly the working tree.
|
|
||||||
With a prefix argument reset the working tree otherwise don't.
|
|
||||||
\n(git reset --mixed|--hard COMMIT)"
|
|
||||||
(interactive (list (magit-reset-read-branch-or-commit
|
|
||||||
(if current-prefix-arg
|
|
||||||
(concat (magit--propertize-face "Hard" 'bold)
|
|
||||||
" reset %s to")
|
|
||||||
"Reset %s to"))
|
|
||||||
current-prefix-arg))
|
|
||||||
(magit-reset-internal (if hard "--hard" "--mixed") commit))
|
|
||||||
|
|
||||||
(defun magit-reset-read-branch-or-commit (prompt)
|
|
||||||
"Prompt for and return a ref to reset HEAD to.
|
|
||||||
|
|
||||||
PROMPT is a format string, where either the current branch name
|
|
||||||
or \"detached head\" will be substituted for %s."
|
|
||||||
(magit-read-branch-or-commit
|
|
||||||
(format prompt (or (magit-get-current-branch) "detached head"))))
|
|
||||||
|
|
||||||
(defun magit-reset-internal (arg commit &optional path)
|
|
||||||
(when (and (not (member arg '("--hard" nil)))
|
|
||||||
(equal (magit-rev-parse commit)
|
|
||||||
(magit-rev-parse "HEAD~")))
|
|
||||||
(with-temp-buffer
|
|
||||||
(magit-git-insert "show" "-s" "--format=%B" "HEAD")
|
|
||||||
(when git-commit-major-mode
|
|
||||||
(funcall git-commit-major-mode))
|
|
||||||
(git-commit-setup-font-lock)
|
|
||||||
(git-commit-save-message)))
|
|
||||||
(let ((cmd (if (and (equal commit "HEAD") (not arg)) "unstage" "reset")))
|
|
||||||
(magit-wip-commit-before-change nil (concat " before " cmd))
|
|
||||||
(magit-run-git "reset" arg commit "--" path)
|
|
||||||
(when (equal cmd "unstage")
|
|
||||||
(magit-wip-commit-after-apply nil " after unstage"))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-reset)
|
|
||||||
;;; magit-reset.el ends here
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,546 +0,0 @@
|
||||||
;;; magit-stash.el --- stash support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Support for Git stashes.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
(require 'magit-reflog)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-stash nil
|
|
||||||
"List stashes and show stash diffs."
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
;;;; Diff options
|
|
||||||
|
|
||||||
(defcustom magit-stash-sections-hook
|
|
||||||
'(magit-insert-stash-notes
|
|
||||||
magit-insert-stash-worktree
|
|
||||||
magit-insert-stash-index
|
|
||||||
magit-insert-stash-untracked)
|
|
||||||
"Hook run to insert sections into stash diff buffers."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-stash
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
;;;; Log options
|
|
||||||
|
|
||||||
(defcustom magit-stashes-margin
|
|
||||||
(list (nth 0 magit-log-margin)
|
|
||||||
(nth 1 magit-log-margin)
|
|
||||||
'magit-log-margin-width nil
|
|
||||||
(nth 4 magit-log-margin))
|
|
||||||
"Format of the margin in `magit-stashes-mode' buffers.
|
|
||||||
|
|
||||||
The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).
|
|
||||||
|
|
||||||
If INIT is non-nil, then the margin is shown initially.
|
|
||||||
STYLE controls how to format the author or committer date.
|
|
||||||
It can be one of `age' (to show the age of the commit),
|
|
||||||
`age-abbreviated' (to abbreviate the time unit to a character),
|
|
||||||
or a string (suitable for `format-time-string') to show the
|
|
||||||
actual date. Option `magit-log-margin-show-committer-date'
|
|
||||||
controls which date is being displayed.
|
|
||||||
WIDTH controls the width of the margin. This exists for forward
|
|
||||||
compatibility and currently the value should not be changed.
|
|
||||||
AUTHOR controls whether the name of the author is also shown by
|
|
||||||
default.
|
|
||||||
AUTHOR-WIDTH has to be an integer. When the name of the author
|
|
||||||
is shown, then this specifies how much space is used to do so."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-stash
|
|
||||||
:group 'magit-margin
|
|
||||||
:type magit-log-margin--custom-type
|
|
||||||
:initialize 'magit-custom-initialize-reset
|
|
||||||
:set-after '(magit-log-margin)
|
|
||||||
:set (apply-partially #'magit-margin-set-variable 'magit-stashes-mode))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-stash "magit-stash" nil t)
|
|
||||||
(define-transient-command magit-stash ()
|
|
||||||
"Stash uncommitted changes."
|
|
||||||
:man-page "git-stash"
|
|
||||||
["Arguments"
|
|
||||||
("-u" "Also save untracked files" ("-u" "--include-untracked"))
|
|
||||||
("-a" "Also save untracked and ignored files" ("-a" "--all"))]
|
|
||||||
[["Stash"
|
|
||||||
("z" "both" magit-stash-both)
|
|
||||||
("i" "index" magit-stash-index)
|
|
||||||
("w" "worktree" magit-stash-worktree)
|
|
||||||
("x" "keeping index" magit-stash-keep-index)]
|
|
||||||
["Snapshot"
|
|
||||||
("Z" "both" magit-snapshot-both)
|
|
||||||
("I" "index" magit-snapshot-index)
|
|
||||||
("W" "worktree" magit-snapshot-worktree)
|
|
||||||
("r" "to wip ref" magit-wip-commit)]
|
|
||||||
["Use"
|
|
||||||
("a" "Apply" magit-stash-apply)
|
|
||||||
("p" "Pop" magit-stash-pop)
|
|
||||||
("k" "Drop" magit-stash-drop)]
|
|
||||||
["Inspect"
|
|
||||||
("l" "List" magit-stash-list)
|
|
||||||
("v" "Show" magit-stash-show)]
|
|
||||||
["Transform"
|
|
||||||
("b" "Branch" magit-stash-branch)
|
|
||||||
("B" "Branch here" magit-stash-branch-here)
|
|
||||||
("f" "Format patch" magit-stash-format-patch)]])
|
|
||||||
|
|
||||||
(defun magit-stash-arguments ()
|
|
||||||
(transient-args 'magit-stash))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-both (message &optional include-untracked)
|
|
||||||
"Create a stash of the index and working tree.
|
|
||||||
Untracked files are included according to infix arguments.
|
|
||||||
One prefix argument is equivalent to `--include-untracked'
|
|
||||||
while two prefix arguments are equivalent to `--all'."
|
|
||||||
(interactive (magit-stash-read-args))
|
|
||||||
(magit-stash-save message t t include-untracked t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-index (message)
|
|
||||||
"Create a stash of the index only.
|
|
||||||
Unstaged and untracked changes are not stashed. The stashed
|
|
||||||
changes are applied in reverse to both the index and the
|
|
||||||
worktree. This command can fail when the worktree is not clean.
|
|
||||||
Applying the resulting stash has the inverse effect."
|
|
||||||
(interactive (list (magit-stash-read-message)))
|
|
||||||
(magit-stash-save message t nil nil t 'worktree))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-worktree (message &optional include-untracked)
|
|
||||||
"Create a stash of unstaged changes in the working tree.
|
|
||||||
Untracked files are included according to infix arguments.
|
|
||||||
One prefix argument is equivalent to `--include-untracked'
|
|
||||||
while two prefix arguments are equivalent to `--all'."
|
|
||||||
(interactive (magit-stash-read-args))
|
|
||||||
(magit-stash-save message nil t include-untracked t 'index))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-keep-index (message &optional include-untracked)
|
|
||||||
"Create a stash of the index and working tree, keeping index intact.
|
|
||||||
Untracked files are included according to infix arguments.
|
|
||||||
One prefix argument is equivalent to `--include-untracked'
|
|
||||||
while two prefix arguments are equivalent to `--all'."
|
|
||||||
(interactive (magit-stash-read-args))
|
|
||||||
(magit-stash-save message t t include-untracked t 'index))
|
|
||||||
|
|
||||||
(defun magit-stash-read-args ()
|
|
||||||
(list (magit-stash-read-message)
|
|
||||||
(magit-stash-read-untracked)))
|
|
||||||
|
|
||||||
(defun magit-stash-read-untracked ()
|
|
||||||
(let ((prefix (prefix-numeric-value current-prefix-arg))
|
|
||||||
(args (magit-stash-arguments)))
|
|
||||||
(cond ((or (= prefix 16) (member "--all" args)) 'all)
|
|
||||||
((or (= prefix 4) (member "--include-untracked" args)) t))))
|
|
||||||
|
|
||||||
(defun magit-stash-read-message ()
|
|
||||||
(let* ((default (format "On %s: "
|
|
||||||
(or (magit-get-current-branch) "(no branch)")))
|
|
||||||
(input (magit-read-string "Stash message" default)))
|
|
||||||
(if (equal input default)
|
|
||||||
(concat default (magit-rev-format "%h %s"))
|
|
||||||
input)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-snapshot-both (&optional include-untracked)
|
|
||||||
"Create a snapshot of the index and working tree.
|
|
||||||
Untracked files are included according to infix arguments.
|
|
||||||
One prefix argument is equivalent to `--include-untracked'
|
|
||||||
while two prefix arguments are equivalent to `--all'."
|
|
||||||
(interactive (magit-snapshot-read-args))
|
|
||||||
(magit-snapshot-save t t include-untracked t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-snapshot-index ()
|
|
||||||
"Create a snapshot of the index only.
|
|
||||||
Unstaged and untracked changes are not stashed."
|
|
||||||
(interactive)
|
|
||||||
(magit-snapshot-save t nil nil t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-snapshot-worktree (&optional include-untracked)
|
|
||||||
"Create a snapshot of unstaged changes in the working tree.
|
|
||||||
Untracked files are included according to infix arguments.
|
|
||||||
One prefix argument is equivalent to `--include-untracked'
|
|
||||||
while two prefix arguments are equivalent to `--all'."
|
|
||||||
(interactive (magit-snapshot-read-args))
|
|
||||||
(magit-snapshot-save nil t include-untracked t))
|
|
||||||
|
|
||||||
(defun magit-snapshot-read-args ()
|
|
||||||
(list (magit-stash-read-untracked)))
|
|
||||||
|
|
||||||
(defun magit-snapshot-save (index worktree untracked &optional refresh)
|
|
||||||
(magit-stash-save (concat "WIP on " (magit-stash-summary))
|
|
||||||
index worktree untracked refresh t))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-apply (stash)
|
|
||||||
"Apply a stash to the working tree.
|
|
||||||
Try to preserve the stash index. If that fails because there
|
|
||||||
are staged changes, apply without preserving the stash index."
|
|
||||||
(interactive (list (magit-read-stash "Apply stash")))
|
|
||||||
(if (= (magit-call-git "stash" "apply" "--index" stash) 0)
|
|
||||||
(magit-refresh)
|
|
||||||
(magit-run-git "stash" "apply" stash)))
|
|
||||||
|
|
||||||
(defun magit-stash-pop (stash)
|
|
||||||
"Apply a stash to the working tree and remove it from stash list.
|
|
||||||
Try to preserve the stash index. If that fails because there
|
|
||||||
are staged changes, apply without preserving the stash index
|
|
||||||
and forgo removing the stash."
|
|
||||||
(interactive (list (magit-read-stash "Pop stash")))
|
|
||||||
(if (= (magit-call-git "stash" "apply" "--index" stash) 0)
|
|
||||||
(magit-stash-drop stash)
|
|
||||||
(magit-run-git "stash" "apply" stash)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-drop (stash)
|
|
||||||
"Remove a stash from the stash list.
|
|
||||||
When the region is active offer to drop all contained stashes."
|
|
||||||
(interactive
|
|
||||||
(list (--if-let (magit-region-values 'stash)
|
|
||||||
(magit-confirm 'drop-stashes nil "Drop %i stashes" nil it)
|
|
||||||
(magit-read-stash "Drop stash"))))
|
|
||||||
(dolist (stash (if (listp stash)
|
|
||||||
(nreverse (prog1 stash (setq stash (car stash))))
|
|
||||||
(list stash)))
|
|
||||||
(message "Deleted refs/%s (was %s)" stash
|
|
||||||
(magit-rev-parse "--short" stash))
|
|
||||||
(magit-call-git "rev-parse" stash)
|
|
||||||
(magit-call-git "reflog" "delete" "--updateref" "--rewrite" stash))
|
|
||||||
(when-let ((ref (and (string-match "\\(.+\\)@{[0-9]+}$" stash)
|
|
||||||
(match-string 1 stash))))
|
|
||||||
(unless (string-match "^refs/" ref)
|
|
||||||
(setq ref (concat "refs/" ref)))
|
|
||||||
(unless (magit-rev-verify (concat ref "@{0}"))
|
|
||||||
(magit-run-git "update-ref" "-d" ref)))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-clear (ref)
|
|
||||||
"Remove all stashes saved in REF's reflog by deleting REF."
|
|
||||||
(interactive (let ((ref (or (magit-section-value-if 'stashes) "refs/stash")))
|
|
||||||
(magit-confirm t (format "Drop all stashes in %s" ref))
|
|
||||||
(list ref)))
|
|
||||||
(magit-run-git "update-ref" "-d" ref))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-branch (stash branch)
|
|
||||||
"Create and checkout a new BRANCH from STASH."
|
|
||||||
(interactive (list (magit-read-stash "Branch stash")
|
|
||||||
(magit-read-string-ns "Branch name")))
|
|
||||||
(magit-run-git "stash" "branch" branch stash))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-branch-here (stash branch)
|
|
||||||
"Create and checkout a new BRANCH and apply STASH.
|
|
||||||
The branch is created using `magit-branch-and-checkout', using the
|
|
||||||
current branch or `HEAD' as the start-point."
|
|
||||||
(interactive (list (magit-read-stash "Branch stash")
|
|
||||||
(magit-read-string-ns "Branch name")))
|
|
||||||
(let ((inhibit-magit-refresh t))
|
|
||||||
(magit-branch-and-checkout branch (or (magit-get-current-branch) "HEAD")))
|
|
||||||
(magit-stash-apply stash))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-format-patch (stash)
|
|
||||||
"Create a patch from STASH"
|
|
||||||
(interactive (list (magit-read-stash "Create patch from stash")))
|
|
||||||
(with-temp-file (magit-rev-format "0001-%f.patch" stash)
|
|
||||||
(magit-git-insert "stash" "show" "-p" stash))
|
|
||||||
(magit-refresh))
|
|
||||||
|
|
||||||
;;; Plumbing
|
|
||||||
|
|
||||||
(defun magit-stash-save (message index worktree untracked
|
|
||||||
&optional refresh keep noerror ref)
|
|
||||||
(if (or (and index (magit-staged-files t))
|
|
||||||
(and worktree (magit-unstaged-files t))
|
|
||||||
(and untracked (magit-untracked-files (eq untracked 'all))))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-stash-store message (or ref "refs/stash")
|
|
||||||
(magit-stash-create message index worktree untracked))
|
|
||||||
(if (eq keep 'worktree)
|
|
||||||
(with-temp-buffer
|
|
||||||
(magit-git-insert "diff" "--cached")
|
|
||||||
(magit-run-git-with-input
|
|
||||||
"apply" "--reverse" "--cached" "--ignore-space-change" "-")
|
|
||||||
(magit-run-git-with-input
|
|
||||||
"apply" "--reverse" "--ignore-space-change" "-"))
|
|
||||||
(unless (eq keep t)
|
|
||||||
(if (eq keep 'index)
|
|
||||||
(magit-call-git "checkout" "--" ".")
|
|
||||||
(magit-call-git "reset" "--hard" "HEAD" "--"))
|
|
||||||
(when untracked
|
|
||||||
(magit-call-git "clean" "--force" "-d"
|
|
||||||
(and (eq untracked 'all) "-x")))))
|
|
||||||
(when refresh
|
|
||||||
(magit-refresh)))
|
|
||||||
(unless noerror
|
|
||||||
(user-error "No %s changes to save" (cond ((not index) "unstaged")
|
|
||||||
((not worktree) "staged")
|
|
||||||
(t "local"))))))
|
|
||||||
|
|
||||||
(defun magit-stash-store (message ref commit)
|
|
||||||
(magit-update-ref ref message commit t))
|
|
||||||
|
|
||||||
(defun magit-stash-create (message index worktree untracked)
|
|
||||||
(unless (magit-rev-parse "--verify" "HEAD")
|
|
||||||
(error "You do not have the initial commit yet"))
|
|
||||||
(let ((magit-git-global-arguments (nconc (list "-c" "commit.gpgsign=false")
|
|
||||||
magit-git-global-arguments))
|
|
||||||
(default-directory (magit-toplevel))
|
|
||||||
(summary (magit-stash-summary))
|
|
||||||
(head "HEAD"))
|
|
||||||
(when (and worktree (not index))
|
|
||||||
(setq head (or (magit-commit-tree "pre-stash index" nil "HEAD")
|
|
||||||
(error "Cannot save the current index state"))))
|
|
||||||
(or (setq index (magit-commit-tree (concat "index on " summary) nil head))
|
|
||||||
(error "Cannot save the current index state"))
|
|
||||||
(and untracked
|
|
||||||
(setq untracked (magit-untracked-files (eq untracked 'all)))
|
|
||||||
(setq untracked (magit-with-temp-index nil nil
|
|
||||||
(or (and (magit-update-files untracked)
|
|
||||||
(magit-commit-tree
|
|
||||||
(concat "untracked files on " summary)))
|
|
||||||
(error "Cannot save the untracked files")))))
|
|
||||||
(magit-with-temp-index index "-m"
|
|
||||||
(when worktree
|
|
||||||
(or (magit-update-files (magit-git-items "diff" "-z" "--name-only" head))
|
|
||||||
(error "Cannot save the current worktree state")))
|
|
||||||
(or (magit-commit-tree message nil head index untracked)
|
|
||||||
(error "Cannot save the current worktree state")))))
|
|
||||||
|
|
||||||
(defun magit-stash-summary ()
|
|
||||||
(concat (or (magit-get-current-branch) "(no branch)")
|
|
||||||
": " (magit-rev-format "%h %s")))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
(defvar magit-stashes-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-stash-clear)
|
|
||||||
map)
|
|
||||||
"Keymap for `stashes' section.")
|
|
||||||
|
|
||||||
(defvar magit-stash-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-stash-show)
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-stash-drop)
|
|
||||||
(define-key map "a" 'magit-stash-apply)
|
|
||||||
(define-key map "A" 'magit-stash-pop)
|
|
||||||
map)
|
|
||||||
"Keymap for `stash' sections.")
|
|
||||||
|
|
||||||
(magit-define-section-jumper magit-jump-to-stashes
|
|
||||||
"Stashes" stashes "refs/stash")
|
|
||||||
|
|
||||||
(cl-defun magit-insert-stashes (&optional (ref "refs/stash")
|
|
||||||
(heading "Stashes:"))
|
|
||||||
"Insert `stashes' section showing reflog for \"refs/stash\".
|
|
||||||
If optional REF is non-nil, show reflog for that instead.
|
|
||||||
If optional HEADING is non-nil, use that as section heading
|
|
||||||
instead of \"Stashes:\"."
|
|
||||||
(let ((verified (magit-rev-verify ref))
|
|
||||||
(autostash
|
|
||||||
(and (magit-rebase-in-progress-p)
|
|
||||||
(magit-file-line
|
|
||||||
(magit-git-dir
|
|
||||||
(-> (if (file-directory-p (magit-git-dir "rebase-merge"))
|
|
||||||
"rebase-merge/autostash"
|
|
||||||
"rebase-apply/autostash")))))))
|
|
||||||
(when (or autostash verified)
|
|
||||||
(magit-insert-section (stashes ref)
|
|
||||||
(magit-insert-heading heading)
|
|
||||||
(when autostash
|
|
||||||
(pcase-let ((`(,author ,date ,msg)
|
|
||||||
(split-string
|
|
||||||
(car (magit-git-lines
|
|
||||||
"show" "-q" "--format=%aN%x00%at%x00%s"
|
|
||||||
autostash))
|
|
||||||
"\0")))
|
|
||||||
(magit-insert-section (stash autostash)
|
|
||||||
(insert (propertize "AUTOSTASH" 'font-lock-face 'magit-hash))
|
|
||||||
(insert " " msg "\n")
|
|
||||||
(save-excursion
|
|
||||||
(backward-char)
|
|
||||||
(magit-log-format-margin autostash author date)))))
|
|
||||||
(if verified
|
|
||||||
(magit-git-wash (apply-partially 'magit-log-wash-log 'stash)
|
|
||||||
"reflog" "--format=%gd%x00%aN%x00%at%x00%gs" ref)
|
|
||||||
(insert ?\n)
|
|
||||||
(save-excursion
|
|
||||||
(backward-char)
|
|
||||||
(magit-make-margin-overlay)))))))
|
|
||||||
|
|
||||||
;;; List Stashes
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-list ()
|
|
||||||
"List all stashes in a buffer."
|
|
||||||
(interactive)
|
|
||||||
(magit-stashes-setup-buffer))
|
|
||||||
|
|
||||||
(define-derived-mode magit-stashes-mode magit-reflog-mode "Magit Stashes"
|
|
||||||
"Mode for looking at lists of stashes."
|
|
||||||
:group 'magit-log
|
|
||||||
(hack-dir-local-variables-non-file-buffer))
|
|
||||||
|
|
||||||
(defun magit-stashes-setup-buffer ()
|
|
||||||
(magit-setup-buffer #'magit-stashes-mode nil
|
|
||||||
(magit-buffer-refname "refs/stash")))
|
|
||||||
|
|
||||||
(defun magit-stashes-refresh-buffer ()
|
|
||||||
(magit-insert-section (stashesbuf)
|
|
||||||
(magit-insert-heading (if (equal magit-buffer-refname "refs/stash")
|
|
||||||
"Stashes:"
|
|
||||||
(format "Stashes [%s]:" magit-buffer-refname)))
|
|
||||||
(magit-git-wash (apply-partially 'magit-log-wash-log 'stash)
|
|
||||||
"reflog" "--format=%gd%x00%aN%x00%at%x00%gs" magit-buffer-refname)))
|
|
||||||
|
|
||||||
(cl-defmethod magit-buffer-value (&context (major-mode magit-stashes-mode))
|
|
||||||
magit-buffer-refname)
|
|
||||||
|
|
||||||
(defvar magit--update-stash-buffer nil)
|
|
||||||
|
|
||||||
(defun magit-stashes-maybe-update-stash-buffer (&optional _)
|
|
||||||
"When moving in the stashes buffer, update the stash buffer.
|
|
||||||
If there is no stash buffer in the same frame, then do nothing."
|
|
||||||
(when (derived-mode-p 'magit-stashes-mode)
|
|
||||||
(magit--maybe-update-stash-buffer)))
|
|
||||||
|
|
||||||
(defun magit--maybe-update-stash-buffer ()
|
|
||||||
(when-let ((stash (magit-section-value-if 'stash))
|
|
||||||
(buffer (magit-get-mode-buffer 'magit-stash-mode nil t)))
|
|
||||||
(if magit--update-stash-buffer
|
|
||||||
(setq magit--update-stash-buffer (list stash buffer))
|
|
||||||
(setq magit--update-stash-buffer (list stash buffer))
|
|
||||||
(run-with-idle-timer
|
|
||||||
magit-update-other-window-delay nil
|
|
||||||
(let ((args (with-current-buffer buffer
|
|
||||||
(let ((magit-direct-use-buffer-arguments 'selected))
|
|
||||||
(magit-show-commit--arguments)))))
|
|
||||||
(lambda ()
|
|
||||||
(pcase-let ((`(,stash ,buf) magit--update-stash-buffer))
|
|
||||||
(setq magit--update-stash-buffer nil)
|
|
||||||
(when (buffer-live-p buf)
|
|
||||||
(let ((magit-display-buffer-noselect t))
|
|
||||||
(apply #'magit-stash-show stash args))))
|
|
||||||
(setq magit--update-stash-buffer nil)))))))
|
|
||||||
|
|
||||||
;;; Show Stash
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-stash-show (stash &optional args files)
|
|
||||||
"Show all diffs of a stash in a buffer."
|
|
||||||
(interactive (cons (or (and (not current-prefix-arg)
|
|
||||||
(magit-stash-at-point))
|
|
||||||
(magit-read-stash "Show stash"))
|
|
||||||
(pcase-let ((`(,args ,files)
|
|
||||||
(magit-diff-arguments 'magit-stash-mode)))
|
|
||||||
(list (delete "--stat" args) files))))
|
|
||||||
(magit-stash-setup-buffer stash args files))
|
|
||||||
|
|
||||||
(define-derived-mode magit-stash-mode magit-diff-mode "Magit Stash"
|
|
||||||
"Mode for looking at individual stashes."
|
|
||||||
:group 'magit-diff
|
|
||||||
(hack-dir-local-variables-non-file-buffer))
|
|
||||||
|
|
||||||
(defun magit-stash-setup-buffer (stash args files)
|
|
||||||
(magit-setup-buffer #'magit-stash-mode nil
|
|
||||||
(magit-buffer-revision stash)
|
|
||||||
(magit-buffer-range (format "%s^..%s" stash stash))
|
|
||||||
(magit-buffer-diff-args args)
|
|
||||||
(magit-buffer-diff-files files)))
|
|
||||||
|
|
||||||
(defun magit-stash-refresh-buffer ()
|
|
||||||
(magit-set-header-line-format
|
|
||||||
(concat (capitalize magit-buffer-revision) " "
|
|
||||||
(propertize (magit-rev-format "%s" magit-buffer-revision)
|
|
||||||
'font-lock-face
|
|
||||||
(list :weight 'normal :foreground
|
|
||||||
(face-attribute 'default :foreground)))))
|
|
||||||
(setq magit-buffer-revision-hash (magit-rev-parse magit-buffer-revision))
|
|
||||||
(magit-insert-section (stash)
|
|
||||||
(magit-run-section-hook 'magit-stash-sections-hook)))
|
|
||||||
|
|
||||||
(cl-defmethod magit-buffer-value (&context (major-mode magit-stash-mode))
|
|
||||||
magit-buffer-revision)
|
|
||||||
|
|
||||||
(defun magit-stash-insert-section (commit range message &optional files)
|
|
||||||
(magit-insert-section (commit commit)
|
|
||||||
(magit-insert-heading message)
|
|
||||||
(magit--insert-diff "diff" range "-p" "--no-prefix" magit-buffer-diff-args
|
|
||||||
"--" (or files magit-buffer-diff-files))))
|
|
||||||
|
|
||||||
(defun magit-insert-stash-notes ()
|
|
||||||
"Insert section showing notes for a stash.
|
|
||||||
This shows the notes for stash@{N} but not for the other commits
|
|
||||||
that make up the stash."
|
|
||||||
(magit-insert-section section (note)
|
|
||||||
(magit-insert-heading "Notes")
|
|
||||||
(magit-git-insert "notes" "show" magit-buffer-revision)
|
|
||||||
(if (= (point)
|
|
||||||
(oref section content))
|
|
||||||
(magit-cancel-section)
|
|
||||||
(insert "\n"))))
|
|
||||||
|
|
||||||
(defun magit-insert-stash-index ()
|
|
||||||
"Insert section showing staged changes of the stash."
|
|
||||||
(magit-stash-insert-section
|
|
||||||
(format "%s^2" magit-buffer-revision)
|
|
||||||
(format "%s^..%s^2" magit-buffer-revision magit-buffer-revision)
|
|
||||||
"Staged"))
|
|
||||||
|
|
||||||
(defun magit-insert-stash-worktree ()
|
|
||||||
"Insert section showing unstaged changes of the stash."
|
|
||||||
(magit-stash-insert-section
|
|
||||||
magit-buffer-revision
|
|
||||||
(format "%s^2..%s" magit-buffer-revision magit-buffer-revision)
|
|
||||||
"Unstaged"))
|
|
||||||
|
|
||||||
(defun magit-insert-stash-untracked ()
|
|
||||||
"Insert section showing the untracked files commit of the stash."
|
|
||||||
(let ((stash magit-buffer-revision)
|
|
||||||
(rev (concat magit-buffer-revision "^3")))
|
|
||||||
(when (magit-rev-verify rev)
|
|
||||||
(magit-stash-insert-section (format "%s^3" stash)
|
|
||||||
(format "%s^..%s^3" stash stash)
|
|
||||||
"Untracked files"
|
|
||||||
(magit-git-items "ls-tree" "-z" "--name-only"
|
|
||||||
"-r" "--full-tree" rev)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-stash)
|
|
||||||
;;; magit-stash.el ends here
|
|
Binary file not shown.
|
@ -1,793 +0,0 @@
|
||||||
;;; magit-status.el --- the grand overview -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements the status buffer.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-status nil
|
|
||||||
"Inspect and manipulate Git repositories."
|
|
||||||
:link '(info-link "(magit)Status Buffer")
|
|
||||||
:group 'magit-modes)
|
|
||||||
|
|
||||||
(defcustom magit-status-mode-hook nil
|
|
||||||
"Hook run after entering Magit-Status mode."
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom magit-status-headers-hook
|
|
||||||
'(magit-insert-error-header
|
|
||||||
magit-insert-diff-filter-header
|
|
||||||
magit-insert-head-branch-header
|
|
||||||
magit-insert-upstream-branch-header
|
|
||||||
magit-insert-push-branch-header
|
|
||||||
magit-insert-tags-header)
|
|
||||||
"Hook run to insert headers into the status buffer.
|
|
||||||
|
|
||||||
This hook is run by `magit-insert-status-headers', which in turn
|
|
||||||
has to be a member of `magit-status-sections-hook' to be used at
|
|
||||||
all."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'hook
|
|
||||||
:options '(magit-insert-error-header
|
|
||||||
magit-insert-diff-filter-header
|
|
||||||
magit-insert-repo-header
|
|
||||||
magit-insert-remote-header
|
|
||||||
magit-insert-head-branch-header
|
|
||||||
magit-insert-upstream-branch-header
|
|
||||||
magit-insert-push-branch-header
|
|
||||||
magit-insert-tags-header))
|
|
||||||
|
|
||||||
(defcustom magit-status-sections-hook
|
|
||||||
'(magit-insert-status-headers
|
|
||||||
magit-insert-merge-log
|
|
||||||
magit-insert-rebase-sequence
|
|
||||||
magit-insert-am-sequence
|
|
||||||
magit-insert-sequencer-sequence
|
|
||||||
magit-insert-bisect-output
|
|
||||||
magit-insert-bisect-rest
|
|
||||||
magit-insert-bisect-log
|
|
||||||
magit-insert-untracked-files
|
|
||||||
magit-insert-unstaged-changes
|
|
||||||
magit-insert-staged-changes
|
|
||||||
magit-insert-stashes
|
|
||||||
magit-insert-unpushed-to-pushremote
|
|
||||||
magit-insert-unpushed-to-upstream-or-recent
|
|
||||||
magit-insert-unpulled-from-pushremote
|
|
||||||
magit-insert-unpulled-from-upstream)
|
|
||||||
"Hook run to insert sections into a status buffer."
|
|
||||||
:package-version '(magit . "2.12.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom magit-status-initial-section '(1)
|
|
||||||
"The section point is placed on when a status buffer is created.
|
|
||||||
|
|
||||||
When such a buffer is merely being refreshed or being shown again
|
|
||||||
after it was merely buried, then this option has no effect.
|
|
||||||
|
|
||||||
If this is nil, then point remains on the very first section as
|
|
||||||
usual. Otherwise it has to be a list of integers and section
|
|
||||||
identity lists. The members of that list are tried in order
|
|
||||||
until a matching section is found.
|
|
||||||
|
|
||||||
An integer means to jump to the nth section, 1 for example
|
|
||||||
jumps over the headings. To get a section's \"identity list\"
|
|
||||||
use \\[universal-argument] \\[magit-describe-section-briefly].
|
|
||||||
|
|
||||||
If, for example, you want to jump to the commits that haven't
|
|
||||||
been pulled from the upstream, or else the second section, then
|
|
||||||
use: (((unpulled . \"..@{upstream}\") (status)) 1).
|
|
||||||
|
|
||||||
See option `magit-section-initial-visibility-alist' for how to
|
|
||||||
control the initial visibility of the jumped to section."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type '(choice (const :tag "as usual" nil)
|
|
||||||
(repeat (choice (number :tag "nth top-level section")
|
|
||||||
(sexp :tag "section identity")))))
|
|
||||||
|
|
||||||
(defcustom magit-status-goto-file-position nil
|
|
||||||
"Whether to go to position corresponding to file position.
|
|
||||||
|
|
||||||
If this is non-nil and the current buffer is visiting a file,
|
|
||||||
then `magit-status' tries to go to the position in the status
|
|
||||||
buffer that corresponds to the position in the file-visiting
|
|
||||||
buffer. This jumps into either the diff of unstaged changes
|
|
||||||
or the diff of staged changes.
|
|
||||||
|
|
||||||
If the previously current buffer does not visit a file, or if
|
|
||||||
the file has neither unstaged nor staged changes then this has
|
|
||||||
no effect.
|
|
||||||
|
|
||||||
The command `magit-status-here' tries to go to that position,
|
|
||||||
regardless of the value of this option."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-status-show-hashes-in-headers nil
|
|
||||||
"Whether headers in the status buffer show hashes.
|
|
||||||
The functions which respect this option are
|
|
||||||
`magit-insert-head-branch-header',
|
|
||||||
`magit-insert-upstream-branch-header', and
|
|
||||||
`magit-insert-push-branch-header'."
|
|
||||||
:package-version '(magit . "2.4.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-status-margin
|
|
||||||
(list nil
|
|
||||||
(nth 1 magit-log-margin)
|
|
||||||
'magit-log-margin-width nil
|
|
||||||
(nth 4 magit-log-margin))
|
|
||||||
"Format of the margin in `magit-status-mode' buffers.
|
|
||||||
|
|
||||||
The value has the form (INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH).
|
|
||||||
|
|
||||||
If INIT is non-nil, then the margin is shown initially.
|
|
||||||
STYLE controls how to format the author or committer date.
|
|
||||||
It can be one of `age' (to show the age of the commit),
|
|
||||||
`age-abbreviated' (to abbreviate the time unit to a character),
|
|
||||||
or a string (suitable for `format-time-string') to show the
|
|
||||||
actual date. Option `magit-log-margin-show-committer-date'
|
|
||||||
controls which date is being displayed.
|
|
||||||
WIDTH controls the width of the margin. This exists for forward
|
|
||||||
compatibility and currently the value should not be changed.
|
|
||||||
AUTHOR controls whether the name of the author is also shown by
|
|
||||||
default.
|
|
||||||
AUTHOR-WIDTH has to be an integer. When the name of the author
|
|
||||||
is shown, then this specifies how much space is used to do so."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:group 'magit-margin
|
|
||||||
:type magit-log-margin--custom-type
|
|
||||||
:initialize 'magit-custom-initialize-reset
|
|
||||||
:set-after '(magit-log-margin)
|
|
||||||
:set (apply-partially #'magit-margin-set-variable 'magit-status-mode))
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-init (directory)
|
|
||||||
"Initialize a Git repository, then show its status.
|
|
||||||
|
|
||||||
If the directory is below an existing repository, then the user
|
|
||||||
has to confirm that a new one should be created inside. If the
|
|
||||||
directory is the root of the existing repository, then the user
|
|
||||||
has to confirm that it should be reinitialized.
|
|
||||||
|
|
||||||
Non-interactively DIRECTORY is (re-)initialized unconditionally."
|
|
||||||
(interactive
|
|
||||||
(let ((directory (file-name-as-directory
|
|
||||||
(expand-file-name
|
|
||||||
(read-directory-name "Create repository in: ")))))
|
|
||||||
(when-let ((toplevel (magit-toplevel directory)))
|
|
||||||
(setq toplevel (expand-file-name toplevel))
|
|
||||||
(unless (y-or-n-p (if (file-equal-p toplevel directory)
|
|
||||||
(format "Reinitialize existing repository %s? "
|
|
||||||
directory)
|
|
||||||
(format "%s is a repository. Create another in %s? "
|
|
||||||
toplevel directory)))
|
|
||||||
(user-error "Abort")))
|
|
||||||
(list directory)))
|
|
||||||
;; `git init' does not understand the meaning of "~"!
|
|
||||||
(magit-call-git "init" (magit-convert-filename-for-git
|
|
||||||
(expand-file-name directory)))
|
|
||||||
(magit-status-setup-buffer directory))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-status (&optional directory cache)
|
|
||||||
"Show the status of the current Git repository in a buffer.
|
|
||||||
|
|
||||||
If the current directory isn't located within a Git repository,
|
|
||||||
then prompt for an existing repository or an arbitrary directory,
|
|
||||||
depending on option `magit-repository-directories', and show the
|
|
||||||
status of the selected repository instead.
|
|
||||||
|
|
||||||
* If that option specifies any existing repositories, then offer
|
|
||||||
those for completion and show the status buffer for the
|
|
||||||
selected one.
|
|
||||||
|
|
||||||
* Otherwise read an arbitrary directory using regular file-name
|
|
||||||
completion. If the selected directory is the top-level of an
|
|
||||||
existing working tree, then show the status buffer for that.
|
|
||||||
|
|
||||||
* Otherwise offer to initialize the selected directory as a new
|
|
||||||
repository. After creating the repository show its status
|
|
||||||
buffer.
|
|
||||||
|
|
||||||
These fallback behaviors can also be forced using one or more
|
|
||||||
prefix arguments:
|
|
||||||
|
|
||||||
* With two prefix arguments (or more precisely a numeric prefix
|
|
||||||
value of 16 or greater) read an arbitrary directory and act on
|
|
||||||
it as described above. The same could be accomplished using
|
|
||||||
the command `magit-init'.
|
|
||||||
|
|
||||||
* With a single prefix argument read an existing repository, or
|
|
||||||
if none can be found based on `magit-repository-directories',
|
|
||||||
then fall back to the same behavior as with two prefix
|
|
||||||
arguments."
|
|
||||||
(interactive
|
|
||||||
(let ((magit--refresh-cache (list (cons 0 0))))
|
|
||||||
(list (and (or current-prefix-arg (not (magit-toplevel)))
|
|
||||||
(magit-read-repository
|
|
||||||
(>= (prefix-numeric-value current-prefix-arg) 16)))
|
|
||||||
magit--refresh-cache)))
|
|
||||||
(let ((magit--refresh-cache (or cache (list (cons 0 0)))))
|
|
||||||
(if directory
|
|
||||||
(let ((toplevel (magit-toplevel directory)))
|
|
||||||
(setq directory (file-name-as-directory
|
|
||||||
(expand-file-name directory)))
|
|
||||||
(if (and toplevel (file-equal-p directory toplevel))
|
|
||||||
(magit-status-setup-buffer directory)
|
|
||||||
(when (y-or-n-p
|
|
||||||
(if toplevel
|
|
||||||
(format "%s is a repository. Create another in %s? "
|
|
||||||
toplevel directory)
|
|
||||||
(format "Create repository in %s? " directory)))
|
|
||||||
;; Creating a new repository invalidates cached values.
|
|
||||||
(setq magit--refresh-cache nil)
|
|
||||||
(magit-init directory))))
|
|
||||||
(magit-status-setup-buffer default-directory))))
|
|
||||||
|
|
||||||
(put 'magit-status 'interactive-only 'magit-status-setup-buffer)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defalias 'magit 'magit-status
|
|
||||||
"An alias for `magit-status' for better discoverability.
|
|
||||||
|
|
||||||
Instead of invoking this alias for `magit-status' using
|
|
||||||
\"M-x magit RET\", you should bind a key to `magit-status'
|
|
||||||
and read the info node `(magit)Getting Started', which
|
|
||||||
also contains other useful hints.")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-status-here ()
|
|
||||||
"Like `magit-status' but with non-nil `magit-status-goto-file-position'."
|
|
||||||
(interactive)
|
|
||||||
(let ((magit-status-goto-file-position t))
|
|
||||||
(call-interactively #'magit-status)))
|
|
||||||
|
|
||||||
(put 'magit-status-here 'interactive-only 'magit-status-setup-buffer)
|
|
||||||
|
|
||||||
(defvar magit--remotes-using-recent-git nil)
|
|
||||||
|
|
||||||
(defun magit--tramp-asserts (directory)
|
|
||||||
(when-let ((remote (file-remote-p directory)))
|
|
||||||
(unless (member remote magit--remotes-using-recent-git)
|
|
||||||
(if-let ((version (let ((default-directory directory))
|
|
||||||
(magit-git-version))))
|
|
||||||
(if (version<= magit--minimal-git version)
|
|
||||||
(push version magit--remotes-using-recent-git)
|
|
||||||
(display-warning 'magit (format "\
|
|
||||||
Magit requires Git >= %s, but on %s the version is %s.
|
|
||||||
|
|
||||||
If multiple Git versions are installed on the host, then the
|
|
||||||
problem might be that TRAMP uses the wrong executable.
|
|
||||||
|
|
||||||
First check the value of `magit-git-executable'. Its value is
|
|
||||||
used when running git locally as well as when running it on a
|
|
||||||
remote host. The default value is \"git\", except on Windows
|
|
||||||
where an absolute path is used for performance reasons.
|
|
||||||
|
|
||||||
If the value already is just \"git\" but TRAMP never-the-less
|
|
||||||
doesn't use the correct executable, then consult the info node
|
|
||||||
`(tramp)Remote programs'.\n" magit--minimal-git remote version) :error))
|
|
||||||
(display-warning 'magit (format "\
|
|
||||||
Magit cannot find Git on %s.
|
|
||||||
|
|
||||||
First check the value of `magit-git-executable'. Its value is
|
|
||||||
used when running git locally as well as when running it on a
|
|
||||||
remote host. The default value is \"git\", except on Windows
|
|
||||||
where an absolute path is used for performance reasons.
|
|
||||||
|
|
||||||
If the value already is just \"git\" but TRAMP never-the-less
|
|
||||||
doesn't find the executable, then consult the info node
|
|
||||||
`(tramp)Remote programs'.\n" remote) :error)))))
|
|
||||||
|
|
||||||
;;; Mode
|
|
||||||
|
|
||||||
(defvar magit-status-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map magit-mode-map)
|
|
||||||
(define-key map "jz" 'magit-jump-to-stashes)
|
|
||||||
(define-key map "jt" 'magit-jump-to-tracked)
|
|
||||||
(define-key map "jn" 'magit-jump-to-untracked)
|
|
||||||
(define-key map "ju" 'magit-jump-to-unstaged)
|
|
||||||
(define-key map "js" 'magit-jump-to-staged)
|
|
||||||
(define-key map "jfu" 'magit-jump-to-unpulled-from-upstream)
|
|
||||||
(define-key map "jfp" 'magit-jump-to-unpulled-from-pushremote)
|
|
||||||
(define-key map "jpu" 'magit-jump-to-unpushed-to-upstream)
|
|
||||||
(define-key map "jpp" 'magit-jump-to-unpushed-to-pushremote)
|
|
||||||
(define-key map "ja" 'magit-jump-to-assume-unchanged)
|
|
||||||
(define-key map "jw" 'magit-jump-to-skip-worktree)
|
|
||||||
(define-key map [remap dired-jump] 'magit-dired-jump)
|
|
||||||
map)
|
|
||||||
"Keymap for `magit-status-mode'.")
|
|
||||||
|
|
||||||
(define-derived-mode magit-status-mode magit-mode "Magit"
|
|
||||||
"Mode for looking at Git status.
|
|
||||||
|
|
||||||
This mode is documented in info node `(magit)Status Buffer'.
|
|
||||||
|
|
||||||
\\<magit-mode-map>\
|
|
||||||
Type \\[magit-refresh] to refresh the current buffer.
|
|
||||||
Type \\[magit-section-toggle] to expand or hide the section at point.
|
|
||||||
Type \\[magit-visit-thing] to visit the change or commit at point.
|
|
||||||
|
|
||||||
Type \\[magit-dispatch] to invoke major commands.
|
|
||||||
|
|
||||||
Staging and applying changes is documented in info node
|
|
||||||
`(magit)Staging and Unstaging' and info node `(magit)Applying'.
|
|
||||||
|
|
||||||
\\<magit-hunk-section-map>Type \
|
|
||||||
\\[magit-apply] to apply the change at point, \
|
|
||||||
\\[magit-stage] to stage,
|
|
||||||
\\[magit-unstage] to unstage, \
|
|
||||||
\\[magit-discard] to discard, or \
|
|
||||||
\\[magit-reverse] to reverse it.
|
|
||||||
|
|
||||||
\\<magit-status-mode-map>\
|
|
||||||
Type \\[magit-commit] to create a commit.
|
|
||||||
|
|
||||||
\\{magit-status-mode-map}"
|
|
||||||
:group 'magit-status
|
|
||||||
(hack-dir-local-variables-non-file-buffer)
|
|
||||||
(setq imenu-create-index-function
|
|
||||||
'magit-imenu--status-create-index-function))
|
|
||||||
|
|
||||||
(put 'magit-status-mode 'magit-diff-default-arguments
|
|
||||||
'("--no-ext-diff"))
|
|
||||||
(put 'magit-status-mode 'magit-log-default-arguments
|
|
||||||
'("-n256" "--decorate"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-status-setup-buffer (&optional directory)
|
|
||||||
(unless directory
|
|
||||||
(setq directory default-directory))
|
|
||||||
(magit--tramp-asserts directory)
|
|
||||||
(let* ((default-directory directory)
|
|
||||||
(d (magit-diff--get-value 'magit-status-mode))
|
|
||||||
(l (magit-log--get-value 'magit-status-mode))
|
|
||||||
(file (and magit-status-goto-file-position
|
|
||||||
(magit-file-relative-name)))
|
|
||||||
(line (and file (line-number-at-pos)))
|
|
||||||
(col (and file (current-column)))
|
|
||||||
(buf (magit-setup-buffer #'magit-status-mode nil
|
|
||||||
(magit-buffer-diff-args (nth 0 d))
|
|
||||||
(magit-buffer-diff-files (nth 1 d))
|
|
||||||
(magit-buffer-log-args (nth 0 l))
|
|
||||||
(magit-buffer-log-files (nth 1 l)))))
|
|
||||||
(when file
|
|
||||||
(with-current-buffer buf
|
|
||||||
(let ((staged (magit-get-section '((staged) (status)))))
|
|
||||||
(if (and staged
|
|
||||||
(cadr (magit-diff--locate-hunk file line staged)))
|
|
||||||
(magit-diff--goto-position file line col staged)
|
|
||||||
(let ((unstaged (magit-get-section '((unstaged) (status)))))
|
|
||||||
(unless (and unstaged
|
|
||||||
(magit-diff--goto-position file line col unstaged))
|
|
||||||
(when staged
|
|
||||||
(magit-diff--goto-position file line col staged))))))))
|
|
||||||
buf))
|
|
||||||
|
|
||||||
(defun magit-status-refresh-buffer ()
|
|
||||||
(magit-git-exit-code "update-index" "--refresh")
|
|
||||||
(magit-insert-section (status)
|
|
||||||
(magit-run-section-hook 'magit-status-sections-hook)))
|
|
||||||
|
|
||||||
(defun magit-status-goto-initial-section ()
|
|
||||||
"In a `magit-status-mode' buffer, jump `magit-status-initial-section'.
|
|
||||||
Actually doing so is deferred until `magit-refresh-buffer-hook'
|
|
||||||
runs `magit-status-goto-initial-section-1'. That function then
|
|
||||||
removes itself from the hook, so that this only happens when the
|
|
||||||
status buffer is first created."
|
|
||||||
(when (and magit-status-initial-section
|
|
||||||
(derived-mode-p 'magit-status-mode))
|
|
||||||
(add-hook 'magit-refresh-buffer-hook
|
|
||||||
'magit-status-goto-initial-section-1 nil t)))
|
|
||||||
|
|
||||||
(defun magit-status-goto-initial-section-1 ()
|
|
||||||
"In a `magit-status-mode' buffer, jump `magit-status-initial-section'.
|
|
||||||
This function removes itself from `magit-refresh-buffer-hook'."
|
|
||||||
(when-let ((section
|
|
||||||
(--some (if (integerp it)
|
|
||||||
(nth (1- it)
|
|
||||||
(magit-section-siblings (magit-current-section)
|
|
||||||
'next))
|
|
||||||
(magit-get-section it))
|
|
||||||
magit-status-initial-section)))
|
|
||||||
(goto-char (oref section start))
|
|
||||||
(when-let ((vis (cdr (assq 'magit-status-initial-section
|
|
||||||
magit-section-initial-visibility-alist))))
|
|
||||||
(if (eq vis 'hide)
|
|
||||||
(magit-section-hide section)
|
|
||||||
(magit-section-show section))))
|
|
||||||
(remove-hook 'magit-refresh-buffer-hook
|
|
||||||
'magit-status-goto-initial-section-1 t))
|
|
||||||
|
|
||||||
(defun magit-status-maybe-update-revision-buffer (&optional _)
|
|
||||||
"When moving in the status buffer, update the revision buffer.
|
|
||||||
If there is no revision buffer in the same frame, then do nothing."
|
|
||||||
(when (derived-mode-p 'magit-status-mode)
|
|
||||||
(magit--maybe-update-revision-buffer)))
|
|
||||||
|
|
||||||
(defun magit-status-maybe-update-stash-buffer (&optional _)
|
|
||||||
"When moving in the status buffer, update the stash buffer.
|
|
||||||
If there is no stash buffer in the same frame, then do nothing."
|
|
||||||
(when (derived-mode-p 'magit-status-mode)
|
|
||||||
(magit--maybe-update-stash-buffer)))
|
|
||||||
|
|
||||||
(defun magit-status-maybe-update-blob-buffer (&optional _)
|
|
||||||
"When moving in the status buffer, update the blob buffer.
|
|
||||||
If there is no blob buffer in the same frame, then do nothing."
|
|
||||||
(when (derived-mode-p 'magit-status-mode)
|
|
||||||
(magit--maybe-update-blob-buffer)))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
;;;; Special Headers
|
|
||||||
|
|
||||||
(defun magit-insert-status-headers ()
|
|
||||||
"Insert header sections appropriate for `magit-status-mode' buffers.
|
|
||||||
The sections are inserted by running the functions on the hook
|
|
||||||
`magit-status-headers-hook'."
|
|
||||||
(if (magit-rev-verify "HEAD")
|
|
||||||
(magit-insert-headers 'magit-status-headers-hook)
|
|
||||||
(insert "In the beginning there was darkness\n\n")))
|
|
||||||
|
|
||||||
(defvar magit-error-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-process-buffer)
|
|
||||||
map)
|
|
||||||
"Keymap for `error' sections.")
|
|
||||||
|
|
||||||
(defun magit-insert-error-header ()
|
|
||||||
"Insert the message about the Git error that just occurred.
|
|
||||||
|
|
||||||
This function is only aware of the last error that occur when Git
|
|
||||||
was run for side-effects. If, for example, an error occurs while
|
|
||||||
generating a diff, then that error won't be inserted. Refreshing
|
|
||||||
the status buffer causes this section to disappear again."
|
|
||||||
(when magit-this-error
|
|
||||||
(magit-insert-section (error 'git)
|
|
||||||
(insert (propertize (format "%-10s" "GitError! ")
|
|
||||||
'font-lock-face 'magit-section-heading))
|
|
||||||
(insert (propertize magit-this-error
|
|
||||||
'font-lock-face 'font-lock-warning-face))
|
|
||||||
(when-let ((key (car (where-is-internal 'magit-process-buffer))))
|
|
||||||
(insert (format " [Type `%s' for details]" (key-description key))))
|
|
||||||
(insert ?\n))
|
|
||||||
(setq magit-this-error nil)))
|
|
||||||
|
|
||||||
(defun magit-insert-diff-filter-header ()
|
|
||||||
"Insert a header line showing the effective diff filters."
|
|
||||||
(let ((ignore-modules (magit-ignore-submodules-p)))
|
|
||||||
(when (or ignore-modules
|
|
||||||
magit-buffer-diff-files)
|
|
||||||
(insert (propertize (format "%-10s" "Filter! ")
|
|
||||||
'font-lock-face 'magit-section-heading))
|
|
||||||
(when ignore-modules
|
|
||||||
(insert ignore-modules)
|
|
||||||
(when magit-buffer-diff-files
|
|
||||||
(insert " -- ")))
|
|
||||||
(when magit-buffer-diff-files
|
|
||||||
(insert (mapconcat #'identity magit-buffer-diff-files " ")))
|
|
||||||
(insert ?\n))))
|
|
||||||
|
|
||||||
;;;; Reference Headers
|
|
||||||
|
|
||||||
(defun magit-insert-head-branch-header (&optional branch)
|
|
||||||
"Insert a header line about the current branch.
|
|
||||||
If `HEAD' is detached, then insert information about that commit
|
|
||||||
instead. The optional BRANCH argument is for internal use only."
|
|
||||||
(let ((branch (or branch (magit-get-current-branch)))
|
|
||||||
(output (magit-rev-format "%h %s" (or branch "HEAD"))))
|
|
||||||
(string-match "^\\([^ ]+\\) \\(.*\\)" output)
|
|
||||||
(magit-bind-match-strings (commit summary) output
|
|
||||||
(when (equal summary "")
|
|
||||||
(setq summary "(no commit message)"))
|
|
||||||
(if branch
|
|
||||||
(magit-insert-section (branch branch)
|
|
||||||
(insert (format "%-10s" "Head: "))
|
|
||||||
(when magit-status-show-hashes-in-headers
|
|
||||||
(insert (propertize commit 'font-lock-face 'magit-hash) ?\s))
|
|
||||||
(insert (propertize branch 'font-lock-face 'magit-branch-local))
|
|
||||||
(insert ?\s)
|
|
||||||
(insert (funcall magit-log-format-message-function branch summary))
|
|
||||||
(insert ?\n))
|
|
||||||
(magit-insert-section (commit commit)
|
|
||||||
(insert (format "%-10s" "Head: "))
|
|
||||||
(insert (propertize commit 'font-lock-face 'magit-hash))
|
|
||||||
(insert ?\s)
|
|
||||||
(insert (funcall magit-log-format-message-function nil summary))
|
|
||||||
(insert ?\n))))))
|
|
||||||
|
|
||||||
(defun magit-insert-upstream-branch-header (&optional branch upstream keyword)
|
|
||||||
"Insert a header line about the upstream of the current branch.
|
|
||||||
If no branch is checked out, then insert nothing. The optional
|
|
||||||
arguments are for internal use only."
|
|
||||||
(when-let ((branch (or branch (magit-get-current-branch))))
|
|
||||||
(let ((remote (magit-get "branch" branch "remote"))
|
|
||||||
(merge (magit-get "branch" branch "merge"))
|
|
||||||
(rebase (magit-get "branch" branch "rebase")))
|
|
||||||
(when (or remote merge)
|
|
||||||
(unless upstream
|
|
||||||
(setq upstream (magit-get-upstream-branch branch)))
|
|
||||||
(magit-insert-section (branch upstream)
|
|
||||||
(pcase rebase
|
|
||||||
("true")
|
|
||||||
("false" (setq rebase nil))
|
|
||||||
(_ (setq rebase (magit-get-boolean "pull.rebase"))))
|
|
||||||
(insert (format "%-10s" (or keyword (if rebase "Rebase: " "Merge: "))))
|
|
||||||
(insert
|
|
||||||
(if upstream
|
|
||||||
(concat (and magit-status-show-hashes-in-headers
|
|
||||||
(concat (propertize (magit-rev-format "%h" upstream)
|
|
||||||
'font-lock-face 'magit-hash)
|
|
||||||
" "))
|
|
||||||
upstream " "
|
|
||||||
(funcall magit-log-format-message-function upstream
|
|
||||||
(funcall magit-log-format-message-function nil
|
|
||||||
(or (magit-rev-format "%s" upstream)
|
|
||||||
"(no commit message)"))))
|
|
||||||
(cond
|
|
||||||
((magit--unnamed-upstream-p remote merge)
|
|
||||||
(concat (propertize merge 'font-lock-face 'magit-branch-remote)
|
|
||||||
" from "
|
|
||||||
(propertize remote 'font-lock-face 'bold)))
|
|
||||||
((magit--valid-upstream-p remote merge)
|
|
||||||
(if (equal remote ".")
|
|
||||||
(concat
|
|
||||||
(propertize merge 'font-lock-face 'magit-branch-local)
|
|
||||||
(propertize " does not exist"
|
|
||||||
'font-lock-face 'font-lock-warning-face))
|
|
||||||
(concat
|
|
||||||
(propertize merge 'font-lock-face 'magit-branch-remote)
|
|
||||||
(propertize " does not exist on "
|
|
||||||
'font-lock-face 'font-lock-warning-face)
|
|
||||||
(propertize remote 'font-lock-face 'magit-branch-remote))))
|
|
||||||
(t
|
|
||||||
(propertize "invalid upstream configuration"
|
|
||||||
'font-lock-face 'font-lock-warning-face)))))
|
|
||||||
(insert ?\n))))))
|
|
||||||
|
|
||||||
(defun magit-insert-push-branch-header ()
|
|
||||||
"Insert a header line about the branch the current branch is pushed to."
|
|
||||||
(when-let ((branch (magit-get-current-branch))
|
|
||||||
(target (magit-get-push-branch branch)))
|
|
||||||
(magit-insert-section (branch target)
|
|
||||||
(insert (format "%-10s" "Push: "))
|
|
||||||
(insert
|
|
||||||
(if (magit-rev-verify target)
|
|
||||||
(concat target " "
|
|
||||||
(and magit-status-show-hashes-in-headers
|
|
||||||
(concat (propertize (magit-rev-format "%h" target)
|
|
||||||
'font-lock-face 'magit-hash)
|
|
||||||
" "))
|
|
||||||
(funcall magit-log-format-message-function target
|
|
||||||
(funcall magit-log-format-message-function nil
|
|
||||||
(or (magit-rev-format "%s" target)
|
|
||||||
"(no commit message)"))))
|
|
||||||
(let ((remote (magit-get-push-remote branch)))
|
|
||||||
(if (magit-remote-p remote)
|
|
||||||
(concat target
|
|
||||||
(propertize " does not exist"
|
|
||||||
'font-lock-face 'font-lock-warning-face))
|
|
||||||
(concat remote
|
|
||||||
(propertize " remote does not exist"
|
|
||||||
'font-lock-face 'font-lock-warning-face))))))
|
|
||||||
(insert ?\n))))
|
|
||||||
|
|
||||||
(defun magit-insert-tags-header ()
|
|
||||||
"Insert a header line about the current and/or next tag."
|
|
||||||
(let* ((this-tag (magit-get-current-tag nil t))
|
|
||||||
(next-tag (magit-get-next-tag nil t))
|
|
||||||
(this-cnt (cadr this-tag))
|
|
||||||
(next-cnt (cadr next-tag))
|
|
||||||
(this-tag (car this-tag))
|
|
||||||
(next-tag (car next-tag))
|
|
||||||
(both-tags (and this-tag next-tag t)))
|
|
||||||
(when (or this-tag next-tag)
|
|
||||||
(magit-insert-section (tag (or this-tag next-tag))
|
|
||||||
(insert (format "%-10s" (if both-tags "Tags: " "Tag: ")))
|
|
||||||
(cl-flet ((insert-count
|
|
||||||
(tag count face)
|
|
||||||
(insert (concat (propertize tag 'font-lock-face 'magit-tag)
|
|
||||||
(and (> count 0)
|
|
||||||
(format " (%s)"
|
|
||||||
(propertize
|
|
||||||
(format "%s" count)
|
|
||||||
'font-lock-face face)))))))
|
|
||||||
(when this-tag (insert-count this-tag this-cnt 'magit-branch-local))
|
|
||||||
(when both-tags (insert ", "))
|
|
||||||
(when next-tag (insert-count next-tag next-cnt 'magit-tag)))
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
;;;; Auxiliary Headers
|
|
||||||
|
|
||||||
(defun magit-insert-user-header ()
|
|
||||||
"Insert a header line about the current user."
|
|
||||||
(let ((name (magit-get "user.name"))
|
|
||||||
(email (magit-get "user.email")))
|
|
||||||
(when (and name email)
|
|
||||||
(magit-insert-section (user name)
|
|
||||||
(insert (format "%-10s" "User: "))
|
|
||||||
(insert (propertize name 'font-lock-face 'magit-log-author))
|
|
||||||
(insert " <" email ">\n")))))
|
|
||||||
|
|
||||||
(defun magit-insert-repo-header ()
|
|
||||||
"Insert a header line showing the path to the repository top-level."
|
|
||||||
(let ((topdir (magit-toplevel)))
|
|
||||||
(magit-insert-section (repo topdir)
|
|
||||||
(insert (format "%-10s%s\n" "Repo: " (abbreviate-file-name topdir))))))
|
|
||||||
|
|
||||||
(defun magit-insert-remote-header ()
|
|
||||||
"Insert a header line about the remote of the current branch.
|
|
||||||
|
|
||||||
If no remote is configured for the current branch, then fall back
|
|
||||||
showing the \"origin\" remote, or if that does not exist the first
|
|
||||||
remote in alphabetic order."
|
|
||||||
(when-let ((name (magit-get-some-remote))
|
|
||||||
;; Under certain configurations it's possible for url
|
|
||||||
;; to be nil, when name is not, see #2858.
|
|
||||||
(url (magit-get "remote" name "url")))
|
|
||||||
(magit-insert-section (remote name)
|
|
||||||
(insert (format "%-10s" "Remote: "))
|
|
||||||
(insert (propertize name 'font-lock-face 'magit-branch-remote) ?\s)
|
|
||||||
(insert url ?\n))))
|
|
||||||
|
|
||||||
;;;; File Sections
|
|
||||||
|
|
||||||
(defvar magit-untracked-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-discard)
|
|
||||||
(define-key map "s" 'magit-stage)
|
|
||||||
map)
|
|
||||||
"Keymap for the `untracked' section.")
|
|
||||||
|
|
||||||
(magit-define-section-jumper magit-jump-to-untracked "Untracked files" untracked)
|
|
||||||
|
|
||||||
(defun magit-insert-untracked-files ()
|
|
||||||
"Maybe insert a list or tree of untracked files.
|
|
||||||
|
|
||||||
Do so depending on the value of `status.showUntrackedFiles'.
|
|
||||||
Note that even if the value is `all', Magit still initially
|
|
||||||
only shows directories. But the directory sections can then
|
|
||||||
be expanded using \"TAB\".
|
|
||||||
|
|
||||||
If the first element of `magit-buffer-diff-files' is a
|
|
||||||
directory, then limit the list to files below that. The value
|
|
||||||
value of that variable can be set using \"D -- DIRECTORY RET g\"."
|
|
||||||
(let* ((show (or (magit-get "status.showUntrackedFiles") "normal"))
|
|
||||||
(base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base)))
|
|
||||||
(unless (equal show "no")
|
|
||||||
(if (equal show "all")
|
|
||||||
(when-let ((files (magit-untracked-files nil base)))
|
|
||||||
(magit-insert-section (untracked)
|
|
||||||
(magit-insert-heading "Untracked files:")
|
|
||||||
(magit-insert-files files base)
|
|
||||||
(insert ?\n)))
|
|
||||||
(when-let ((files
|
|
||||||
(--mapcat (and (eq (aref it 0) ??)
|
|
||||||
(list (substring it 3)))
|
|
||||||
(magit-git-items "status" "-z" "--porcelain"
|
|
||||||
(magit-ignore-submodules-p)
|
|
||||||
"--" base))))
|
|
||||||
(magit-insert-section (untracked)
|
|
||||||
(magit-insert-heading "Untracked files:")
|
|
||||||
(dolist (file files)
|
|
||||||
(magit-insert-section (file file)
|
|
||||||
(insert (propertize file 'font-lock-face 'magit-filename) ?\n)))
|
|
||||||
(insert ?\n)))))))
|
|
||||||
|
|
||||||
(magit-define-section-jumper magit-jump-to-tracked "Tracked files" tracked)
|
|
||||||
|
|
||||||
(defun magit-insert-tracked-files ()
|
|
||||||
"Insert a tree of tracked files.
|
|
||||||
|
|
||||||
If the first element of `magit-buffer-diff-files' is a
|
|
||||||
directory, then limit the list to files below that. The value
|
|
||||||
value of that variable can be set using \"D -- DIRECTORY RET g\"."
|
|
||||||
(when-let ((files (magit-list-files)))
|
|
||||||
(let* ((base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base)))
|
|
||||||
(magit-insert-section (tracked nil t)
|
|
||||||
(magit-insert-heading "Tracked files:")
|
|
||||||
(magit-insert-files files base)
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
(defun magit-insert-ignored-files ()
|
|
||||||
"Insert a tree of ignored files.
|
|
||||||
|
|
||||||
If the first element of `magit-buffer-diff-files' is a
|
|
||||||
directory, then limit the list to files below that. The value
|
|
||||||
of that variable can be set using \"D -- DIRECTORY RET g\"."
|
|
||||||
(when-let ((files (magit-ignored-files)))
|
|
||||||
(let* ((base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base)))
|
|
||||||
(magit-insert-section (tracked nil t)
|
|
||||||
(magit-insert-heading "Ignored files:")
|
|
||||||
(magit-insert-files files base)
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
(magit-define-section-jumper magit-jump-to-skip-worktree "Skip-worktree files" skip-worktree)
|
|
||||||
|
|
||||||
(defun magit-insert-skip-worktree-files ()
|
|
||||||
"Insert a tree of skip-worktree files.
|
|
||||||
|
|
||||||
If the first element of `magit-buffer-diff-files' is a
|
|
||||||
directory, then limit the list to files below that. The value
|
|
||||||
of that variable can be set using \"D -- DIRECTORY RET g\"."
|
|
||||||
(when-let ((files (magit-skip-worktree-files)))
|
|
||||||
(let* ((base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base)))
|
|
||||||
(magit-insert-section (skip-worktree nil t)
|
|
||||||
(magit-insert-heading "Skip-worktree files:")
|
|
||||||
(magit-insert-files files base)
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
(magit-define-section-jumper magit-jump-to-assume-unchanged "Assume-unchanged files" assume-unchanged)
|
|
||||||
|
|
||||||
(defun magit-insert-assume-unchanged-files ()
|
|
||||||
"Insert a tree of files that are assumed to be unchanged.
|
|
||||||
|
|
||||||
If the first element of `magit-buffer-diff-files' is a
|
|
||||||
directory, then limit the list to files below that. The value
|
|
||||||
of that variable can be set using \"D -- DIRECTORY RET g\"."
|
|
||||||
(when-let ((files (magit-assume-unchanged-files)))
|
|
||||||
(let* ((base (car magit-buffer-diff-files))
|
|
||||||
(base (and base (file-directory-p base) base)))
|
|
||||||
(magit-insert-section (assume-unchanged nil t)
|
|
||||||
(magit-insert-heading "Assume-unchanged files:")
|
|
||||||
(magit-insert-files files base)
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
(defun magit-insert-files (files directory)
|
|
||||||
(while (and files (string-prefix-p (or directory "") (car files)))
|
|
||||||
(let ((dir (file-name-directory (car files))))
|
|
||||||
(if (equal dir directory)
|
|
||||||
(let ((file (pop files)))
|
|
||||||
(magit-insert-section (file file)
|
|
||||||
(insert (propertize file 'font-lock-face 'magit-filename) ?\n)))
|
|
||||||
(magit-insert-section (file dir t)
|
|
||||||
(insert (propertize dir 'file 'magit-filename) ?\n)
|
|
||||||
(magit-insert-heading)
|
|
||||||
(setq files (magit-insert-files files dir))))))
|
|
||||||
files)
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-status)
|
|
||||||
;;; magit-status.el ends here
|
|
Binary file not shown.
|
@ -1,665 +0,0 @@
|
||||||
;;; magit-submodule.el --- submodule support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2011-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
(defvar x-stretch-cursor)
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-module-sections-hook
|
|
||||||
'(magit-insert-modules-overview
|
|
||||||
magit-insert-modules-unpulled-from-upstream
|
|
||||||
magit-insert-modules-unpulled-from-pushremote
|
|
||||||
magit-insert-modules-unpushed-to-upstream
|
|
||||||
magit-insert-modules-unpushed-to-pushremote)
|
|
||||||
"Hook run by `magit-insert-modules'.
|
|
||||||
|
|
||||||
That function isn't part of `magit-status-sections-hook's default
|
|
||||||
value, so you have to add it yourself for this hook to have any
|
|
||||||
effect."
|
|
||||||
:package-version '(magit . "2.11.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'hook)
|
|
||||||
|
|
||||||
(defcustom magit-module-sections-nested t
|
|
||||||
"Whether `magit-insert-modules' wraps inserted sections.
|
|
||||||
|
|
||||||
If this is non-nil, then only a single top-level section
|
|
||||||
is inserted. If it is nil, then all sections listed in
|
|
||||||
`magit-module-sections-hook' become top-level sections."
|
|
||||||
:package-version '(magit . "2.11.0")
|
|
||||||
:group 'magit-status
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-submodule-list-mode-hook '(hl-line-mode)
|
|
||||||
"Hook run after entering Magit-Submodule-List mode."
|
|
||||||
:package-version '(magit . "2.9.0")
|
|
||||||
:group 'magit-repolist
|
|
||||||
:type 'hook
|
|
||||||
:get 'magit-hook-custom-get
|
|
||||||
:options '(hl-line-mode))
|
|
||||||
|
|
||||||
(defcustom magit-submodule-list-columns
|
|
||||||
'(("Path" 25 magit-modulelist-column-path nil)
|
|
||||||
("Version" 25 magit-repolist-column-version nil)
|
|
||||||
("Branch" 20 magit-repolist-column-branch nil)
|
|
||||||
("B<U" 3 magit-repolist-column-unpulled-from-upstream ((:right-align t)))
|
|
||||||
("B>U" 3 magit-repolist-column-unpushed-to-upstream ((:right-align t)))
|
|
||||||
("B<P" 3 magit-repolist-column-unpulled-from-pushremote ((:right-align t)))
|
|
||||||
("B>P" 3 magit-repolist-column-unpushed-to-pushremote ((:right-align t)))
|
|
||||||
("B" 3 magit-repolist-column-branches ((:right-align t)))
|
|
||||||
("S" 3 magit-repolist-column-stashes ((:right-align t))))
|
|
||||||
"List of columns displayed by `magit-list-submodules'.
|
|
||||||
|
|
||||||
Each element has the form (HEADER WIDTH FORMAT PROPS).
|
|
||||||
|
|
||||||
HEADER is the string displayed in the header. WIDTH is the width
|
|
||||||
of the column. FORMAT is a function that is called with one
|
|
||||||
argument, the repository identification (usually its basename),
|
|
||||||
and with `default-directory' bound to the toplevel of its working
|
|
||||||
tree. It has to return a string to be inserted or nil. PROPS is
|
|
||||||
an alist that supports the keys `:right-align' and `:pad-right'."
|
|
||||||
:package-version '(magit . "2.8.0")
|
|
||||||
:group 'magit-repolist-mode
|
|
||||||
:type `(repeat (list :tag "Column"
|
|
||||||
(string :tag "Header Label")
|
|
||||||
(integer :tag "Column Width")
|
|
||||||
(function :tag "Inserter Function")
|
|
||||||
(repeat :tag "Properties"
|
|
||||||
(list (choice :tag "Property"
|
|
||||||
(const :right-align)
|
|
||||||
(const :pad-right)
|
|
||||||
(symbol))
|
|
||||||
(sexp :tag "Value"))))))
|
|
||||||
|
|
||||||
(defcustom magit-submodule-remove-trash-gitdirs nil
|
|
||||||
"Whether `magit-submodule-remove' offers to trash module gitdirs.
|
|
||||||
|
|
||||||
If this is nil, then that command does not offer to do so unless
|
|
||||||
a prefix argument is used. When this is t, then it does offer to
|
|
||||||
do so even without a prefix argument.
|
|
||||||
|
|
||||||
In both cases the action still has to be confirmed unless that is
|
|
||||||
disabled using the option `magit-no-confirm'. Doing the latter
|
|
||||||
and also setting this variable to t will lead to tears."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
;;; Popup
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule "magit-submodule" nil t)
|
|
||||||
(define-transient-command magit-submodule ()
|
|
||||||
"Act on a submodule."
|
|
||||||
:man-page "git-submodule"
|
|
||||||
["Arguments"
|
|
||||||
("-f" "Force" ("-f" "--force"))
|
|
||||||
("-r" "Recursive" "--recursive")
|
|
||||||
("-N" "Do not fetch" ("-N" "--no-fetch"))
|
|
||||||
("-C" "Checkout tip" "--checkout")
|
|
||||||
("-R" "Rebase onto tip" "--rebase")
|
|
||||||
("-M" "Merge tip" "--merge")
|
|
||||||
("-U" "Use upstream tip" "--remote")]
|
|
||||||
["One module actions"
|
|
||||||
("a" magit-submodule-add)
|
|
||||||
("r" magit-submodule-register)
|
|
||||||
("p" magit-submodule-populate)
|
|
||||||
("u" magit-submodule-update)
|
|
||||||
("s" magit-submodule-synchronize)
|
|
||||||
("d" magit-submodule-unpopulate)
|
|
||||||
("k" "Remove" magit-submodule-remove)]
|
|
||||||
["All modules actions"
|
|
||||||
("l" "List all modules" magit-list-submodules)
|
|
||||||
("f" "Fetch all modules" magit-fetch-modules)])
|
|
||||||
|
|
||||||
(defun magit-submodule-arguments (&rest filters)
|
|
||||||
(--filter (and (member it filters) it)
|
|
||||||
(transient-args 'magit-submodule)))
|
|
||||||
|
|
||||||
(defclass magit--git-submodule-suffix (transient-suffix)
|
|
||||||
())
|
|
||||||
|
|
||||||
(cl-defmethod transient-format-description ((obj magit--git-submodule-suffix))
|
|
||||||
(let ((value (delq nil (mapcar 'transient-infix-value transient--suffixes))))
|
|
||||||
(replace-regexp-in-string
|
|
||||||
"\\[--[^]]+\\]"
|
|
||||||
(lambda (match)
|
|
||||||
(format (propertize "[%s]" 'face 'transient-inactive-argument)
|
|
||||||
(mapconcat (lambda (arg)
|
|
||||||
(propertize arg 'face
|
|
||||||
(if (member arg value)
|
|
||||||
'transient-argument
|
|
||||||
'transient-inactive-argument)))
|
|
||||||
(save-match-data
|
|
||||||
(split-string (substring match 1 -1) "|"))
|
|
||||||
(propertize "|" 'face 'transient-inactive-argument))))
|
|
||||||
(cl-call-next-method obj))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-add "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-add (url &optional path name args)
|
|
||||||
"Add the repository at URL as a module.
|
|
||||||
|
|
||||||
Optional PATH is the path to the module relative to the root of
|
|
||||||
the superproject. If it is nil, then the path is determined
|
|
||||||
based on the URL. Optional NAME is the name of the module. If
|
|
||||||
it is nil, then PATH also becomes the name."
|
|
||||||
:class 'magit--git-submodule-suffix
|
|
||||||
:description "Add git submodule add [--force]"
|
|
||||||
(interactive
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let* ((url (magit-read-string-ns "Add submodule (remote url)"))
|
|
||||||
(path (let ((read-file-name-function
|
|
||||||
(if (or (eq read-file-name-function 'ido-read-file-name)
|
|
||||||
(advice-function-member-p
|
|
||||||
'ido-read-file-name
|
|
||||||
read-file-name-function))
|
|
||||||
;; The Ido variant doesn't work properly here.
|
|
||||||
#'read-file-name-default
|
|
||||||
read-file-name-function)))
|
|
||||||
(directory-file-name
|
|
||||||
(file-relative-name
|
|
||||||
(read-directory-name
|
|
||||||
"Add submodules at path: " nil nil nil
|
|
||||||
(and (string-match "\\([^./]+\\)\\(\\.git\\)?$" url)
|
|
||||||
(match-string 1 url))))))))
|
|
||||||
(list url
|
|
||||||
(directory-file-name path)
|
|
||||||
(magit-submodule-read-name-for-path path)
|
|
||||||
(magit-submodule-arguments "--force")))))
|
|
||||||
(magit-submodule-add-1 url path name args))
|
|
||||||
|
|
||||||
(defun magit-submodule-add-1 (url &optional path name args)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-submodule--maybe-reuse-gitdir name path)
|
|
||||||
(magit-run-git-async "submodule" "add"
|
|
||||||
(and name (list "--name" name))
|
|
||||||
args "--" url path)
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(if (> (process-exit-status process) 0)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(process-put process 'inhibit-refresh t)
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(unless (version< (magit-git-version) "2.12.0")
|
|
||||||
(magit-call-git "submodule" "absorbgitdirs" path))
|
|
||||||
(magit-refresh)))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-submodule-read-name-for-path (path &optional prefer-short)
|
|
||||||
(let* ((path (directory-file-name (file-relative-name path)))
|
|
||||||
(name (file-name-nondirectory path)))
|
|
||||||
(push (if prefer-short path name) minibuffer-history)
|
|
||||||
(magit-read-string-ns
|
|
||||||
"Submodule name" nil (cons 'minibuffer-history 2)
|
|
||||||
(or (--keep (pcase-let ((`(,var ,val) (split-string it "=")))
|
|
||||||
(and (equal val path)
|
|
||||||
(cadr (split-string var "\\."))))
|
|
||||||
(magit-git-lines "config" "--list" "-f" ".gitmodules"))
|
|
||||||
(if prefer-short name path)))))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-register "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-register (modules)
|
|
||||||
"Register MODULES.
|
|
||||||
|
|
||||||
With a prefix argument act on all suitable modules. Otherwise,
|
|
||||||
if the region selects modules, then act on those. Otherwise, if
|
|
||||||
there is a module at point, then act on that. Otherwise read a
|
|
||||||
single module from the user."
|
|
||||||
;; This command and the underlying "git submodule init" do NOT
|
|
||||||
;; "initialize" modules. They merely "register" modules in the
|
|
||||||
;; super-projects $GIT_DIR/config file, the purpose of which is to
|
|
||||||
;; allow users to change such values before actually initializing
|
|
||||||
;; the modules.
|
|
||||||
:description "Register git submodule init"
|
|
||||||
(interactive
|
|
||||||
(list (magit-module-confirm "Register" 'magit-module-no-worktree-p)))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "submodule" "init" "--" modules)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-populate "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-populate (modules)
|
|
||||||
"Create MODULES working directories, checking out the recorded commits.
|
|
||||||
|
|
||||||
With a prefix argument act on all suitable modules. Otherwise,
|
|
||||||
if the region selects modules, then act on those. Otherwise, if
|
|
||||||
there is a module at point, then act on that. Otherwise read a
|
|
||||||
single module from the user."
|
|
||||||
;; This is the command that actually "initializes" modules.
|
|
||||||
;; A module is initialized when it has a working directory,
|
|
||||||
;; a gitlink, and a .gitmodules entry.
|
|
||||||
:description "Populate git submodule update --init"
|
|
||||||
(interactive
|
|
||||||
(list (magit-module-confirm "Populate" 'magit-module-no-worktree-p)))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "submodule" "update" "--init" "--" modules)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-update "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-update (modules args)
|
|
||||||
"Update MODULES by checking out the recorded commits.
|
|
||||||
|
|
||||||
With a prefix argument act on all suitable modules. Otherwise,
|
|
||||||
if the region selects modules, then act on those. Otherwise, if
|
|
||||||
there is a module at point, then act on that. Otherwise read a
|
|
||||||
single module from the user."
|
|
||||||
;; Unlike `git-submodule's `update' command ours can only update
|
|
||||||
;; "initialized" modules by checking out other commits but not
|
|
||||||
;; "initialize" modules by creating the working directories.
|
|
||||||
;; To do the latter we provide the "setup" command.
|
|
||||||
:class 'magit--git-submodule-suffix
|
|
||||||
:description "Update git submodule update [--force] [--no-fetch]
|
|
||||||
[--remote] [--recursive] [--checkout|--rebase|--merge]"
|
|
||||||
(interactive
|
|
||||||
(list (magit-module-confirm "Update" 'magit-module-worktree-p)
|
|
||||||
(magit-submodule-arguments
|
|
||||||
"--force" "--remote" "--recursive" "--checkout" "--rebase" "--merge"
|
|
||||||
"--no-fetch")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "submodule" "update" args "--" modules)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-synchronize "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-synchronize (modules args)
|
|
||||||
"Synchronize url configuration of MODULES.
|
|
||||||
|
|
||||||
With a prefix argument act on all suitable modules. Otherwise,
|
|
||||||
if the region selects modules, then act on those. Otherwise, if
|
|
||||||
there is a module at point, then act on that. Otherwise read a
|
|
||||||
single module from the user."
|
|
||||||
:class 'magit--git-submodule-suffix
|
|
||||||
:description "Synchronize git submodule sync [--recursive]"
|
|
||||||
(interactive
|
|
||||||
(list (magit-module-confirm "Synchronize" 'magit-module-worktree-p)
|
|
||||||
(magit-submodule-arguments "--recursive")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "submodule" "sync" args "--" modules)))
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-submodule-unpopulate "magit-submodule" nil t)
|
|
||||||
(define-suffix-command magit-submodule-unpopulate (modules args)
|
|
||||||
"Remove working directories of MODULES.
|
|
||||||
|
|
||||||
With a prefix argument act on all suitable modules. Otherwise,
|
|
||||||
if the region selects modules, then act on those. Otherwise, if
|
|
||||||
there is a module at point, then act on that. Otherwise read a
|
|
||||||
single module from the user."
|
|
||||||
;; Even though a package is "uninitialized" (it has no worktree)
|
|
||||||
;; the super-projects $GIT_DIR/config may never-the-less set the
|
|
||||||
;; module's url. This may happen if you `deinit' and then `init'
|
|
||||||
;; to register (NOT initialize). Because the purpose of `deinit'
|
|
||||||
;; is to remove the working directory AND to remove the url, this
|
|
||||||
;; command does not limit itself to modules that have no working
|
|
||||||
;; directory.
|
|
||||||
:class 'magit--git-submodule-suffix
|
|
||||||
:description "Unpopulate git submodule deinit [--force]"
|
|
||||||
(interactive
|
|
||||||
(list (magit-module-confirm "Unpopulate")
|
|
||||||
(magit-submodule-arguments "--force")))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-run-git-async "submodule" "deinit" args "--" modules)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-submodule-remove (modules args trash-gitdirs)
|
|
||||||
"Unregister MODULES and remove their working directories.
|
|
||||||
|
|
||||||
For safety reasons, do not remove the gitdirs and if a module has
|
|
||||||
uncomitted changes, then do not remove it at all. If a module's
|
|
||||||
gitdir is located inside the working directory, then move it into
|
|
||||||
the gitdir of the superproject first.
|
|
||||||
|
|
||||||
With the \"--force\" argument offer to remove dirty working
|
|
||||||
directories and with a prefix argument offer to delete gitdirs.
|
|
||||||
Both actions are very dangerous and have to be confirmed. There
|
|
||||||
are additional safety precautions in place, so you might be able
|
|
||||||
to recover from making a mistake here, but don't count on it."
|
|
||||||
(interactive
|
|
||||||
(list (if-let ((modules (magit-region-values 'magit-module-section t)))
|
|
||||||
(magit-confirm 'remove-modules nil "Remove %i modules" nil modules)
|
|
||||||
(list (magit-read-module-path "Remove module")))
|
|
||||||
(magit-submodule-arguments "--force")
|
|
||||||
current-prefix-arg))
|
|
||||||
(when (version< (magit-git-version) "2.12.0")
|
|
||||||
(error "This command requires Git v2.12.0"))
|
|
||||||
(when magit-submodule-remove-trash-gitdirs
|
|
||||||
(setq trash-gitdirs t))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(when-let
|
|
||||||
((modified
|
|
||||||
(-filter (lambda (module)
|
|
||||||
(let ((default-directory (file-name-as-directory
|
|
||||||
(expand-file-name module))))
|
|
||||||
(and (cddr (directory-files default-directory))
|
|
||||||
(magit-anything-modified-p))))
|
|
||||||
modules)))
|
|
||||||
(if (member "--force" args)
|
|
||||||
(if (magit-confirm 'remove-dirty-modules
|
|
||||||
"Remove dirty module %s"
|
|
||||||
"Remove %i dirty modules"
|
|
||||||
t modified)
|
|
||||||
(dolist (module modified)
|
|
||||||
(let ((default-directory (file-name-as-directory
|
|
||||||
(expand-file-name module))))
|
|
||||||
(magit-git "stash" "push"
|
|
||||||
"-m" "backup before removal of this module")))
|
|
||||||
(setq modules (cl-set-difference modules modified)))
|
|
||||||
(if (cdr modified)
|
|
||||||
(message "Omitting %s modules with uncommitted changes: %s"
|
|
||||||
(length modified)
|
|
||||||
(mapconcat #'identity modified ", "))
|
|
||||||
(message "Omitting module %s, it has uncommitted changes"
|
|
||||||
(car modified)))
|
|
||||||
(setq modules (cl-set-difference modules modified))))
|
|
||||||
(when modules
|
|
||||||
(let ((alist
|
|
||||||
(and trash-gitdirs
|
|
||||||
(--map (split-string it "\0")
|
|
||||||
(magit-git-lines "submodule" "foreach" "-q"
|
|
||||||
"printf \"$sm_path\\0$name\n\"")))))
|
|
||||||
(magit-git "submodule" "absorbgitdirs" "--" modules)
|
|
||||||
(magit-git "submodule" "deinit" args "--" modules)
|
|
||||||
(magit-git "rm" args "--" modules)
|
|
||||||
(when (and trash-gitdirs
|
|
||||||
(magit-confirm 'trash-module-gitdirs
|
|
||||||
"Trash gitdir of module %s"
|
|
||||||
"Trash gitdirs of %i modules"
|
|
||||||
t modules))
|
|
||||||
(dolist (module modules)
|
|
||||||
(if-let ((name (cadr (assoc module alist))))
|
|
||||||
;; Disregard if `magit-delete-by-moving-to-trash'
|
|
||||||
;; is nil. Not doing so would be too dangerous.
|
|
||||||
(delete-directory (magit-git-dir
|
|
||||||
(convert-standard-filename
|
|
||||||
(concat "modules/" name)))
|
|
||||||
t t)
|
|
||||||
(error "BUG: Weird module name and/or path for %s" module)))))
|
|
||||||
(magit-refresh))))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules ()
|
|
||||||
"Insert submodule sections.
|
|
||||||
Hook `magit-module-sections-hook' controls which module sections
|
|
||||||
are inserted, and option `magit-module-sections-nested' controls
|
|
||||||
whether they are wrapped in an additional section."
|
|
||||||
(when-let ((modules (magit-list-module-paths)))
|
|
||||||
(if magit-module-sections-nested
|
|
||||||
(magit-insert-section (modules nil t)
|
|
||||||
(magit-insert-heading
|
|
||||||
(format "%s (%s)"
|
|
||||||
(propertize "Modules"
|
|
||||||
'font-lock-face 'magit-section-heading)
|
|
||||||
(length modules)))
|
|
||||||
(magit-insert-section-body
|
|
||||||
(magit--insert-modules)))
|
|
||||||
(magit--insert-modules))))
|
|
||||||
|
|
||||||
(defun magit--insert-modules (&optional _section)
|
|
||||||
(magit-run-section-hook 'magit-module-sections-hook))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules-overview ()
|
|
||||||
"Insert sections for all modules.
|
|
||||||
For each section insert the path and the output of `git describe --tags',
|
|
||||||
or, failing that, the abbreviated HEAD commit hash."
|
|
||||||
(when-let ((modules (magit-list-module-paths)))
|
|
||||||
(magit-insert-section (modules nil t)
|
|
||||||
(magit-insert-heading
|
|
||||||
(format "%s (%s)"
|
|
||||||
(propertize "Modules overview"
|
|
||||||
'font-lock-face 'magit-section-heading)
|
|
||||||
(length modules)))
|
|
||||||
(magit-insert-section-body
|
|
||||||
(magit--insert-modules-overview)))))
|
|
||||||
|
|
||||||
(defvar magit-modules-overview-align-numbers t)
|
|
||||||
|
|
||||||
(defun magit--insert-modules-overview (&optional _section)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let* ((modules (magit-list-module-paths))
|
|
||||||
(path-format (format "%%-%is "
|
|
||||||
(min (apply 'max (mapcar 'length modules))
|
|
||||||
(/ (window-width) 2))))
|
|
||||||
(branch-format (format "%%-%is " (min 25 (/ (window-width) 3)))))
|
|
||||||
(dolist (module modules)
|
|
||||||
(let ((default-directory
|
|
||||||
(expand-file-name (file-name-as-directory module))))
|
|
||||||
(magit-insert-section (magit-module-section module t)
|
|
||||||
(insert (propertize (format path-format module)
|
|
||||||
'font-lock-face 'magit-diff-file-heading))
|
|
||||||
(if (not (file-exists-p ".git"))
|
|
||||||
(insert "(unpopulated)")
|
|
||||||
(insert (format
|
|
||||||
branch-format
|
|
||||||
(--if-let (magit-get-current-branch)
|
|
||||||
(propertize it 'font-lock-face 'magit-branch-local)
|
|
||||||
(propertize "(detached)" 'font-lock-face 'warning))))
|
|
||||||
(--if-let (magit-git-string "describe" "--tags")
|
|
||||||
(progn (when (and magit-modules-overview-align-numbers
|
|
||||||
(string-match-p "\\`[0-9]" it))
|
|
||||||
(insert ?\s))
|
|
||||||
(insert (propertize it 'font-lock-face 'magit-tag)))
|
|
||||||
(--when-let (magit-rev-format "%h")
|
|
||||||
(insert (propertize it 'font-lock-face 'magit-hash)))))
|
|
||||||
(insert ?\n))))))
|
|
||||||
(insert ?\n))
|
|
||||||
|
|
||||||
(defvar magit-modules-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-list-submodules)
|
|
||||||
map)
|
|
||||||
"Keymap for `modules' sections.")
|
|
||||||
|
|
||||||
(defvar magit-module-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map magit-file-section-map)
|
|
||||||
(unless (featurep 'jkl)
|
|
||||||
(define-key map "\C-j" 'magit-submodule-visit))
|
|
||||||
(define-key map [C-return] 'magit-submodule-visit)
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-submodule-visit)
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-submodule-unpopulate)
|
|
||||||
(define-key map "K" 'magit-file-untrack)
|
|
||||||
(define-key map "R" 'magit-file-rename)
|
|
||||||
map)
|
|
||||||
"Keymap for `module' sections.")
|
|
||||||
|
|
||||||
(defun magit-submodule-visit (module &optional other-window)
|
|
||||||
"Visit MODULE by calling `magit-status' on it.
|
|
||||||
Offer to initialize MODULE if it's not checked out yet.
|
|
||||||
With a prefix argument, visit in another window."
|
|
||||||
(interactive (list (or (magit-section-value-if 'module)
|
|
||||||
(magit-read-module-path "Visit module"))
|
|
||||||
current-prefix-arg))
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((path (expand-file-name module)))
|
|
||||||
(cond
|
|
||||||
((file-exists-p (expand-file-name ".git" module))
|
|
||||||
(magit-diff-visit-directory path other-window))
|
|
||||||
((y-or-n-p (format "Initialize submodule '%s' first?" module))
|
|
||||||
(magit-run-git-async "submodule" "update" "--init" "--" module)
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(let ((magit-process-raise-error t))
|
|
||||||
(magit-process-sentinel process event))
|
|
||||||
(when (and (eq (process-status process) 'exit)
|
|
||||||
(= (process-exit-status process) 0))
|
|
||||||
(magit-diff-visit-directory path other-window)))))
|
|
||||||
((file-exists-p path)
|
|
||||||
(dired-jump other-window (concat path "/.")))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules-unpulled-from-upstream ()
|
|
||||||
"Insert sections for modules that haven't been pulled from the upstream.
|
|
||||||
These sections can be expanded to show the respective commits."
|
|
||||||
(magit--insert-modules-logs "Modules unpulled from @{upstream}"
|
|
||||||
'modules-unpulled-from-upstream
|
|
||||||
"HEAD..@{upstream}"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules-unpulled-from-pushremote ()
|
|
||||||
"Insert sections for modules that haven't been pulled from the push-remote.
|
|
||||||
These sections can be expanded to show the respective commits."
|
|
||||||
(magit--insert-modules-logs "Modules unpulled from @{push}"
|
|
||||||
'modules-unpulled-from-pushremote
|
|
||||||
"HEAD..@{push}"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules-unpushed-to-upstream ()
|
|
||||||
"Insert sections for modules that haven't been pushed to the upstream.
|
|
||||||
These sections can be expanded to show the respective commits."
|
|
||||||
(magit--insert-modules-logs "Modules unmerged into @{upstream}"
|
|
||||||
'modules-unpushed-to-upstream
|
|
||||||
"@{upstream}..HEAD"))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-insert-modules-unpushed-to-pushremote ()
|
|
||||||
"Insert sections for modules that haven't been pushed to the push-remote.
|
|
||||||
These sections can be expanded to show the respective commits."
|
|
||||||
(magit--insert-modules-logs "Modules unpushed to @{push}"
|
|
||||||
'modules-unpushed-to-pushremote
|
|
||||||
"@{push}..HEAD"))
|
|
||||||
|
|
||||||
(defun magit--insert-modules-logs (heading type range)
|
|
||||||
"For internal use, don't add to a hook."
|
|
||||||
(unless (magit-ignore-submodules-p)
|
|
||||||
(when-let ((modules (magit-list-module-paths)))
|
|
||||||
(magit-insert-section section ((eval type) nil t)
|
|
||||||
(string-match "\\`\\(.+\\) \\([^ ]+\\)\\'" heading)
|
|
||||||
(magit-insert-heading
|
|
||||||
(propertize (match-string 1 heading)
|
|
||||||
'font-lock-face 'magit-section-heading)
|
|
||||||
" "
|
|
||||||
(propertize (match-string 2 heading)
|
|
||||||
'font-lock-face 'magit-branch-remote)
|
|
||||||
":")
|
|
||||||
(magit-with-toplevel
|
|
||||||
(dolist (module modules)
|
|
||||||
(when (magit-module-worktree-p module)
|
|
||||||
(let ((default-directory
|
|
||||||
(expand-file-name (file-name-as-directory module))))
|
|
||||||
(when (magit-file-accessible-directory-p default-directory)
|
|
||||||
(magit-insert-section sec (magit-module-section module t)
|
|
||||||
(magit-insert-heading
|
|
||||||
(propertize module
|
|
||||||
'font-lock-face 'magit-diff-file-heading)
|
|
||||||
":")
|
|
||||||
(magit-git-wash
|
|
||||||
(apply-partially 'magit-log-wash-log 'module)
|
|
||||||
"-c" "push.default=current" "log" "--oneline" range)
|
|
||||||
(when (> (point)
|
|
||||||
(oref sec content))
|
|
||||||
(delete-char -1))))))))
|
|
||||||
(if (> (point)
|
|
||||||
(oref section content))
|
|
||||||
(insert ?\n)
|
|
||||||
(magit-cancel-section))))))
|
|
||||||
|
|
||||||
;;; List
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-list-submodules ()
|
|
||||||
"Display a list of the current repository's submodules."
|
|
||||||
(interactive)
|
|
||||||
(magit-display-buffer
|
|
||||||
(or (magit-get-mode-buffer 'magit-submodule-list-mode)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-generate-new-buffer 'magit-submodule-list-mode))))
|
|
||||||
(magit-submodule-list-mode)
|
|
||||||
(magit-submodule-list-refresh)
|
|
||||||
(tabulated-list-print))
|
|
||||||
|
|
||||||
(defvar magit-submodule-list-mode-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(set-keymap-parent map magit-repolist-mode-map)
|
|
||||||
map)
|
|
||||||
"Local keymap for Magit-Submodule-List mode buffers.")
|
|
||||||
|
|
||||||
(define-derived-mode magit-submodule-list-mode tabulated-list-mode "Modules"
|
|
||||||
"Major mode for browsing a list of Git submodules."
|
|
||||||
:group 'magit-repolist-mode
|
|
||||||
(setq-local x-stretch-cursor nil)
|
|
||||||
(setq tabulated-list-padding 0)
|
|
||||||
(setq tabulated-list-sort-key (cons "Path" nil))
|
|
||||||
(setq tabulated-list-format
|
|
||||||
(vconcat (mapcar (pcase-lambda (`(,title ,width ,_fn ,props))
|
|
||||||
(nconc (list title width t)
|
|
||||||
(-flatten props)))
|
|
||||||
magit-submodule-list-columns)))
|
|
||||||
(tabulated-list-init-header)
|
|
||||||
(add-hook 'tabulated-list-revert-hook 'magit-submodule-list-refresh nil t)
|
|
||||||
(setq imenu-prev-index-position-function
|
|
||||||
#'magit-imenu--submodule-prev-index-position-function)
|
|
||||||
(setq imenu-extract-index-name-function
|
|
||||||
#'magit-imenu--submodule-extract-index-name-function))
|
|
||||||
|
|
||||||
(defun magit-submodule-list-refresh ()
|
|
||||||
(setq tabulated-list-entries
|
|
||||||
(-keep (lambda (module)
|
|
||||||
(let ((default-directory
|
|
||||||
(expand-file-name (file-name-as-directory module))))
|
|
||||||
(and (file-exists-p ".git")
|
|
||||||
(list module
|
|
||||||
(vconcat
|
|
||||||
(--map (or (funcall (nth 2 it) module) "")
|
|
||||||
magit-submodule-list-columns))))))
|
|
||||||
(magit-list-module-paths))))
|
|
||||||
|
|
||||||
(defun magit-modulelist-column-path (path)
|
|
||||||
"Insert the relative path of the submodule."
|
|
||||||
path)
|
|
||||||
|
|
||||||
;;; Utilities
|
|
||||||
|
|
||||||
(defun magit-submodule--maybe-reuse-gitdir (name path)
|
|
||||||
(let ((gitdir
|
|
||||||
(magit-git-dir (convert-standard-filename (concat "modules/" name)))))
|
|
||||||
(when (and (file-exists-p gitdir)
|
|
||||||
(not (file-exists-p path)))
|
|
||||||
(pcase (read-char-choice
|
|
||||||
(concat
|
|
||||||
gitdir " already exists.\n"
|
|
||||||
"Type [u] to use the existing gitdir and create the working tree\n"
|
|
||||||
" [r] to rename the existing gitdir and clone again\n"
|
|
||||||
" [t] to trash the existing gitdir and clone again\n"
|
|
||||||
" [C-g] to abort ")
|
|
||||||
'(?u ?r ?t))
|
|
||||||
(?u (magit-submodule--restore-worktree (expand-file-name path) gitdir))
|
|
||||||
(?r (rename-file gitdir (concat gitdir "-"
|
|
||||||
(format-time-string "%F-%T"))))
|
|
||||||
(?t (delete-directory gitdir t t))))))
|
|
||||||
|
|
||||||
(defun magit-submodule--restore-worktree (worktree gitdir)
|
|
||||||
(make-directory worktree t)
|
|
||||||
(with-temp-file (expand-file-name ".git" worktree)
|
|
||||||
(insert "gitdir: " (file-relative-name gitdir worktree) "\n"))
|
|
||||||
(let ((default-directory worktree))
|
|
||||||
(magit-call-git "reset" "--hard" "HEAD" "--")))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-submodule)
|
|
||||||
;;; magit-submodule.el ends here
|
|
Binary file not shown.
|
@ -1,182 +0,0 @@
|
||||||
;;; magit-subtree.el --- subtree support for Magit -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2011-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-subtree "magit-subtree" nil t)
|
|
||||||
(define-transient-command magit-subtree ()
|
|
||||||
"Import or export subtrees."
|
|
||||||
:man-page "git-subtree"
|
|
||||||
["Actions"
|
|
||||||
("i" "Import" magit-subtree-import)
|
|
||||||
("e" "Export" magit-subtree-export)])
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-subtree-import "magit-subtree" nil t)
|
|
||||||
(define-transient-command magit-subtree-import ()
|
|
||||||
"Import subtrees."
|
|
||||||
:man-page "git-subtree"
|
|
||||||
["Arguments"
|
|
||||||
(magit-subtree:--prefix)
|
|
||||||
(magit-subtree:--message)
|
|
||||||
("-s" "Squash" "--squash")]
|
|
||||||
["Actions"
|
|
||||||
[("a" "Add" magit-subtree-add)
|
|
||||||
("c" "Add commit" magit-subtree-add-commit)]
|
|
||||||
[("m" "Merge" magit-subtree-merge)
|
|
||||||
("f" "Pull" magit-subtree-pull)]])
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-subtree-export "magit-subtree" nil t)
|
|
||||||
(define-transient-command magit-subtree-export ()
|
|
||||||
"Export subtrees."
|
|
||||||
:man-page "git-subtree"
|
|
||||||
["Arguments"
|
|
||||||
(magit-subtree:--prefix)
|
|
||||||
(magit-subtree:--annotate)
|
|
||||||
(magit-subtree:--branch)
|
|
||||||
(magit-subtree:--onto)
|
|
||||||
("-i" "Ignore joins" "--ignore-joins")
|
|
||||||
("-j" "Rejoin" "--rejoin")]
|
|
||||||
["Actions"
|
|
||||||
("p" "Push" magit-subtree-push)
|
|
||||||
("s" "Split" magit-subtree-split)])
|
|
||||||
|
|
||||||
(define-infix-argument magit-subtree:--prefix ()
|
|
||||||
:description "Prefix"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-P"
|
|
||||||
:argument "--prefix="
|
|
||||||
:reader 'magit-subtree-read-prefix)
|
|
||||||
|
|
||||||
(defun magit-subtree-read-prefix (prompt &optional default _history)
|
|
||||||
(let* ((insert-default-directory nil)
|
|
||||||
(topdir (magit-toplevel))
|
|
||||||
(prefix (read-directory-name (concat prompt ": ") topdir default)))
|
|
||||||
(if (file-name-absolute-p prefix)
|
|
||||||
;; At least `ido-mode's variant is not compatible.
|
|
||||||
(if (string-prefix-p topdir prefix)
|
|
||||||
(file-relative-name prefix topdir)
|
|
||||||
(user-error "%s isn't inside the repository at %s" prefix topdir))
|
|
||||||
prefix)))
|
|
||||||
|
|
||||||
(define-infix-argument magit-subtree:--message ()
|
|
||||||
:description "Message"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-m"
|
|
||||||
:argument "--message=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-subtree:--annotate ()
|
|
||||||
:description "Annotate"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "-a"
|
|
||||||
:argument "--annotate=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-subtree:--branch ()
|
|
||||||
:description "Branch"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-b"
|
|
||||||
:argument "--branch=")
|
|
||||||
|
|
||||||
(define-infix-argument magit-subtree:--onto ()
|
|
||||||
:description "Onto"
|
|
||||||
:class 'transient-option
|
|
||||||
:key "-o"
|
|
||||||
:argument "--onto="
|
|
||||||
:reader 'magit-transient-read-revision)
|
|
||||||
|
|
||||||
(defun magit-subtree-prefix (transient prompt)
|
|
||||||
(--if-let (--first (string-prefix-p "--prefix=" it)
|
|
||||||
(transient-args transient))
|
|
||||||
(substring it 9)
|
|
||||||
(magit-subtree-read-prefix prompt)))
|
|
||||||
|
|
||||||
(defun magit-subtree-arguments (transient)
|
|
||||||
(--remove (string-prefix-p "--prefix=" it)
|
|
||||||
(transient-args transient)))
|
|
||||||
|
|
||||||
(defun magit-git-subtree (subcmd prefix &rest args)
|
|
||||||
(magit-run-git-async "subtree" subcmd (concat "--prefix=" prefix) args))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-add (prefix repository ref args)
|
|
||||||
"Add REF from REPOSITORY as a new subtree at PREFIX."
|
|
||||||
(interactive
|
|
||||||
(cons (magit-subtree-prefix 'magit-subtree-import "Add subtree")
|
|
||||||
(let ((remote (magit-read-remote-or-url "From repository")))
|
|
||||||
(list remote
|
|
||||||
(magit-read-refspec "Ref" remote)
|
|
||||||
(magit-subtree-arguments 'magit-subtree-import)))))
|
|
||||||
(magit-git-subtree "add" prefix args repository ref))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-add-commit (prefix commit args)
|
|
||||||
"Add COMMIT as a new subtree at PREFIX."
|
|
||||||
(interactive
|
|
||||||
(list (magit-subtree-prefix 'magit-subtree-import "Add subtree")
|
|
||||||
(magit-read-string-ns "Commit")
|
|
||||||
(magit-subtree-arguments 'magit-subtree-import)))
|
|
||||||
(magit-git-subtree "add" prefix args commit))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-merge (prefix commit args)
|
|
||||||
"Merge COMMIT into the PREFIX subtree."
|
|
||||||
(interactive
|
|
||||||
(list (magit-subtree-prefix 'magit-subtree-import "Merge into subtree")
|
|
||||||
(magit-read-string-ns "Commit")
|
|
||||||
(magit-subtree-arguments 'magit-subtree-import)))
|
|
||||||
(magit-git-subtree "merge" prefix args commit))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-pull (prefix repository ref args)
|
|
||||||
"Pull REF from REPOSITORY into the PREFIX subtree."
|
|
||||||
(interactive
|
|
||||||
(cons (magit-subtree-prefix 'magit-subtree-import "Pull into subtree")
|
|
||||||
(let ((remote (magit-read-remote-or-url "From repository")))
|
|
||||||
(list remote
|
|
||||||
(magit-read-refspec "Ref" remote)
|
|
||||||
(magit-subtree-arguments 'magit-subtree-import)))))
|
|
||||||
(magit-git-subtree "pull" prefix args repository ref))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-push (prefix repository ref args)
|
|
||||||
"Extract the history of the subtree PREFIX and push it to REF on REPOSITORY."
|
|
||||||
(interactive (list (magit-subtree-prefix 'magit-subtree-export "Push subtree")
|
|
||||||
(magit-read-remote-or-url "To repository")
|
|
||||||
(magit-read-string-ns "To reference")
|
|
||||||
(magit-subtree-arguments 'magit-subtree-export)))
|
|
||||||
(magit-git-subtree "push" prefix args repository ref))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-subtree-split (prefix commit args)
|
|
||||||
"Extract the history of the subtree PREFIX."
|
|
||||||
(interactive (list (magit-subtree-prefix 'magit-subtree-export "Split subtree")
|
|
||||||
(magit-read-string-ns "Commit")
|
|
||||||
(magit-subtree-arguments 'magit-subtree-export)))
|
|
||||||
(magit-git-subtree "split" prefix args commit))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-subtree)
|
|
||||||
;;; magit-subtree.el ends here
|
|
Binary file not shown.
|
@ -1,193 +0,0 @@
|
||||||
;;; magit-tag.el --- tag functionality -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements tag commands.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-tag "magit" nil t)
|
|
||||||
(define-transient-command magit-tag ()
|
|
||||||
"Create or delete a tag."
|
|
||||||
:man-page "git-tag"
|
|
||||||
["Arguments"
|
|
||||||
("-f" "Force" ("-f" "--force"))
|
|
||||||
("-a" "Annotate" ("-a" "--annotate"))
|
|
||||||
("-s" "Sign" ("-s" "--sign"))
|
|
||||||
(magit-tag:--local-user)]
|
|
||||||
[["Create"
|
|
||||||
("t" "tag" magit-tag-create)
|
|
||||||
("r" "release" magit-tag-release)]
|
|
||||||
["Do"
|
|
||||||
("k" "delete" magit-tag-delete)
|
|
||||||
("p" "prune" magit-tag-prune)]])
|
|
||||||
|
|
||||||
(defun magit-tag-arguments ()
|
|
||||||
(transient-args 'magit-tag))
|
|
||||||
|
|
||||||
(define-infix-argument magit-tag:--local-user ()
|
|
||||||
:description "Sign as"
|
|
||||||
:class 'transient-option
|
|
||||||
:shortarg "-u"
|
|
||||||
:argument "--local-user="
|
|
||||||
:reader 'magit-read-gpg-secret-key
|
|
||||||
:history-key 'magit:--gpg-sign)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-tag-create (name rev &optional args)
|
|
||||||
"Create a new tag with the given NAME at REV.
|
|
||||||
With a prefix argument annotate the tag.
|
|
||||||
\n(git tag [--annotate] NAME REV)"
|
|
||||||
(interactive (list (magit-read-tag "Tag name")
|
|
||||||
(magit-read-branch-or-commit "Place tag on")
|
|
||||||
(let ((args (magit-tag-arguments)))
|
|
||||||
(when current-prefix-arg
|
|
||||||
(cl-pushnew "--annotate" args))
|
|
||||||
args)))
|
|
||||||
(magit-run-git-with-editor "tag" args name rev))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-tag-delete (tags)
|
|
||||||
"Delete one or more tags.
|
|
||||||
If the region marks multiple tags (and nothing else), then offer
|
|
||||||
to delete those, otherwise prompt for a single tag to be deleted,
|
|
||||||
defaulting to the tag at point.
|
|
||||||
\n(git tag -d TAGS)"
|
|
||||||
(interactive (list (--if-let (magit-region-values 'tag)
|
|
||||||
(magit-confirm t nil "Delete %i tags" nil it)
|
|
||||||
(magit-read-tag "Delete tag" t))))
|
|
||||||
(magit-run-git "tag" "-d" tags))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-tag-prune (tags remote-tags remote)
|
|
||||||
"Offer to delete tags missing locally from REMOTE, and vice versa."
|
|
||||||
(interactive
|
|
||||||
(let* ((remote (magit-read-remote "Prune tags using remote"))
|
|
||||||
(tags (magit-list-tags))
|
|
||||||
(rtags (prog2 (message "Determining remote tags...")
|
|
||||||
(magit-remote-list-tags remote)
|
|
||||||
(message "Determining remote tags...done")))
|
|
||||||
(ltags (-difference tags rtags))
|
|
||||||
(rtags (-difference rtags tags)))
|
|
||||||
(unless (or ltags rtags)
|
|
||||||
(message "Same tags exist locally and remotely"))
|
|
||||||
(unless (magit-confirm t
|
|
||||||
"Delete %s locally"
|
|
||||||
"Delete %i tags locally"
|
|
||||||
'noabort ltags)
|
|
||||||
(setq ltags nil))
|
|
||||||
(unless (magit-confirm t
|
|
||||||
"Delete %s from remote"
|
|
||||||
"Delete %i tags from remote"
|
|
||||||
'noabort rtags)
|
|
||||||
(setq rtags nil))
|
|
||||||
(list ltags rtags remote)))
|
|
||||||
(when tags
|
|
||||||
(magit-call-git "tag" "-d" tags))
|
|
||||||
(when remote-tags
|
|
||||||
(magit-run-git-async "push" remote (--map (concat ":" it) remote-tags))))
|
|
||||||
|
|
||||||
(defvar magit-release-tag-regexp "\\`\
|
|
||||||
\\(?1:\\(?:v\\(?:ersion\\)?\\|r\\(?:elease\\)?\\)?[-_]?\\)?\
|
|
||||||
\\(?2:[0-9]+\\(?:\\.[0-9]+\\)*\\)\\'"
|
|
||||||
"Regexp used to parse release tag names.
|
|
||||||
The first submatch must match the prefix, if any.
|
|
||||||
The second submatch must match the version string.")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-tag-release (tag msg)
|
|
||||||
"Create an annotated release tag.
|
|
||||||
|
|
||||||
Assume that release tags match `magit-release-tag-regexp'.
|
|
||||||
|
|
||||||
First prompt for the name of the new tag using the highest
|
|
||||||
existing tag as initial input and leaving it to the user to
|
|
||||||
increment the desired part of the version string.
|
|
||||||
|
|
||||||
Then prompt for the message of the new tag. Base the proposed
|
|
||||||
tag message on the message of the highest tag, provided that
|
|
||||||
that contains the corresponding version string and substituting
|
|
||||||
the new version string for that. Otherwise propose something
|
|
||||||
like \"Foo-Bar 1.2.3\", given, for example, a TAG \"v1.2.3\" and a
|
|
||||||
repository located at something like \"/path/to/foo-bar\".
|
|
||||||
|
|
||||||
Then call \"git tag --annotate --sign -m MSG TAG\" to create the,
|
|
||||||
tag, regardless of whether these arguments are enabled in the
|
|
||||||
popup. Finally show the refs buffer to let the user quickly
|
|
||||||
review the result."
|
|
||||||
(interactive
|
|
||||||
(save-match-data
|
|
||||||
(pcase-let*
|
|
||||||
((`(,pver ,ptag ,pmsg) (car (magit--list-releases)))
|
|
||||||
(tag (read-string "Create release tag: " ptag))
|
|
||||||
(ver (and (string-match magit-release-tag-regexp tag)
|
|
||||||
(match-string 2 tag)))
|
|
||||||
(msg (cond ((and pver (string-match (regexp-quote pver) pmsg))
|
|
||||||
(replace-match ver t t pmsg))
|
|
||||||
((and ptag (string-match (regexp-quote ptag) pmsg))
|
|
||||||
(replace-match tag t t pmsg))
|
|
||||||
(t (format "%s %s"
|
|
||||||
(capitalize
|
|
||||||
(file-name-nondirectory
|
|
||||||
(directory-file-name (magit-toplevel))))
|
|
||||||
ver)))))
|
|
||||||
(list tag (read-string (format "Message for %S: " tag) msg)))))
|
|
||||||
(magit-run-git-async "tag" "--annotate" "--sign" "-m" msg tag)
|
|
||||||
(set-process-sentinel
|
|
||||||
magit-this-process
|
|
||||||
(lambda (process event)
|
|
||||||
(when (memq (process-status process) '(exit signal))
|
|
||||||
(magit-process-sentinel process event)
|
|
||||||
(magit-refs-setup-buffer "HEAD" (magit-show-refs-arguments))))))
|
|
||||||
|
|
||||||
(defun magit--list-releases ()
|
|
||||||
"Return a list of releases.
|
|
||||||
The list is ordered, beginning with the highest release.
|
|
||||||
Each release element has the form (VERSION TAG MESSAGE).
|
|
||||||
`magit-release-tag-regexp' is used to determine whether
|
|
||||||
a tag qualifies as a release tag."
|
|
||||||
(save-match-data
|
|
||||||
(mapcar
|
|
||||||
#'cdr
|
|
||||||
(nreverse
|
|
||||||
(cl-sort (cl-mapcan
|
|
||||||
(lambda (line)
|
|
||||||
(and (string-match " +" line)
|
|
||||||
(let ((tag (substring line 0 (match-beginning 0)))
|
|
||||||
(msg (substring line (match-end 0))))
|
|
||||||
(and (string-match magit-release-tag-regexp tag)
|
|
||||||
(let ((ver (match-string 2 tag)))
|
|
||||||
(list (list (version-to-list ver)
|
|
||||||
ver tag msg)))))))
|
|
||||||
;; Cannot rely on "--sort=-version:refname" because
|
|
||||||
;; that gets confused if the version prefix has changed.
|
|
||||||
(magit-git-lines "tag" "-n"))
|
|
||||||
;; The inverse of this function does not exist.
|
|
||||||
#'version-list-< :key #'car)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-tag)
|
|
||||||
;;; magit-tag.el ends here
|
|
Binary file not shown.
|
@ -1,202 +0,0 @@
|
||||||
;;; magit-transient.el --- support for transients -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements Magit-specific prefix and suffix classes,
|
|
||||||
;; and their methods.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'transient)
|
|
||||||
|
|
||||||
(require 'magit-git)
|
|
||||||
(require 'magit-mode)
|
|
||||||
(require 'magit-process)
|
|
||||||
|
|
||||||
;;; Classes
|
|
||||||
|
|
||||||
(defclass magit--git-variable (transient-variable)
|
|
||||||
((scope :initarg :scope)))
|
|
||||||
|
|
||||||
(defclass magit--git-variable:choices (magit--git-variable)
|
|
||||||
((choices :initarg :choices)
|
|
||||||
(fallback :initarg :fallback :initform nil)
|
|
||||||
(default :initarg :default :initform nil)))
|
|
||||||
|
|
||||||
(defclass magit--git-variable:urls (magit--git-variable)
|
|
||||||
((seturl-arg :initarg :seturl-arg :initform nil)))
|
|
||||||
|
|
||||||
;;; Methods
|
|
||||||
;;;; Init
|
|
||||||
|
|
||||||
(cl-defmethod transient-init-scope ((obj magit--git-variable))
|
|
||||||
(oset obj scope
|
|
||||||
(cond (transient--prefix
|
|
||||||
(oref transient--prefix scope))
|
|
||||||
((slot-boundp obj 'scope)
|
|
||||||
(funcall (oref obj scope) obj)))))
|
|
||||||
|
|
||||||
(cl-defmethod transient-init-value ((obj magit--git-variable))
|
|
||||||
(let ((variable (format (oref obj variable)
|
|
||||||
(oref obj scope))))
|
|
||||||
(oset obj variable variable)
|
|
||||||
(oset obj value
|
|
||||||
(cond ((oref obj multi-value)
|
|
||||||
(magit-get-all variable))
|
|
||||||
(t
|
|
||||||
(magit-git-string "config" "--local" variable))))))
|
|
||||||
|
|
||||||
;;;; Read
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-read :around ((obj magit--git-variable:urls))
|
|
||||||
(mapcar (lambda (url)
|
|
||||||
(if (string-prefix-p "~" url)
|
|
||||||
(expand-file-name url)
|
|
||||||
url))
|
|
||||||
(cl-call-next-method obj)))
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-read ((obj magit--git-variable:choices))
|
|
||||||
(let ((choices (oref obj choices)))
|
|
||||||
(when (functionp choices)
|
|
||||||
(setq choices (funcall choices)))
|
|
||||||
(if-let ((value (oref obj value)))
|
|
||||||
(cadr (member value choices))
|
|
||||||
(car choices))))
|
|
||||||
|
|
||||||
;;;; Readers
|
|
||||||
|
|
||||||
(defun magit-transient-read-person (prompt initial-input history)
|
|
||||||
(magit-completing-read
|
|
||||||
prompt
|
|
||||||
(mapcar (lambda (line)
|
|
||||||
(save-excursion
|
|
||||||
(and (string-match "\\`[\s\t]+[0-9]+\t" line)
|
|
||||||
(list (substring line (match-end 0))))))
|
|
||||||
(magit-git-lines "shortlog" "-n" "-s" "-e" "HEAD"))
|
|
||||||
nil nil initial-input history))
|
|
||||||
|
|
||||||
(defun magit-transient-read-revision (prompt initial-input history)
|
|
||||||
(or (magit-completing-read prompt (cons "HEAD" (magit-list-refnames))
|
|
||||||
nil nil initial-input history
|
|
||||||
(or (magit-branch-or-commit-at-point)
|
|
||||||
(magit-get-current-branch)))
|
|
||||||
(user-error "Nothing selected")))
|
|
||||||
|
|
||||||
;;;; Set
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-set ((obj magit--git-variable) value)
|
|
||||||
(let ((variable (oref obj variable)))
|
|
||||||
(oset obj value value)
|
|
||||||
(if (oref obj multi-value)
|
|
||||||
(magit-set-all value variable)
|
|
||||||
(magit-set value variable))
|
|
||||||
(magit-refresh)
|
|
||||||
(unless (or value transient--prefix)
|
|
||||||
(message "Unset %s" variable))))
|
|
||||||
|
|
||||||
(cl-defmethod transient-infix-set ((obj magit--git-variable:urls) values)
|
|
||||||
(let ((previous (oref obj value))
|
|
||||||
(seturl (oref obj seturl-arg))
|
|
||||||
(remote (oref transient--prefix scope)))
|
|
||||||
(oset obj value values)
|
|
||||||
(dolist (v (-difference values previous))
|
|
||||||
(magit-call-git "remote" "set-url" seturl "--add" remote v))
|
|
||||||
(dolist (v (-difference previous values))
|
|
||||||
(magit-call-git "remote" "set-url" seturl "--delete" remote
|
|
||||||
(concat "^" (regexp-quote v) "$")))
|
|
||||||
(magit-refresh)))
|
|
||||||
|
|
||||||
;;;; Draw
|
|
||||||
|
|
||||||
(cl-defmethod transient-format-description ((obj magit--git-variable))
|
|
||||||
(or (oref obj description)
|
|
||||||
(oref obj variable)))
|
|
||||||
|
|
||||||
(cl-defmethod transient-format-value ((obj magit--git-variable))
|
|
||||||
(if-let ((value (oref obj value)))
|
|
||||||
(if (oref obj multi-value)
|
|
||||||
(if (cdr value)
|
|
||||||
(mapconcat (lambda (v)
|
|
||||||
(concat "\n "
|
|
||||||
(propertize v 'face 'transient-value)))
|
|
||||||
value "")
|
|
||||||
(propertize (car value) 'face 'transient-value))
|
|
||||||
(propertize (car (split-string value "\n"))
|
|
||||||
'face 'transient-value))
|
|
||||||
(propertize "unset" 'face 'transient-inactive-value)))
|
|
||||||
|
|
||||||
(cl-defmethod transient-format-value ((obj magit--git-variable:choices))
|
|
||||||
(let* ((variable (oref obj variable))
|
|
||||||
(choices (oref obj choices))
|
|
||||||
(local (magit-git-string "config" "--local" variable))
|
|
||||||
(global (magit-git-string "config" "--global" variable))
|
|
||||||
(default (oref obj default))
|
|
||||||
(fallback (oref obj fallback))
|
|
||||||
(fallback (and fallback
|
|
||||||
(when-let ((val (magit-get fallback)))
|
|
||||||
(concat fallback ":" val)))))
|
|
||||||
(when (functionp choices)
|
|
||||||
(setq choices (funcall choices)))
|
|
||||||
(concat
|
|
||||||
(propertize "[" 'face 'transient-inactive-value)
|
|
||||||
(mapconcat (lambda (choice)
|
|
||||||
(propertize choice 'face (if (equal choice local)
|
|
||||||
(if (member choice choices)
|
|
||||||
'transient-value
|
|
||||||
'font-lock-warning-face)
|
|
||||||
'transient-inactive-value)))
|
|
||||||
(if (and local (not (member local choices)))
|
|
||||||
(cons local choices)
|
|
||||||
choices)
|
|
||||||
(propertize "|" 'face 'transient-inactive-value))
|
|
||||||
(and (or global fallback default)
|
|
||||||
(concat
|
|
||||||
(propertize "|" 'face 'transient-inactive-value)
|
|
||||||
(cond (global
|
|
||||||
(propertize (concat "global:" global)
|
|
||||||
'face (cond (local
|
|
||||||
'transient-inactive-value)
|
|
||||||
((member global choices)
|
|
||||||
'transient-value)
|
|
||||||
(t
|
|
||||||
'font-lock-warning-face))))
|
|
||||||
(fallback
|
|
||||||
(propertize fallback
|
|
||||||
'face (if local
|
|
||||||
'transient-inactive-value
|
|
||||||
'transient-value)))
|
|
||||||
(default
|
|
||||||
(propertize (concat "default:" default)
|
|
||||||
'face (if local
|
|
||||||
'transient-inactive-value
|
|
||||||
'transient-value))))))
|
|
||||||
(propertize "]" 'face 'transient-inactive-value))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-transient)
|
|
||||||
;;; magit-transient.el ends here
|
|
||||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load diff
Binary file not shown.
|
@ -1,432 +0,0 @@
|
||||||
;;; magit-wip.el --- commit snapshots to work-in-progress refs -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library defines tree global modes which automatically commit
|
|
||||||
;; snapshots to branch-specific work-in-progress refs before and after
|
|
||||||
;; making changes, and two commands which can be used to do so on
|
|
||||||
;; demand.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(eval-when-compile
|
|
||||||
(require 'subr-x))
|
|
||||||
|
|
||||||
(require 'magit-core)
|
|
||||||
(require 'magit-log)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defgroup magit-wip nil
|
|
||||||
"Automatically commit to work-in-progress refs."
|
|
||||||
:link '(info-link "(magit)Wip Modes")
|
|
||||||
:group 'magit-modes
|
|
||||||
:group 'magit-essentials)
|
|
||||||
|
|
||||||
(defgroup magit-wip-legacy nil
|
|
||||||
"It is better to not use these modes individually."
|
|
||||||
:link '(info-link "(magit)Legacy Wip Modes")
|
|
||||||
:group 'magit-wip)
|
|
||||||
|
|
||||||
(defcustom magit-wip-mode-lighter " Wip"
|
|
||||||
"Lighter for Magit-Wip mode."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-wip-after-save-local-mode-lighter ""
|
|
||||||
"Lighter for Magit-Wip-After-Save-Local mode."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip-legacy
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-wip-after-apply-mode-lighter ""
|
|
||||||
"Lighter for Magit-Wip-After-Apply mode."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip-legacy
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-wip-before-change-mode-lighter ""
|
|
||||||
"Lighter for Magit-Wip-Before-Change mode."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip-legacy
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-wip-initial-backup-mode-lighter ""
|
|
||||||
"Lighter for Magit-Wip-Initial Backup mode."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip-legacy
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
(defcustom magit-wip-merge-branch nil
|
|
||||||
"Whether to merge the current branch into its wip ref.
|
|
||||||
|
|
||||||
If non-nil and the current branch has new commits, then it is
|
|
||||||
merged into the wip ref before creating a new wip commit. This
|
|
||||||
makes it easier to inspect wip history and the wip commits are
|
|
||||||
never garbage collected.
|
|
||||||
|
|
||||||
If nil and the current branch has new commits, then the wip ref
|
|
||||||
is reset to the tip of the branch before creating a new wip
|
|
||||||
commit. With this setting wip commits are eventually garbage
|
|
||||||
collected. This is currently the default."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defcustom magit-wip-namespace "refs/wip/"
|
|
||||||
"Namespace used for work-in-progress refs.
|
|
||||||
The wip refs are named \"<namespace/>index/<branchref>\"
|
|
||||||
and \"<namespace/>wtree/<branchref>\". When snapshots
|
|
||||||
are created while the `HEAD' is detached then \"HEAD\"
|
|
||||||
is used as `branch-ref'."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:type 'string)
|
|
||||||
|
|
||||||
;;; Modes
|
|
||||||
|
|
||||||
(define-minor-mode magit-wip-mode
|
|
||||||
"Save uncommitted changes to work-in-progress refs.
|
|
||||||
|
|
||||||
Whenever appropriate (i.e. when dataloss would be a possibility
|
|
||||||
otherwise) this mode causes uncommitted changes to be committed
|
|
||||||
to dedicated work-in-progress refs.
|
|
||||||
|
|
||||||
For historic reasons this mode is implemented on top of four
|
|
||||||
other `magit-wip-*' modes, which can also be used individually,
|
|
||||||
if you want finer control over when the wip refs are updated;
|
|
||||||
but that is discouraged."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:lighter magit-wip-mode-lighter
|
|
||||||
:global t
|
|
||||||
(let ((arg (if magit-wip-mode 1 -1)))
|
|
||||||
(magit-wip-after-save-mode arg)
|
|
||||||
(magit-wip-after-apply-mode arg)
|
|
||||||
(magit-wip-before-change-mode arg)
|
|
||||||
(magit-wip-initial-backup-mode arg)))
|
|
||||||
|
|
||||||
(define-minor-mode magit-wip-after-save-local-mode
|
|
||||||
"After saving, also commit to a worktree work-in-progress ref.
|
|
||||||
|
|
||||||
After saving the current file-visiting buffer this mode also
|
|
||||||
commits the changes to the worktree work-in-progress ref for
|
|
||||||
the current branch.
|
|
||||||
|
|
||||||
This mode should be enabled globally by turning on the globalized
|
|
||||||
variant `magit-wip-after-save-mode'."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:lighter magit-wip-after-save-local-mode-lighter
|
|
||||||
(if magit-wip-after-save-local-mode
|
|
||||||
(if (and buffer-file-name (magit-inside-worktree-p t))
|
|
||||||
(add-hook 'after-save-hook 'magit-wip-commit-buffer-file t t)
|
|
||||||
(setq magit-wip-after-save-local-mode nil)
|
|
||||||
(user-error "Need a worktree and a file"))
|
|
||||||
(remove-hook 'after-save-hook 'magit-wip-commit-buffer-file t)))
|
|
||||||
|
|
||||||
(defun magit-wip-after-save-local-mode-turn-on ()
|
|
||||||
(and buffer-file-name
|
|
||||||
(magit-inside-worktree-p t)
|
|
||||||
(magit-file-tracked-p buffer-file-name)
|
|
||||||
(magit-wip-after-save-local-mode)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-globalized-minor-mode magit-wip-after-save-mode
|
|
||||||
magit-wip-after-save-local-mode magit-wip-after-save-local-mode-turn-on
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip)
|
|
||||||
|
|
||||||
(defun magit-wip-commit-buffer-file (&optional msg)
|
|
||||||
"Commit visited file to a worktree work-in-progress ref.
|
|
||||||
|
|
||||||
Also see `magit-wip-after-save-mode' which calls this function
|
|
||||||
automatically whenever a buffer visiting a tracked file is saved."
|
|
||||||
(interactive)
|
|
||||||
(--when-let (magit-wip-get-ref)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(let ((file (file-relative-name buffer-file-name)))
|
|
||||||
(magit-wip-commit-worktree
|
|
||||||
it (list file)
|
|
||||||
(format (cond (msg)
|
|
||||||
((called-interactively-p 'any)
|
|
||||||
"wip-save %s after save")
|
|
||||||
(t
|
|
||||||
"autosave %s after save"))
|
|
||||||
file))))))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-minor-mode magit-wip-after-apply-mode
|
|
||||||
"Commit to work-in-progress refs.
|
|
||||||
|
|
||||||
After applying a change using any \"apply variant\"
|
|
||||||
command (apply, stage, unstage, discard, and reverse) commit the
|
|
||||||
affected files to the current wip refs. For each branch there
|
|
||||||
may be two wip refs; one contains snapshots of the files as found
|
|
||||||
in the worktree and the other contains snapshots of the entries
|
|
||||||
in the index."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:lighter magit-wip-after-apply-mode-lighter
|
|
||||||
:global t)
|
|
||||||
|
|
||||||
(defun magit-wip-commit-after-apply (&optional files msg)
|
|
||||||
(when magit-wip-after-apply-mode
|
|
||||||
(magit-wip-commit files msg)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(define-minor-mode magit-wip-before-change-mode
|
|
||||||
"Commit to work-in-progress refs before certain destructive changes.
|
|
||||||
|
|
||||||
Before invoking a revert command or an \"apply variant\"
|
|
||||||
command (apply, stage, unstage, discard, and reverse) commit the
|
|
||||||
affected tracked files to the current wip refs. For each branch
|
|
||||||
there may be two wip refs; one contains snapshots of the files
|
|
||||||
as found in the worktree and the other contains snapshots of the
|
|
||||||
entries in the index.
|
|
||||||
|
|
||||||
Only changes to files which could potentially be affected by the
|
|
||||||
command which is about to be called are committed."
|
|
||||||
:package-version '(magit . "2.1.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:lighter magit-wip-before-change-mode-lighter
|
|
||||||
:global t)
|
|
||||||
|
|
||||||
(defun magit-wip-commit-before-change (&optional files msg)
|
|
||||||
(when magit-wip-before-change-mode
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-wip-commit files msg))))
|
|
||||||
|
|
||||||
(define-minor-mode magit-wip-initial-backup-mode
|
|
||||||
"Before saving a buffer for the first time, commit to a wip ref."
|
|
||||||
:package-version '(magit . "2.90.0")
|
|
||||||
:group 'magit-wip
|
|
||||||
:lighter magit-wip-initial-backup-mode-lighter
|
|
||||||
:global t
|
|
||||||
(if magit-wip-initial-backup-mode
|
|
||||||
(add-hook 'before-save-hook 'magit-wip-commit-initial-backup)
|
|
||||||
(remove-hook 'before-save-hook 'magit-wip-commit-initial-backup)))
|
|
||||||
|
|
||||||
(defvar-local magit-wip-buffer-backed-up nil)
|
|
||||||
(put 'magit-wip-buffer-backed-up 'permanent-local t)
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-wip-commit-initial-backup ()
|
|
||||||
"Before saving, commit current file to a worktree wip ref.
|
|
||||||
|
|
||||||
The user has to add this function to `before-save-hook'.
|
|
||||||
|
|
||||||
Commit the current state of the visited file before saving the
|
|
||||||
current buffer to that file. This backs up the same version of
|
|
||||||
the file as `backup-buffer' would, but stores the backup in the
|
|
||||||
worktree wip ref, which is also used by the various Magit Wip
|
|
||||||
modes, instead of in a backup file as `backup-buffer' would.
|
|
||||||
|
|
||||||
This function ignores the variables that affect `backup-buffer'
|
|
||||||
and can be used along-side that function, which is recommended
|
|
||||||
because this function only backs up files that are tracked in
|
|
||||||
a Git repository."
|
|
||||||
(when (and (not magit-wip-buffer-backed-up)
|
|
||||||
buffer-file-name
|
|
||||||
(magit-inside-worktree-p t)
|
|
||||||
(magit-file-tracked-p buffer-file-name))
|
|
||||||
(let ((magit-save-repository-buffers nil))
|
|
||||||
(magit-wip-commit-buffer-file "autosave %s before save"))
|
|
||||||
(setq magit-wip-buffer-backed-up t)))
|
|
||||||
|
|
||||||
;;; Core
|
|
||||||
|
|
||||||
(defun magit-wip-commit (&optional files msg)
|
|
||||||
"Commit all tracked files to the work-in-progress refs.
|
|
||||||
|
|
||||||
Interactively, commit all changes to all tracked files using
|
|
||||||
a generic commit message. With a prefix-argument the commit
|
|
||||||
message is read in the minibuffer.
|
|
||||||
|
|
||||||
Non-interactively, only commit changes to FILES using MSG as
|
|
||||||
commit message."
|
|
||||||
(interactive (list nil (if current-prefix-arg
|
|
||||||
(magit-read-string "Wip commit message")
|
|
||||||
"wip-save tracked files")))
|
|
||||||
(--when-let (magit-wip-get-ref)
|
|
||||||
(magit-wip-commit-index it files msg)
|
|
||||||
(magit-wip-commit-worktree it files msg)))
|
|
||||||
|
|
||||||
(defun magit-wip-commit-index (ref files msg)
|
|
||||||
(let* ((wipref (magit--wip-index-ref ref))
|
|
||||||
(parent (magit-wip-get-parent ref wipref))
|
|
||||||
(tree (magit-git-string "write-tree")))
|
|
||||||
(magit-wip-update-wipref ref wipref tree parent files msg "index")))
|
|
||||||
|
|
||||||
(defun magit-wip-commit-worktree (ref files msg)
|
|
||||||
(let* ((wipref (magit--wip-wtree-ref ref))
|
|
||||||
(parent (magit-wip-get-parent ref wipref))
|
|
||||||
(tree (magit-with-temp-index parent "--reset"
|
|
||||||
(if files
|
|
||||||
(magit-call-git "add" "--" files)
|
|
||||||
(magit-with-toplevel
|
|
||||||
(magit-call-git "add" "-u" ".")))
|
|
||||||
(magit-git-string "write-tree"))))
|
|
||||||
(magit-wip-update-wipref ref wipref tree parent files msg "worktree")))
|
|
||||||
|
|
||||||
(defun magit-wip-update-wipref (ref wipref tree parent files msg start-msg)
|
|
||||||
(cond
|
|
||||||
((and (not (equal parent wipref))
|
|
||||||
(or (not magit-wip-merge-branch)
|
|
||||||
(not (magit-rev-verify wipref))))
|
|
||||||
(setq start-msg (concat "start autosaving " start-msg))
|
|
||||||
(magit-update-ref wipref start-msg
|
|
||||||
(magit-git-string "commit-tree" "--no-gpg-sign"
|
|
||||||
"-p" parent "-m" start-msg
|
|
||||||
(concat parent "^{tree}")))
|
|
||||||
(setq parent wipref))
|
|
||||||
((and magit-wip-merge-branch
|
|
||||||
(or (not (magit-rev-ancestor-p ref wipref))
|
|
||||||
(not (magit-rev-ancestor-p
|
|
||||||
(concat (magit-git-string "log" "--format=%H"
|
|
||||||
"-1" "--merges" wipref)
|
|
||||||
"^2")
|
|
||||||
ref))))
|
|
||||||
(setq start-msg (format "merge %s into %s" ref start-msg))
|
|
||||||
(magit-update-ref wipref start-msg
|
|
||||||
(magit-git-string "commit-tree" "--no-gpg-sign"
|
|
||||||
"-p" wipref "-p" ref
|
|
||||||
"-m" start-msg
|
|
||||||
(concat ref "^{tree}")))
|
|
||||||
(setq parent wipref)))
|
|
||||||
(when (magit-git-failure "diff-tree" "--quiet" parent tree "--" files)
|
|
||||||
(unless (and msg (not (= (aref msg 0) ?\s)))
|
|
||||||
(let ((len (length files)))
|
|
||||||
(setq msg (concat
|
|
||||||
(cond ((= len 0) "autosave tracked files")
|
|
||||||
((> len 1) (format "autosave %s files" len))
|
|
||||||
(t (concat "autosave "
|
|
||||||
(file-relative-name (car files)
|
|
||||||
(magit-toplevel)))))
|
|
||||||
msg))))
|
|
||||||
(magit-update-ref wipref msg
|
|
||||||
(magit-git-string "commit-tree" "--no-gpg-sign"
|
|
||||||
"-p" parent "-m" msg tree))))
|
|
||||||
|
|
||||||
(defun magit-wip-get-ref ()
|
|
||||||
(let ((ref (or (magit-git-string "symbolic-ref" "HEAD") "HEAD")))
|
|
||||||
(and (magit-rev-verify ref)
|
|
||||||
ref)))
|
|
||||||
|
|
||||||
(defun magit-wip-get-parent (ref wipref)
|
|
||||||
(if (and (magit-rev-verify wipref)
|
|
||||||
(equal (magit-git-string "merge-base" wipref ref)
|
|
||||||
(magit-rev-verify ref)))
|
|
||||||
wipref
|
|
||||||
ref))
|
|
||||||
|
|
||||||
(defun magit--wip-index-ref (&optional ref)
|
|
||||||
(magit--wip-ref "index/" ref))
|
|
||||||
|
|
||||||
(defun magit--wip-wtree-ref (&optional ref)
|
|
||||||
(magit--wip-ref "wtree/" ref))
|
|
||||||
|
|
||||||
(defun magit--wip-ref (namespace &optional ref)
|
|
||||||
(concat magit-wip-namespace namespace
|
|
||||||
(or (and ref (string-prefix-p "refs/" ref) ref)
|
|
||||||
(when-let ((branch (or ref (magit-get-current-branch))))
|
|
||||||
(concat "refs/heads/" branch))
|
|
||||||
"HEAD")))
|
|
||||||
|
|
||||||
(defun magit-wip-maybe-add-commit-hook ()
|
|
||||||
(when (and magit-wip-merge-branch
|
|
||||||
(magit-wip-any-enabled-p))
|
|
||||||
(add-hook 'git-commit-post-finish-hook 'magit-wip-commit nil t)))
|
|
||||||
|
|
||||||
(defun magit-wip-any-enabled-p ()
|
|
||||||
(or magit-wip-mode
|
|
||||||
magit-wip-after-save-local-mode
|
|
||||||
magit-wip-after-save-mode
|
|
||||||
magit-wip-after-apply-mode
|
|
||||||
magit-wip-before-change-mode
|
|
||||||
magit-wip-initial-backup-mode))
|
|
||||||
|
|
||||||
;;; Log
|
|
||||||
|
|
||||||
(defun magit-wip-log-index (args files)
|
|
||||||
"Show log for the index wip ref of the current branch."
|
|
||||||
(interactive (magit-log-arguments))
|
|
||||||
(magit-log-setup-buffer (list (magit--wip-index-ref)) args files))
|
|
||||||
|
|
||||||
(defun magit-wip-log-worktree (args files)
|
|
||||||
"Show log for the worktree wip ref of the current branch."
|
|
||||||
(interactive (magit-log-arguments))
|
|
||||||
(magit-log-setup-buffer (list (magit--wip-wtree-ref)) args files))
|
|
||||||
|
|
||||||
(defun magit-wip-log-current (branch args files count)
|
|
||||||
"Show log for the current branch and its wip refs.
|
|
||||||
With a negative prefix argument only show the worktree wip ref.
|
|
||||||
The absolute numeric value of the prefix argument controls how
|
|
||||||
many \"branches\" of each wip ref are shown."
|
|
||||||
(interactive
|
|
||||||
(nconc (list (or (magit-get-current-branch) "HEAD"))
|
|
||||||
(magit-log-arguments)
|
|
||||||
(list (prefix-numeric-value current-prefix-arg))))
|
|
||||||
(magit-wip-log branch args files count))
|
|
||||||
|
|
||||||
(defun magit-wip-log (branch args files count)
|
|
||||||
"Show log for a branch and its wip refs.
|
|
||||||
With a negative prefix argument only show the worktree wip ref.
|
|
||||||
The absolute numeric value of the prefix argument controls how
|
|
||||||
many \"branches\" of each wip ref are shown."
|
|
||||||
(interactive
|
|
||||||
(nconc (list (magit-completing-read
|
|
||||||
"Log branch and its wip refs"
|
|
||||||
(-snoc (magit-list-local-branch-names) "HEAD")
|
|
||||||
nil t nil 'magit-revision-history
|
|
||||||
(or (magit-branch-at-point)
|
|
||||||
(magit-get-current-branch)
|
|
||||||
"HEAD")))
|
|
||||||
(magit-log-arguments)
|
|
||||||
(list (prefix-numeric-value current-prefix-arg))))
|
|
||||||
(magit-log-setup-buffer (nconc (list branch)
|
|
||||||
(magit-wip-log-get-tips
|
|
||||||
(magit--wip-wtree-ref branch)
|
|
||||||
(abs count))
|
|
||||||
(and (>= count 0)
|
|
||||||
(magit-wip-log-get-tips
|
|
||||||
(magit--wip-index-ref branch)
|
|
||||||
(abs count))))
|
|
||||||
args files))
|
|
||||||
|
|
||||||
(defun magit-wip-log-get-tips (wipref count)
|
|
||||||
(when-let ((reflog (magit-git-lines "reflog" wipref)))
|
|
||||||
(let (tips)
|
|
||||||
(while (and reflog (> count 1))
|
|
||||||
(setq reflog (cl-member "^[^ ]+ [^:]+: restart autosaving"
|
|
||||||
reflog :test #'string-match-p))
|
|
||||||
(when (and (cadr reflog)
|
|
||||||
(string-match "^[^ ]+ \\([^:]+\\)" (cadr reflog)))
|
|
||||||
(push (match-string 1 (cadr reflog)) tips))
|
|
||||||
(setq reflog (cddr reflog))
|
|
||||||
(cl-decf count))
|
|
||||||
(cons wipref (nreverse tips)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-wip)
|
|
||||||
;;; magit-wip.el ends here
|
|
Binary file not shown.
|
@ -1,184 +0,0 @@
|
||||||
;;; magit-worktree.el --- worktree support -*- lexical-binding: t -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2010-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; This library implements support for `git-worktree'.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'magit)
|
|
||||||
|
|
||||||
;;; Options
|
|
||||||
|
|
||||||
(defcustom magit-worktree-read-directory-name-function 'read-directory-name
|
|
||||||
"Function used to read a directory for worktree commands.
|
|
||||||
This is called with one argument, the prompt, and can be used
|
|
||||||
to e.g. use a base directory other than `default-directory'.
|
|
||||||
Used by `magit-worktree-checkout' and `magit-worktree-branch'."
|
|
||||||
:package-version '(magit . "2.91.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'function)
|
|
||||||
|
|
||||||
;;; Commands
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-worktree "magit-worktree" nil t)
|
|
||||||
(define-transient-command magit-worktree ()
|
|
||||||
"Act on a worktree."
|
|
||||||
:man-page "git-worktree"
|
|
||||||
[["Create new"
|
|
||||||
("b" "worktree" magit-worktree-checkout)
|
|
||||||
("c" "branch and worktree" magit-worktree-branch)]
|
|
||||||
["Commands"
|
|
||||||
("m" "Move worktree" magit-worktree-move)
|
|
||||||
("k" "Delete worktree" magit-worktree-delete)
|
|
||||||
("g" "Visit worktree" magit-worktree-status)]])
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-worktree-checkout (path branch)
|
|
||||||
"Checkout BRANCH in a new worktree at PATH."
|
|
||||||
(interactive
|
|
||||||
(let ((branch (magit-read-branch-or-commit "Checkout")))
|
|
||||||
(list (funcall magit-worktree-read-directory-name-function
|
|
||||||
(format "Checkout %s in new worktree: " branch))
|
|
||||||
branch)))
|
|
||||||
(magit-run-git "worktree" "add" (expand-file-name path) branch)
|
|
||||||
(magit-diff-visit-directory path))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-worktree-branch (path branch start-point &optional force)
|
|
||||||
"Create a new BRANCH and check it out in a new worktree at PATH."
|
|
||||||
(interactive
|
|
||||||
`(,(funcall magit-worktree-read-directory-name-function
|
|
||||||
"Create worktree: ")
|
|
||||||
,@(magit-branch-read-args "Create and checkout branch")
|
|
||||||
,current-prefix-arg))
|
|
||||||
(magit-run-git "worktree" "add" (if force "-B" "-b")
|
|
||||||
branch (expand-file-name path) start-point)
|
|
||||||
(magit-diff-visit-directory path))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-worktree-move (worktree path)
|
|
||||||
"Move WORKTREE to PATH."
|
|
||||||
(interactive
|
|
||||||
(list (magit-completing-read "Move worktree"
|
|
||||||
(cdr (magit-list-worktrees))
|
|
||||||
nil t nil nil
|
|
||||||
(magit-section-value-if 'worktree))
|
|
||||||
(funcall magit-worktree-read-directory-name-function
|
|
||||||
"Move worktree to: ")))
|
|
||||||
(if (file-directory-p (expand-file-name ".git" worktree))
|
|
||||||
(user-error "You may not move the main working tree")
|
|
||||||
(let ((preexisting-directory (file-directory-p path)))
|
|
||||||
(when (and (zerop (magit-call-git "worktree" "move" worktree
|
|
||||||
(expand-file-name path)))
|
|
||||||
(not (file-exists-p default-directory))
|
|
||||||
(derived-mode-p 'magit-status-mode))
|
|
||||||
(kill-buffer)
|
|
||||||
(magit-diff-visit-directory
|
|
||||||
(if preexisting-directory
|
|
||||||
(concat (file-name-as-directory path)
|
|
||||||
(file-name-nondirectory worktree))
|
|
||||||
path)))
|
|
||||||
(magit-refresh))))
|
|
||||||
|
|
||||||
(defun magit-worktree-delete (worktree)
|
|
||||||
"Delete a worktree, defaulting to the worktree at point.
|
|
||||||
The primary worktree cannot be deleted."
|
|
||||||
(interactive
|
|
||||||
(list (magit-completing-read "Delete worktree"
|
|
||||||
(cdr (magit-list-worktrees))
|
|
||||||
nil t nil nil
|
|
||||||
(magit-section-value-if 'worktree))))
|
|
||||||
(if (file-directory-p (expand-file-name ".git" worktree))
|
|
||||||
(user-error "Deleting %s would delete the shared .git directory" worktree)
|
|
||||||
(let ((primary (file-name-as-directory (caar (magit-list-worktrees)))))
|
|
||||||
(magit-confirm-files (if magit-delete-by-moving-to-trash 'trash 'delete)
|
|
||||||
(list "worktree"))
|
|
||||||
(when (file-exists-p worktree)
|
|
||||||
(let ((delete-by-moving-to-trash magit-delete-by-moving-to-trash))
|
|
||||||
(delete-directory worktree t magit-delete-by-moving-to-trash)))
|
|
||||||
(if (file-exists-p default-directory)
|
|
||||||
(magit-run-git "worktree" "prune")
|
|
||||||
(let ((default-directory primary))
|
|
||||||
(magit-run-git "worktree" "prune"))
|
|
||||||
(when (derived-mode-p 'magit-status-mode)
|
|
||||||
(kill-buffer)
|
|
||||||
(magit-status-setup-buffer primary))))))
|
|
||||||
|
|
||||||
(defun magit-worktree-status (worktree)
|
|
||||||
"Show the status for the worktree at point.
|
|
||||||
If there is no worktree at point, then read one in the
|
|
||||||
minibuffer. If the worktree at point is the one whose
|
|
||||||
status is already being displayed in the current buffer,
|
|
||||||
then show it in Dired instead."
|
|
||||||
(interactive
|
|
||||||
(list (or (magit-section-value-if 'worktree)
|
|
||||||
(magit-completing-read
|
|
||||||
"Show status for worktree"
|
|
||||||
(cl-delete (directory-file-name (magit-toplevel))
|
|
||||||
(magit-list-worktrees)
|
|
||||||
:test #'equal :key #'car)))))
|
|
||||||
(magit-diff-visit-directory worktree))
|
|
||||||
|
|
||||||
;;; Sections
|
|
||||||
|
|
||||||
(defvar magit-worktree-section-map
|
|
||||||
(let ((map (make-sparse-keymap)))
|
|
||||||
(define-key map [remap magit-visit-thing] 'magit-worktree-status)
|
|
||||||
(define-key map [remap magit-delete-thing] 'magit-worktree-delete)
|
|
||||||
map)
|
|
||||||
"Keymap for `worktree' sections.")
|
|
||||||
|
|
||||||
(defun magit-insert-worktrees ()
|
|
||||||
"Insert sections for all worktrees.
|
|
||||||
If there is only one worktree, then insert nothing."
|
|
||||||
(let ((worktrees (magit-list-worktrees)))
|
|
||||||
(when (> (length worktrees) 1)
|
|
||||||
(magit-insert-section (worktrees)
|
|
||||||
(magit-insert-heading "Worktrees:")
|
|
||||||
(let* ((cols
|
|
||||||
(mapcar
|
|
||||||
(pcase-lambda (`(,path ,barep ,commit ,branch))
|
|
||||||
(cons (cond
|
|
||||||
(branch (propertize
|
|
||||||
branch 'font-lock-face 'magit-branch-local))
|
|
||||||
(commit (propertize (magit-rev-abbrev commit)
|
|
||||||
'font-lock-face 'magit-hash))
|
|
||||||
(barep "(bare)"))
|
|
||||||
path))
|
|
||||||
worktrees))
|
|
||||||
(align (1+ (-max (--map (string-width (car it)) cols)))))
|
|
||||||
(pcase-dolist (`(,head . ,path) cols)
|
|
||||||
(magit-insert-section (worktree path)
|
|
||||||
(insert head)
|
|
||||||
(indent-to align)
|
|
||||||
(insert (let ((r (file-relative-name path))
|
|
||||||
(a (abbreviate-file-name path)))
|
|
||||||
(if (< (string-width r) (string-width a)) r a)))
|
|
||||||
(insert ?\n))))
|
|
||||||
(insert ?\n)))))
|
|
||||||
|
|
||||||
;;; _
|
|
||||||
(provide 'magit-worktree)
|
|
||||||
;;; magit-worktree.el ends here
|
|
Binary file not shown.
|
@ -1,596 +0,0 @@
|
||||||
;;; magit.el --- A Git porcelain inside Emacs -*- lexical-binding: t; coding: utf-8 -*-
|
|
||||||
|
|
||||||
;; Copyright (C) 2008-2019 The Magit Project Contributors
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the AUTHORS.md file which
|
|
||||||
;; lists all contributors. If not, see http://magit.vc/authors.
|
|
||||||
|
|
||||||
;; Author: Marius Vollmer <marius.vollmer@gmail.com>
|
|
||||||
;; Maintainer: Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
;; Kyle Meyer <kyle@kyleam.com>
|
|
||||||
;; Noam Postavsky <npostavs@users.sourceforge.net>
|
|
||||||
;; Former-Maintainers:
|
|
||||||
;; Nicolas Dudebout <nicolas.dudebout@gatech.edu>
|
|
||||||
;; Peter J. Weisberg <pj@irregularexpressions.net>
|
|
||||||
;; Phil Jackson <phil@shellarchive.co.uk>
|
|
||||||
;; Rémi Vanicat <vanicat@debian.org>
|
|
||||||
;; Yann Hodique <yann.hodique@gmail.com>
|
|
||||||
|
|
||||||
;; Keywords: git tools vc
|
|
||||||
;; Homepage: https://github.com/magit/magit
|
|
||||||
|
|
||||||
;; Magit requires at least GNU Emacs 25.1 and Git 2.2.0.
|
|
||||||
|
|
||||||
;; Magit is free software; you can redistribute it and/or modify it
|
|
||||||
;; under the terms of the GNU General Public License as published by
|
|
||||||
;; the Free Software Foundation; either version 3, or (at your option)
|
|
||||||
;; any later version.
|
|
||||||
;;
|
|
||||||
;; Magit is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
||||||
;; License for more details.
|
|
||||||
;;
|
|
||||||
;; You should have received a copy of the GNU General Public License
|
|
||||||
;; along with Magit. If not, see http://www.gnu.org/licenses.
|
|
||||||
|
|
||||||
;;; Commentary:
|
|
||||||
|
|
||||||
;; Magit is an interface to the version control system Git,
|
|
||||||
;; implemented as an Emacs package. Magit aspires to be a complete
|
|
||||||
;; Git porcelain. While we cannot (yet) claim, that Magit wraps and
|
|
||||||
;; improves upon each and every Git command, it is complete enough to
|
|
||||||
;; allow even experienced Git users to perform almost all of their
|
|
||||||
;; daily version control tasks directly from within Emacs. While many
|
|
||||||
;; fine Git clients exist, only Magit and Git itself deserve to be
|
|
||||||
;; called porcelains.
|
|
||||||
|
|
||||||
;;; Code:
|
|
||||||
|
|
||||||
(require 'cl-lib)
|
|
||||||
(require 'dash)
|
|
||||||
|
|
||||||
(require 'subr-x)
|
|
||||||
|
|
||||||
(require 'with-editor)
|
|
||||||
(require 'git-commit)
|
|
||||||
(require 'magit-core)
|
|
||||||
(require 'magit-diff)
|
|
||||||
(require 'magit-log)
|
|
||||||
(require 'magit-wip)
|
|
||||||
(require 'magit-apply)
|
|
||||||
(require 'magit-repos)
|
|
||||||
|
|
||||||
(require 'format-spec)
|
|
||||||
(require 'package nil t) ; used in `magit-version'
|
|
||||||
|
|
||||||
(defconst magit--minimal-git "2.2.0")
|
|
||||||
(defconst magit--minimal-emacs "25.1")
|
|
||||||
|
|
||||||
;;; Faces
|
|
||||||
|
|
||||||
(defface magit-header-line
|
|
||||||
'((t :inherit magit-section-heading))
|
|
||||||
"Face for the `header-line' in some Magit modes.
|
|
||||||
Note that some modes, such as `magit-log-select-mode', have their
|
|
||||||
own faces for the `header-line', or for parts of the
|
|
||||||
`header-line'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-header-line-key
|
|
||||||
'((t :inherit magit-popup-key))
|
|
||||||
"Face for keys in the `header-line'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-dimmed
|
|
||||||
'((((class color) (background light)) :foreground "grey50")
|
|
||||||
(((class color) (background dark)) :foreground "grey50"))
|
|
||||||
"Face for text that shouldn't stand out."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-hash
|
|
||||||
'((((class color) (background light)) :foreground "grey60")
|
|
||||||
(((class color) (background dark)) :foreground "grey40"))
|
|
||||||
"Face for the sha1 part of the log output."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-tag
|
|
||||||
'((((class color) (background light)) :foreground "Goldenrod4")
|
|
||||||
(((class color) (background dark)) :foreground "LightGoldenrod2"))
|
|
||||||
"Face for tag labels shown in log buffer."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-branch-remote
|
|
||||||
'((((class color) (background light)) :foreground "DarkOliveGreen4")
|
|
||||||
(((class color) (background dark)) :foreground "DarkSeaGreen2"))
|
|
||||||
"Face for remote branch head labels shown in log buffer."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-branch-remote-head
|
|
||||||
'((((class color) (background light)) :inherit magit-branch-remote :box t)
|
|
||||||
(((class color) (background dark)) :inherit magit-branch-remote :box t))
|
|
||||||
"Face for current branch."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-branch-local
|
|
||||||
'((((class color) (background light)) :foreground "SkyBlue4")
|
|
||||||
(((class color) (background dark)) :foreground "LightSkyBlue1"))
|
|
||||||
"Face for local branches."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-branch-current
|
|
||||||
'((((class color) (background light)) :inherit magit-branch-local :box t)
|
|
||||||
(((class color) (background dark)) :inherit magit-branch-local :box t))
|
|
||||||
"Face for current branch."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-branch-upstream
|
|
||||||
'((t :slant italic))
|
|
||||||
"Face for upstream branch.
|
|
||||||
This face is only used in logs and it gets combined
|
|
||||||
with `magit-branch-local', `magit-branch-remote'
|
|
||||||
and/or `magit-branch-remote-head'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-head
|
|
||||||
'((((class color) (background light)) :inherit magit-branch-local)
|
|
||||||
(((class color) (background dark)) :inherit magit-branch-local))
|
|
||||||
"Face for the symbolic ref `HEAD'."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-refname
|
|
||||||
'((((class color) (background light)) :foreground "grey30")
|
|
||||||
(((class color) (background dark)) :foreground "grey80"))
|
|
||||||
"Face for refnames without a dedicated face."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-refname-stash
|
|
||||||
'((t :inherit magit-refname))
|
|
||||||
"Face for stash refnames."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-refname-wip
|
|
||||||
'((t :inherit magit-refname))
|
|
||||||
"Face for wip refnames."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-refname-pullreq
|
|
||||||
'((t :inherit magit-refname))
|
|
||||||
"Face for pullreq refnames."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-keyword
|
|
||||||
'((t :inherit font-lock-string-face))
|
|
||||||
"Face for parts of commit messages inside brackets."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-keyword-squash
|
|
||||||
'((t :inherit font-lock-warning-face))
|
|
||||||
"Face for squash! and fixup! keywords in commit messages."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-good
|
|
||||||
'((t :foreground "green"))
|
|
||||||
"Face for good signatures."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-bad
|
|
||||||
'((t :foreground "red" :weight bold))
|
|
||||||
"Face for bad signatures."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-untrusted
|
|
||||||
'((t :foreground "cyan"))
|
|
||||||
"Face for good untrusted signatures."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-expired
|
|
||||||
'((t :foreground "orange"))
|
|
||||||
"Face for signatures that have expired."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-expired-key
|
|
||||||
'((t :inherit magit-signature-expired))
|
|
||||||
"Face for signatures made by an expired key."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-revoked
|
|
||||||
'((t :foreground "violet red"))
|
|
||||||
"Face for signatures made by a revoked key."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-signature-error
|
|
||||||
'((t :foreground "firebrick3"))
|
|
||||||
"Face for signatures that cannot be checked (e.g. missing key)."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-cherry-unmatched
|
|
||||||
'((t :foreground "cyan"))
|
|
||||||
"Face for unmatched cherry commits."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-cherry-equivalent
|
|
||||||
'((t :foreground "magenta"))
|
|
||||||
"Face for equivalent cherry commits."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
(defface magit-filename
|
|
||||||
'((t :weight normal))
|
|
||||||
"Face for filenames."
|
|
||||||
:group 'magit-faces)
|
|
||||||
|
|
||||||
;;; Dispatch Popup
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-dispatch "magit" nil t)
|
|
||||||
(define-transient-command magit-dispatch ()
|
|
||||||
"Invoke a Magit command from a list of available commands."
|
|
||||||
["Transient and dwim commands"
|
|
||||||
[("A" "Apply" magit-cherry-pick)
|
|
||||||
("b" "Branch" magit-branch)
|
|
||||||
("B" "Bisect" magit-bisect)
|
|
||||||
("c" "Commit" magit-commit)
|
|
||||||
("C" "Clone" magit-clone)
|
|
||||||
("d" "Diff" magit-diff)
|
|
||||||
("D" "Diff (change)" magit-diff-refresh)
|
|
||||||
("e" "Ediff (dwim)" magit-ediff-dwim)
|
|
||||||
("E" "Ediff" magit-ediff)]
|
|
||||||
[("f" "Fetch" magit-fetch)
|
|
||||||
("F" "Pull" magit-pull)
|
|
||||||
("l" "Log" magit-log)
|
|
||||||
("L" "Log (change)" magit-log-refresh)
|
|
||||||
("m" "Merge" magit-merge)
|
|
||||||
("M" "Remote" magit-remote)
|
|
||||||
("o" "Submodule" magit-submodule)
|
|
||||||
("O" "Subtree" magit-subtree)]
|
|
||||||
[("P" "Push" magit-push)
|
|
||||||
("r" "Rebase" magit-rebase)
|
|
||||||
("t" "Tag" magit-tag)
|
|
||||||
("T" "Note" magit-notes)
|
|
||||||
("V" "Revert" magit-revert)
|
|
||||||
("w" "Apply patches" magit-am)
|
|
||||||
("W" "Format patches" magit-patch)
|
|
||||||
("X" "Reset" magit-reset)]
|
|
||||||
[("y" "Show Refs" magit-show-refs)
|
|
||||||
("Y" "Cherries" magit-cherry)
|
|
||||||
("z" "Stash" magit-stash)
|
|
||||||
("!" "Run" magit-run)
|
|
||||||
("%" "Worktree" magit-worktree)]]
|
|
||||||
["Applying changes"
|
|
||||||
:if-derived magit-mode
|
|
||||||
[("a" "Apply" magit-apply)
|
|
||||||
("v" "Reverse" magit-reverse)
|
|
||||||
("k" "Discard" magit-discard)]
|
|
||||||
[("s" "Stage" magit-stage)
|
|
||||||
("u" "Unstage" magit-unstage)]
|
|
||||||
[("S" "Stage all" magit-stage-modified)
|
|
||||||
("U" "Unstage all" magit-unstage-all)]]
|
|
||||||
["Essential commands"
|
|
||||||
:if-derived magit-mode
|
|
||||||
("g" " refresh current buffer" magit-refresh)
|
|
||||||
("<tab>" " toggle section at point" magit-section-toggle)
|
|
||||||
("<return>" "visit thing at point" magit-visit-thing)
|
|
||||||
("C-h m" " show all key bindings" describe-mode)])
|
|
||||||
|
|
||||||
;;; Git Popup
|
|
||||||
|
|
||||||
(defcustom magit-shell-command-verbose-prompt t
|
|
||||||
"Whether to show the working directory when reading a command.
|
|
||||||
This affects `magit-git-command', `magit-git-command-topdir',
|
|
||||||
`magit-shell-command', and `magit-shell-command-topdir'."
|
|
||||||
:package-version '(magit . "2.11.0")
|
|
||||||
:group 'magit-commands
|
|
||||||
:type 'boolean)
|
|
||||||
|
|
||||||
(defvar magit-git-command-history nil)
|
|
||||||
|
|
||||||
;;;###autoload (autoload 'magit-run "magit" nil t)
|
|
||||||
(define-transient-command magit-run ()
|
|
||||||
"Run git or another command, or launch a graphical utility."
|
|
||||||
[["Run git subcommand"
|
|
||||||
("!" "in repository root" magit-git-command-topdir)
|
|
||||||
("p" "in working directory" magit-git-command)]
|
|
||||||
["Run shell command"
|
|
||||||
("s" "in repository root" magit-shell-command-topdir)
|
|
||||||
("S" "in working directory" magit-shell-command)]
|
|
||||||
["Launch"
|
|
||||||
("k" "gitk" magit-run-gitk)
|
|
||||||
("a" "gitk --all" magit-run-gitk-all)
|
|
||||||
("b" "gitk --branches" magit-run-gitk-branches)
|
|
||||||
("g" "git gui" magit-run-git-gui)]])
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-git-command (command)
|
|
||||||
"Execute COMMAND asynchronously; display output.
|
|
||||||
|
|
||||||
Interactively, prompt for COMMAND in the minibuffer. \"git \" is
|
|
||||||
used as initial input, but can be deleted to run another command.
|
|
||||||
|
|
||||||
With a prefix argument COMMAND is run in the top-level directory
|
|
||||||
of the current working tree, otherwise in `default-directory'."
|
|
||||||
(interactive (list (magit-read-shell-command nil "git ")))
|
|
||||||
(magit--shell-command command))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-git-command-topdir (command)
|
|
||||||
"Execute COMMAND asynchronously; display output.
|
|
||||||
|
|
||||||
Interactively, prompt for COMMAND in the minibuffer. \"git \" is
|
|
||||||
used as initial input, but can be deleted to run another command.
|
|
||||||
|
|
||||||
COMMAND is run in the top-level directory of the current
|
|
||||||
working tree."
|
|
||||||
(interactive (list (magit-read-shell-command t "git ")))
|
|
||||||
(magit--shell-command command (magit-toplevel)))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-shell-command (command)
|
|
||||||
"Execute COMMAND asynchronously; display output.
|
|
||||||
|
|
||||||
Interactively, prompt for COMMAND in the minibuffer. With a
|
|
||||||
prefix argument COMMAND is run in the top-level directory of
|
|
||||||
the current working tree, otherwise in `default-directory'."
|
|
||||||
(interactive (list (magit-read-shell-command)))
|
|
||||||
(magit--shell-command command))
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-shell-command-topdir (command)
|
|
||||||
"Execute COMMAND asynchronously; display output.
|
|
||||||
|
|
||||||
Interactively, prompt for COMMAND in the minibuffer. COMMAND
|
|
||||||
is run in the top-level directory of the current working tree."
|
|
||||||
(interactive (list (magit-read-shell-command t)))
|
|
||||||
(magit--shell-command command (magit-toplevel)))
|
|
||||||
|
|
||||||
(defun magit--shell-command (command &optional directory)
|
|
||||||
(let ((default-directory (or directory default-directory))
|
|
||||||
(process-environment process-environment))
|
|
||||||
(push "GIT_PAGER=cat" process-environment)
|
|
||||||
(magit-start-process shell-file-name nil
|
|
||||||
shell-command-switch command))
|
|
||||||
(magit-process-buffer))
|
|
||||||
|
|
||||||
(defun magit-read-shell-command (&optional toplevel initial-input)
|
|
||||||
(let ((dir (abbreviate-file-name
|
|
||||||
(if (or toplevel current-prefix-arg)
|
|
||||||
(or (magit-toplevel)
|
|
||||||
(magit--not-inside-repository-error))
|
|
||||||
default-directory))))
|
|
||||||
(read-shell-command (if magit-shell-command-verbose-prompt
|
|
||||||
(format "Async shell command in %s: " dir)
|
|
||||||
"Async shell command: ")
|
|
||||||
initial-input 'magit-git-command-history)))
|
|
||||||
|
|
||||||
;;; Font-Lock Keywords
|
|
||||||
|
|
||||||
(defconst magit-font-lock-keywords
|
|
||||||
(eval-when-compile
|
|
||||||
`((,(concat "(\\(magit-define-section-jumper\\)\\_>"
|
|
||||||
"[ \t'\(]*"
|
|
||||||
"\\(\\(?:\\sw\\|\\s_\\)+\\)?")
|
|
||||||
(1 'font-lock-keyword-face)
|
|
||||||
(2 'font-lock-function-name-face nil t))
|
|
||||||
(,(concat "(" (regexp-opt '("magit-insert-section"
|
|
||||||
"magit-section-case"
|
|
||||||
"magit-bind-match-strings"
|
|
||||||
"magit-with-temp-index"
|
|
||||||
"magit-with-blob"
|
|
||||||
"magit-with-toplevel") t)
|
|
||||||
"\\_>")
|
|
||||||
. 1))))
|
|
||||||
|
|
||||||
(font-lock-add-keywords 'emacs-lisp-mode magit-font-lock-keywords)
|
|
||||||
|
|
||||||
;;; Version
|
|
||||||
|
|
||||||
(defvar magit-version 'undefined
|
|
||||||
"The version of Magit that you're using.
|
|
||||||
Use the function by the same name instead of this variable.")
|
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun magit-version (&optional print-dest)
|
|
||||||
"Return the version of Magit currently in use.
|
|
||||||
If optional argument PRINT-DEST is non-nil, output
|
|
||||||
stream (interactively, the echo area, or the current buffer with
|
|
||||||
a prefix argument), also print the used versions of Magit, Git,
|
|
||||||
and Emacs to it."
|
|
||||||
(interactive (list (if current-prefix-arg (current-buffer) t)))
|
|
||||||
(let ((magit-git-global-arguments nil)
|
|
||||||
(toplib (or load-file-name buffer-file-name))
|
|
||||||
debug)
|
|
||||||
(unless (and toplib
|
|
||||||
(equal (file-name-nondirectory toplib) "magit.el"))
|
|
||||||
(setq toplib (locate-library "magit.el")))
|
|
||||||
(setq toplib (and toplib (file-chase-links toplib)))
|
|
||||||
(push toplib debug)
|
|
||||||
(when toplib
|
|
||||||
(let* ((topdir (file-name-directory toplib))
|
|
||||||
(gitdir (expand-file-name
|
|
||||||
".git" (file-name-directory
|
|
||||||
(directory-file-name topdir))))
|
|
||||||
(static (locate-library "magit-version.el" nil (list topdir)))
|
|
||||||
(static (and static (file-chase-links static))))
|
|
||||||
(or (progn
|
|
||||||
(push 'repo debug)
|
|
||||||
(when (and (file-exists-p gitdir)
|
|
||||||
;; It is a repo, but is it the Magit repo?
|
|
||||||
(file-exists-p
|
|
||||||
(expand-file-name "../lisp/magit.el" gitdir)))
|
|
||||||
(push t debug)
|
|
||||||
;; Inside the repo the version file should only exist
|
|
||||||
;; while running make.
|
|
||||||
(when (and static (not noninteractive))
|
|
||||||
(ignore-errors (delete-file static)))
|
|
||||||
(setq magit-version
|
|
||||||
(let ((default-directory topdir))
|
|
||||||
(magit-git-string "describe" "--tags" "--dirty")))))
|
|
||||||
(progn
|
|
||||||
(push 'static debug)
|
|
||||||
(when (and static (file-exists-p static))
|
|
||||||
(push t debug)
|
|
||||||
(load-file static)
|
|
||||||
magit-version))
|
|
||||||
(when (featurep 'package)
|
|
||||||
(push 'elpa debug)
|
|
||||||
(ignore-errors
|
|
||||||
(--when-let (assq 'magit package-alist)
|
|
||||||
(push t debug)
|
|
||||||
(setq magit-version
|
|
||||||
(and (fboundp 'package-desc-version)
|
|
||||||
(package-version-join
|
|
||||||
(package-desc-version (cadr it))))))))
|
|
||||||
(progn
|
|
||||||
(push 'dirname debug)
|
|
||||||
(let ((dirname (file-name-nondirectory
|
|
||||||
(directory-file-name topdir))))
|
|
||||||
(when (string-match "\\`magit-\\([0-9]\\{8\\}\\.[0-9]*\\)"
|
|
||||||
dirname)
|
|
||||||
(setq magit-version (match-string 1 dirname))))))))
|
|
||||||
(if (stringp magit-version)
|
|
||||||
(when print-dest
|
|
||||||
(princ (format "Magit %s, Git %s, Emacs %s, %s"
|
|
||||||
(or magit-version "(unknown)")
|
|
||||||
(or (let ((magit-git-debug
|
|
||||||
(lambda (err)
|
|
||||||
(display-warning '(magit git)
|
|
||||||
err :error))))
|
|
||||||
(magit-git-version t))
|
|
||||||
"(unknown)")
|
|
||||||
emacs-version
|
|
||||||
system-type)
|
|
||||||
print-dest))
|
|
||||||
(setq debug (reverse debug))
|
|
||||||
(setq magit-version 'error)
|
|
||||||
(when magit-version
|
|
||||||
(push magit-version debug))
|
|
||||||
(unless (equal (getenv "TRAVIS") "true")
|
|
||||||
;; The repository is a sparse clone.
|
|
||||||
(message "Cannot determine Magit's version %S" debug)))
|
|
||||||
magit-version))
|
|
||||||
|
|
||||||
;;; Debugging Tools
|
|
||||||
|
|
||||||
(defun magit-debug-git-executable ()
|
|
||||||
"Display a buffer with information about `magit-git-executable'.
|
|
||||||
See info node `(magit)Debugging Tools' for more information."
|
|
||||||
(interactive)
|
|
||||||
(with-current-buffer (get-buffer-create "*magit-git-debug*")
|
|
||||||
(pop-to-buffer (current-buffer))
|
|
||||||
(erase-buffer)
|
|
||||||
(insert (concat
|
|
||||||
(format "magit-git-executable: %S" magit-git-executable)
|
|
||||||
(and (not (file-name-absolute-p magit-git-executable))
|
|
||||||
(format " [%S]" (executable-find magit-git-executable)))
|
|
||||||
(format " (%s)\n"
|
|
||||||
(let* ((errmsg nil)
|
|
||||||
(magit-git-debug (lambda (err) (setq errmsg err))))
|
|
||||||
(or (magit-git-version t) errmsg)))))
|
|
||||||
(insert (format "exec-path: %S\n" exec-path))
|
|
||||||
(--when-let (cl-set-difference
|
|
||||||
(-filter #'file-exists-p (remq nil (parse-colon-path
|
|
||||||
(getenv "PATH"))))
|
|
||||||
(-filter #'file-exists-p (remq nil exec-path))
|
|
||||||
:test #'file-equal-p)
|
|
||||||
(insert (format " entries in PATH, but not in exec-path: %S\n" it)))
|
|
||||||
(dolist (execdir exec-path)
|
|
||||||
(insert (format " %s (%s)\n" execdir (car (file-attributes execdir))))
|
|
||||||
(when (file-directory-p execdir)
|
|
||||||
(dolist (exec (directory-files
|
|
||||||
execdir t (concat
|
|
||||||
"\\`git" (regexp-opt exec-suffixes) "\\'")))
|
|
||||||
(insert (format " %s (%s)\n" exec
|
|
||||||
(let* ((magit-git-executable exec)
|
|
||||||
(errmsg nil)
|
|
||||||
(magit-git-debug (lambda (err) (setq errmsg err))))
|
|
||||||
(or (magit-git-version t) errmsg)))))))))
|
|
||||||
|
|
||||||
;;; Startup Asserts
|
|
||||||
|
|
||||||
(defun magit-startup-asserts ()
|
|
||||||
(when-let ((val (getenv "GIT_DIR")))
|
|
||||||
(setenv "GIT_DIR")
|
|
||||||
(message "Magit unset $GIT_DIR (was %S). See \
|
|
||||||
https://github.com/magit/magit/wiki/Don't-set-$GIT_DIR-and-alike" val))
|
|
||||||
(when-let ((val (getenv "GIT_WORK_TREE")))
|
|
||||||
(setenv "GIT_WORK_TREE")
|
|
||||||
(message "Magit unset $GIT_WORK_TREE (was %S). See \
|
|
||||||
https://github.com/magit/magit/wiki/Don't-set-$GIT_DIR-and-alike" val))
|
|
||||||
(let ((version (magit-git-version)))
|
|
||||||
(when (and version
|
|
||||||
(version< version magit--minimal-git)
|
|
||||||
(not (equal (getenv "TRAVIS") "true")))
|
|
||||||
(display-warning 'magit (format "\
|
|
||||||
Magit requires Git >= %s, you are using %s.
|
|
||||||
|
|
||||||
If this comes as a surprise to you, because you do actually have
|
|
||||||
a newer version installed, then that probably means that the
|
|
||||||
older version happens to appear earlier on the `$PATH'. If you
|
|
||||||
always start Emacs from a shell, then that can be fixed in the
|
|
||||||
shell's init file. If you start Emacs by clicking on an icon,
|
|
||||||
or using some sort of application launcher, then you probably
|
|
||||||
have to adjust the environment as seen by graphical interface.
|
|
||||||
For X11 something like ~/.xinitrc should work.
|
|
||||||
|
|
||||||
If you use Tramp to work inside remote Git repositories, then you
|
|
||||||
have to make sure a suitable Git is used on the remote machines
|
|
||||||
too.\n" magit--minimal-git version) :error)))
|
|
||||||
(when (version< emacs-version magit--minimal-emacs)
|
|
||||||
(display-warning 'magit (format "\
|
|
||||||
Magit requires Emacs >= %s, you are using %s.
|
|
||||||
|
|
||||||
If this comes as a surprise to you, because you do actually have
|
|
||||||
a newer version installed, then that probably means that the
|
|
||||||
older version happens to appear earlier on the `$PATH'. If you
|
|
||||||
always start Emacs from a shell, then that can be fixed in the
|
|
||||||
shell's init file. If you start Emacs by clicking on an icon,
|
|
||||||
or using some sort of application launcher, then you probably
|
|
||||||
have to adjust the environment as seen by graphical interface.
|
|
||||||
For X11 something like ~/.xinitrc should work.\n"
|
|
||||||
magit--minimal-emacs emacs-version)
|
|
||||||
:error)))
|
|
||||||
|
|
||||||
;;; Loading Libraries
|
|
||||||
|
|
||||||
(provide 'magit)
|
|
||||||
|
|
||||||
(cl-eval-when (load eval)
|
|
||||||
(require 'magit-status)
|
|
||||||
(require 'magit-refs)
|
|
||||||
(require 'magit-files)
|
|
||||||
(require 'magit-reset)
|
|
||||||
(require 'magit-branch)
|
|
||||||
(require 'magit-merge)
|
|
||||||
(require 'magit-tag)
|
|
||||||
(require 'magit-worktree)
|
|
||||||
(require 'magit-notes)
|
|
||||||
(require 'magit-sequence)
|
|
||||||
(require 'magit-commit)
|
|
||||||
(require 'magit-remote)
|
|
||||||
(require 'magit-clone)
|
|
||||||
(require 'magit-fetch)
|
|
||||||
(require 'magit-pull)
|
|
||||||
(require 'magit-push)
|
|
||||||
(require 'magit-bisect)
|
|
||||||
(require 'magit-stash)
|
|
||||||
(require 'magit-blame)
|
|
||||||
(require 'magit-obsolete)
|
|
||||||
(require 'magit-submodule)
|
|
||||||
(unless (load "magit-autoloads" t t)
|
|
||||||
(require 'magit-patch)
|
|
||||||
(require 'magit-subtree)
|
|
||||||
(require 'magit-ediff)
|
|
||||||
(require 'magit-gitignore)
|
|
||||||
(require 'magit-extras)
|
|
||||||
(require 'git-rebase)
|
|
||||||
(require 'magit-imenu)
|
|
||||||
(require 'magit-bookmark)))
|
|
||||||
|
|
||||||
(eval-after-load 'bookmark
|
|
||||||
'(require 'magit-bookmark))
|
|
||||||
|
|
||||||
(if after-init-time
|
|
||||||
(progn (magit-startup-asserts)
|
|
||||||
(magit-version))
|
|
||||||
(add-hook 'after-init-hook #'magit-startup-asserts t)
|
|
||||||
(add-hook 'after-init-hook #'magit-version t))
|
|
||||||
|
|
||||||
;;; magit.el ends here
|
|
Binary file not shown.
|
@ -1,189 +0,0 @@
|
||||||
This is magit.info, produced by makeinfo version 6.5 from magit.texi.
|
|
||||||
|
|
||||||
Copyright (C) 2015-2019 Jonas Bernoulli <jonas@bernoul.li>
|
|
||||||
|
|
||||||
You can redistribute this document and/or modify it under the terms
|
|
||||||
of the GNU General Public License as published by the Free Software
|
|
||||||
Foundation, either version 3 of the License, or (at your option)
|
|
||||||
any later version.
|
|
||||||
|
|
||||||
This document is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
INFO-DIR-SECTION Emacs
|
|
||||||
START-INFO-DIR-ENTRY
|
|
||||||
* Magit: (magit). Using Git from Emacs with Magit.
|
|
||||||
END-INFO-DIR-ENTRY
|
|
||||||
|
|
||||||
|
|
||||||
Indirect:
|
|
||||||
magit.info-1: 754
|
|
||||||
magit.info-2: 302345
|
|
||||||
|
|
||||||
Tag Table:
|
|
||||||
(Indirect)
|
|
||||||
Node: Top754
|
|
||||||
Node: Introduction6475
|
|
||||||
Node: Installation11198
|
|
||||||
Node: Installing from Melpa11528
|
|
||||||
Node: Installing from the Git Repository12601
|
|
||||||
Node: Post-Installation Tasks14949
|
|
||||||
Node: Getting Started16234
|
|
||||||
Node: Interface Concepts21683
|
|
||||||
Node: Modes and Buffers22044
|
|
||||||
Node: Switching Buffers23793
|
|
||||||
Node: Naming Buffers28563
|
|
||||||
Node: Quitting Windows31870
|
|
||||||
Node: Automatic Refreshing of Magit Buffers33616
|
|
||||||
Node: Automatic Saving of File-Visiting Buffers36468
|
|
||||||
Node: Automatic Reverting of File-Visiting Buffers37653
|
|
||||||
Node: Risk of Reverting Automatically42648
|
|
||||||
Node: Sections45030
|
|
||||||
Node: Section Movement45956
|
|
||||||
Node: Section Visibility50517
|
|
||||||
Node: Section Hooks56594
|
|
||||||
Node: Section Types and Values59001
|
|
||||||
Node: Section Options60304
|
|
||||||
Node: Transient Commands60776
|
|
||||||
Node: Transient Arguments and Buffer Variables62013
|
|
||||||
Node: Completion Confirmation and the Selection69031
|
|
||||||
Node: Action Confirmation69475
|
|
||||||
Node: Completion and Confirmation76825
|
|
||||||
Node: The Selection80011
|
|
||||||
Node: The hunk-internal region82910
|
|
||||||
Node: Support for Completion Frameworks83999
|
|
||||||
Node: Additional Completion Options88906
|
|
||||||
Node: Running Git89505
|
|
||||||
Node: Viewing Git Output89778
|
|
||||||
Node: Git Process Status90911
|
|
||||||
Node: Running Git Manually91876
|
|
||||||
Node: Git Executable94346
|
|
||||||
Node: Global Git Arguments96628
|
|
||||||
Node: Inspecting97434
|
|
||||||
Node: Status Buffer98591
|
|
||||||
Node: Status Sections102581
|
|
||||||
Node: Status Header Sections108133
|
|
||||||
Node: Status Module Sections110763
|
|
||||||
Node: Status Options113268
|
|
||||||
Node: Repository List115143
|
|
||||||
Node: Logging118181
|
|
||||||
Node: Refreshing Logs120744
|
|
||||||
Node: Log Buffer122190
|
|
||||||
Node: Log Margin126046
|
|
||||||
Node: Select from Log129225
|
|
||||||
Node: Reflog131450
|
|
||||||
Node: Cherries133107
|
|
||||||
Node: Diffing134955
|
|
||||||
Node: Refreshing Diffs138036
|
|
||||||
Node: Commands Available in Diffs141615
|
|
||||||
Node: Diff Options144151
|
|
||||||
Node: Revision Buffer149189
|
|
||||||
Node: Ediffing152519
|
|
||||||
Node: References Buffer156167
|
|
||||||
Node: References Sections166687
|
|
||||||
Node: Bisecting167548
|
|
||||||
Node: Visiting Files and Blobs169361
|
|
||||||
Node: General-Purpose Visit Commands169831
|
|
||||||
Node: Visiting Files and Blobs from a Diff170787
|
|
||||||
Node: Blaming174246
|
|
||||||
Node: Manipulating180809
|
|
||||||
Node: Creating Repository181151
|
|
||||||
Node: Cloning Repository181706
|
|
||||||
Node: Staging and Unstaging186949
|
|
||||||
Node: Staging from File-Visiting Buffers191032
|
|
||||||
Node: Applying192200
|
|
||||||
Node: Committing194093
|
|
||||||
Node: Initiating a Commit194676
|
|
||||||
Node: Editing Commit Messages198061
|
|
||||||
Node: Branching208453
|
|
||||||
Node: The Two Remotes208679
|
|
||||||
Node: Branch Commands211332
|
|
||||||
Node: Branch Git Variables223716
|
|
||||||
Node: Auxiliary Branch Commands229107
|
|
||||||
Node: Merging230225
|
|
||||||
Node: Resolving Conflicts234233
|
|
||||||
Node: Rebasing239234
|
|
||||||
Node: Editing Rebase Sequences244244
|
|
||||||
Node: Information About In-Progress Rebase248572
|
|
||||||
Ref: Information About In-Progress Rebase-Footnote-1257454
|
|
||||||
Node: Cherry Picking258050
|
|
||||||
Node: Reverting262381
|
|
||||||
Node: Resetting263830
|
|
||||||
Node: Stashing265484
|
|
||||||
Node: Transferring270185
|
|
||||||
Node: Remotes270407
|
|
||||||
Node: Remote Commands270559
|
|
||||||
Node: Remote Git Variables274640
|
|
||||||
Node: Fetching277019
|
|
||||||
Node: Pulling279373
|
|
||||||
Node: Pushing280566
|
|
||||||
Node: Plain Patches284174
|
|
||||||
Node: Maildir Patches285665
|
|
||||||
Node: Miscellaneous287179
|
|
||||||
Node: Tagging287495
|
|
||||||
Node: Notes289423
|
|
||||||
Node: Submodules291795
|
|
||||||
Node: Listing Submodules292013
|
|
||||||
Node: Submodule Transient293941
|
|
||||||
Node: Subtree296463
|
|
||||||
Node: Worktree298439
|
|
||||||
Node: Common Commands299544
|
|
||||||
Node: Wip Modes302345
|
|
||||||
Node: Wip Graph307278
|
|
||||||
Node: Legacy Wip Modes309592
|
|
||||||
Node: Minor Mode for Buffers Visiting Files312487
|
|
||||||
Node: Minor Mode for Buffers Visiting Blobs319588
|
|
||||||
Node: Customizing320401
|
|
||||||
Node: Per-Repository Configuration321997
|
|
||||||
Node: Essential Settings323646
|
|
||||||
Node: Safety323970
|
|
||||||
Node: Performance325735
|
|
||||||
Node: Microsoft Windows Performance332452
|
|
||||||
Node: MacOS Performance333643
|
|
||||||
Ref: MacOS Performance-Footnote-1334348
|
|
||||||
Node: Plumbing334430
|
|
||||||
Node: Calling Git335259
|
|
||||||
Node: Getting a Value from Git336784
|
|
||||||
Node: Calling Git for Effect339870
|
|
||||||
Node: Section Plumbing346390
|
|
||||||
Node: Creating Sections346618
|
|
||||||
Node: Section Selection350518
|
|
||||||
Node: Matching Sections352317
|
|
||||||
Node: Refreshing Buffers358290
|
|
||||||
Node: Conventions361438
|
|
||||||
Node: Theming Faces361630
|
|
||||||
Node: FAQ369745
|
|
||||||
Node: FAQ - How to ...?370187
|
|
||||||
Node: How to show git's output?370547
|
|
||||||
Node: How to install the gitman info manual?371301
|
|
||||||
Node: How to show diffs for gpg-encrypted files?372271
|
|
||||||
Node: How does branching and pushing work?372867
|
|
||||||
Node: Can Magit be used as ediff-version-control-package?373230
|
|
||||||
Node: FAQ - Issues and Errors375219
|
|
||||||
Node: Magit is slow376151
|
|
||||||
Node: I changed several thousand files at once and now Magit is unusable376365
|
|
||||||
Node: I am having problems committing377094
|
|
||||||
Node: I am using MS Windows and cannot push with Magit377575
|
|
||||||
Node: I am using OS X and SOMETHING works in shell but not in Magit378192
|
|
||||||
Node: Diffs contain control sequences378998
|
|
||||||
Node: Expanding a file to show the diff causes it to disappear380111
|
|
||||||
Node: Point is wrong in the COMMIT_EDITMSG buffer380662
|
|
||||||
Node: The mode-line information isn't always up-to-date381708
|
|
||||||
Node: A branch and tag sharing the same name breaks SOMETHING382790
|
|
||||||
Node: My Git hooks work on the command-line but not inside Magit383678
|
|
||||||
Node: git-commit-mode isn't used when committing from the command-line384524
|
|
||||||
Node: Point ends up inside invisible text when jumping to a file-visiting buffer386791
|
|
||||||
Node: Debugging Tools387589
|
|
||||||
Node: Keystroke Index389476
|
|
||||||
Node: Command Index423263
|
|
||||||
Node: Function Index460091
|
|
||||||
Node: Variable Index476310
|
|
||||||
|
|
||||||
End Tag Table
|
|
||||||
|
|
||||||
|
|
||||||
Local Variables:
|
|
||||||
coding: utf-8
|
|
||||||
End:
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue