pax_global_header00006660000000000000000000000064133735474040014524gustar00rootroot0000000000000052 comment=791901b2f1d26fa0a383147fe77948a9abc753da magit-2.90.1/000077500000000000000000000000001337354740400127165ustar00rootroot00000000000000magit-2.90.1/.dir-locals.el000066400000000000000000000005171337354740400153520ustar00rootroot00000000000000((nil (bug-reference-bug-regexp . "#\\(?2:[0-9]+\\)") (bug-reference-url-format . "https://github.com/magit/magit/issues/%s")) (emacs-lisp-mode (eval . (bug-reference-mode 1)) (indent-tabs-mode . nil)) (makefile-gmake-mode (outline-regexp . "##")) (git-commit-mode (git-commit-major-mode . git-commit-elisp-text-mode))) magit-2.90.1/.github/000077500000000000000000000000001337354740400142565ustar00rootroot00000000000000magit-2.90.1/.github/CONTRIBUTING.md000066400000000000000000000023731337354740400165140ustar00rootroot00000000000000Reporting issues and suggesting features ======================================== To report bugs and suggest new feature use the [issue tracker][issues]. Code contributions ================== If you have some code which you would like to be merged, then open a [pull request][pulls]. Please create atomic commits with descriptive commit messages and use a dedicated feature branch (`b s` might help with the latter). Documentation contributions =========================== Improving the documentation is always a good way to get started contributing to some project. In the case of Magit this is somewhat complicated by the fact that we use some custom extensions. Some meta documentation can be found [here][metadocs]. TL;DR — Edit `magit.org`. Do not edit `magit.texi`. And don't touch the version numbers. The maintainers will then update `magit.texi` and the version numbers in `magit.org` and amend those changes to your commit. Donations ========= Please also consider to contribute by making a [monetary donation][donations]. [donations]: https://magit.vc/donate/ [issues]: https://github.com/magit/magit/issues [metadocs]: https://github.com/magit/magit/wiki/Documentation-tools-and-conventions [pulls]: https://github.com/magit/magit/pulls magit-2.90.1/.github/ISSUE_TEMPLATE/000077500000000000000000000000001337354740400164415ustar00rootroot00000000000000magit-2.90.1/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000024641337354740400211410ustar00rootroot00000000000000--- name: Bug report about: Report a defect --- Please explain (1) what behavior you expected (2) what behavior you observed (3) and how we can reproduce the issue. Also post the output of M-x magit-version RET Before reporting a defect please try to reproduce it using an Emacs instance in which only Magit and its dependencies have been loaded. Other packages or your configuration should not be loaded. This makes it easier to determine whether the issue lays with Magit or something else. If you run Magit from its Git repository, then you can do so using: $ cd /path/to/magit $ make emacs-Q Alternatively, run `M-x magit-emacs-Q-command RET` to save a shell command to the `kill-ring` and the system's clip-board, which you can then copy into a shell to run. Finally, if that didn't work and you have installed Magit from Melpa, then run commands similar to the ones below, but use tab completion to replace the various Ns with the correct versions: $ cd ~/.emacs.d/elpa/magit-N $ emacs -Q --debug-init --eval '(setq debug-on-error t)' -L ../dash-N -L ../git-commit-N -L ../magit-popup-N -L ../with-editor-N -L ../ghub-N -L . -l magit More debugging tools are described in the manual [6]. [6]: https://magit.vc/manual/magit/Debugging-Tools.html ---- now delete this line and everything above ---- magit-2.90.1/.github/ISSUE_TEMPLATE/feature_request.md000066400000000000000000000013121337354740400221630ustar00rootroot00000000000000--- name: Feature request about: Suggest a new feature --- Before you ask for a new feature to be added to Magit or for an existing feature to be improved, please make sure that what are asking for does not already exist by consulting the documentation [1]. Before you ask for a new argument to be added to some popup, see this [2] page. Then describe the feature you would like to see in Magit and why it would be useful to you. You might also want to describe any alternative solutions or features you've considered. [1]: https://magit.vc/manual/magit/#Top [2]: https://github.com/magit/magit/wiki/Additional-proposed-infix-arguments-and-suffix-commands ---- now delete this line and everything above ---- magit-2.90.1/.github/ISSUE_TEMPLATE/support_request.md000066400000000000000000000011011337354740400222400ustar00rootroot00000000000000--- name: Support request about: Do NOT open support requests here --- DO NOT use this issue tracker for support requests. Please use the Emacs StackExchange site [1] or Emacs subreddit [2] for support requests. But before you do that please read the list of frequently asked questions [3] and consult the manual [4] and a search engine. We only use this issue tracker for feature requests and bug reports. [1]: https://emacs.stackexchange.com [2]: https://www.reddit.com/r/emacs [3]: https://magit.vc/manual/magit/FAQ.html [4]: https://magit.vc/manual/magit/#Top magit-2.90.1/.github/PULL_REQUEST_TEMPLATE000066400000000000000000000047261337354740400174710ustar00rootroot00000000000000================================================================= Use a dedicated feature branch ================================================================= Please use a dedicated feature branch for your feature request, instead of asking us to merge "your-fork/master" into the "origin/master". The use of dedicated branches makes it much more convenient to deal with pull-requests, especially when using Magit to do so. If you were about to open a pull-request asking us to merge your version of "master", then see [1] for instructions on how to quickly fix that and some information on why we ask you to do so. Additionally we ask you to allow us to push to the branch you want us to merge. We might want to push additional commits and/or make minor changes. Please make sure the box next to "Allow edits from maintainers" is checked before creating the pull-request. [1]: https://github.com/magit/magit/wiki/Dedicated-pull-request-branches ================================================================= Do NOT use Github to edit files and create commit messages ================================================================= Unless you are aware of all the pitfalls and take great care to avoid them, the use of Github results in many small defects, including but not limited to trailing whitespace, commit messages containing overlong lines and no newline at the very end, and "GitHub " being used as the committer. The last one cannot even be avoided, which I consider as an affront. Github is an insufficient interface for editing files and creating commits. Please don't do it when contributing to Magit. ================================================================= What you should write here ================================================================= Please summarize the changes made in the commits. Explain why you are making these changes, not just what changes you are making. This also applies to the commit messages. ================================================================= How to update the manual ================================================================= If you make changes to the manual, then edit only "magit.org". Do not manually edit "magit.texi". The latter has to be generated from the former. If you want to do that yourself, then follow the instructions at [2]. Otherwise a maintainer will do it and amend that to your commit. [2]: https://github.com/magit/magit/wiki/Documentation-tools-and-conventions magit-2.90.1/.gitignore000066400000000000000000000005121337354740400147040ustar00rootroot00000000000000*.elc *~ /*.tar /*.tar.gz /Documentation/*.epub /Documentation/*.html /Documentation/*.info /Documentation/*.pdf /Documentation/META-INF/ /Documentation/OEBPS/ /Documentation/dir /Documentation/epub.xml /Documentation/magit/ /Documentation/mimetype /Documentation/stats/ /config.mk /lisp/magit-autoloads.el /lisp/magit-version.el magit-2.90.1/.mailmap000066400000000000000000000065401337354740400143440ustar00rootroot00000000000000Alex Dunn Alex Ott Andriy Kmit' Bar Magal Benjamin Motz Bradley Wright Buster Copley Chillar Anand Christophe Junke Damien Cassou David Abrahams Dean Kariniemi <8913263+d3k4r@users.noreply.github.com> Dennis Paskorz Evgkeni Sampelnikof Evgkeni Sampelnikof Fabian Wiget Fritz Stelzer Graham Clark Ivan Brennan Jesse Alama Joakim Jalap Jon Vanderwijk Jonas Bernoulli Jonas Bernoulli Kan-Ru Chen Leo Liu Luís Oliveira Luís Oliveira Luís Borges de Oliveira Marc Herbert Marc Herbert Marcel Wolf marcel-wolf Marian Schubert Marius Vollmer Marius Vollmer Marius Vollmer Marius Vollmer Marius Vollmer Mark Karpov N. Troy de Freitas <9503857+ntdef@users.noreply.github.com> Natalie Weizenbaum Nathan Weizenbaum Noam Postavsky Noam Postavsky Peter J. Weisberg Peter Vasil Phil Sainty Philippe Vaucher Raimon Grau Rémi Vanicat Rüdiger Sonderfeld Seong-Kook Shin Silent Sphere Sylvain Rousseau Syohei Yoshida Sébastien Gross Tunc Uzlu Wei Huang Wilfred Hughes Wouter Bolsterlee Yann Hodique Yann Hodique Yann Hodique Yuichi Higashi Óscar Fuentes Óscar Fuentes Óscar Fuentes magit-2.90.1/.travis.yml000066400000000000000000000031721337354740400150320ustar00rootroot00000000000000sudo: false language: generic env: global: - CURL="curl -fsSkL --retry 9 --retry-delay 9" - GHRAW="https://raw.githubusercontent.com" matrix: - EMACS_VERSION=25.1 # 25.2 is identical to 25.3 except for a critical security bug in # enriched text mode (see Emacs Bug#28350). - EMACS_VERSION=25.3 - EMACS_VERSION=26.1 - EMACS_VERSION=26 # 26.1.50, emacs-26 branch, built daily - EMACS_VERSION=master # 27.0.50, master branch, built daily allow_failures: - env: EMACS_VERSION=master install: - $CURL -O https://github.com/npostavs/emacs-travis/releases/download/bins/emacs-bin-${EMACS_VERSION}.tar.gz - tar -xaf emacs-bin-${EMACS_VERSION}.tar.gz -C / - export EMACS=/tmp/emacs/bin/emacs - $CURL -O ${GHRAW}/magnars/dash.el/master/dash.el - $CURL -O ${GHRAW}/magit/ghub/master/ghub.el - $CURL -O ${GHRAW}/magit/ghub/master/ghub-graphql.el - $CURL -O ${GHRAW}/vermiculus/graphql.el/master/graphql.el - $CURL -O ${GHRAW}/magit/magit-popup/master/magit-popup.el - $CURL -O ${GHRAW}/volrath/treepy.el/master/treepy.el - $CURL -O ${GHRAW}/magit/with-editor/master/with-editor.el - $EMACS -Q --batch -L . -f batch-byte-compile dash.el ghub.el ghub-graphql.el graphql.el magit-popup.el treepy.el with-editor.el - $EMACS --version script: - git config --global user.name "A U Thor" - git config --global user.email a.u.thor@example.com - git tag 0 - make lisp EMACSBIN=$EMACS DASH_DIR=$PWD - make test EMACSBIN=$EMACS DASH_DIR=$PWD notifications: email: # Default is change, but that includes a new branch's 1st success. on_success: never on_failure: always # The default. magit-2.90.1/Documentation/000077500000000000000000000000001337354740400155275ustar00rootroot00000000000000magit-2.90.1/Documentation/AUTHORS.md000066400000000000000000000270701337354740400172040ustar00rootroot00000000000000Authors ======= 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 Maintainer ---------- - Jonas Bernoulli Developers ---------- - Kyle Meyer - Noam Postavsky Retired Maintainers and Developers ---------------------------------- - Nicolas Dudebout - Peter J. Weisberg - Pieter Praet - Phil Jackson - Rémi Vanicat - Yann Hodique Contributors ------------ - Aaron Culich - Aaron Madlon-Kay - Abdo Roig-Maranges - Adam Benanti <0entropy@protonmail.com> - Adam Porter - Adam Spiers - Adeodato Simó - Ævar Arnfjörð Bjarmason - Alan Falloon - Alban Gruin - Aleksey Uimanov - Alexander Gramiak - Alex Branham - Alex Dunn - Alexey Voinov - Alex Kost - Alex Ott - Allen - Allen Li - Andreas Fuchs - Andreas Liljeqvist - Andreas Rottmann - Andrei Chițu - Andrew Kirkpatrick - Andrew Schwartzmeyer - Andrey Smirnov - Andriy Kmit' - Andy Sawyer - Aria Edmonds - Arialdo Martini - Barak A. Pearlmutter - Bar Magal - Bart Bakker - Basil L. Contovounesios - Bastian Beischer - Benjamin Motz - Ben North - Ben Walton - Bob Uhl - Bradley Wright - Brandon W Maister - Brian Warner - Bryan Shell - Buster Copley - Carl Lieberman - Chillar Anand - Chris Bernard - Chris Done - Chris LaRose - Chris Moore - Chris Ring - Chris Shoemaker - Christian Dietrich - Christian Kluge - Christophe Junke - Christopher Monsanto - Cornelius Mika - Craig Andera - Dale Hagglund - Damien Cassou - Dan Erikson - Daniel Brockman - Daniel Farina - Daniel Gröber - Daniel Hackney - Daniel Kraus - Daniel Mai - Dan LaManna - Dato Simó - David Abrahams - David Ellison - David Hull - David L. Rager - David Wallin - Dean Kariniemi <8913263+d3k4r@users.noreply.github.com> - Dennis Paskorz - Divye Kapoor - Dominique Quatravaux - Duianto Vebotci - Eli Barzilay - Eric Davis - Eric Prud'hommeaux - Eric Schulte - Erik Anderson - Evgkeni Sampelnikof - Eyal Lotem - Fabian Wiget - Felix Geller - Felix Yan - Feng Li - Florian Ragwitz - Fritz Grabo - Fritz Stelzer - Geoff Shannon - George Kadianakis - Graham Clark - Graham Dobbins - Greg A. Woods - Greg Lucas - Greg Sexton - Guillaume Martres - Hannu Koivisto - Hans-Peter Deifel - Ian Eure - Ingo Lohmar - Ioan-Adrian Ratiu - Ivan Brennan - Jan Tatarik - Jasper St. Pierre - Jeff Bellegarde - Jeff Dairiki - Jeremy Meng - Jesse Alama - Jim Blandy - Joakim Jalap - Johann Klähn - John Mastro - John Morris - John Wiegley - Jonas Bernoulli - Jonathan Leech-Pepin - Jonathan Roes - Jon Vanderwijk - Jordan Galby - Jordan Greenberg - Josiah Schwab - Julien Danjou - Justin Burkett - Justin Caratzas - Justin Guenther - Justin Thomas - Kan-Ru Chen - Kenny Ballou - Keshav Kini - Kevin Brubeck Unhammer - Kévin Le Gouguec - Kimberly Wolk - Kyle Meyer - Laurent Laffont - Laverne Schrock - Leandro Facchinetti - Lele Gaifax - Leo Liu - Leonardo Etcheverry - Lingchao Xin - Li-Yun Chang - Lluís Vilanova - Loic Dachary - Louis Roché - Luís Oliveira - Luke Amdor - Mak Kolybabi - Manuel Vázquez Acosta - Marcel Wolf - Marc Herbert - Marcin Bachry - Marco Craveiro - Marco Wahl - Marc Sherry - Marian Schubert - Mario Rodas - Marius Vollmer - Mark Hepburn - Mark Karpov - Mark Oteiza - Matthew Fluet - Matthieu Hauglustaine - Matus Goljer - Michael Fogleman - Michael Griffiths - Michael Heerdegen - Michal Sojka - Miciah Masters - Miles Bader - Miloš Mošić - Mitchel Humpherys - Moritz Bunkus - Natalie Weizenbaum - Nguyễn Tuấn Anh - Nic Ferier - Nick Alcock - Nick Alexander - Nick Dimiduk - Nicklas Lindgren - Nicolas Dudebout - Nicolas Petton - Nicolas Richard - Nikolay Martynov - Noam Postavsky - N. Troy de Freitas - Ole Arndt - Oleh Krehel - Orivej Desh - Óscar Fuentes - Paul Stadig - Pavel Holejsovsky - Pekka Pessi - Peter Eisentraut - Peter Jaros - Peter J. Weisberg - Peter Vasil - Philippe Vaucher - Philipp Haselwarter - Philipp Stephani - Philip Weaver - Phil Jackson - Phil Sainty - Pierre Neidhardt - Pieter Praet - Prathamesh Sonpatki - rabio - Radon Rosborough - Rafael Laboissiere - Raimon Grau - Ramkumar Ramachandra - Remco van 't Veer - Rémi Vanicat - René Stadler - Richard Kim - Robert Boone - Robin Green - Roger Crew - Romain Francoise - Ron Parker - Roy Crihfield - Rüdiger Sonderfeld - Russell Black - Ryan C. Thompson - Samuel Bronson - Samuel W. Flint - Sanjoy Das - Sean Allred - Sean Bryant - Sean Whitton - Sebastian Wiesner - Sébastien Gross - Seong-Kook Shin - Sergey Pashinin - Sergey Vinokurov - Servilio Afre Puentes - Silent Sphere - Štěpán Němec - Steven Chow - Steven E. Harris - Steven Thomas - Steven Vancoillie - Steve Purcell - Suhail Shergill - Sylvain Rousseau - Syohei Yoshida - Takafumi Arakaki - Teemu Likonen - Teruki Shigitani - Thierry Volpiatto - Thomas A Caswell - Thomas Frössman - Thomas Jost - Thomas Riccardi - Tibor Simko - Timo Juhani Lindfors - Tim Perkins - Tim Wraight - Ting-Yu Lin - Tom Feist - Tunc Uzlu - Vineet Naik - Vladimir Panteleev - Wei Huang - Wilfred Hughes - Win Treese - Wouter Bolsterlee - Xavier Noria - Xu Chunyang - Yann Hodique - York Zhao - Yuichi Higashi - Yuri Khan - Zach Latta magit-2.90.1/Documentation/BACKERS.md000066400000000000000000000544461337354740400171400ustar00rootroot00000000000000Thanks to your contributions and enthusiastic support the Magit [crowdfunding campaign][1] was a huge success! A special thanks goes to [Mojotech][2], [Directangular][3] and [Google Open Source][4] for their very generous contributions. [1]: https://www.kickstarter.com/projects/1681258897/its-magit-the-magical-git-client [2]: https://www.mojotech.com [3]: https://www.directangular.com [4]: https://opensource.google.com I would also like to thank each one of the almost two thousand other backers. It was very motivating to learn that so many users care that much about Magit and the well-being of its maintainer. Thanks! Jonas Bernoulli ------------------------------------------------------------ These are some of the 1987 backers: (If you backed the campaign and would like to be mentioned here but are not, then please fill out the backer survey.) - 4xrsJCr9 - <3 - @amirrajan - @arthurnn - @nietaki - @seriousben - A.I. - A.Weiher - Aaron Lee - Aaron Madlon-Kay - Aaron Mathews - Aaron Schumacher - Abdullah Alleweeth - Abrahán Fernández Nieto - Ada - Adam Benzan - Adam Bobrow - Adam Collard - Adam Olsen - Adam Patterson - Adam Shannon - Adam Sjøgren - Adriaan Leijnse - Adrian Bradd - Al Scott - Alan Pavičić - Alan Pearce - Alan Shutko - Alastair Rankine - Alberto Donato - Aleix Conchillo Flaque - Aleksandar Simić - Aleksandr Ivanov - Aleksei Fedotov - Alex Bennée - Alex Branham - Alex Dempsey - Alex Murray - Alex Reinhart - Alex Schroeder - Alex Speed Kjeldsen - Alex Wiles - Alex ter Weele - Alexander Goldstein - Alexander Lamaison - Alexander Simms - Alexander Stankov - Alexandre Bertails - Alexandre Duret-Lutz - Alexandre Héaumé - Alexandre Julliard - Alexey Egorov - Alexey Kapustin - Alexis Marie Wright - Aleš Bizjak - Alfredo Aguirre - Allen Short - Amin Bandali - Anatolii Smolianinov - Anatolij Prihosko - Anatoly Kudinov - Andre Aberer - Andrea Crotti - Andrea Di Persio - Andreas Aronsson - Andreas J - Andreas Marschke - Andreas Textor - Andreas Vollert - Andreas Zweili - Andrej Depperschmidt - Andres Mariscal - Andrew C May - Andrew Childs - Andrew Cowper - Andrew Cox - Andrew Evans - Andrew Fray - Andrew Grytsenko - Andrew J Cosgriff - Andrew Macgregor - Andrew McDermott - Andrew Mullins - Andrew Sanchez - Andrew Schwartzmeyer - Andrew Shugarts - Andrew Slough - Andrew Sullivan - Andrew Talbot - Andrew Tropin - Andrew Watts - Andrzej Skiba - András Simonyi - Andy Bold - Andy Moreland - Anntoin - Anonymous - Anselm Lingnau - Anthony Cowley - Anthony Hobbs - Anticrisis - Anton Orlov - Antoni Batchelli - Antonio Miranda - Aran Cox - Arjen Wiersma - Arjun - Arnaud Meuret - Arne Brasseur - Arne Redlich - Arong Pan - Arthur A. Gleckler - Arthur Leonard Andersen - Artur Malabarba - Artyom Kazak - Ash - Asherah - Asilata Bapat - Audun Gevelt - August Lilleaas - Baishampayan Ghose - Balaji Sivaraman - Baldur - Barak - Barry Gitarts - Barry McLarnon - Bascht - Ben Hollis - Ben Leggett - Ben Plantinga - Ben Swift - Benaiah Mischenko - Benedek Fazekas - Benedikt Terhechte - Beni Cherniavsky-Paskin - Benjamin Beckwith - Benjamin Hipple - Benjamin Kudria - Benjamin Ragheb - Benjamin Savs - Benoit Daffos - Biao Xie - Bill Stilwell - Bjarke Vad - Björn Larsson - Bob Duke - Bob Sun - Bob Uhl - Bobby Burden III - Bodil Stokke - Boris Dušek - Boyd Adamson - Bozhidar Batsov - Brandon Adams - Brandon Belew - Brandon Dixon - Brandon Fulk - Brandon Orther - Brendan Fahy - Brendan Jackman - Brendan Kirby - Brett Witty - Brian Brunswick - Brian Carlson - Brian Cobb - Brian Danilko - Brian Gruber - Brian Hicks - Brian James Rubinton - Brian Leonard - Brian Sniffen - Brian Warner - Bridger Howell - Brooke Mitchell - Bruce Ravel - Bruno Jacquet - Bryan Gilbert - Bryan Willson Berry - Bryce Kerley - Cai Kechao - Caibin Chen - Caleb McCaffery - Calogero Lo Leggio - Cameron Higby-Naquin - Cameron Stitt - Carl Lange - Carlo Sciolla - Carlos Antonio Neira Bustos - Carlos Rocha - Carsten Strotmann - Carsten.Koenig@hotmail.de - Caspar - Cena Mayo - Chad Stovern - Chaitanya Koparkar - Chandan Rajendra - Chao Liu from GRASP Lab, UPenn - Charl P. Botha - Charles L.G. Comstock - Charlie Brodie - Charlie McMackin - Chas B. - Chase Wang - Chen Rotem Levy - Chris Charles - Chris Douty - Chris Gray - Chris Hanson - Chris Johnson Bidler - Chris Lample - Chris Lindholm - Chris Mann - Chris McDevitt - Chris McGrath - Chris Nyland - Chris R (offby1@) - Chris Sims - Chris Taylor - Christian 'gicmo' Kellner - Christian Berg - Christian Johansen - Christian Johansson - Christian Lenke - Christian Romney - Christian Zang - Christine und Arne Köhn - Christoffer Schultz Jensen - Christoph Egger - Christoph Lange - Christoph Paa - Christophe Garion - Christophe Junke - Christophe Troestler - Christophe Vu-Brugier - Christopher Adams - Christopher Genovese - Christopher Giroir - Christopher Jenkins - Christopher Jordan - Christopher M. Becker - Cicero Jones - Clay Haapala - Cliff Wulfman - Clément Pit-Claudel - Colin McLear - Colin P. D. Powell - Constantine Khrulev - Courtland Jones - Craig Andera - Craig Hawco - Curt Brune - D. Sere - Damian Dobroczynski - Damien G. - Damien Merenne - Damien Pollet - Dan Davison - Dan Harms - Dan Jones - Dan LaManna - Dan Torop - Daniel - Daniel Bowman - Daniel Caixinha - Daniel Cowgill - Daniel Grady - Daniel J. Rothblatt - Daniel Kraus - Daniel Luna - Daniel Ma - Daniel Mai - Daniel Molina - Daniel S. F. Alves - Daniel Skarda - Daniel Tamai - Daniel V - Daniel de Haas - Daniël de Kok - Darren Aldredge - Darryl Okahata - Dave Aitken - Dave Churchill - Dave Kochbeck - Dave Liepmann - Dave Pearson - Dave Pretty - David Arnold - David Berg Marklund - David Duncan - David Ellison - David Goldfarb - David Hodges - David Hull - David Krauser - David Leimbach - David Mayfield - David Pathakjee - David Radkowski - David Robillard - David S. Rosenberg - David Scarpetti - David Stone - David Vázquez - David Wen Riccardi-Zhu - David Zuber - Davidbrcz - Davide Restivo - Dean Sellis - Deepu Mohan Puthrote - Denis Haine - Derek Chen-Becker - Derek Scherger - Derek Slager - Derek Upham - Devin - Diane Trout - DictatorBob - Diego Vicente Martín - Dieter Komendera - Diez Roggisch - Difrex - Dimitre Liotev - Dimitris Platis - Dirk Breuer - Divan Santana - Dmitry Alexeev - Dmitry Dzema - Dmitry Lazurkin - Dmitry Polyanitsa - Dmitry Tymchuk - Dominique Dumont - Don Spencer - DonBørn - Doug MacEachern - Dr. Jobo - Drew Raines - Dustin Maas - Dustin Paluch - Dylan Fitzgerald - Dylan Moore - Eddie Hillenbrand - Eduardo Apolinario - Eduardo Ruiz Macias - Edward Faulkner - Edward Knyshov - Edward Steere - Edwin Stearns - Elaina Martineau - Eli Naeher - Elias Castegren - Elis ""etu"" Hirwing - Elsa Gonsiorowski - Emanuel Tannert - Emil Bergström - Emil Klarskov - Emil Lundmark - Emilio y Marcelo - Emre Sevinç - Eric B. Decker - Eric Brown - Eric E. Moore - Eric Hogberg - Eric Hopkins - Eric Seidel - Erik Anderson - Erik Edrosa - Erik Nordlund - Erik Pischel - Erik Swanson - Erik W. B. - Erik Winkels - Erkki Seppälä - Erwin Junge - Esben Sparre Andreasen - Ethan Feldman - Ethan Glasser-Camp - Ettore Berardi - Eugene Rwagasore - Eugene Tan - Evan Rowley - Evgeniy Tyurkin - Ezekiel Elin - Fabian - Fabian Otto - Felipe M. - Felix Panozzo - Fernando Dobladez - Fernando Varesi - Fitz Elliott - Flavien COGEZ - Florian Adamsky - Florian Bruhin (The Compiler) - Florian Kempenich - Florian Schmaus - Florian Stock - Florian Ulivi - Foivos Zakkak - Foxtur - Fran Burstall - Francesc Elies - Francesc Rocher - Frank Roland - František Haifler - François Morlet - Fred Akalin - Fred Boiteux - Fred Kroon - Frederic Dumont - Frederik Beaujean - Fritz Grabo - Frontside Software - Fumitaka Tokumitsu - Gabriel Adomnicai - Gabriel J. Pérez Irizarry - Gaby Launay - Galder Zamarreño - Galin Yordanov - Garvin Guan - Gary Trakhman - Gavin Mercer - Geoff MacIntosh - Geoff Pado - Geoff Wozniak - Geoffrey J. Teale - George Pittarelli - Gerard Paapu - Gerard Ryan - Gergely Nagy - Gergely Polonkai - Giang-Son Nguyen - Giorgos Logiotatidis - Gitty McGitface - Gitty McGitface - Glenn R. Martin - Gordon Freeman - Gordon Gustafson - Greece <3 magit - Greg Chevalley - Greg Leppert - Gregg Hernandez - Guido Schmidt - Guilhem Doulcier - Guillaume Ayoub - Guillaume Marceau - Guillermo Ramos - GuiltyDolphin - Gustav Wikström - Gwenhael Le Moine - Harald Hvaal - Hector Castro - Henri Jones - Henrik Ahlgren - Henrik Kjerringvåg - Henrik Renlund - Henry Laxen - Henry Robinson - Henry Walshaw - Hertz - Herwig Stuetz - Hiren Shah - Hiroki Kiyohara - Hiroshi Tsutsui - Hoel - Holger Dürer - Horst Gutmann - Hung Pham - Hynek Schlawack - Håkan Nilsson - Ian Johnson - Ian Kerins - Ian Warford - Ibrahim Awwal - Icarus Sparry - Igor Bronshteyn - Igor Kupczyński - Ikuru K - Ilja Kocken - Illia Shestakov - Ingar Almklov - Ionov Valentine - Isaac Karth - Israel Herraiz - Itamar Ravid - Itamar Turner-Trauring - Iulian Costan - Ivan Kanis - Ivan Timokhin - Ivo Reyes Román - J Alexander Feldman-Crough - Jacek Generowicz - Jack Angers - Jack Kelly - Jack Letourneau - Jack Moffitt - Jack Wong - Jacob Covington - Jacob Ilsø Christensen - Jacob Moeller - Jacob O'Donnell - Jaga Santagostino - Jaidev Sridhar - Jake McCrary - Jakub Chmielarz - Jakub Narębski - James Felix Black - James Ferguson - James Orr - James Sharman - James Tranovich - James Valleroy - Jamie McClymont - Jamie Nicol - Jan Mas Rovira - Jan Rychter - Jan Seeger - Jan Vincent Liwanag - Jangseop Shin - Jared Miller - Jarno Malmari - Jarrett P - Jason Blevins - Jason Orendorff - Jasper Spaans - Jeff Bauer - Jeff McCarrell - Jeff Tecca - Jeff Waltzer - Jeff Whitmire - Jeff Workman - Jeffrey I. Schiller - Jeffrey Panczyk - Jennifer Kowalsky - Jens-Peter Thiry - Jeremiah Peschka - Jeremy Burks - Jeremy Huffman - Jeroen AH - Jeroen Faijdherbe - Jeroen Tiebout - Jessica Claire Edwards - Jethro Kuan - Jiashu Wang - Jim Blandy - Jim Menard - Jingcheng Xu - Jiten K. Pathy - Joachim 'Troglobit' Nilsson - Joakim Ohlrogge - Joakim Verona - Joe Balancio - Joe DeVivo - Joe Gallo - Joe Kiniry - Joerg Jaspert (Ganneff) - Johan Bay - Johan Ekenberg - Johan Forsberg - Johan K. Jensen - Johan S. - Johan Sandblom - Johan Sternerup - Johannes 'ksjogo' Goslar - Johannes Beigel - Johannes Grødem - Johannes Rainer - Johannes W. - John Anthony - John Cinnamond - John D. Hume - John Giannelos - John Haman - John Krumpotick - John Mastro - John Peloquin - John Urquhart Ferguson - Johnny Chadda - Jon Irving - Jon M. Dugan - Jon Raphaelson - Jon Snader - Jonas Serych - Jonas Strømsodd - Jonathan Arnett (J3RN) - Jonathan Lai - Jonathan Miller - Jonathan Rothberg - Jonathan del Strother - Joonas Sarajärvi - Joost Diepenmaat - Jordan Galby - Jordan Mulcahey - Jordon Biondo - Joren Van Onder - Jorge Dias - Jorge Santiago - Jos - Josep Egea - Joseph Churchill - Joseph Garvin - Joseph Jaoudi - Joseph Mingrone - Josh Berry - Josh Comer - Josh Elsasser - Josh Lipschultz - Josh Medeski - Josh Mōller-Mara - Josh Skidmore - Josh Tilles - Josh Valentine - Joshua B. Smith - Joshua E Cook - Joshua F. McMichael - Josiah Schwab - Jostein Kjønigsen - Jouni K. Seppänen - Joël Franusic - Juan E. Maya - Juan Edi - Juan Pedro Bolívar Puente (https://sinusoid.al) - Julian Kniephoff - Julien Blanchard - Julio Borja Barra - Justin Kaipada - Justin Schell - Justin Smestad - Justin Talbott - Justin Wood - Justine Tunney - Jörg Ramb - Jürgen Hackl - Kamen Naydenov - Kamil & Hassan - Kara Woo - Karl Voit - Karthikeyan S - Katherine Lai - Kaushal Modi - Kaushik Chakraborty (kaychaks) - Kavita Varsani - Kazushige Hosokawa - Kazuya Sakakihara - Keiichi Watanabe - Keith Amidon - Keith Mantell - Kelly McLaughlin - Ken Olstad - Kent Primrose - Kevin Christen - Kevin Grimes, II - Kevin J Foley - Kevin Kelley - Khan Thompson - Kieran Healy - Kieran Trezona-le Comte - Kim Frederiksen - Kim Gräsman - Kiran Kulkarni - Klāvs Taube - Konrad Voelkel - Koray Al - Kostiantyn Rybnikov - Kridsada Thanabulpong - Krista Victorsen - Kristoffer - Kungsgeten - Kushal Pisavadia - Kyle Brooks - Kyle Machulis (qDot) - Kyle Oba - Kyle Purdon - Kyle Schwab - Kyle Sexton - Kévin Le Gouguec - Lardière Sébastien - Lars Hesel Christensen - Laurence Rochfort - Laurent Charignon - Laurent Gatto - Leandro Cardoso - Lefteris Karapetsas - LegoNigel - Leo Breebaart - Leo C. Stein - Leo Martel - Leron Culbreath - Les Jones - Levi I. Tan Ong - Liam Stewart - Luca Manzoni - Lucas Meyers - Lucian Mogosanu - Ludwig PACIFICI - Luis Miguel Castañeda - Luis Osa - Luke Amdor - Luke Francl - Lute Kamstra - Luís Oliveira - Léo Gillot-Lamure - M. Ian Graham - Maarten Grachten - Maciek Swiech, PhD - Magit is full of magic! - Magnar Sveen - Magnus Malm - Magnus Nyberg (nxtr) - Mahinshaw@gmail.com - Mak Kolybabi - Maksym Planeta - Mandy - Manfred Kroehnert - Manish Sharma - Mansur Ziatdinov - Manuel Alonso - Manuel Frischknecht - Manuel Kallenbach - Manuel Uberti - Marc Massar - Marc Nijdam - Marc Sherry - Marc T. Henry de Frahan - Marcel Bollmann - Marcello Nicoletti - Marcin Cieślak - Marcin Swieczkowski - Marco Dalla Stella - Marco Wahl - Marcus Geiger - Marcus Klemm - Marcus Puchalla - Mark A. Hershberger - Mark Faldborg - Mark Hepburn - Mark Jeffcoat - Mark Meredith - Mark Ranallo - Mark Schaake - Mark Stradling - Mark Tran - Mark Triggs - Markus Fix - Marshall Quander - Mart van de Wege - Marten Lienen - Marti Bolivar - Martin Buchmann - Martin Frost - Martin Geisler - Martin Huschenbett - Martin Luethi - Martin Mauch - Martin Myrseth - Martin Polak - Martin Rechsteiner - Martin Yrjölä - Martin Šlouf - Martino Visintin - Martins Grunskis - Mary Jo Brodzik - Masayuki Onjo - Mateusz Probachta (beetleman) - Mathew Robinson - Mathieu Corbin - Mathieu Tartare - Matija Zezelj - Matt Curtis - Matt Haffner - Matt Kramer - Matt Savoie - Matt Usifer - Matthew Bregg - Matthew Curry - Matthew Fluet - Matthew Gregg - Matthew Hitchman - Matthew Piziak - Matthew Plant - Matthew Wells - Matthias Güdemann - Matthias Nüßler - Matti Niemenmaa - Mattias Bengtsson - Matías Aguirre - Mauricio Aldazosa Mariaca - Mauricio Collares - Max B. Hansson - Max Diefenbach - Max Tweddell - Max Willsey - Maxim Ivanov - Maxim Rurenko - Mayank Jain - Meiyo Peng - Melioratus - Menno Finlay-Smits - Micah Anderson - Michael Abrahams - Michael Droettboom - Michael Engelhardt - Michael Gracie - Michael Griffiths - Michael Hansen - Michael Kleehammer - Michael Krasnyk - Michael McCracken - Michael Moreno - Michael Overmeyer - Michael Sloan - Michael Welsh Duggan - Michal Buczko - Michał Politowski - Mickaël Salihi - Miguel Fernandes - Mihai Rinzis - Mikael Kermorgant - Mikael Springer - Mike Ashley - Mike Crowe - Mike Danylchuk - Mike Gulick - Mike Hewitson - Mike Monette - Mike T. Miller - Mike Travers - Mike Wagg - Mike Zamansky - Mikhail Pankov - Mikhail Pontus - Mikko Värri - Miks Kalnins (MaikuMori) - Milan Zamazal - Miles Clark - Miloš Mošić - Mingwei Zhang - Miranda Dobbs - Mirzhan Irkegulov - Mitchell A. Gordon - Mitchell Bright - Mitsutaka Takeda - Mohammed Ismail Ansari (myTerminal) - Moiz Bookwala - Moritz Bunkus - Morten Slot Kristensen - Mr. Wacky - Mrinal Purohit - Murilo Pereira - Murphy McMahon - Nab Inno - Nat Knight - Nate Eagleson - Nathan Collins - Nathan Hitchings - Nathan Sain - Naupaka Zimmerman - Neil Baylis - Neil Durant - Neurolit - Niall Dooley (doolio) - Nick Alcock - Nick Fitzgerald - Nick Higham - Nick Spain - Nicolas Dudebout - Nicolas Ha - Nicolas Hafner - Nicolas Morey-Chaisemartin - Nicolò Balzarotti - Niels Widger - Nikita Dudnik - Nikita Leshenko - Nikk Folts - Niko Felger - Nikolai Nespor - Nikos Fertakis - Nils - Nils Grunwald - Nils Pascal Illenseer - Niluge_KiWi - Nishioka Wataru - Nishiyama Nobuyuki - Noah Hoffman - Noel Markham - Norbert Kiesel - Norman Walsh - Norman Yamada - Ola Nilsson - Ole Jørgen Brønner - Ole petter Orhagen - Oleg Ivanov - Oleg Kostyuchenko - Oleg Matrokhin - Oliver Caldwell - Oliver Eidel - Oliver Marks - Oliver Reiter - Olivier Berger - Olivier Tharan - Olivier Yiptong - Ollie Charles (ocharles) - Onorio Catenacci - P. Kunze - Paolo G. Giarrusso - Pasi Heikkinen - Patrick Brown - Patrick Chung - Patrick Haun - Patrick Kelley - Patrick Nguyen - Patrick Thomson - Paul Hankes Drielsma - Paul Healy - Paul Kalupnieks - Paul Oliver - Paul R. Jorgensen - Paul Reiter - Paul Young - Pavel Khlopin - Pavel Panchekha - Pawan Dubey - Paweł Damasiewicz - Paweł Kapała - Pedro Pinto - Pedro Romano - Per Bergqwist - Peter Borocz - Peter Brachwitz - Peter Buckley - Peter Cheng - Peter Christensen - Peter Vasil - Phil Austin - Phil Dixon - Phil Sung - Philip Sequeira - Philip Tran - Philipp Baschke - Philipp Klippel - Philippe Bernery - Philippe Cavalaria - Philippe Vaucher - Pierre Lrz - Pierre Neidhardt - Praveen Perera - Radon Rosborough - Ramanathan Sivagurunathan - Rami Massoud - Rami Ylimäki - Raniere Silva - Rasmus Rygaard - Ray Hixson - Remco - Remote Viewer - Renat Galimov - Renato Aguiar - Rey Wright - Rhys Powell - Riccardo Cambiassi - Richard Bonichon - Richard Murri - Richard Petri - Richard Thames - Rickard Sundin - Rob Donnelly - Robert Helgesson - Robert Postill - Robert Steward - Robert Stuttaford - Robin Neatherway - Rodrigo - Roland Reckel - Romain Deterre - Roman Kashitsyn - Romario López - Ron Lusk - Ronan Barzic - Rory Gibson - Rory Molinari - Ross Donaldson - Ross Lonstein - Rouven Czerwinski - Royall Spence - Ruben Bakker - Ruben Maher - Rupert Swarbrick - Russell Healy - Rutger Prins - Ruud - Ryan C. Thompson - Ryan Eschinger - Ryan Kaskel - Ryan Mulligan - Ryan Prior - Ryan Seals - Ryan Shaw - Rémi Vanicat - Rörd Hinrichsen - Rúnar Berg Baugsson Sigríðarson - SM - SabreWolfy - Sagun Khatri - Saint Aardvark the Carpeted - Sajith Sasidharan - Sam Bleckley - Sam Blumenthal - Sam Brightman - Sam Halliday - Sam Pillsworth - Samuel Cole - Samuel Evans-Powell - Samuel Tonini - Sangho Na - Santi de Ledesma - Saul Reynolds-Haertle - Sayash K - Scott Barron - Scott Determan - Scott Dubinsky - Scott Jacobsen - Scott Ross - Sean Allred - Sean Andrews - Sean Bowman - Sean Grove (@sgrove) - Sean J Williamson - Sean McAfee - Sean Patrick Hagen - Seb Kri - Sebastian Nørgaard - Sebastian Schlag - Sergey Kostrukov - Sergey Timanin - Shane Celis - Shaun Lee - Shigenobu Nishikawa - Shingo Fukuyama - Shmulik Regev - Shreyas Ragavan - Shubhang Mani - ShuffelBag - Shun Yu - Simon Altschuler - Simon Benfold - Simon Brown - Simon Fenton - Simon Gregersen - Simon Génier - Simon Law - Sir Garbagetruck - Skip - Slava Barinov - Sliim - Spruce Bondera - Stefan Arentz - Steffen Weinreich - Stelian Ionescu - Stephan Schmitt - Stephan Schubert - Stephen Childs - Stephen Pegoraro - Stephen Whipple - Stephen York - Steven Rémot - Stian Eikeland - Stig Brautaset - StupidCodeFactory - Stéfan van der Walt - Sumit J - Superbil - Sven Koschnicke - Sven Rubben - Sverre Johansen - Swaroop C H - Sylvain Rousseau - Szabolcs Szilágyi - Søren Lund - Taavi Tani - Takaaki Ishikawa - Takeshi Teshima - Tamas K. Papp - Tarjei Bærland - Tassilo Horn - Taylor Skidmore - TeMPOraL - Terje Sten Bjerkseth - Tero Paloheimo - The Mad Hatter - Thomas A Caswell - Thomas Felber - Thomas Gazagnaire - Thomas Hisch - Thomas Moulia - Thomas Skardal - Thommy H. - Thor Adam - Tianxiang Xiong - Tibor Csögör - Tilmann Singer - Tim Howes - Tim Johns - Tim Perkins (@tprk77) - Tim Scheer - Tim Zallin - Ting-Yu Lin - Titus von der Malsburg - Tjaart van der Walt - Tobias Fankhänel - Tom Lyons (tbl3rd) - Tom Ridge - Tom Talbot - Tom W. - Tom van der Sommen - Tomasz Legutko - Tomás Solar Castro - Tony Finch - Tony Kemp - Toon Claes - Topher Brown - Tore Brede - Travis B. Hartwell - Travis Luckenbaugh - Travis Poulsen - Tresi Arvizo - Trevoke - Trevor Spiteri - Tritlo - Troy Hinckley - Tuomas Kareinen - Tushar Tyagi - Tyler Romeo - Tyler Sellon - USAMI Kenta (tadsan, zonuexe) - Umar Arshad - Vaibhav Jain - Valtteri - Varun Madiath - Venkateswara Rao Mandela - Victor Shulyak - Victory Ejevika - Vincent Demeester - Vincent Pomageot - Vindaar - Vitor Capela - Vivek Das Mohapatra - Vlad - Vlad Buslov - Vladimir Shemankov - Volker Haas - Václav Haisman - Wei Tang - Wei-ju Wu - Wendel Scardua - Wilfred Hughes - Will Fleming - Will Hughes - Will Newton - Will Roe - Willi Ballenthin - William Casarin - William Henney - William Oberndorfer - Willy Lee - Willy Rempel - Wolfgang Stief - Xi Omicron Sigma - Xuan Bi - Yanko Simeonov - Zecho - Yasushi SHOJI (""yashi"") - Yen, Tzu-Hsi - Yolanda Cadalbert - YoungFrog - Yu Miura - Yuquan Fu - Yuri Albuquerque - Yuri Bronshtein - Yuri Khan - Yuta Yamada - Yuuki Harano - Zach Ingbretsen - Zach Kost-Smith - Zachary Kim - Zachary Stevens - ZaharK - Zev Blut - Zhiming Wang - Zotan - Zsolt Botykai - agzam.ibragimov@gmail.com - alex@olkhovskiy.com - andrew.smirnov@gmail.com - andron94 - aneesh.kumar@gmail.com - apeyroux - baby-gnu.org - bigjust - bmac - bsdmatburt@gmail.com - bzg - cbbrowne - cfuhrman@gmail.com - chpeer - cmacrae - cms - comandante345 - danmilon - db48x - designernasser@gmail.com - dgoeke@gmail.com - djeis - dlowe - dom.parry@gmail.com - elseorand - empty - enderozcan - frank.patz@gmail.com - frankyxhl - gabriele.lana@gmail.com - gaetano - gdcosta@gmail.com - genehack - george.l - gingeralesy - gmasgras@gmail.com - goosetherumfoodle - greetings_from_italy - gregory@brusick.ch - gsnewmark - haff - hensansi - hugurp - ilitzroth@gmail.com - iwan - jakobj - jao - jarvisschultz - joesmoe10@gmail.com - jonasac - joranvar - jvshahid - jward - jwerak - k-sunako - kalle.lindqvist@mykolab.com - karate expert - karronoli - kenneth@geisshirt.dk - kiwanami - kltm - krvkir - l26wangca@gmail.com - laduke - lambdageek - lischenko - lobachevsky - luke@balooga.com - mail.urfi@gmail.com - manojm.321@gmail.com - marco 'rho lambda pi' rolappe - mats manet - mds2 - miguelgr - milan.v.mitrovic@gmail.com - mr.adtaylor@gmail.com - n2o - netWorms - nick.lanham.nexus@gmail.com - ninesigns - nivekuil - noonker - nyyManni - ojab - oppenlander - pancho horrillo - paralin - patrickwinter@posteo.ch - pcmantz@mcpantz.org - pepone.onrez@gmail.com - peter ""git push -f"" aaser - pitometsu - rafael@micubiculo.com - rails-to-cosmos - ray keung - rdomigan - realloc() - roomkey.com - rouadec - runejuhl - sbaker617 - shino - simon.leinen@gmail.com - snowball - sponrad - stask - steffen@g7n.dk - taku0 - tanzoniteblack - thirteen37 - thomas.stenhaug@gmail.com - thomasf@jossystem.se - toby cabot - tomterl - trobanga - trocster - turnspike.com - tuxtimo - tzz@lifelogs.com - umejam - vaartis - vargonaut - vincenzo.disomma@gmail.com - wtp - www.drinkiwiki.com - yewton - yoshinori kawahara - zerth - Álvaro González Sotillo - Åsmund Grammeltvedt - Étienne BERSAC - Étienne Deparis - Ömer Yildiz - Łukasz Korecki magit-2.90.1/Documentation/Makefile000066400000000000000000000146651337354740400172030ustar00rootroot00000000000000-include ../config.mk include ../default.mk ## ################################################################### .PHONY: texi install clean AUTHORS.md stats all: info ## Build ############################################################# info: $(INFOPAGES) dir html: $(HTMLFILES) pdf: $(PDFFILES) epub: $(EPUBFILES) %.info: %.texi @printf "Generating $@\n" @$(MAKEINFO) --no-split $< -o $@ dir: magit.info @printf "Generating dir\n" @echo $^ | xargs -n 1 $(INSTALL_INFO) --dir=$@ HTML_FIXUP_CSS = '//a\ \ \n\ \n\ \n\ \n' HTML_FIXUP_ONLOAD = 's///' HTML_FIXUP_MENU = '/<\/body>/i
<\/div>' %.html: %.texi @printf "Generating $@\n" @$(MAKEINFO) --html --no-split $(MANUAL_HTML_ARGS) $< @sed -i -e $(HTML_FIXUP_CSS) -e $(HTML_FIXUP_ONLOAD) -e $(HTML_FIXUP_MENU) $@ html-dir: $(TEXIFILES) @printf "Generating magit/*.html\n" @$(MAKEINFO) --html $(MANUAL_HTML_ARGS) magit.texi @for f in $$(find magit -name '*.html') ; do \ sed -i -e $(HTML_FIXUP_CSS) -e $(HTML_FIXUP_ONLOAD) -e $(HTML_FIXUP_MENU) $$f ; \ done %.pdf: %.texi @printf "Generating $@\n" @texi2pdf --clean $< > /dev/null %.epub: %.texi @printf "Generating $@\n" @makeinfo --docbook $< -o epub.xml @xsltproc $(DOCBOOK_XSL) epub.xml 2> /dev/null @echo "application/epub+zip" > mimetype @zip -X --quiet --recurse-paths -0 $@ mimetype @zip -X --quiet --recurse-paths -9 --no-dir-entries $@ META-INF OEBPS @$(RMDIR) $(EPUBTRASH) ## Install ########################################################### install: install-info install-docs install-docs: install-info @$(MKDIR) $(DESTDIR)$(docdir) $(CP) AUTHORS.md $(DESTDIR)$(docdir) install-info: info @$(MKDIR) $(DESTDIR)$(infodir) $(CP) $(INFOPAGES) $(DESTDIR)$(infodir) ## Clean ############################################################# clean: @printf "Cleaning Documentation/*...\n" @$(RMDIR) dir $(INFOPAGES) $(HTMLFILES) $(HTMLDIRS) $(PDFFILES) @$(RMDIR) $(EPUBFILES) $(EPUBTRASH) ## Release management ################################################ ORG_ARGS = --batch -Q $(ORG_LOAD_PATH) ORG_ARGS += -l magit-utils.el -l org-man -l ox-extra -l ox-texinfo+.el ORG_EVAL = --eval "(ox-extras-activate '(ignore-headlines))" ORG_EVAL += --eval "(setq indent-tabs-mode nil)" ORG_EVAL += --eval "(setq org-src-preserve-indentation nil)" ORG_EVAL += --funcall org-texinfo-export-to-texinfo # This target first bumps version strings in the Org source. The # necessary tools might be missing so other targets do not depend # on this target and it has to be run explicitly when appropriate. # # AMEND=t make texi Update manual to be amended to HEAD. # VERSION=N make texi Update manual for release. # texi: @$(EMACSBIN) $(ORG_ARGS) $(PKG).org $(ORG_EVAL) @printf "\n" >> $(PKG).texi @rm -f $(PKG).texi~ stats: @printf "Generating statistics\n" @gitstats -c style=/assets/stats.css -c max_authors=999 $(TOP) $(statsdir) authors: AUTHORS.md AUTHORS.md: @printf "Generating AUTHORS.md..." @test -e $(TOP).git \ && (printf "$$AUTHORS_HEADER\n" > $@ \ && git log --pretty=format:'- %aN <%aE>' | sort -u >> $@ \ && printf "done\n" ; ) \ || printf "FAILED (non-fatal)\n" DOMAIN ?= magit.vc PUBLISH_PATH ?= /manual/ RELEASE_PATH ?= /manual/$(VERSION)/ S3_BUCKET ?= s3://$(DOMAIN) PUBLISH_TARGET = $(S3_BUCKET)$(PUBLISH_PATH) RELEASE_TARGET = $(S3_BUCKET)$(RELEASE_PATH) CFRONT_DIST ?= E2LUHBKU1FBV02 CFRONT_PATHS = $(PKG).html $(PKG).pdf $(PKG)/* comma := , empty := space := $(empty) $(empty) publish-stats: stats @printf "Uploading statistics...\n" @aws s3 sync $(statsdir) $(S3_BUCKET)/stats/ @printf "Uploaded to $(PUBLISH_URL)/stats/\n" @printf "Generating CDN invalidation\n" @aws cloudfront create-invalidation \ --distribution-id $(CFRONT_DIST) --paths "/stats/*" > /dev/null publish-manuals: $(PUBLISH_TARGETS) @printf "Uploading manuals... $(PUBLISH_TARGETS)\n" @aws s3 cp $(PKG).html $(PUBLISH_TARGET) @aws s3 cp $(PKG).pdf $(PUBLISH_TARGET) @aws s3 cp $(PKG).epub $(PUBLISH_TARGET) @printf "upload: ./$(PKG)/* to $(PUBLISH_TARGET)*\n" @aws s3 sync --delete $(PKG) $(PUBLISH_TARGET)$(PKG)/ > /dev/null @printf "Generating CDN invalidation\n" @aws cloudfront create-invalidation --distribution-id $(CFRONT_DIST) --paths \ "$(subst $(space),$(comma),$(addprefix $(PUBLISH_PATH),$(CFRONT_PATHS)))" > /dev/null release-manuals: $(PUBLISH_TARGETS) @printf "Uploading release manuals...\n" @aws s3 cp $(PKG).html $(RELEASE_TARGET) @aws s3 cp $(PKG).pdf $(RELEASE_TARGET) @aws s3 cp $(PKG).epub $(RELEASE_TARGET) @printf "upload: ./$(PKG)/* to $(RELEASE_TARGET)*\n" @aws s3 sync --delete $(PKG) $(RELEASE_TARGET)$(PKG)/ > /dev/null @printf "Generating CDN invalidation\n" @aws cloudfront create-invalidation --distribution-id $(CFRONT_DIST) --paths \ "$(subst $(space),$(comma),$(addprefix $(RELEASE_PATH),$(CFRONT_PATHS)))" > /dev/null # Templates ########################################################## define AUTHORS_HEADER 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 Maintainer ---------- - Jonas Bernoulli Developers ---------- - Kyle Meyer - Noam Postavsky Retired Maintainers and Developers ---------------------------------- - Nicolas Dudebout - Peter J. Weisberg - Pieter Praet - Phil Jackson - Rémi Vanicat - Yann Hodique Contributors ------------ endef export AUTHORS_HEADER magit-2.90.1/Documentation/RelNotes/000077500000000000000000000000001337354740400172625ustar00rootroot00000000000000magit-2.90.1/Documentation/RelNotes/0.5.1.txt000066400000000000000000000002701337354740400204630ustar00rootroot00000000000000Magit v0.5.1 Release Notes ========================== This is the first release of Magit. Enjoy! Released 14 August 2008 by Marius Vollmer. Authors ------- 157 Marius Vollmer magit-2.90.1/Documentation/RelNotes/0.6.1.txt000066400000000000000000000007721337354740400204730ustar00rootroot00000000000000Magit v0.6.1 Release Notes ========================== Released 16 October 2008 by Marius Vollmer. Changes since v0.5.1 -------------------- Almost everything has changed. Some highlights: * Magit now works with Git 1.6.0. (John Wiegley) * Support for interactive rewriting. * Sections can be shown and hidden. * Staging, unstaging, applying, reverting and discarding changes can now be done line-by-line, not only hunk-by-hunk. Authors ------- 212 Marius Vollmer - John Wiegley magit-2.90.1/Documentation/RelNotes/0.7.0.txt000066400000000000000000000041421337354740400204660ustar00rootroot00000000000000Magit v0.7.0 Release Notes ========================== Released 8 March 2009 by Marius Vollmer. Changes since v0.6.1 -------------------- * Tagging, on 't' and 'T'. * Stashing, on 'z' and 'Z'. * Wazzup, on 'w'. Wazzup gives you an overview over how other branches relate to the current one. * There is more control over pushing. 'P' now takes a prefix argument and pushing a branch without a default remote will ask for one. * Logs have changed a bit: 'l' shows the traditional brief log, and 'L' shows a more verbose log. Use the prefix arg to specify the range of the log. * M-x magit-status doesn't prompt anymore for a directory when invoked from within a Git repository. Use C-u to force a prompt. * When you have nothing staged, 'c' will now explicitly ask whether to commit everything instead of just going ahead and do it. This can be customized. * The digit keys '1', '2', '3', and '4' now show sections on the respective level and hide everything below. With Meta, they work on all sections; without, they work only on sections that are a parent or child of the current section. * Typing '+' and '-' will change the size of hunks, via the "-U" option to git diff. '0' resets hunks to their default size. * Typing 'k' on the "Untracked files" section title will offer to delete all untracked files. * Magit understands a bit of git-svn: the status buffer shows unpushed and unpulled commits, 'N r' runs git svn rebase, and 'N c' runs git svn dcommit. * Magit now also works when the direcory is accessed via tramp. * M-x magit-status can also create new repositories when given a directory that is not a Git repository. * Magit works better with oldish Gits that don't understand "--graph", for example. * The name of the Git program and common options for it can be customized. Authors ------- 107 Marius Vollmer 18 John Wiegley 9 Alexey Voinov 5 Marcin Bachry 3 Rémi Vanicat 2 Alex Ott 2 René Stadler 2 Steve Purcell 1 Daniel Farina 1 David Wallin 1 Ian Eure 1 Jesse Alama magit-2.90.1/Documentation/RelNotes/0.8.0.txt000066400000000000000000000027331337354740400204730ustar00rootroot00000000000000Magit v0.8.0 Release Notes ========================== Released 7 May 2010 by Phil Jackson. Changes since v0.7.0 -------------------- * By setting magit-repo-dirs, you can get better repo completion. Magit will offer all subdirectories (upto magit-repo-dirs level deep) of the listed directories when magit-status asks for a directory to work on. You can get the old behavior with a double prefix to magit-status. * Hitting 'c' or 'C' while resolving a conflict in the middle of a rebase will offer to continue the rebase instead of trying to commit your changes. * Pulling will ask which branch to pull from when you don't have a default branch configured. * Switching to a remote branch will offer to create a local tracking branch for it. * Hitting C-c C-s while editing a commit message will toggle the "--signoff" option. * Hitting 's' on the "Untracked files" section title will stage all untracked files. * Hitting 'C-u S' will stage all untracked and tracked files. * Performance improvements in the status buffer. * Bug fixes to make Magit work better with newer Gits. Authors ------- 66 Phil Jackson 53 Marius Vollmer 27 Rémi Vanicat 7 Alexey Voinov 5 Hannu Koivisto 5 Roger Crew 4 John Wiegley 4 Moritz Bunkus 3 Ben Walton 2 Marcin Bachry 2 Óscar Fuentes 1 David Abrahams 1 Leo Liu 1 Pavel Holejsovsky 1 Ramkumar Ramachandra 1 Steve Purcell magit-2.90.1/Documentation/RelNotes/0.8.1.txt000066400000000000000000000012131337354740400204640ustar00rootroot00000000000000Magit v0.8.1 Release Notes ========================== Released 10 June 2010 by Phil Jackson. Changes since v0.8.0 -------------------- * New library `rebase-mode.el'. Edit Git rebase files. * New commands `magit-log-all' and `magit-log-first-parent'. * New command `magit-git-command'. Run any Git command. * `magit-remote-update' learned to fetch just the current remote. * `magit-tag' learned to place the tag on something other than HEAD. Authors ------- 55 Phil Jackson 7 Rémi Vanicat 7 Ævar Arnfjörð Bjarmason 4 Natalie Weizenbaum 2 Ramkumar Ramachandra 1 Mark Hepburn 1 Moritz Bunkus magit-2.90.1/Documentation/RelNotes/0.8.2.txt000066400000000000000000000010451337354740400204700ustar00rootroot00000000000000Magit v0.8.2 Release Notes ========================== Released 10 July 2010 by Phil Jackson. Changes since v0.8.1 -------------------- * Use shorter more human readable representations for refs. * Optionally show refs for remote branches the way Git would. * Tell VC to update the mode-line for us. Authors ------- 21 Phil Jackson 18 Natalie Weizenbaum 2 Alan Falloon 2 Moritz Bunkus 2 Rémi Vanicat 1 Alex Ott 1 Leo Liu 1 Sean Bryant 1 Ævar Arnfjörð Bjarmason 1 Óscar Fuentes magit-2.90.1/Documentation/RelNotes/1.0.0.txt000066400000000000000000000044561337354740400204700ustar00rootroot00000000000000Magit v1.0.0 Release Notes ========================== Released 23 March 2011 by Phil Jackson. Changes since v0.8.2 -------------------- * New library `magit-key-mode.el'. From a popup buffer dispatch Magit/Emacs commands which wrap Git commands and select the arguments passed to Git. Group various sets of related commands in new menus and adjust them accordingly. * New library `magit-svn.el' based on code previously in `magit.el'. Improve the implementation. Control `git svn' from Magit. * New library `magit-topgit.el' based on code previously in `magit.el'. Improve the implementation. Control TopGit from Magit. * Provide a wrapper for `completing-read'. Support using iswitchb to do completion. * Fixed and improved information shown during a rebase. * New macro `magit-define-inserter' to define functions which insert sections. * New macro `magit-add-action'. A hook-like extension mechanism for commands that behave differently based on the type of the section at point. * New macro `magit-define-command'. Like `defun' but also define a hook in addition to the function/command. If a hook function succeeds do not run the function body as passed to this macro. * New commands `magit-add-change-log-entry' and `magit-add-change-log-entry-other-window'. * New command `magit-change-what-branch-tracks'. * New commands `magit-run-git-gui' and `magit-run-gitk'. * Various new submodule commands. * Various new branch commands. * Various new log commands. Remove some old log commands. * Make reflog commands more like the log commands. * Numerous bugfixes and tweaks. Authors ------- 197 Phil Jackson 27 Natalie Weizenbaum 25 Óscar Fuentes 22 Moritz Bunkus 20 Rémi Vanicat 17 Aaron Culich 10 Timo Juhani Lindfors 8 Ramkumar Ramachandra 8 Ævar Arnfjörð Bjarmason 6 Yann Hodique 5 Hannu Koivisto 5 Julien Danjou 5 Peter J. Weisberg 4 Leo Liu 3 Robin Green 2 Brian Warner 2 Christian Kluge 2 Marc Herbert 1 Andreas Fuchs 1 Chris Bernard 1 David Abrahams 1 Dominique Quatravaux 1 John Wiegley 1 Paul Stadig 1 Philip Weaver 1 Remco van 't Veer 1 Robert Boone 1 Rüdiger Sonderfeld 1 Tom Feist magit-2.90.1/Documentation/RelNotes/1.1.0.txt000066400000000000000000000052311337354740400204610ustar00rootroot00000000000000Magit v1.1.0 Release Notes ========================== Released 23 December 2011 by Yann Hodique. Changes since v1.0.0 -------------------- * Added distinct faces for various different kinds of refs. * Completely redesigned existing faces. * Added library `magit-classic-theme.el' for users who like the old faces better. * Share many more key bindings between all Magit modes. Previously many commands were only available in certain buffers, even though they are useful in all Magit buffers. * Added library `magit-simple-keys.el' for users who don't like the popups. * Added support for using Ido to do completion. * Added support for Ediff. * Added shell script `magit'. * Added library `magit-bisect.el'. * Added library `magit-stgit.el'. * Added mode `magit-svn-mode'. * Added mode `magit-topgit-mode'. * Added mode `magit-rebase-mode'. * Added buttons to commit buffer to cylce to commits which were previously shown. The commands are `magit-show-commit-backward' and `magit-show-commit-forward. * Defined backward compatibility implementations of some Emacs functions. * Type changes are now shown in diffs. * Added option `magit-set-upstream-on-push'. * Added option `magit-default-tracking-name-function'. * Added option `magit-log-auto-more'. * Added option `magit-create-branch-behaviour'. * Added option `magit-status-buffer-switch-function'. * Added option `magit-rewrite-inclusive'. * Added options `magit-highlight-trailing-whitespace' and `magit-highlight-indentation'. * Added command `magit-show'. Visit REVISION:FILE. * Added command `magit-delete-branch-forced'. * Added command `magit-log-edit-toggle-author'. * `magit-reset-working-tree' learned to remove untracked files. * `magit-push' learned to set the upstream branch. Authors ------- 152 Peter J. Weisberg 55 Yann Hodique 18 Phil Jackson 18 Pieter Praet 18 Rémi Vanicat 12 Moritz Bunkus 10 Lluís Vilanova 8 Eli Barzilay 7 Nicolas Dudebout 6 Roger Crew 5 Štěpán Němec 3 David Abrahams 3 Hannu Koivisto 3 Jeff Bellegarde 3 Rüdiger Sonderfeld 2 Alan Falloon 2 Andreas Rottmann 2 Andrew Kirkpatrick 2 Craig Andera 2 Jasper St. Pierre 1 Andrey Smirnov 1 Bastian Beischer 1 Chris Moore 1 Daniel Brockman 1 Eric Davis 1 George Kadianakis 1 Kimberly Wolk 1 Luke Amdor 1 Luís Borges de Oliveira 1 Marc Herbert 1 Marco Craveiro 1 Ramkumar Ramachandra 1 Steve Purcell 1 Thomas Jost 1 Tibor Simko 1 Tom Feist 1 Ævar Arnfjörð Bjarmason magit-2.90.1/Documentation/RelNotes/1.1.1.txt000066400000000000000000000010201337354740400204520ustar00rootroot00000000000000Magit v1.1.1 Release Notes ========================== Released 14 January 2012 by Yann Hodique. Changes since v1.1.0 -------------------- * `magit-svn-get-local-ref' learned to expand branch specs containing braces. * `magit-log-edit' learned to amend and create commits with no message. * Several other fixes and improvements. Authors ------- 6 Nicolas Dudebout 6 Yann Hodique 1 Graham Clark 1 Justin Caratzas 1 Peter J. Weisberg 1 Ryan C. Thompson 1 Timo Juhani Lindfors magit-2.90.1/Documentation/RelNotes/1.1.2.txt000066400000000000000000000012371337354740400204650ustar00rootroot00000000000000Magit v1.1.2 Release Notes ========================== Released 23 September 2012 by Yann Hodique. Changes since v1.1.1 -------------------- * Modes now have proper mode-line lighters. * Hook variables are now defined semi-explicitly. * Uninteresting refs are no longer shown in logs. * The deprecated `assoc' libary is no longer used. * Several other fixes and improvements. Authors ------- 13 Yann Hodique 9 Peter J. Weisberg 2 Jonas Bernoulli 2 Ramkumar Ramachandra 1 Bradley Wright 1 Bryan Shell 1 Damien Cassou 1 Eric Davis 1 John Wiegley 1 Nic Ferier 1 Nick Alcock 1 Rémi Vanicat magit-2.90.1/Documentation/RelNotes/1.2.0.txt000066400000000000000000000033241337354740400204630ustar00rootroot00000000000000Magit v1.2.0 Release Notes ========================== Released 23 September 2012 by Yann Hodique. Changes since v1.1.2 -------------------- * Rewrote the branch manager. * Diffs are optionally refined using `diff-refine-hunk'. * Added library `magit-blame.el' defining new mode `magit-blame-mode'. * Added library `magit-wip.el' defining new modes `magit-wip-save-mode' and `magit-wip-mode'. * New section movement commands; `magit-goto-next-sibling-section' and `magit-goto-previous-sibling-section'. * Added command `magit-file-log'. * Added command `magit-manual-merge'. * `magit-delete-branch-force' was merged into `magit-delete-branch'. * `magit-move-branch' learned to force the rename. * `magit-reset-working-tree' learned to remove ignored files. * `magit-pull' learned to set `branch.BRANCH.merge'. * `magit-log-edit' learned to respect GIT_AUTHOR_EMAIL, GIT_AUTHOR_NAME and GIT_AUTHOR_DATE. * `magit-visit-item' learned to visit untracked files, diffs and hunks. * Added option `magit-sha1-abbrev-length'. Authors ------- 157 Yann Hodique 61 Nicolas Dudebout 14 Peter J. Weisberg 12 Jonas Bernoulli 10 Ryan C. Thompson 7 Miles Bader 6 Damien Cassou 5 Samuel Bronson 4 Dale Hagglund 4 Eli Barzilay 4 Takafumi Arakaki 4 rabio 3 Leonardo Etcheverry 3 Nick Alcock 3 Rémi Vanicat 3 Rüdiger Sonderfeld 2 Graham Clark 2 Hans-Peter Deifel 2 Moritz Bunkus 1 Andreas Liljeqvist 1 Christian Dietrich 1 Christopher Monsanto 1 Daniel Hackney 1 Hannu Koivisto 1 John Wiegley 1 Jonathan Roes 1 Ole Arndt 1 Ron Parker 1 Suhail Shergill magit-2.90.1/Documentation/RelNotes/1.2.1.txt000066400000000000000000000004551337354740400204660ustar00rootroot00000000000000Magit v1.2.1 Release Notes ========================== Released 23 May 2014 by Jonas Bernoulli. Changes since v1.2.0 -------------------- * `magit-delete-directory' was rewritten to deal with an incompatible change in `delete-directory' in Emacs v24.4. Authors ------- 1 Jonas Bernoulli magit-2.90.1/Documentation/RelNotes/1.2.2.txt000066400000000000000000000005531337354740400204660ustar00rootroot00000000000000Magit v1.2.2 Release Notes ========================== Released 23 October 2014 by Jonas Bernoulli. Changes since v1.2.1 -------------------- * `magit-delete-directory' uses itself when deleting recursively, instead of `org-delete-directory' which it was copied from. * Many byte-compile warnings were addressed. Authors ------- 5 Jonas Bernoulli magit-2.90.1/Documentation/RelNotes/1.4.0.txt000066400000000000000000000204121337354740400204620ustar00rootroot00000000000000Magit v1.4.0 Release Notes ========================== Released 1 April 2015 by Jonas Bernoulli. This release sits in the middle of a commit marathon that lasted for more than 4700 commits. When I became Magit's new maintainer during the summer of 2013 Magit was already a big success, but underneath its shiny surface it was having some serious problems. Over the years the source had gotten very disorganized and many old abstractions were no longer sufficient. Unfortunately existing code had almost never been adjusted when new features had been added, leading to a lot of new code that worked around limitations of existing code. This was clearly not sustainable in the long run, and so I started cleaning up and replacing the existing abstractions with simpler, yet often more powerful implementations. Unfortunately his had to happen incrementally as it was seldom possible to cleanup one area without making substantial changes elsewhere. Along the way I also addressed many of the hundreds of feature requests, but that was more of a bonus - the focus was on getting the codebase ready for future improvements. At the beginning of 2014 I moved development to the new next branch. Working on a branch which was not used by thousands of Melpa users allowed me to move faster and users were no longer affected by the occasional regression. But it also meant that I now had to maintain two branches. In hindsight I should have released the master branch as 1.3.0 at that time, despite all the known defects it had. Since then I have finished the cleanup on the next branch and then moved on to implement many new features. On the master branch the focus was on bugfixes and the occasional backport. This release is based on the master branch. Later this spring 2.1.0 will be released based on the next branch. Compiling a list of all changes in 1.4.0 would by a major amount of work in itself, so instead the below list is for the most part limited to major changes, which enabled the user visible changes. Many users don't have to be told about the new features anyway - they have been using them for more than a year now. Changes since v1.2.2 -------------------- * The libraries `magit-topgit.el', `magit-stgit.el', and `magit-svn.el' all reincarnated as separate repository. * The libraries `magit-classic-theme.el' and `magit-simple-keys.el', which allowed users to undo some of the changes in older releases, were removed. * The library `rebase-mode.el' was renamed to `git-rebase-mode.el' and moved to the `magit/git-modes' repository. * The library `magit-log-edit-mode.el' was removed and replaced with `git-commit-mode.el' from the `magit/git-modes' repository. * The functionality provided by the library `magit-bisect.el' was replaced with a new implementation in `magit.el'. * The package `cl-lib` is now used instead of the obsolete `cl'. * The library `magit.el' no longer lacks any recognizable structure. * The macro `magit-define-command' was removed. The hook that was defined in addition to the command only served to make things more complicated and the generated doc-string was insufficient. * The use of "section actions" has been reduced to a minimum. Commands that behave differently depending on the type of the current section still use `magit-section-case' or in some cases even `magit-section-action', but the preferred way for users to add new variants now is to add a new command to the type-specific section keymap, instead of the hooks defined by `magit-section-action'. * More work is done directly in `magit-with-section'. Most of the helper functions were removed. These functions were not intended to be used directly, but that did not keep contributors from doing so, leading to many inconsistencies. * The mode machinery was massively refactored. Most importantly the new macro `magit-mode-setup' was added, replacing the old `magit-mode-init' which forgoes most of the things each and every of its callers has to do, which let to many inconsistencies * The refresh machinery was massively refactored. A refresh now has to be requested more explicitly by either calling `magit-refresh' or one of the functions that call Git and then the former. Also, refreshing now more often correctly preserves point. * Washing diffs now takes less cycles. Previously the code used to wash diffs was very complicated. It passed around state using many dynamically bound variables, and called `git diff' many times. Now we call `git diff' once and then wash its output in one go. * Commits and stashes are now washed using the regular diffwasher. * Low-level functions for running Git were massively refactored, and many new variants were added. Previously many callers had to deal with the gory details themselves (and usually did it badly). * The output from processes is now logged in a dedicated buffer. From this buffer it's also possible to kill a running process. * The Wazzup buffer was massively refactored. All options to optionally make it faster were removed, as it is now faster out-of-the-box without sacrificing any functionality at all. * Many more competing abstractions were unified. It was common to have one no longer sufficient core abstraction, and several competing wrapper abstractions. In most cases this has been replaced with a single, less complex implementation, which serves all of the current use cases. * Refreshing "after a asynchronous process has run" now happens after the process has actually finished. That was always the intention, but not what actually used to happen. * The commit message is no longer provided when calling `git commit'. Instead Git populates a file with a template and then uses $EDITOR to have the user edit that. This did not work so well for a while but now we succeed in having the emacsclient being used as $EDITOR. * A new Branch Manager was added. * Log learned to show optionally show author information in the margin. * Terminology with regards to what a tracking branch is, was fixed. * When creating a new branch the default choice is what Git would default to, instead of some silly name. * Tools used to test whether Git supports certain features was removed. Instead we now require a non-ancient version of Git. * The shell script `magit' reincarnated as a separate repository. Authors ------- 1838 Jonas Bernoulli 171 Yann Hodique 121 Pieter Praet 59 Rémi Vanicat 24 Nicolas Dudebout 21 Takafumi Arakaki 16 acple 14 Phil Jackson 13 Rüdiger Sonderfeld 12 Mitchel Humpherys 8 Servilio Afre Puentes 7 Ramkumar Ramachandra 7 Teruki Shigitani 6 Lluís Vilanova 6 Sergey Vinokurov 5 Thierry Volpiatto 4 Moritz Bunkus 4 Noam Postavsky 4 Seong-Kook Shin 3 Laurent Laffont 3 Leonardo Etcheverry 3 Loic Dachary 3 Raimon Grau 3 Sébastien Gross 2 Bastian Beischer 2 Damien Cassou 2 Evgkeni Sampelnikof 2 Greg A. Woods 2 Greg Sexton 2 Jesse Alama 2 Leandro Facchinetti 2 Nguyễn Tuấn Anh 2 Nick Alexander 2 Pekka Pessi 2 Philippe Vaucher 2 Rafael Laboissiere 2 Sebastian Wiesner 1 Abdo Roig-Maranges 1 Adam Spiers 1 Andrei Chițu 1 Andrew Schwartzmeyer 1 Brandon W Maister 1 Chris Done 1 Chris Ring 1 Christopher Monsanto 1 Cornelius Mika 1 Dan LaManna 1 David Hull 1 Dennis Paskorz 1 Divye Kapoor 1 Eric Schulte 1 Felix Geller 1 Feng Li 1 Geoff Shannon 1 Jan Tatarik 1 Jeff Dairiki 1 John Wiegley 1 Jordan Greenberg 1 Kyle Meyer 1 Lele Gaifax 1 Manuel Vázquez Acosta 1 Marcel Wolf 1 Marian Schubert 1 Matus Goljer 1 Nick Dimiduk 1 Nicolas Richard 1 Peter J. Weisberg 1 Philipp Haselwarter 1 Prathamesh Sonpatki 1 Romain Francoise 1 Roy Crihfield 1 Sanjoy Das 1 Sergey Pashinin 1 Steve Purcell 1 Steven Chow 1 Steven Thomas 1 Thomas Frössman 1 Thomas Riccardi 1 Ting-Yu Lin 1 Wilfred Hughes 1 Win Treese 1 York Zhao 1 aaa707 1 Ævar Arnfjörð Bjarmason magit-2.90.1/Documentation/RelNotes/1.4.1.txt000066400000000000000000000015031337354740400204630ustar00rootroot00000000000000Magit v1.4.1 Release Notes ========================== Released 12 April 2015 by Jonas Bernoulli. This is a bugfix release. Changes since v1.4.0 -------------------- * The external library `magit-log-edit.el' is no longer supported. If it is still installed, then instruct the user to remove it. * The function `magit-maybe-show-setup-instructions' is now run even when `magit' has not been loaded by the time `after-init-hook' ran. * Invalid `:package-version' keywords in option definitions were fixed. In some cases the value was "2.1.0" instead of "1.4.0". * Some unnecessary obsolete-variable definitions were removed. * Running tests on Travis CI was fixed. * The Makefile, README.md, and release notes received minor fixes and cleanup. Authors ------- 9 Jonas Bernoulli 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/1.4.2.txt000066400000000000000000000010021337354740400204560ustar00rootroot00000000000000Magit v1.4.2 Release Notes ========================== Released 8 June 2015 by Jonas Bernoulli. This is a bugfix release. Changes since v1.4.1 -------------------- * Automatic revers of file-visiting buffers now works again in Emacs version 24.5. It was broken due to an incompatible change in that Emacs release. * Git's reflogs sometimes end with bogus entries. We now work around that when listing stashes. Authors ------- 11 Jonas Bernoulli 1 Peter Vasil 1 Steven E. Harris magit-2.90.1/Documentation/RelNotes/2.1.0.txt000066400000000000000000000470431337354740400204710ustar00rootroot00000000000000Magit v2.1.0 Release Notes ========================== Released 1 July 2015 by Jonas Bernoulli. This release marks the end of a commit marathon that lasted for more than 4700 commits. It is the first major release in over two and a half years. The last major release was 1.2.0, which was released under old leadership. Version 1.4.0, which I released earlier this year, for the most part consisted of changes that prepared for this release (so you might want to read the respective release notes too). This release comes with many new and exciting features, but the most important change is the massive increase in consistency both in the user interface and the internal abstractions. Magit always provided a very intuitive staging interface, which is vastly superior to `git add --interactive'. This release extends this to other apply variants. Starting with this release, other areas have also begun to be more than just incremental improvements over what Git itself provides. But this is still limited to certain features which have gotten more attention than others (most prominently rebasing). Interlude --------- The code base is finally in a state that allows me to concentrate on implementing my vision of what version control could be like. But this will only be possible if, unlike during the last two and a half years, I am being paid for my work. I intend to run a fund-raising campaign, but you can already donate now (see http://magit.vc/donations.html). I am also looking for corporate sponsorship and/or employment. One area where Magit actually lags behind other Git clients is integration with Git hosting platforms and code review tools. I hope that these platforms have an interest in being supported by the best Git client and are willing to pay for it. I am very interested in a job that would let me work on Magit *and* on other projects, which would benefit from the skills I have acquired integrating two complex systems and dealing with all the social and technical challenges that arise when running a popular project. Changes since v1.4.0 -------------------- * A new manual has been added. It's much more comprehensive than the old manual and instead of just documenting the various commands and options, it also explains concepts and plumbing functions, and comes with extensive indices for commands, functions, and options. Actually three new manuals were added; the packages `magit-popup' and `with-editor' are documented in separate manuals. The manuals are written in Org mode and then exported to Texinfo. * Performance is much better now. In most cases this was achieved by delaying work until it is actually needed. Most importantly diffs are only partially washed until being fully expanded. Some features come in a fancy and in a fast variant; when that is the case, we now usually default to the fast variant. * Many options can now be set on a per-repository basis, and the manual describes how to do so. (Actually this was always possible but, because it was undocumented, nobody did it.) It's possible to define "repository classes", e.g. "huge repositories", and then add the respective repositories to that class. This is very useful in order to turn off certain features only in repositories where they would have a negative impact on performance, without having to do it for each repository individually. * Many faces have been simplified. Most importantly, section heading faces no longer set a background color (except for hunk headings) and instead just use the default background. Refname faces no longer set the background color or the box property. * Many, probably the majority of, functions, variables, and faces have been renamed, which was necessary because there was very little consistency before. Most importantly, the names of commands and options now begin with a prefix that includes the name of the respective git sub-command. For example, the names of all commands and options related to diffing now begin with `magit-diff-'. Many plumbing functions and variables were also renamed. In some cases, that also lead to shared prefixes, such as `magit-process-', `magit-mode-', `magit-git-', and `magit-insert-'. But many plumbing functions and variables continue to use names whose only common part is the `magit-' prefix. Future renames will be performed at well defined times and obsolete function/variable definitions will be provided for backward compatibility. No renames are planned at present. * The external libraries `git-commit-mode.el' and `git-rebase-mode.el' are no longer required and have to be uninstalled because they conflict with their successors `git-commit.el' and `git-rebase.el', which are now maintained inside the Magit repository instead of the Git-Modes repository. The library `git-commit.el' can be used without Magit, so it is distributed as a separate Elpa package. However, `git-rebase.el' now depends on several Magit libraries and is therefore distributed as part of the `magit' package. * The library `magit-key-mode.el' was removed and replaced with `magit-popup.el'. The new implementation is much more flexible and easier to use than the old one. Major new features include setting default arguments directly inside the popup and macros for defining new popups and extending existing popups. This new library can also be used by packages that are not related to Magit and is therefore available as a separate Elpa package. * The library `with-editor.el' was added. Its purpose is to use the emacsclient as $GIT_EDITOR when git is started as a subprocess and requires an editor. This is used while committing and rebasing. This also works over Tramp, where a "sleeping editor" shell script is used to communicate over standard output instead of a socket like the emacsclient does. The `1.4.0' release already supported this, but this release splits this feature into a separate library. And now that it is a separate library, it can also be used by packages that are not related to Magit. `with-editor.el' is distributed as a separate Elpa package. * All libraries are now located in the new `lisp/' subdirectory. * The library `magit.el' has been split into many new libraries. The code base is now much better organized. Together with the description of plumbing commands in the manual, this should make it much easier for contributors to get started. * The library `magit-wip.el' has been rewritten from scratch and no longer depends on the external and unmaintained shell script from https://github.com/bartman/git-wip. * There are now three different modes that commit to the work-in-progress refs before/after certain events, and in addition to the old working tree wip refs, these modes now also commit to index wip refs. When these new modes are turned on, Git's protection of committed (but dangling) changes is effectively extended to uncommitted changes (which some exceptions). These modes are not enabled by default due to performance concerns. * The library `magit-blame.el' has been rewritten from scratch. The new implementation can blame recursively, jump to the next/previous chunk from the same commit, replace headings with separator lines, scroll the revision buffer for the chunk at point (like log buffers), and fine-tune the arguments for `git blame' using a popup. * The new library `magit-ediff.el' replaces the old Ediff support. The new implementation comes with a dwim command and a popup, and it relies less on high-level functions provided by VC and Ediff itself, because many of those turned out to be unsuitable. * The popular third-party library `dash.el' is now required. This is the only mandatory external dependency now, except for Git and Emacs themselves, of course. * When using Ido inside Magit, users now have to install the third-party library `ido-completing-read+.el'. This is necessary because the function `ido-completing-read', which is part of the built-in library `ido.el', is not a sufficient drop-in replacement for `completing-read'. * The new macro `magit-insert-section' replaces `magit-with-section'. The macros `magit-cmd-insert-section' and `magit-git-insert-section' were removed without a direct replacement. * The new functions `magit-insert' and `magit-put-face-property' take care of working around the fact that negative overlay priorities are not supported, i.e., that overlays always take precedence against text properties. Previously this was done in various places, and not always correctly (e.g., in some cases overlays did not evaporate). * The section visibility and movement commands were rewritten from scratch. All those commands now share the prefix `magit-section-' and edge cases are handled better. New commands were added that allow cycling the visibility of sections and their children. From a user perspective Magit's section handling is now quite similar to that of Org mode. * The macro `magit-section-action' was removed. The related macro `magit-section-case' still exists and will continue to do so. The action variant provided user-customizable hooks, but these hooks were rarely, if ever, used. Instead of such action hooks, users who wish to extend Magit now have to use type-specific section keymaps. * Section highlighting was rewritten from scratch. The new implementation uses hooks to allow washing certain section types differently than others - without obfuscating the simple cases. Washing diffs is much more complicated than washing all other sections, and that part has been factored out. The washing of all other section types is now quite simple. * The appearance of the region now indicates whether it is valid as a selection. As far as Magit is concerned, valid selections are hunk internal regions and regions that mark sibling sections of the same type. When a region does not satisfy one of these, then it is displayed the sames as in other buffers and Magit cannot act on it. * The new option `magit-no-confirm' makes it easy to forgo having to confirm potentially dangerous actions. Many of these actions are only dangerous for users who don't know how to undo them. When the wip modes are turned on, many more previously fatal actions can be easily undone. Adding `safe-with-wip' here makes it unnecessary to confirm these actions. * The new Refs buffer combines the features of the old Wazzup and Branch Manager buffers into one, more powerful and efficient synthesis. For each reference, cherries can be shown by expanding the ref section, but unlike in the Wazzup buffer, the cherries are not calculated until the expansion happens, making it vastly more efficient. Besides local and remote branches, the buffer now also lists tags, and users can add additional sections listing other refs, e.g., stashes. The format of refs headers is now customizable. * File-visiting buffers are now reverted without using code from the built-in `autorevert.el` library. The function we previously used was intended for internal use only and indeed, changes made there broke Magit in the past. * The new option `magit-revert-buffers' controls whether and how buffers visiting tracked files are reverted. As before, such buffers are reverted by default. But by default this is now done rather noisily to encourage users to read the doc-string and pick what is right for them. It's now also possible to revert asynchronously and for the user to be asked every time there are buffers that could be reverted. This option replaces `magit-auto-revert-mode`. * Many new section inserters are available. Some are variations of default inserters; `magit-insert-unpulled-cherries', for example, is like `magit-insert-unpulled-commits' but prefixes each commit with "+" or "-" to indicate its "cherry state". Other inserters are completely new (e.g., `magit-insert-unpulled-module-commits'). * The header sections in status buffers can now be customized using the new `magit-status-headers-hook'. This is an additional section insertion hook; separating it from `magit-status-sections-hook' gives users complete control over what information is displayed in the headers, while still making the first header the parent section of all the other header lines. * Many commands that previously could only act on the section at point can now act on all sections selected by a region, which can span sibling sections of the same type. * Many commands now more intelligently dwim based on the section at point. * Where it makes sense, completion and confirmation have been merged into a single user action. Many commands that previously allowed carrying out or aborting some action now also allow the user to act on something different from the default choice. Where one previously had to confirm with `yes RET', one now confirms with just `RET' (to accept the default choice, which previously was the only choice). * The distinction between the various "apply variants" has been clearly worked out, and they now all provide the same feature set. The variants are: stage, unstage, discard, reverse, and "regular apply". In all cases, it is possible to act on a file or hunk, or part of a hunk. When acting on the hunk level, all variants are implemented on top of `git apply', thus the name "apply variants". Un-/staging has always been one of Magit's most beloved features, and this release takes it to the next level by making the other apply variants just as consistent, powerful, and intuitive to use. All apply variants are context aware, meaning that, for example, the stage variant knows that an already staged change cannot be staged. That leads to better error messages. * The committing prefix now features additional variants. It was already possible to quickly create a fixup or squash commit; the new variants do that and then also instantly perform a rebase to actually combine these commits with their intended target commits. * Rebase sequences are now initiated from the new rebasing prefix. Several rebasing variants exist, of course including basic "rebase onto something" and interactive rebase. Other variants automatically detect and combine squash and fixup commits with their intended targets. Others let the user edit or reword a single commit, without having to go through the steps that are irrelevant in these cases. * When a rebase sequence stops at a commit, then the rebasing prefix instead features suffix commands for continuing, editing, or aborting the sequence; or skipping the current commit. * When a rebase sequence stops, the status buffer displays a list of the already applied and yet-to-be applied commits. These commits can be acted on like those in logs. * Cherry-picking, reverting, and applying patches using `git am' are treated the same way as rebasing. A prefix command features several variants to initiate the sequence. When a sequence is in progress, then the same prefix instead features suffix commands for continuing or aborting the sequence, and the status buffer lists the relevant commits. * The magit-specific "rewriting" feature has been removed because it was a hybrid of "rebasing" and "cherry-picking" and vastly inferior to both of them. * The merging prefix features several new convenient merge variants. * Merges can now be previewed before actually carrying them out. * When a merge results in conflicts then the commits being merged are listed in the status buffer, making it easier to review conflicting changes in the context they were created. * Its now possible to discard one side of a conflict directly from the hunk containing the conflict, using the regular discard key `k'. It's also possible to restore a conflict. * When using an existing branch as the starting-point of a new branch, it is now automatically configured as the upstream branch. * The branching prefix now features suffix commands for un-/setting the upstream branch. Previously this was coupled with pushing in a truly obscure way. * Branch descriptions can now be displayed in the refs or status buffer, and the description can be edited using a suffix command from the branching prefix. * The URL of a remote can now be changed from the remoting prefix. * A new pulling prefix command was added, which features several new pulling variants. Previously only one pulling command existed and it had to be controlled using prefix arguments, which was very cumbersome. * A new pushing prefix command was added, which features several new pushing variants. Previously only one pushing command existed and it had to be controlled using prefix arguments, which was very cumbersome. * The various tagging commands are now suffix commands of the new tagging prefix command. * It is now possible to stash, or create a snapshot from, just the staged or the unstaged changes, instead of both. Suffix commands for branching, listing, and showing stashes were added to the stashing prefix * When creating stashes the new implementation in `magit-wip.el' is used instead of `git stash'. This allows the user to create snapshot stashes without touching any files in the working tree. * The submodule prefix now features new suffix commands for adding, setting up, and fetching modules. * Submodules with unmerged commits can now be displayed in the status buffer. Sections representing submodules can be expanded to show their unpulled commits. These commits can be acted on like commits belonging to the super-project. * Support for displaying diffs inside the log buffer instead of in a separate diff buffer has been removed. It might come back one day, but the old implementation had just fallen behind regular one-line log too much. * The logging prefix features many new infix arguments and suffix commands, which can now be combined in more flexible ways than before. * Many commands that previously read a single commit, branch, or file in the minibuffer, can now read multiple, comma-separated items from the user, while providing completion candidates for all of them. Likewise, when selecting a range, completion is available for the second commit too. * All of Git's reset variants are now exposed as individual commands, but not all of them have a key binding by default. This was just the tip of the iceberg. Authors ------- 2187 Jonas Bernoulli 28 Sebastian Wiesner 25 Kyle Meyer 19 Noam Postavsky 17 Pieter Praet 12 Rémi Vanicat 9 Florian Ragwitz 5 Philippe Vaucher 5 Ramkumar Ramachandra 4 Cornelius Mika 4 Kan-Ru Chen 4 Syohei Yoshida 3 Alex Dunn 3 Alex Kost 3 Nicolas Richard 2 Eric Schulte 2 Ingo Lohmar 2 Mitchel Humpherys 2 Peter Eisentraut 2 Ryan C. Thompson 1 Adeodato Simó 1 Andrew Schwartzmeyer 1 Andy Sawyer 1 Bradley Wright 1 Guillaume Martres 1 John Mastro 1 John Wiegley 1 Julien Danjou 1 Lingchao Xin 1 Mark Oteiza 1 Michael Fogleman 1 Michael Griffiths 1 Michal Sojka 1 Natalie Weizenbaum 1 Oleh Krehel 1 Peter Vasil 1 Rüdiger Sonderfeld 1 Steven E. Harris 1 Teemu Likonen 1 Thomas A Caswell 1 Tim Perkins 1 Tim Wraight 1 Wei Huang 1 Xavier Noria magit-2.90.1/Documentation/RelNotes/2.10.0.txt000066400000000000000000000072341337354740400205470ustar00rootroot00000000000000It's Magit! A Git Porcelain inside Emacs ========================================= 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. For more information about Magit, see https://magit.vc. If Magit helps you be more productive, then please consider donating at https://magit.vc/donate/. Magit v2.10.0 Release Notes =========================== Released 4 January 2017 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.10.0, representing 85 commits by six people over one month. Also see https://emacsair.me/2017/01/04/magit-2.10. Changes since v2.9.0 -------------------- * Many new, well organized, libraries were added, consisting of code that was previously located inside a messier "magit.el". #2908 * The function `magit-display-buffer' now sets the focus on the frame used to display the selected window. #2865 * The Custom groups are better organized now. New groups were added, but many options also moved between groups that already existed before. 422d776e, 33c5c1ca * Many Custom groups and options now link to the relevant Info nodes and to other relevant groups. 810d7fb4 * Many doc-strings were improved, added, and fixed. 47aae617 * Added the function `magit-repolist-column-dirty', which can be added to `magit-repolist-columns' and `magit-submodule-list-columns'. #2907 * The obsolete variable `magit-repository-directory-depth' is no longer defined as an option. 09993c39 * The obsolete hook variable `magit-status-refresh-hook' is no longer defined explicitly. 7e96e831 Fixes since v2.9.0 ------------------ * Customizations of hooks were ignored, if the `custom-set-variables' form was evaluated before the Magit libraries were loaded. #2902 * When rebase stopped at a commit, point was no longer placed on that commit. #2884 * When creating a commit, `magit-display-buffer-fullcolumn-most-v1' filled the entire frame, hiding the commit message buffer. #2891 * The commands `magit-reflog' and `magit-reflog-current' reported a revision's reflog as empty when the name of a file in the repository, relative to the top-level directory, matched the revision name. 5264ffcb * The function `magit-repolist-column-upstream' returned the current branch instead of its upstream. 46acbd6d * The functions `magit-repolist-column-unpulled-from-upstream' and `magit-repolist-column-unpushed-to-upstream' raised a type error if the upstream was configured but did not exist. #2904 * The default values of the options `magit-submodule-list-columns' and `magit-repolist-columns' didn't match the documentation and the Custom type. But the code that that uses these values is resilient against that defect and so the only effect was that the values were reported as mismatched in the Custom interface. 79f6af23 * The Custom type of option `magit-update-other-window-delay' didn't match the default value. eb6d8bde * The shell command generated by `magit-emacs-Q-command' could end up trying to load a directory as a library, due to a bug in Emacs. 83980c66, debbugs#16406 This release also contains documentation updates and typo fixes. Authors ------- 68 Jonas Bernoulli 13 Kyle Meyer 1 Aleksey Uimanov 1 Alexander Gramiak 1 Noam Postavsky 1 Wouter Bolsterlee magit-2.90.1/Documentation/RelNotes/2.10.1.txt000066400000000000000000000037351337354740400205520ustar00rootroot00000000000000Magit v2.10.1 Release Notes =========================== Changes since v2.10.0 --------------------- * The command `ido-enter-magit-status' is now being autoloaded. #2918 * The minor-mode `bug-reference-mode' is now being suggested when customizing `magit-revision-mode-hook' and `git-commit-setup-hook'. e0d57c49 * The function `magit-version' can now deal with the Magit libraries being symlinked to, which is required for the new `straight' package manager. #2967 Fixes since v2.10.0 ------------------- * When multiple stashes were selected by the region, responding "no" when asked to confirm the deletion of these stashes resulted in a type error. #2917 * The function `magit-split-range' choked on ranges if one of the revisions was omitted, breaking a diff variant and potentially other uses as well. #2928 * The function `magit-commit-setup' called without an argument, which causes the option `enable-local-variables' to be ignored. #2946 * When committing inside a repository that was created using `git init --separate-git-dir', the diff buffer was empty, instead of showing the changes about to be committed. For some reason that git command, unlike other commands that do essentially the same thing, does not set `core.worktree', which confused Magit. #2955 * In the repository list buffer, the columns that are supposed to list unpushed and unpulled commit counts, were blank. #2960 * The command `magit-reflog-head' did not properly format reflog lines for branch renaming events. 2a268e20 * The commands `magit-diff-show-or-scroll-down' and `magit-diff-or-scroll-up' scrolled instead of updated the revision or stash buffer, when that already showed the requested reference but that reference no longer pointed at the same revision. #2966 This release also contains typo fixes and other documentation fixes. Authors ------- 16 Jonas Bernoulli 4 Kyle Meyer 2 Alex Kost 1 Kévin Le Gouguec 1 Radon Rosborough magit-2.90.1/Documentation/RelNotes/2.10.2.txt000066400000000000000000000030311337354740400205400ustar00rootroot00000000000000Magit v2.10.2 Release Notes =========================== Changes since v2.10.1 --------------------- * The new command `git-rebase-noop' adds a noop action during a rebase. It can be used to make git perform a rebase even if none of the commits are selected. #2991 Fixes since v2.10.1 ------------------- * Cherry-picking a commit with multiple parents was not possible, because "--mainline" was treated as a switch rather than an option, and because of a too-strict assertion that only single-parent commits can be cherry-picked. #2978 * `magit-abbrev-length' mishandled two edge cases, returning 0 when called within an empty repository or outside of a repository. 077740f5 * A bug fix in the last release broke the visit-file functionality in diff buffers displayed while committing. #2988 * Diff buffers did not recognize "rev^-n" as a short-hand for "rev^n..rev" (new in Git v2.11), resulting in the buffer header incorrectly indicating that the diff was between "rev^-n" and the working tree. 293f0cc8 * In diff buffers created using the dotted range notation, the command `magit-diff-visit-file' incorrectly swapped which revision was visited for deleted and added lines. For example, with the range "rev1..rev2", calling `magit-diff-visit-file' on a deleted line visited the blob for rev2. c24f32cd This release also contains other minor improvements, bug fixes, and documentation fixes. Authors ------- 10 Jonas Bernoulli 9 Kyle Meyer 1 Ben North 1 Fabian Wiget 1 Mark Oteiza magit-2.90.1/Documentation/RelNotes/2.10.3.txt000066400000000000000000000023571337354740400205530ustar00rootroot00000000000000Magit v2.10.3 Release Notes =========================== Changes since v2.10.2 --------------------- * The new command `magit-do-async-shell-command' opens the file at point with `dired-do-async-shell-command'. "&" is now bound to this command. #2992 Fixes since v2.10.2 ------------------- * The command `magit-bisect-run' now uses a shell to run the command entered in response to the "Enter shell command" prompt. #3001 * Discarding a renamed file failed if the original file was within a directory that no longer existed. #2998 * When inserting information about a rebase in progress into the status buffer, "exec" lines were treated as a commit, leading to an error. #3002 * The command `magit-blame' failed in blob-visiting buffers if the corresponding file no longer exists in the HEAD or the index. * The command `magit-remote-add' asked whether to set the new remote as the `remote.pushDefault', when that variable is already set and and it was configured not to ask in that case. 4f565039 This release also contains typo fixes and documentation improvements. Authors ------- 10 Jonas Bernoulli 2 Kyle Meyer 1 Basil L. Contovounesios 1 Damien Cassou 1 Duianto Vebotci 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.11.0.txt000066400000000000000000000214331337354740400205450ustar00rootroot00000000000000It's Magit! A Git Porcelain inside Emacs ========================================= 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. For more information about Magit, see https://magit.vc. Magit needs your help ===================== If Magit helps you be more productive, then please consider backing the fundraising campaign on Kickstarter. Thanks! <3 https://www.kickstarter.com/projects/1681258897/its-magit-the-magical-git-client?ref=ej621y Magit v2.11.0 Release Notes =========================== Released 13th September 2017 by Jonas Bernoulli. I am pleased to announce the release of Magit version 2.11.0, representing 303 commits by 26 contributors over six months. Also see https://emacsair.me/2017/09/12/magit-2.11. Changes since v2.10.3 --------------------- * The popup `magit-remote-popup' now exposes the `-f' switch for `git remote add', which allows the user to control whether information from the remote is fetched after the remote is added. The default behavior is still to fetch after adding a remote (i.e., the switch is enabled by default). #2997 * Added option `magit-list-refs-sortby' to allow more control over the order of refs in prompts. #2872 * The Magit wrappers around the default Emacs completion functions now override the default behavior of alphabetically sorting choices when displaying them in the "*Completions*" buffer. In repositories with many release tags, the new behavior prevents completion prompts from being dominated by version tags instead of branch names. #2925 * The commands `magit-git-command', `magit-git-command-topdir', `magit-shell-command', and `magit-shell-command-topdir' now use `read-shell-command' to read the command and a shell to run it. Packages like `pcmpl-git' and `bash-completion' can now be used to get command-line completion when using these commands. #2951 * The commands `magit-git-command' and `magit-git-command-topdir' can now call arbitrary commands. The initial-value when reading the command is "git ", and you can remove that to call something else. #2951 * Added option `magit-shell-command-verbose-prompt'. #2951 * The function `magit-branch-or-commit-at-point' now offers the appropriate default choice in a `magit-merge-preview-mode' buffer and in blob-visiting buffers. #3039, #3066 * On Travis tests are now run against all supported Emacs releases, as well as against snapshots of the `master' and `emacs-25' branches. #3046 * Added command `magit-debug-git-executable'. #3044 * Added new function `magit-display-file-buffer-other-window' to be used as `magit-display-file-buffer-function'. * Added `--mainline' switch to `magit-revert-popup'. #3018 * Added `magit-file-checkout' to `magit-reset-popup'. #3052 * When a revision is shown from a log buffer, the revision buffer now inherits the file restriction of the log buffer. #3056 * Added new command `magit-diff-toggle-file-filter'. #3062 * Added new option `magit-use-sticky-arguments' that provides more control over how diff and log commands reuse arguments from existing buffers. #3074 * Added imenu support in log, revision, and status buffers. #3022 * Added command `magit-abort-dwim` to abort the current operation. Depending on the context, this will abort a merge, a rebase, a patch application, a cherry-pick, a revert, or a bisect. #3017 * The command `magit-clone' now suggests a directory name that more closely follows `git clone' when no directory is given. #3079 * The commands `magit-subtree-add', `magit-subtree-pull', and `magit-subtree-push' now offer more completion candidates. #3081 * The log buffer now shows the line range restriction (i.e. `-L' argument) in its header. #3075 * Added new functions `magit-repolist-column-branches' and `magit-repolist-column-stashes', which insert the count of branches and stashes into submodules and repository list buffers. By default they are used in submodule lists but not in the repository list. * Text inside brackets in commit messages (including when shown in a log) are now highlighted using face `magit-keyword'. * Invocations of git are cached over the whole body of `magit-run-git', not just during the status buffer refresh. This should make staging and unstaging slightly faster. #3096 * When reading a value for the `--reuse-message' option, the popup `magit-commit-popup' now prompts with all ref names, offering `ORIG_HEAD' as the default if it exists. #3110 * Added bookmark support in status, refs, log, reflog, stashes, cherry, diff, revision, stash, and submodule-list buffers. #3113 * Added new function `magit-insert-modules', a wrapper around the existing `magit-insert-modules-*' functions. Also added options `magit-module-sections-hook' and `magit-module-sections-nested', to allow tuning the behavior of this function. #3141 * Renamed function `magit-insert-submodules' to `magit-insert-modules-overview' for consistency with other `magit-insert-modules-*' functions. #3141 * Inserting module sections is much faster now. #3141 * Added `--no-verify' switch to `magit-rebase-popup'. #3144 * The `--no-verify' switch in `magit-commit-popup' is now bound to "h" instead of "n" for consistency with `magit-push-popup' and `magit-rebase-popup'. #3144 * Added support for the file "EDIT_DESCRIPTION", which is used instead of "BRANCH_DESCRIPTION" for editing a branch's description as of Git 2.13.0. #3149 Fixes since v2.10.3 ------------------- * Rebasing was sometimes interrupted by an error about the index lock already being held. This happened because VC asynchronously checks for files with conflict, which involved using a git command that grabs the lock. Magit now redefines that VC command to use a git command that does not grab the lock. #2708, debbug#21559 * Adding an untracked subdirectory as a submodule failed if a remote was not configured for the subdirectory repository. #3047 * Parsing the log buffer failed if the log displayed a ref that contained parentheses in its name. #3028 * Parsing the `git show' and `git log' output for a signed commit failed with the Git variable `log.showSignature' enabled. #3061 * When deleting the current branch, `magit-branch-delete' did not ask for confirmation in some cases. #3058 * When using a non-standard `magit-display-file-buffer-function' that does not select the window used to display the buffer, then the point in that window was not adjusted. #3082 * `git-rebase-mode' did wrongly assume that there is no space after the comment character in action lines that are commented out. #3085 * The command `magit-show-commit' mistakenly displayed a tag's commit when point was on a branch with the same name. #3098 * The command `magit-log-buffer-file' miscalculated line numbers from the region. #3075 * Staging a link failed when it points to a repository. * When setting the upstream of a branch that isn't the current branch, the user was asked what branch to use as the upstream of the current branch anyway, even though the correct branch would then be modified. * When deleting a branch that is merged into the current branch but not into its own upstream branch, then the user was not offered to force the deletion, causing it to fail. #3107 * With `find-file-visit-truename' set to a non-nil value, the commands `magit-status' and `magit-init' failed to detect when their directory argument was a symlink that resolved to the output of `magit-toplevel'. #3115 * Using an url instead of a remote name as `branch..remote' was not properly supported, causing issues when trying to pull or push. #3116 * The log margin displayed invalid information for cherries. #3163 This release also contains the fixes described in the v2.10.{1,2,3} release notes, as well as other minor improvements, bug fixes, typo fixes, and documentation fixes. Authors ------- 148 Jonas Bernoulli 93 Kyle Meyer 15 Damien Cassou 15 Noam Postavsky 5 Basil L. Contovounesios 3 Justin Guenther 2 Alex Kost 2 Duianto Vebotci 2 Radon Rosborough 2 Štěpán Němec 1 Adam Benanti 1 Allen Li 1 Ben North 1 Erik Anderson 1 Eyal Lotem 1 Fabian Wiget 1 Ioan-Adrian Ratiu 1 Jeremy Meng 1 Justin Burkett 1 Justin Thomas 1 Kévin Le Gouguec 1 Marc Sherry 1 Mark Karpov 1 Mark Oteiza 1 Sean Whitton 1 Yuri Khan magit-2.90.1/Documentation/RelNotes/2.12.0.txt000066400000000000000000000670441337354740400205560ustar00rootroot00000000000000It's Magit! A Git Porcelain inside Emacs ========================================= Magit is a text-based Git user interface that puts an unmatched focus on streamlining workflows. Commands are invoked using short mnemonic key sequences that take the cursor’s position in the highly actionable interface into account to provide context-sensitive behavior. With Magit you can do nearly everything that you can do when using Git on the command-line, but at greater speed and while taking advantage of advanced features that previously seemed too daunting to use on a daily basis. Many users will find that by using Magit they can become more effective Git user. For more information about Magit, see https://magit.vc and https://emacsair.me/2017/09/01/campaign-articles. Magit v2.12.0 Release Notes =========================== Released 29th March 2018 by Jonas Bernoulli. I am pleased to announce the release of Magit version 2.12.0, representing 610 commits by 30 contributors over six months. Also see https://emacsair.me/2018/03/29/magit-2.12. Upcoming breaking changes ------------------------- * An upcoming release will remove support for older versions of Emacs. It isn't yet certain in what Magit release that will happen and what the new minimal version of Emacs will be. You should consider to update to the latest Emacs release now, or at least to v25.1, which was released one and a half years ago. * Likewise support for older versions of Git is going to be removed. You should update to at least v2.4, which was released almost three years ago. Older releases don't get security updates anymore, which is another reason to update. * The option `magit-no-confirm-default' has been demoted to a variable and will be removed in v2.13.0. Please migrate your customizations to the new option `magit-dwim-selection'. #3232 Changes since v2.11.0 --------------------- * Added new commands `magit-previous-line' and `magit-next-line' as substitutes for `previous-line' and `next-line'. Magit's selection mechanism is based on the region but selects an area that is larger than the region. This causes shift-selection to select two lines on the first invocation when using the vanilla commands. On section headings and inside hunk bodies the new magit-specific variants don't move point on the first invocation and thereby they only select a single section or line. Which inconsistency you prefer is a matter of preference. #2912 To use the Magit-specific variants add this to your init file: (define-key magit-mode-map [remap previous-line] 'magit-previous-line) (define-key magit-mode-map [remap next-line] 'magit-next-line) * The command `magit-refs-popup' now remembers arguments and they are displayed in the header-line of `magit-refs-mode' buffers. The popup command still invokes the default action by default when invoked from another buffer, but when invoked from a `magit-refs-mode' buffer it now shows the popup. #2898 * The module overview section now shows a hash for modules that don't have a tag and column alignment is optimized. #3160 * The diff that is being displayed while committing learned about a few more special cases. #3095 * Added new command `magit-branch-or-checkout' as a potential substitute for `magit-checkout'. Setup instructions can be found in the manual. #3104 * Added new customizable options `magit-log-highlight-keywords' and `magit-diff-highlight-keywords', which control whether text inside brackets is highlighted in magit-log and magit-diff buffers respectively. #3190 * When the names of Magit buffers are not uniquified then their names now end with an asterisk. When the `uniquify' package is used, then that still is not possible due to limitations in that package. #2841 * When selecting a fixup target then the log graph, which makes it less likely that you attempt to modify a merged commit, which would result in the merges being lost when rebasing. c0209c74d * Added the existing commands `magit-blame' and `magit-blob-next' to the `magit-file-popup' popup. * Added new command `magit-blame-reverse'. See the updated manual for information on how to best use this and other blaming commands. #3055 * Keywords in brackets are now being highlighted in `magit-refs-mode' and `git-rebase-mode' buffers, and the headers of `magit-status-mode' buffers, like they already were in logs. #3179 * Added new variable `magit-buffer-lock-functions' to support third-party packages in creating Magit-like buffers. #3191 * Improve padding of head-line and add new faces `magit-header-line-key' and `magit-header-line-log-select'. #3194 * When a stash has a note attached to it, then show it in the `magit-stash-mode' buffer. aff2fba8f * Added new command `magit-rebase-remove-commit' to the rebase popup. * The remote popup can now be used to set various remote related variables. #3165 * Added new commands `magit-patch-apply' and `magit-patch-apply-popup'. The latter is available from inside `magit-am-popup' ("w"). #2940 * Added new command `magit-patch-save' for saving a diff into a patch file. In diff buffers it is bound to "C-x C-w". #2950 * Added new command `magit-stash-branch-here', which — unlike the existing `magit-stash-branch' — creates a branch that starts at the current HEAD instead of at the commit that was current when the stash was created. #2935 * Added new command `magit-dired-log' intended to be bound in `dired-mode-map'. #3011 * The list of rebase actions displayed in the status buffer now also shows "exec" actions. #3003 * While it exists, the stash created by `git rebase --autostash' is now also displayed in the list of stashes. #3146 * When the current branch has no upstream or when all commits have already been pushed there, then the status buffer now shows `magit-log-section-commit-count' recent commits. If you previously used `magit-insert-unpulled-from-upstream-or-recent', then remove that from `magit-status-sections-hook', as it is an obsolete alias for `magit-insert-unpulled-from-upstream' now. #3227 * When switching between showing "Unmerged into " and "Recent commits", preserve the visibility of that section. #3227 * When prompting for a branch to delete, the current branch is no longer offered as default choice, except in cases where it is likely that that is actually what the user wants. #2924 * Added new popup `magit-worktree-popup' and bound "%" to it. #2927 * The commands `magit-file-delete' and `magit-file-untrack' now act on the selected files and with a prefix argument they force the action. #2930 * When requesting the history of a single file that is no longer being tracked, use the `--full-history' argument. Otherwise no history at all would be shown. #3012 * Added new option `magit-patch-save-arguments'. #3218 * Leading tabs in files no longer cause misalignment in diffs. This is done by overriding the mechanism used by the display engine to determine how wide a tab should be, which doesn't work when there are additional characters before the "leading" tabs that should count as an additional, but very short tab-stop. #3185 * The command `magit-visit-ref' now drops the prefix argument before calling `magit-show-commit' when appropriate, and when using the `create-branch' variant and the branch exists, then it offers to simply checking it out instead of resetting it first. #3009 * The output of `magit-list-repositories' is now sorted by module path instead of module name. b6f6cf4a6 * For a long time Magit has supported selecting two or more sibling sections using the region and then acting on that selection instead of only on the current section. Single-section selections were not supported and a region that did not span multiple siblings was not visualized as a selection. Now that is supported. Not every section-aware command was adjusted to take single-section selections into account because in many cases that would have led to undesired changes in behavior. #3026 * The command `magit-branch-spinoff' now spins off just HEAD when that constitutes the single-section selection. Previously one could only spin off all commits that weren't in the upstream yet or at least two commits. #2920 * Added switch `--local-user' to the tag popup. #3237 * When discarding untracked files, then offer to delete the buffers visiting them. #3243 * When there is a valid selection based on the region, then the region itself was never visualized. Now it is, but only if it stays within a single line. #3249 * Added new command `magit-branch-checkout' and bound "l" in the branch popup to it. This command always checks out a local branch. Valid inputs are an existing local branch, a remote branch for which no corresponding local branch exists, and a new branch name that doesn't match the name of any existing local or remote branch. #2906 * The command `magit-show-commit' now offers the revision at point as the default completion choice if the less generic mechanisms used to determine the "current" revision fail. This is useful for visiting revisions mentioned in commit messages. #2949 * Hashes inside commit messages are now turned into `commit' sections. Note that this can be disabled and that even if you do so you can still visit the commit at point using "RET". #2949 * The documentation regarding completion, confirmation, the selection, and the hunk-internal region was significantly extended. It might be worth reading that. * Added new option `magit-dwim-selection', which allows configuring commands that would otherwise ask the user to select among possible candidates to use the default instead, with or without confirmation. #3232 * When there is a stash at point, then the commands `magit-stash-drop' and `magit-stash-pop' now ask for confirmation. The former command previously allowed users to select another stash instead and the latter used to act on the stash at point without giving the user a chance to abort. These changes are implemented using the new option `magit-dwim-selection' and can easily be reverted. #2916 * Aborting a commit is seen as an error by Git and like all such errors it was reported to users, which led to confusion and a few bug reports. Now that non-error is being suppressed. #2932 * The option `magit-ref-namespaces' was demoted to a variable and its format changed. #2923 * Some refs that are being displayed in logs are now being compressed to save space while providing more information. #2923 * Added new option `magit-submodule-fetch-jobs'. By default multiple modules are being fetched in parallel now. #3261 * The command `magit-show-commit' now also shows notes specified using `notes.displayRef', not just those specified using `core.notesRef'. #2857 * The package `magit-popup' is maintained in its own repository now. 4d5d9bfac * The popup `magit-notes-popup' now shows the values of the relevant variables and allows changing them. #2857 * The cherry-picking commands now try to use or not use the `--mainline' argument as appropriate instead of erroring out. #2980 * Added `magit' as an alias for `magit-status' because I have been told that that improves discoverability. This might or might not make it easier for users to get started with Magit without taking a brief glimpse at the documentation. #3290 * The command `magit-log-buffer-file' now also works in Dired buffers. * The commands `magit-stage-untracked' has been taught about the Borg package manager. When staging a package repository it now offers to also assimilate (aka install) that package. dc857e2ed * Added new command `magit-browse-pull-request', which reads an open pull request and then visits it in a browser. For now this only supports Github, but other Git forges will be supported in the future. #3134 * Added new commands `magit-checkout-pull-request' and `magit-branch-pull-request' to the branch popup. For now they only support Github, but other Git forges will be supported in the future. #3134 * The command `magit-branch-delete' now offers to also delete the corresponding remote after deleting a local branch that was created with `magit-branch-pull-request' or `magit-checkout-pull-request', provided that remote has no other tracking branches. #3134 * When it is not possible to blame in reverse, then the blame popup does not offer that command anymore. c6ef61b2e * The mode line process indicator, displayed in the mode line when Git is run for side-effects, is now more visible than before, and is additionally used to highlight process errors. New face `magit-mode-line-process' is applied to the mode line process indicator to improve the visibility of pending asynchronous processes (in particular), as Magit remains responsive after initiating such commands (for instance fetching or rebasing), but will not update its buffers until the process has completed, which might take longer than anticipated. Customize this face if you wish to make this indicator more (or less) visible. #3284 If the Git process returns an error, the mode line process indicator is no longer removed, and new face `magit-mode-line-process-error` is applied to highlight the error status. Details of the error from the process buffer are also provided as a tool-tip. The error indicator will remain visible in the mode line until a magit buffer is refreshed. If you do not want errors to be indicated in the mode line, customize the `magit-process-display-mode-line-error' user option. #3297 * When staging and unstaging at the file level and there are arguments that cause whitespace differences to be hidden, then apply the visible changes using `git-apply' instead of using `git-add' and `git-rm' because doing that would also un-/stage the invisible changes. #3102 * Added new command `magit-diff-visit-file-other-window'. It isn't bound by default because that would result in changes to existing key bindings, which is something that is frowned upon. To use this command add something like this to your init file. #2833 (define-key magit-file-section-map (kbd "SPC") 'magit-diff-visit-file-other-window) (define-key magit-hunk-section-map (kbd "SPC") 'magit-diff-visit-file-other-window) * The widths of tabs in diffs can now be adjusted to match the widths that would be used in the corresponding file-visiting buffers. This is disabled by default because it can be expensive to determine the appropriate values (and also unnecessary when using spaces for indentation). Use the new option `magit-diff-adjust-tab-width' to control if and when the tab widths should be adjusted. #2929 * Added documentation about how to contribute to the documentation. * In the references buffer the remote part of the branch names are now hidden in the remote specific lists of branches by default, which is done to preserves space. The option `magit-refs-show-remote-prefix' can be used to revert this change. * The mode `git-commit-mode' now offers three font-lock levels, including one that is fruitier than the previous font-lock level. Local and remote branches are shown using different colors now. 7a50bfdb0 ff * When a signed tag points at the shown revision, then the revision buffer now also contains information about the tag signature. #3015 * The commands `magit-remote-remove' and `magit-branch-delete' now unset the relevant push-remote related variables, which Git fails to do, unlike for other variable affected by the removal of a remote or branch. Likewise the command `magit-remote-rename' now renames such variables. #2850 * Depending on the value of the new `magit-branch-rename-push-target' option the command `magit-branch-rename' may now also preserve the local branch's push-remote or even rename the push branch on the remote. The default is to do both. #2850 * Added argument `--subject-prefix' to the patch popup. 24ce90832 * The section visibility is now being cached for all sections. Previously this was only done for some sections. When a section disappeared and later appeared again, then it went back to its initial visibility. The option `magit-section-cache-visibility' can be used to restrict the cache to certain sections again. #2780 * The section visibility cache can now also remember that a section should be expanded instead of being hidden when the latter is the default and the section reappears. Previously only the opposite was possible. #2780 * For `magit-status-mode' and `magit-refs-mode' buffers the visibility cache now persists when killing the buffer. #2780 * Added command `magit-remote-prune-refspec', which is necessary because Git does not ignore invalid refspecs and instead refuses to fetch using only the refspecs that are still valid. #3134 * Sections are now defined as classes instead of as structs. This is only a first step towards taking advantage of generic methods. A few subclasses are already being defined and dedicated slot accessors have been deprecated in favor of `oref'. 651a9abcc ff * When asking the user whether to save modified file-visiting buffers during a refresh, then also allow them to remember the choice for the current session. I still think it is better to just always save by setting the option `magit-save-repository-buffers' to `dontask'. #3344 * The terminology about modules as used by Git is ambiguous. Magit now avoids the term "initialized" and instead uses the term "populated" to refer to a module whose working directory exists. The names of commands have been adjusted accordingly. For example, unlike "git submodule init", which does *not* actually "initialize" a module, `magit-submodule-popuplate' does "populate" a module (using "git submodule update --init"). #2911 * Most module commands now default to act on the selected modules or if no modules are selected the current module, if any. Otherwise they fall back to read a single module from the user. Previously some of these commands acted on all modules and it was not possible to perform the respective actions on a subset of modules. Acting on all suitable modules is still possible using a prefix argument. #2911 * Many arguments have been added to the module popup. #2911 * Added new option `magit-refs-filter-alist', which allows omitting some references from being displayed in `magit-refs-mode' buffers. * Added new command `magit-merge-squash'. #3348 * Several new libraries were created from code previously in magit.el. 0d6389680 * Added new commands `magit-merge-absorb' and `magit-merge-into', which not only merge a local branch into another but also remove the merged branch. #2922. * Added new commands `magit-cherry-harvest', `magit-cherry-donate', `magit-cherry-spinout' and `magit-cherry-spinoff', which move commits from one branch to another and also remove them from the branch where they were previously located. #2921 * Added new command `magit-diff-unmerged' and taught `magit-diff-dwim' about unmerged changes too. #3382 * The command `magit-push-refspecs' got its own history variable. #3361 * By default the names of Magit buffers now either have a star at both ends, or at neither when using the `uniquify' package. 831372a4f * Added new commands `magit-branch-shelve' and `magit-branch-unshelve'. Use them to replace a branch with a less visible ref while preserving the ref log. This is useful for work that you probably but not certainly will end up discarding. You might want to add these commands to the branch popup. 568b11f64 * The look of `magit-refs-mode' buffers was changed to save horizontal space and three new options `magit-refs-primary-column-width', `magit-refs-focus-column-width' and `magit-refs-pad-commit-counts' were added. #3378 * When the dispatch popup is invoked in non-Magit buffers, then certain actions that cannot be used there are no longer shown. 83cc91a30 * When the dispatch popup is invoked in a file-visiting buffer, then it now also lists the actions from the file popup. 40361273a * Added new variable `magit-log-format-message-function'. #3384 * Added commands `magit-commit-reshelve' and `magit-reshelve-since', replacing and improving upon commands from the `magit-rockstar' package, which was deprecated. The former changes the dates of HEAD and the latter those of a range of commits leading up to HEAD. * Added argument `--reverse' to the log popup. When that argument is used, then the incompatible `--graph' is silently dropped. 07e1d69d2 * Added new option `magit-log-header-line-function'. #3395 * Added new command `magit-remote-prune'. 6258dd92c * Added new hook `magit-unwind-refresh-hook', which is like the existing `magit-post-refresh-hook' except that is runs even if an error occurs during the refresh. 9f838cc04 Fixes since v2.11.0 ------------------- * `git-commit-propertize-diff' could end up making the buffer read-only. 746f2361b bc1093846 magit-popup: locally set help-window-select when describing function c9689c670 magit-popup: locally set another display-buffer variable * `git-rebase-mode-show-keybindings' failed to process non-English usage instructions in interactive rebase buffers. #3175 * The refresh cache was not properly invalidated after creating a new repository. 7a1f1eb44 * The `with-editor-mode' minor-mode was sometimes enabled twice in the same buffer. 9be36868b * For bare repositories all files were shown as being deleted in some contexts. b5f05c457 * When a command was invoked from a popup and it set `this-command', then that was later overwritten. a74c9b9d4 * While setting `magit-credential-cache-daemon-socket's initial value an error occurred when `credential.helper's value is the empty string. 4b15d5825 * Fixup commands did not warn about merges in the rebase range until after creating the fixup commit. #3176 * Instant fixup allowed selecting a commit that is not reachable from HEAD, which, for the instant variants (but only those), clearly is a user mistake that should be caught immediately. #3176 * If `magit-git-executable' is an absolute path, then an error occurred in `magit-debug-git-executable'. 9b7e34c29 8ed2eb4f5 magit-branch-reset: use magit-local-branch-at-point * The previous window configuration was not restored by `magit-log-select-pick' and `magit-log-select-quit'. #3211 * When `magit-branch-spinoff' failed to perform the checkout it never-the-less attempted to perform the subsequent steps. #3210 * Jumping to the correct location in a man page failed for many switches and options. deb482063 ff * The default action of `magit-branch-config-popup' was a command that isn't even available in the popup. eaa836fe2 * The command `magit-branch-spinoff' didn't try to prevent the user from entering a string containing whitespace as a branch name. bd6055ab2 * The command `magit-commit' failed to commit everything after asking for confirmation if it is called from a subdirectory. #3221 * The command `magit-completing-read' didn't offer any completion candidates. 387257f20 * In some cases an error occured when showing the remote popup because the length of the remotes name was not taken into account. a9177e5b9 * The command `magit-branch-rename' failed to rename a local branch if a tag existed with the same name. #3222 * The command `magit-file-delete' ignored the prefix argument instead of forcing the action as intended. 0df686bfd * Fixed a broken highlighting special case. #3238 * When staging all unstaged changes using "s" on "Unstaged changes" while there also are staged changes, then the user was not asked for confirmation. #3238 * When reverting a commit users are required to edit the revert message on some platforms but not on others. #3239 * In a secondary worktree `magit-git-dir' failed to return a remote path when the repository is accessed using Tramp. #3228 * When the user chose the default offered by `magit-patch-apply', then that function failed to expand the file-name so that Git would understand it. ab00c5ba2 * The face `magit-graph' was also used for the commit message, which only was noticeable when the face was customized. It appears that nobody ever did that. 47e94767b * When `magit-branch-read-upstream-first' is nil, then the value returned by `magit-branch-read-args' was broken. #3268 * Fixed encoding of non-ascii filename arguments to git on `windows-nt' systems. #3250 * A bug in `magit-list-active-notes-refs' slowed down `magit-show-commit'. #3275 * The command `magit-worktree-checkout' wasn't able to checkout arbitrary commits, just refs. #3277 * Due to misunderstood `flyspell' implementation details `git-commit-turn-on-flyspell' did some unnecessary work and made claims that are not actually true. 24c966082 * When the git executable could not be found, then Magit often claimed that the user was doing something outside of a Git repository instead. #3310 * The command `magit-submodule-add' always used a kludge that is only needed when using Ido, resulting in a unnecessary removal of functionality. 5e43377d2 * The function `magit-maybe-save-repository-buffers' in some cases needlessly redisplayed a message. #3319 * The branch description was displayed in weird ways in a few places. d98c44bd7, 9003b85da * When stashing untracked files, then the untracked files in subdirectories were not removed from the working tree. #3334 * The command `magit-worktree-delete' failed to delete a worktree when its directory no longer existed. #3355 * A kludge used to work around a bug in Emacs 24 prevented `magit-copy-buffer-revision' from deactivating the mark. #3352 * When visiting the last blob that still had the line at point in a diff, then that only jumped to the correct line, but not the correct column. ebe3b5229 * For unpopulated modules `magit-list-submodules' showed information about the super-repository instead. Now such modules are omitted. 1c4fa9b14 * The commands `magit-am-apply-patches' and `magit-am-apply-maildir' did not work over Tramp because they passed Tramp file names directly to git. This was fixed in a way that should prevent similar issues elsewhere. #3368 * The function `magit-branch-commit-at-point' preferred tags over branches, which is a strange default for most callers. f2b318856 * The arguments set in the popup were ignored when displaying tags in refs buffers. ae007a757 * When `magit-diff-section-arguments' calls for it, then all diff-related sections are supposed to be limited to a subdirectory, but sections listing untracked and tracked files ignored it. #3376 * Saving wip refs often failed because `magit-update-ref' used the refresh cache. e0e1a44f3 * Buffers listing repositories using `tabulated-list-mode' did not preserve point when being refreshed. 2f0302635 This release also contains other minor improvements, bug fixes, typo fixes, and documentation fixes. Authors ------- 500 Jonas Bernoulli 26 Kyle Meyer 15 Phil Sainty 13 Alexander Gramiak 13 Noam Postavsky 7 Sean Allred 4 Basil L. Contovounesios 3 Bastian Beischer 3 Damien Cassou 3 Štěpán Němec 2 Bar Magal 2 Daniel Mai 2 Matthew Fluet 1 Chris LaRose 1 Daniel Gröber 1 Daniel Kraus 1 David Ellison 1 Fritz Stelzer 1 Jim Blandy 1 John Mastro 1 Kenny Ballou 1 Matthieu Hauglustaine 1 Matus Goljer 1 Orivej Desh 1 Philipp Stephani 1 Radon Rosborough 1 Vladimir Panteleev 1 Wilfred Hughes 1 Wouter Bolsterlee 1 Xu Chunyang magit-2.90.1/Documentation/RelNotes/2.12.1.txt000066400000000000000000000004521337354740400205450ustar00rootroot00000000000000Magit v2.12.1 Release Notes =========================== Fixes since v2.12.0 ------------------- * Magit 2.12.0 depended on a non-existent Magit-Popup version. * Key bindings in `magit-remote-popup' conflicted. Authors ------- 8 Jonas Bernoulli 1 Dean Kariniemi 1 Phil Sainty magit-2.90.1/Documentation/RelNotes/2.13.0.txt000066400000000000000000000117061337354740400205510ustar00rootroot00000000000000It's Magit! A Git Porcelain inside Emacs ========================================= Magit is a text-based Git user interface that puts an unmatched focus on streamlining workflows. Commands are invoked using short mnemonic key sequences that take the cursor’s position in the highly actionable interface into account to provide context-sensitive behavior. With Magit you can do nearly everything that you can do when using Git on the command-line, but at greater speed and while taking advantage of advanced features that previously seemed too daunting to use on a daily basis. Many users will find that by using Magit they can become more effective Git user. For more information about Magit, see https://magit.vc and https://emacsair.me/2017/09/01/campaign-articles. Magit v2.13.0 Release Notes =========================== Released 2nd June 2018 by Jonas Bernoulli. I am pleased to announce the release of Magit version 2.13.0, representing 166 commits by 18 contributors over two months. Also see https://emacsair.me/2018/06/02/magit-2.13. Upcoming breaking changes ------------------------- * This is the last release to support Emacs 24.4. Going forward at least Emacs 25.1 is required. * This is the last release to support Git 1.9.4. Going forward at least Git 2.4 is required. * Many functions and variables that have been declared obsolete for a while now are going to be removed after this release. All of these changes will happen on "master", the development branch. Note that the snapshot packages on Melpa are built from that branch. If you cannot update Emacs and/or Git now, then you should pin Magit to Melpa-Stable to stick with this release (and bugfix releases) for the time being. Breaking changes ---------------- * As announced earlier, the obsolete option `magit-no-confirm-default' has been removed. #3232 Changes since v2.12.0 --------------------- * Augmenting a file- or blob-visiting buffer with blame information was completely rewritten, making the implementation more robust and adding many new features. It is now possible blame in order to get an answer to the question "what commits remove these lines". It is no longer necessary for the buffer to be put into `read-only-mode', when displaying blame information. New visualization styles were added and users can define their own styles. New commands to visit blobs related to the current chunk were added. * Added new command `magit-tag-release'. This is a fairly opinionated command and its only use to you might be to serve as a template for your own variant. * Added new section inserter `magit-insert-ignored-files', which could be added to `magit-status-sections-hook'. * The mode `global-magit-file-mode' is now enabled by default, making the `magit-file-popup' available on "C-c M-g". 0ec28b97 * Added new commands `magit-log-trace-definition' and `magit-diff-trace-definition', which show a log with diffs about the definition at point. #2588 * Added new commands `magit-edit-line-commit' and `magit-diff-edit-hunk-commit', which allow editing the commit that added the line at point. febe79ba 22b13337 * The interactive prompts for the various reset commands now indicate the branch which is going to be reset. #3438 * Added new option `magit-published-branches', providing an additional safety-net. If you try to modify a commit that has been pushed to one of these branches already, then you are now being asked whether you really want to do that. Do not rely on this exclusively, there are edge-cases that are ambiguous and are not always handled as you might have expected. add4a7f3 ff * Gravatar images are now being inserted asynchronously. #3452 * After deleting the current worktree, `magit-delete-worktree' now shows the status buffer for another worktree. d9cd4611 * Added new command `magit-worktree-checkout-pull-request'. a3d788ec * New variable `magit-get-previous-branch-timeout' limits the amount of time spent in `magit-get-previous-branch'. #3457 Fixes since v2.12.0 ------------------- * The recently added command `magit-branch-pull-request' had various issues concerning pull-requests referencing branches from the upstream repository. #3416 #3417 #3461 * The values of diffstat sections was wrong for sections that represent renamed files. 66d9558f * Time zones were not handled correctly when calculating times for blame headings. #3443 This release also contains the fixes described in the v2.12.1 release notes, as well as other minor improvements, bug fixes, typo fixes, and documentation fixes. Authors ------- 138 Jonas Bernoulli 6 Kyle Meyer 2 Alban Gruin 2 Basil L. Contovounesios 2 Buster Copley 2 Christophe Junke 2 Mario Rodas 2 Phil Sainty 1 Aaron Madlon-Kay 1 Ben North 1 Dean Kariniemi 1 Eli Barzilay 1 Jon Vanderwijk 1 Jonathan Leech-Pepin 1 Justin Guenther 1 Li-Yun Chang 1 Marc Sherry 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.13.1.txt000066400000000000000000000021461337354740400205500ustar00rootroot00000000000000Magit v2.13.1 Release Notes =========================== Fixes since v2.13.0 ------------------- * The prompt used by `magit-rebase-interactive-assert' was wrong. 37d76f409 * `magit-rebase-autosquash' asked for confirmation when the user already confirmed earlier. 02e6c75b6 * `magit-log-wash-rev` errored in ~magit-cherry-mode~, starting with Emacs 26.1. 1ee577b35 * Magit used a completion function to make the built-in completion respect the collection's order. Even though that wasn't necessary for Ivy and Helm it did the same here, which became a problem when a change in Helm caused fuzzy completion to break in combination with a completion function. Likewise a change in Ivy caused Magit's sort order to be ignored, which we work around now. #3476, #3477 * When using cygwin, then `git-commit-setup-font-lock' could end up trying to run git in a non-existent directory. #3505 * `magit-insert-modules-unpushed-to-pushremote' failed to insert anything due to a typo in the used commit range. d4e159f35 Authors ------- 11 Jonas Bernoulli 8 Kyle Meyer 5 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.2.0.txt000066400000000000000000000222231337354740400204630ustar00rootroot00000000000000Magit v2.2.0 Release Notes ========================== Released 16 August 2015 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.2.0, representing 321 commits by 19 people over 6 weeks. I would like to thank Kyle Meyer and Noam Postavsky for joining the developer team and helping me with this release. -- Jonas Changes since v2.1.0 -------------------- * The Elpa packages `with-editor' and `magit-popup' now depend on the package `async' and turn on the mode `async-bytecomp-package-mode'. If available, the mode is turned on even when these packages have not been installed from an Elpa archive. It is being turned on in both of these libraries because any one of them might be the first package from the Magit repository that is being updated. It is possible to prevent the mode from being turned on when loading these libraries by setting `async-bytecomp-allowed-packages' to nil before loading them. If you do that, then you must mention that you have done so when reporting a bug (which might therefore be due to miscompiled files). Turning on `async-bytecomp-package-mode' advises `package--compile', instructing it to compile Magit and its dependencies (as well as others packages listed in `async-bytecomp-allowed-packages' and their dependencies) in a separate Emacs instance. Unfortunately it is necessary that we do this because when an old version of a package is already loaded when a new version is being installed, then the old version sometimes interferes during compilation of the new version, leading to miscompiled files. This usually does not happen very often, but when updating from Magit v1 to v2 then it is expected, which is why users were instructed to uninstall the old version before installing v2.1.0. Unfortunately many users never saw those instructions, so we have no choice but to use this approach to get rid of miscompiled files. * Two new commands have been added to the diff refresh popup that allow the range of the previous diff to be manipulated. `magit-diff-flip-revs' swaps the revisions of the range, and `magit-diff-switch-range-type' toggles between ".." and "..." range types. * The commands `magit-ediff-show-unstaged', `magit-ediff-show-staged', `magit-ediff-show-commit', and `magit-ediff-show-working-tree' have been added to the Ediff popup. * New option `magit-ediff-dwim-show-on-hunks' controls whether calling `magit-ediff-dwim' runs a show variant (`magit-ediff-show-unstaged' or `magit-ediff-show-staged') rather than `magit-ediff-stage' when point is on an uncommitted hunk. * `magit-diff' and `magit-ediff-compare' no longer prompt the user for confirmation when constructing a range from the last and first commits selected by a region. A prefix argument can now be used to specify that the diff is between the second revision and the common ancestor of both revisions (i.e., the "..." range type is used). * `magit-ediff-*' variants now limit file choices to those that have changed between the revisions of interest. If only one file has changed, this file is used without prompting. * `magit-diff' and `magit-ediff-compare' now consider the location at point when choosing the default for the prompt, and this default value usually corresponds with the actions of their DWIM counterparts. * The key in Ediff popup for `magit-ediff-compare' has changed from "d" to "r" to be consistent with the key in the diff popup for the similarly behaved `magit-diff`. * Entering a single commit for the range to `magit-ediff-compare' now compares the commit with the working tree (like `magit-diff' and `git diff') rather than the previous commit. * The popup `magit-diff-refresh-popup' and its suffix commands and helper functions were fixed. Most importantly file arguments and diff-type arguments are no longer lost when this popup is used - it only changes those arguments it is supposed to change. Also the popup only lists the arguments which can actually be used in the current buffer (in status buffers fewer are supported than in diff-only buffers). * The popup `magit-diff-popup' and its suffix commands now use the arguments currently in the `magit-diff-mode' buffer of the current repository. Previously the arguments were always reset to the default value of `magit-diff-arguments'. * The default values of `magit-diff-section-arguments' and `magit-diff-arguments' now contain the `--no-ext-diff' switch. * New popup `magit-log-refresh-popup' allows changing the log arguments used in the current buffer. This allows changing the arguments used in a log buffer without having to specify the reference(s) again. And it makes it possible to change the log arguments used in the status buffer, which previously required that option `magit-log-section-arguments' was customized manually. * When a log is displayed for the purpose of having the user select a commit, then this is now displayed in a buffer separate from the regular log buffer. New option `magit-log-select-buffer-name-format' controls the name of that buffer and new option `magit-log-select-arguments' controls the arguments. * The default value of `magit-log-section-arguments' now contains the `--decorate' switch. * `magit-log-buffer-file' respects the log arguments currently in effect in the repositories log buffer, or if that doesn't exist the default value of `magit-log-arguments'. Because this command is not invoked from the log popup, it's now also possible to turn on the `--follow' using a prefix argument. * Log graphs are no longer shown in color by default, because turning the control sequences into faces is very inefficient. To allow users to get back the colorful graphs, the `--color' switch has been added to the log popup. * In the refs manager, `RET' on a local branch again "visits" that branch by checking it out (like in v1.4). With a prefix argument it instead "visits" the branch by showing information about other refs relative to the visited one (like in v2.1 even without a prefix argument). When the new option `magit-visit-ref-create' is non-nil, then a remote branch is "visited" by creating a new local branch that tracks that remote branch, and checking out that local branch. * To avoid losing any standard functionality, `C-w' and `M-w' now fallback to `kill-ring-save' when the region is active. They also work in more places and in some cases copy more useful information than before. * New option `magit-push-always-verify' has been added because changes in v2.1 caused many users to accidentally push to `master' instead of a remote feature branch as intended. All users should set this option to nil, but only after having read the documentation. The commands that respect this option instruct users to consult its documentation. * Moving through a log using `n' and `p' is now much faster because the revision buffer is no longer recreated for each commit along the way. Because Emacs does not support key-down-events this had to be implemented using a timer, which has the unfortunate effect that it leads to a delay even when only pressing one of these keys briefly to move by a single line. This delay can be adjusted using the new option `magit-diff-auto-show-delay'. * When creating a new branch, first reading the starting point and only then the name of the new branch has advantages. But many users disagree, so the option `magit-branch-read-upstream-first' has been added. It defaults to t. * New commands `magit-wip-log' and `magit-wip-log-current' allow showing log for a branch and its wip refs (which the various wip modes commit to). * New command `magit-submodule-deinit'. * New command `magit-commit-augment' allows the user to pick a commit to squash into and edit the squash commit message. * New push commands `magit-push-implicitly' and `magit-push-quickly'. * When reading user input, many commands now offer a better default choice and better completion candidates. * All apply variants now use `--3way' when called with a prefix argument. * Log commands now respect the entries in the .mailmap file. * The command `magit-pull-current' now also fetches tags by default. * When a file has conflicts then the type of conflict is shown now. * New option `magit-log-show-refname-after-summary'. * New section inserter `magit-insert-user-header'. * New face `magit-section-secondary-heading'. * New commands `magit-run-gitk-all' and `magit-run-gitk-branches'. The existing command `magit-run-gitk' now always calls `gitk' without any arguments. * New commands `magit-shell-command' and `magit-shell-command-topdir'. This release also contains various documentation fixes, code clean-ups, bug fixes, and other small to medium improvements. Authors ------- 225 Jonas Bernoulli 67 Kyle Meyer 8 Noam Postavsky 3 Mitchel Humpherys 2 Greg Lucas 2 Mark Karpov 2 Yuichi Higashi 1 Johann Klähn 1 Josiah Schwab 1 Kan-Ru Chen 1 Nicklas Lindgren 1 Phil Sainty 1 Richard Kim 1 Robin Green 1 Rémi Vanicat 1 Steven Vancoillie 1 Thomas Frössman 1 Ting-Yu Lin 1 Vineet Naik magit-2.90.1/Documentation/RelNotes/2.2.1.txt000066400000000000000000000022601337354740400204630ustar00rootroot00000000000000Magit v2.2.1 Release Notes ========================== Released 24 August 2015 by Jonas Bernoulli. This is a bugfix release. * The version strings in the manual were not set to "2.2" when v2.2.0 was released. * Some menu bindings were not adjusted when commands were renamed. * The "next" tag was never shown in the "Tag(s)" header of the status buffer. * Blaming did not abort gracefully when the user killed the buffer. * Blaming failed on indirect buffers. * Blaming did not detect when a file was untracked. * Blaming passed the wrong line range when the file's buffer was narrowed. * `magit-shell-command-topdir' used `magit-git-command' instead of `magit-shell-command'. * `magit-copy-as-kill' added "nil" to the `kill-ring' when there was nothing useful to put there. * `magit-find-file-hook', `magit-find-index-hook', `magit-refresh-popup-buffer-hook' were used without being defined using `defvar'. * `magit-format-ref-labels' failed to work around a Git bug, resulting in refnames not being colorized when `--simplify-by-decoration' is used. This release also contains various documentation fixes. Authors ------- 16 Jonas Bernoulli 11 Kyle Meyer magit-2.90.1/Documentation/RelNotes/2.2.2.txt000066400000000000000000000027251337354740400204720ustar00rootroot00000000000000Magit v2.2.2 Release Notes ========================== Released 3 September 2015 by Jonas Bernoulli. This is a bugfix release. * `magit-diff-wash-diff' choked on unmerged binary files. #2211 * `magit-blame-popup' did not allow empty input when reading a value for "-C" or "-M". #2208 * The `emacsclient' executables belonging to non-current alternative installations of Emacs on Debian were not considered when setting the default value of `with-editor-emacsclient-executable'. #2217 * `server-edit', which switches to a buffer preferably one with another client, was used when finishing or aborting a `with-editor' session. When `emacsclient' was used to connect to a server and then a commit or rebase was invoked, then there would be another client and switching to its buffer after finishing the commit or rebase would be undesirable. Now we use `server-done' instead. #2197 * When `--stat' abbreviates the name of a file, then that name was stored in the section object instead of the full name. #2199 * `magit-file-relative-name' with non-nil TRACKED failed in Tramp repositories. #2206 * After failing to clone, `magit-clone' also tried to show the status of the non-existent clone. #2203 * `magit-wip-log' did not display a log if the working tree or index ref did not exist. This release also contains various documentation fixes and code clean-ups. Authors ------- 29 Jonas Bernoulli 5 Kyle Meyer 1 Barak A. Pearlmutter magit-2.90.1/Documentation/RelNotes/2.3.0.txt000066400000000000000000000260031337354740400204640ustar00rootroot00000000000000Magit v2.3.0 Release Notes ========================== Released 28 October 2015 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.3.0, representing 367 commits by 12 people over 10 weeks. Changes since v2.2.0 -------------------- * Added `--interactive' switch to `magit-rebase-popup' so that rebase variants which normally perform a non-interactive rebase can be used to perform an interactive rebase too. #2186 * Commands that perform an interactive rebase should no longer be used non-interactively (i.e. they should only be used as commands). #2187 * Rebasing commands now can start with a root commit. Root commits are detected automatically, so users don't have to use the `--root' switch explicitly. #2187 * Added new command `magit-checkout-file'. * Added new option `magit-bury-buffer-function' to give users more control over how Magit buffers are buried, replacing the old binary option `magit-restore-window-configuration'. The default is still the same, i.e. `magit-restore-window-configuration' is used. #2193 * Added new function `magit-mode-quit-window' as a simpler variant to `magit-restore-window-configuration'. #2193 * Information about related refs in `magit-revision-mode' buffers are now grouped in the same section as other headers and are formatted like those other headers instead of like diffstats. The redundant header which previously grouped the related refs section is gone. All headers are inserted by the new `magit-insert-revision-headers' section inserter. #2216 * No longer avoid calling git more than absolutely necessary when creating a `magit-revision-mode' buffer. This simplifies parsing, makes it simpler to prettify how information is presented, allows users to customize how and in what order information is presented, and prepares for faster, asynchronously created diffs. #2216 * The various sections in revision buffers are now inserted using new section inserters named `magit-insert-revision-{*}', all of which are part of the default value of `magit-revision-sections-hook'. #2216 * The various sections in diff buffers are now inserted using new section inserters named `magit-insert-diff-{*}', all of which are part of the default value of `magit-diff-sections-hook'. #2216 * Added new option `magit-revision-headers-format' whose value is passed to `git show --format=' to insert most of the headers, excluding the related-refs headers. The default value now uses placeholders which respect information in the file ".mailmap". #2216 * Removed options `magit-revision-show-notes', `magit-diff-show-xref-buttons', `magit-revision-show-xref-buttons', `magit-diff-show-diffstat', and `magit-revision-show-diffstat'. Whether these sections are inserted is now controlled using the hooks `magit-diff-section-hook' and `magit-revision-section-hook'. #2216 * Gravatar images can now be shown in `magit-revision-buffers'. New option `magit-revision-show-gravatars' controls whether these images should be inserted and can also be used to adjust to customizations of `magit-revision-headers-format'. This feature is not enabled by default due to privacy concerns. Gravatar images are spliced into two halves which are then displayed on separate lines. On OS X the splicing has a bug in some Emacs builds, which causes the top and bottom halves to be interchanged. Setting the new option `magit-revision-use-gravatar-kludge' to `t' works around this issue. #2216 * After using the region to stage or discard parts of a hunk, point is now placed on the beginning of the next or previous block of changed lines. Previously we just jumped to the beginning of the hunk at the same index as the previous hunk, but that often was very far away from where point was before the refresh. #2227 * The function `magit-toplevel' was refactored and many tests were added. It now returns the correct value when a symlink to a sub-directory of a working tree is involved. #2242 * New option `magit-keep-region-overlay' allows displaying the region overlay together with the visualization of a valid Magit selection. See the doc-string for why we think you shouldn't do that, but if you disagree then you can now have it your way. #2091 * Avoid the inefficiency of `git log --graph --max-count=N REV' (it calculates the graph for all reachable commits, not just the N commits), by additionally limiting the history using a range calculated from REV and N, when possible. #2243 * Renamed `magit-file-buffer-mode' to `magit-file-mode'. Related symbols were renamed accordingly. * Added new minor mode `magit-blob-mode' and new commands `magit-blob-previous' and `magit-blob-next'. #2195 * Added new commands `magit-branch-spinoff' and `magit-branch-reset'. #2191 * Added new option `magit-status-expand-stashes'. * In addition to `default-directory' also set `list-buffers-directory' to the top-level of the working tree in Magit buffers, causing that directory to be displayed in the "File" column of the *Buffer List* buffer. * Added a kludge to keep Cygwin and MYSYS2 executables from expanding globs when called from a native Windows Emacs executable. #2281 * Added a revision stack. The new commands `magit-copy-section-value' and `magit-copy-buffer-revision', which are intended for use inside Magit buffers, push an entry to the stack, and the new command `magit-pop-revision-stack' inserts a representation into an editable buffer. New option `magit-pop-revision-stack-format' controls how the representation of the revision is formatted. The old commands `magit-copy-as-kill' and `magit-copy-buffer-thing-as-kill' have been removed. #2225 * The default values of options `magit-commit-extend-override-date' and `magit-commit-extend-override-date' changed to `t'. * Added new option `magit-log-show-margin'. * Added new option `magit-log-remove-graph-args'. #2226 * Added support for showing actionable diffs inside logs. #2226 * Added basic support for tracing the evolution of a region. #2226 * Added new command `magit-stash-format-patch'. * All apply variants learned how to apply multiple hunks at once. #2271 * Regular apply learned how to apply multiple files at once. #2271 * `git-commit-setup' learned to handle Cygwin paths. It had to be taught about that separately from the rest of Magit, because, for historic reasons, we try to keep the `git-commit' package usable without Magit. * The signatures of `magit-mode-setup' and `magit-mode-get-buffer' have changed, and `magit-mode-get-buffer-create' has been removed. Extensions have to be adjusted accordingly. #2282. * All Magit-Mode buffers (including process buffers, but excluding popup, blob-visiting, and file-visiting buffers, whose major-modes do not derive from `magit-mode' and therefore aren't "Magit-Mode buffers") are now displayed using `magit-display-buffer', which is a wrapper around the low-level `display-buffer'. High-level functions such as `pop-to-buffer' and `switch-to-buffer' are no longer used to display Magit buffers. `magit-display-buffer' uses the function specified by the new option `magit-display-buffer-function' to actually display the buffer in some window. The default value is `magit-display-buffer-traditional'. By implementing their own variant to wrap around `display-buffer', users can take complete control over how Magit buffers are displayed. It's also possible to use `display-buffer' directly and specify the display actions in `display-buffer-alist'. Added new options `magit-pre-display-buffer-hook' and `magit-post-display-buffer-hook', and removed the options `magit-status-buffer-switch-function' and `magit-diff-switch-buffer-function'. #2282 * Added new options `magit-generate-buffer-name-function', `magit-buffer-name-format', and `magit-uniquify-buffer-names', replacing the various `magit-{*}-buffer-name-format' options. #2282 * Added new command `magit-toggle-buffer-lock'. Previously it was possible to prevent Magit from reusing an existing buffer to display something else, using the command `magit-rename-buffer' (which was removed). Now this is done by locking the buffer to its value. #2282 * The status buffer is now always refreshed after running a Magit command triggers a refresh. Previously that was only the case if the buffer in which the command was invoked was a Magit buffer too. * Added optional support for refreshing the status buffer every time a buffer visiting a file, which is tracked in the current repository, is saved. To enable this add `magit-after-save-refresh-buffers' to `after-save-hook'. * Added new functions `magit-log-maybe-update-revision-buffer', `magit-log-maybe-update-blob-buffer', `magit-status-maybe-update-revision-buffer', and `magit-status-maybe-update-blob-buffer', and added some of them to `magit-section-movement-hook'. Removed the function `magit-log-maybe-show-commit', which served about the same purpose as these new functions. Previously one had to customize the option `magit-diff-auto-show' to control when the other buffer was updated, now one does so by adding or removing the above functions to or from `magit-section-movement-hook'. The other window is only ever updated now, to initially create it, use `SPC'. #2338 * Added new hook `magit-process-find-password-functions', with no default members. These functions, if any, are run when git requests a password from the user, if there are no such functions, or if they fail, then the user has to type the password as before. Added new function `magit-process-password-auth-source'. It can be added to that hook and uses `auth-source' to get the password from one of the sources it supports. #2311 * Removed broken support for unicode log graphs. * `magit-expand-git-file-name' learned to use the output of `mount' to map Cygwin paths into native Windows paths. `git-commit-setup' now uses `magit-expand-git-file-name' if available. #2348 * Added new function `magit-define-popup-sequence-action' and taught related functions about `:sequence-actions'. * Added new hook `magit-credential-hook' and added new hook function `magit-maybe-start-credential-cache-daemon' to it. This allows starting Git's credential daemon separately, which is necessary because Emacs sends SIGHUP and closes the pty when e.g `git push' (which started the daemon) finishes. Upon receiving that signal the daemon terminates. We work around this by starting the daemon directly before invoking the git subcommand which might need credentials. #2360 This release also contains the changes described in the v2.2.1 and v2.2.2 release notes, as well as various other documentation fixes, code clean-ups, bug fixes, and other small to medium improvements. Authors ------- 305 Jonas Bernoulli 38 Kyle Meyer 15 Noam Postavsky 1 Andriy Kmit' 1 Barak A. Pearlmutter 1 Brian Warner 1 Damien Cassou 1 John Mastro 1 Nicolas Petton 1 Nikolay Martynov 1 Peter Jaros 1 Phil Sainty magit-2.90.1/Documentation/RelNotes/2.3.1.txt000066400000000000000000000016461337354740400204730ustar00rootroot00000000000000Magit v2.3.1 Release Notes ========================== Released 11 November 2015 by Jonas Bernoulli. This is a bugfix release. * `magit-stash-drop' now shows a message with the hash of the dropped stash to make it easier to recover from dropping the wrong stash. * `magit-revert-buffers' now avoids needlessly connecting to unrelated hosts. It first checks whether a given file is on the same host as the repository, and only if that is so it checks whether the file is located inside the repository, using `file-in-directory-p', which, for Tramp files, requires connecting to the remote host. * `magit-commit-message-buffer' no longer hangs when a symlink to the repository is involved. This release also contains various documentation fixes and code clean-ups. Authors ------- 10 Jonas Bernoulli 3 Noam Postavsky 2 Kyle Meyer 1 Carl Lieberman 1 David L. Rager 1 Syohei Yoshida magit-2.90.1/Documentation/RelNotes/2.4.0.txt000066400000000000000000000137121337354740400204700ustar00rootroot00000000000000Magit v2.4.0 Release Notes ========================== Released 18 January 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.4.0, representing 269 commits by 14 people over 12 weeks. Also see http://emacsair.me/2016/01/18/magit-2.4. Changes since v2.3.0 -------------------- * The new mode `magit-auto-revert-mode', a magit-specific globalized variant of `auto-revert-mode', replaces the old implementation, which was configured using the option `magit-revert-buffers'. The new mode is enabled for all users by default. It may be disabled before loading magit by setting `magit-auto-revert-mode' (or the obsolete alias `magit-revert-buffers') to nil. To disable the mode after loading magit, a call to (magit-auto-revert-mode -1) is required. #2474 * The option `magit-refresh-status-buffer' was added, allowing users to prevent automatic refreshes of the status buffer for performance reasons. * All of Git's push-related variables are now honored. #2414 * In addition to the upstream branch, the push-remote (configured using `branch..pushRemote' or `remote.pushDefault') is now also fully supported. #2414 * The status buffer now features up to four logs listing unpulled and unpushed commits. Two for the upstream and two for the push-remote. #2414 * The branch popup now shows the most important Git variables that are in some way related to branches. The values of these variables can now be conveniently changed from that popup. #2414 * The fetch, pull, push, and rebase popups now feature an action which acts on the push-remote, another which acts on the upstream, and yet another which acts on any other source or target. For each of these actions the respective branch is shown in the popup. The actions in the push popup are displayed even if the respective variables are unset - they then offer to set these variables before pushing. Setting `magit-push-current-set-remote-if-missing' to nil disables this. Many key bindings were changed for consistency and safety reasons. Likewise many commands were renamed and their behavior was adjusted. Some new commands, related to the push-remote, were added. #2414 * The command `magit-push-implicitly' was removed from the push popup. The command's doc-string explains how to put it back. If these instructions are followed, then the popup shows what will happen if the command is used. #2453 * The command `magit-push-to-remote' was added. The command's doc-string explains how to add it to the push popup. #2453 * The option `magit-push-always-verify' was removed. That was only a temporary kludge to keep users from shooting themselves in the foot. This is no longer necessary because one now always sees where one is about to push to. #2414 * The popup command `magit-pull-and-fetch-popup' was added as a possible replacement for the separate `magit-push-popup' and `magit-fetch-popup'. #2452 * The option `magit-branch-prefer-remote-upstream' was added for users who prefer to always use remote branches as upstreams. #2447 * The options `magit-clone-set-remote.pushDefault' and `magit-remote-add-set-remote.pushDefault' were added. #2447 * When Git is run for side-effects and exits with a non-zero status, then the respective error message is now inserted into the status buffer. This should help those users who do not see that message when it is being displayed in the echo area. * Popups gained support for a new event type `:variable', which can be used to change the value of Git variables. This can only be used in combination with Magit (just `magit-popup.el' by itself is not sufficient). #2409 * The backward-compatibility kludge `magit-branch-manager' has been removed. The one and only binding to show the refs buffer now is "y"; the "b v" binding has been removed. * The command `with-editor-finish' now runs the new hook `with-editor-post-finish-hook'. * The command `magit-diff-visit-file' now runs the new hook `magit-diff-visit-file-hook'. * When the upstream branch or push remote is configured but the respective branch does not actually exist, then that is now reported in the header of the status buffer. #2390 * The header line about the upstream branch in the status buffer is now prefixed with either "Merge" or "Rebase", depending on the value of `branch..rebase'. #2390 * `magit-define-popup' learned two new arguments, `:setup-function' and `:refresh-function'. These arguments should be used instead of the MODE argument, which is now deprecated. #2389 * Negative text properties are no longer faked; that was just too ugly and inefficient. Since v2.1.0 Magit no longer sets the background color for any faces except for those related to diffs. Third-party themes which still set the background color of non-diff faces have to be adjusted, because the background color of these faces would be shadowed by the highlighting of the current section. This does not apply to diff-related faces because diff sections are highlighted differently from other sections. #2387 * The commands `git-rebase-move-line-up' and `git-rebase-move-line-down' have been extended. When a region is active, they now operate on all lines touched by the region, not just the current line. In addition, a numeric prefix can now be given to specify how many lines the current line or selection is moved across. * The option `magit-popup-display-action' was added. This release also contains the changes described in the v2.3.1 release notes, as well as various other documentation fixes, code clean-ups, bug fixes, and other small to medium improvements. Authors ------- 226 Jonas Bernoulli 22 Kyle Meyer 10 Noam Postavsky 1 Carl Lieberman 1 Damien Cassou 1 David L. Rager 1 John Mastro 1 Lele Gaifax 1 Michael Heerdegen 1 Miloš Mošić 1 Raimon Grau 1 Sylvain Rousseau 1 Syohei Yoshida 1 Zach Latta magit-2.90.1/Documentation/RelNotes/2.4.1.txt000066400000000000000000000014271337354740400204710ustar00rootroot00000000000000Magit v2.4.1 Release Notes ========================== Updates since v2.4.0 -------------------- * Added new utility functions `magit-rev-abbrev', `magit-ref-p', and `magit-tag-p'. Fixes since v2.4.0 ------------------ * When determining the emacsclient executable most suitable for the current emacs instance, With-Editor ignored any executable that is actually named "emacsclient-snapshot". * When determining the most suitable git executable, an error occured if "Git for Windows 1.x" is used and an cygpath executable is available. * An error occured when refreshing the status buffer when there is a new, staged but not yet committed, submodule. This release also contains typofixes. Authors ------- 9 Jonas Bernoulli 4 Kyle Meyer 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.5.0.txt000066400000000000000000000117511337354740400204720ustar00rootroot00000000000000Magit v2.5.0 Release Notes ========================== Released 30 January 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.5.0, representing 78 commits by 4 contributors over 2 weeks. Also see http://emacsair.me/2016/02/10/magit-2.5. Changes since v2.4.0 -------------------- * The library `with-editor.el' reincarnated as a separate repository. It was already available as a separate package, and since it can be of use for packages that have absolutely nothing to do with `magit' it makes sense to maintain it separately. That wasn't done before because that would have made it harder to change it and its users within the magit repository in parallel. I expect there will be few such changes in the future. * Added new library `magit-submodule.el'. It contains code that was previously spread across various libraries. * Added new option `auto-revert-buffer-list-filter' and redefined `auto-revert-buffers' from `autorevert.el' to use it. Added new predicates `magit-auto-revert-buffer-p' and the more restrictive `magit-auto-revert-repository-buffer-p', which are both intended to be used as potential value of the option. For now the option defaults to `nil', but that might change in a future release. When Magit explicitly calls `auto-revert-buffers' (as opposed to when that is called due to a file notification event or by a timer), and `auto-revert-buffer-list-filter' is `nil', then it is let-bound to `magit-auto-revert-repository-buffer-p'. Users who use Tramp and experience delays, should consider setting the option to `magit-auto-revert-repository-buffer-p'. * By default, invoking `magit-unstage' on a committed change now performs an action which is somewhat similar to unstaging. The change is reverted in the index, but not the working tree. This allows extracting changes from HEAD. Setting the new option `magit-unstage-committed' to nil, disables this behavior. Attempting to unstage a committed change would then result in an error again. * Because file notifications may arrive with a delay, the option `magit-auto-revert-immediately' now defaults to `t' even when file notifications can be used, * Like `magit-refresh' already did, `magit-refresh-all' now runs the hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'. * The heading of the section which lists commits that exist in the current branch but not in its upstream was changed from "Unpushed to " to "Unmerged into ", because one usually should merge into that branch instead of pushing to it. * Added new commands `magit-remote-set-head' and `magit-remote-unset-head'. * By default `magit-clone' now deletes the symbolic-ref "origin/HEAD" right after running `git clone', which insists on creating it. The new option `magit-clone-set-remote-head' can be set to `t' to go back to keeping that symbolic-ref. We default to removing it, because it does not actually get automatically updated when the HEAD of the remote changes, which makes it rather pointless. * Added new option `magit-prefer-remote-upstream' which controls whether commands which read the upstream or starting-point from the user would rather offer a local or a remote branch as default completion candidate. * Added the switch `--cover-letter' to `magit-patch-popup', and taught `magit-format-patch' to immediately open the letter in a buffer. * Added new option `++order' to the various log popups. This option and its value are converted to `--VALUE-order' before calling `git'. This option was added instead of the switches `--author-date-order', `--date-order', and `--topo-order' because adding all three would be too noisy and because they are mutually exclusive. Fixes since v2.4.1 ------------------ * Creating a stash in a secondary working tree failed if no other stash already existed in the repository. * Creating a Magit buffer failed if `uniquify-buffer-name-style's value is `nil'. * Resetting a branch to an arbitrary commit caused its upstream configuration to be mangled. * Resetting a branch to another branch caused the former to be configured as the upstream of the latter. That behavior was introduced by accident when the argument `--track' was replaced with the variable `branch.autoSetupMerge' in the popup. Because it would be undesirable to restore the `--track' argument in the popup, one now has to use a prefix argument to set the upstream while resetting. * The manually set state of the margin in log and reflog buffers was not preserved and instead reset to the default state when a command was invoked which changes what log/reflog is being displayed. * Pressing RET on a variable in a popup caused an error. This release also contains the fixes described in the v2.4.1 release notes, as well as various typofixes, documentation updates, code clean-ups, bug fixes, and other small improvements. Authors ------- 62 Jonas Bernoulli 9 Kyle Meyer 4 Noam Postavsky 3 Alex Dunn magit-2.90.1/Documentation/RelNotes/2.6.0.txt000066400000000000000000000120161337354740400204660ustar00rootroot00000000000000Magit v2.6.0 Release Notes ========================== Released 29 March 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.6.0, representing 77 commits by 7 contributors over 2 months. Also see http://emacsair.me/2016/03/29/magit-2.6. Updates since v2.5.0 -------------------- * Added a cache, which memorizes the values of some function calls for the duration of a refresh. This cuts the calls to git in half. * Added new option `magit-diff-hide-trailing-cr-characters'. When its value is non-nil (the default on Windows), then ^M characters at the end of diff lines are hidden. * Added new command `magit-diff-buffer-file-popup' intended for use in file-visiting buffers. It shows the same popup as `magit-diff-popup' but starts out already limited to the visited file. * Added new command `magit-ediff-show-stash', which is available in the Ediff popup and will be used when `magit-ediff-dwim' is called with point on a stash. * Added new command `magit-reset-popup' featuring all the available reset variants. * Added new command `magit-push-refspecs', which allows pushing using one or more comma-separated and refspecs, which are explicitly typed in the minibuffer. * Added new commands `magit-fetch-refspec' and `magit-fetch-branch'. * Added new section inserters `magit-insert-modules-unpulled-from-pushremote' and `magit-insert-modules-unpushed-to-pushremote', and renamed `magit-insert-unpulled-module-commits' to `magit-insert-modules-unpulled-from-upstream' and `magit-insert-unpushed-module-commits' to `magit-insert-modules-unpushed-to-upstream'. * The command `magit-submodule-add' now allows using a module name different from the path of the module. * If `magit-push-current-set-remote-if-missing's value is `default', then the command `magit-push-current-to-pushremote' now offers to set `remote.pushDefault' unless the push-remote is already set in some way. Previously this command offered to set the local value `branch.NAME.pushRemote' for all non-nil values of the option. * When washing the diff that is to be displayed while writing a commit message takes too long, then it is now possible to abort that by pressing `C-g'. Previously that would have aborted the commit. * When `magit-process-raise-error' is non-nil, then the displayed error message now also mentions the `default-directory', which is useful when using Magit as a library in another packages that runs git in many different repositories. * The `magit-insert-section' macro's TYPE argument can now have the form `(eval FORM)' instead of a symbol. An atomic TYPE is never evaluated, but FORM is evaluated at run-time. Fixes since v2.5.0 ------------------ * Staging hunks/regions belonging to files with CRLF line endings on Windows (or, to be precise, when `default-process-coding-system' had CRLF end-of-line conversion) ended up erroneously staging changes with LF line endings. Magit now ensures line endings are preserved by enforcing a `process-coding-system' with LF end-of-line conversion. The new behavior may be disabled by setting the option `magit-process-ensure-unix-line-ending' to `nil'. * If the user sets the variable `magit-auto-revert-mode' or the obsolete alias `magit-revert-buffers' to nil anytime during startup (before or after `magit-autorevert' is loaded) then the mode is now no longer turned on (actually it is explicitly turned off). * When a revision buffer was limited to a set of files, its header line did not say so. * The function `magit-run-git-with-input' had stopped calling `magit-pre-call-git-hook' and logging its git command to the magit-process buffer. * The function `magit-diff-wash-submodule did not handle some less common cases. * The command `magit-section-cycle-diffs' hung when hiding sections. * Invoking `magit-commit-popup's default action by invoking the popup command with a prefix argument failed due to a typo. * The command `magit-toggle-buffer-lock' failed if another buffer is already locked to the same value. * The command `magit-clone' did not switch to the cloned repository before trying to delete the symbolic-ref "origin/HEAD". * The commands `magit-insert-unpulled-from-pushremote' and `magit-insert-unpushed-to-pushremote' missed an edge case when checking whether their section should be inserted into the status buffer. * The command `magit-merge-preview' did not recognize sections for added or deleted files. * The command `magit-show-stash' did not properly handle untracked files that were within subdirectories. * On `windows-nt' systems, having `mount' in `exec-path' caused Magit to assume that git is from Cygwin. * Added a kludge to work around a bug in Apple's OS X which causes `file-accessible-directory-p' to return incorrect results. This release also contains typofixes, documentation updates, and code clean-ups. Authors ------- 53 Jonas Bernoulli 13 Kyle Meyer 4 Luís Oliveira 4 Noam Postavsky 1 Dan Erikson 1 Dato Simó 1 Russell Black magit-2.90.1/Documentation/RelNotes/2.6.1.txt000066400000000000000000000022021337354740400204630ustar00rootroot00000000000000Magit v2.6.1 Release Notes ========================== Fixes since v2.6.0 ------------------ * When a submodule is manually removed without staging the removal, then the status buffer could no longer be updated. * In some cases not all modified submodules were shown in the status buffer. * Visiting a blob did turn on `diff-hl-mode' if the global mode is on. * Stash and wipref were needlessly signed if signing is enabled. * The command `git-commit-save-message' did not strip diffs produced by `git commit --verbose'. * Diffs produced by `git commit --verbose' were not completely highlighted in the commit message buffer. * When the commit message buffer contains nothing but a single line that does not end with a newline, then a warning was shown about there being a non-empty second line. * When installing from Melpa, `async-bytecomp-package-mode' was no longer activated early enough. This release also contains documentation updates, typofixes, fixes for minor bugs, and other small improvements. Authors ------- 14 Jonas Bernoulli 5 Kyle Meyer 1 Fritz Grabo 1 Ingo Lohmar 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.6.2.txt000066400000000000000000000032051337354740400204700ustar00rootroot00000000000000Magit v2.6.2 Release Notes ========================== Changes since v2.6.1 -------------------- * Added new section inserter `magit-insert-submodules'. For each submodule it inserts the module path and a description of its tip. * When re-adding an already configured but for some reason unstaged submodule, then `magit-submodule-add' now offers the configured submodule name as default choice. Fixes since v2.6.1 ------------------ * When possible `git merge (--no-commit|--edit)' perform fast-forward merges, which isn't what one would expect. `magit-merge-nocommit' and `magit-merge-editmsg' now work around that by always using `--no-ff'. * The command `magit-log', when called with `--patch' but without `--graph', deleted the first two characters of file names in the diff. * When performing an instant fixup/squash, the rebase often failed because the commit process still held the lock on `index.lock'. * The command `magit-submodule-add' offered an invalid default choice for the module path and allowed selecting a file that isn't a repository. * `git-rebase-mode' failed to prevent `save-place-mode' from having an effect. * The section inserter `magit-insert-unpulled-from-upstream-or-recent' failed to insert the recent commits instead when no upstream is configured. * Two key bindings in `magit-pull-and-fetch-popup' conflicted. * The default value for `magit-cygwin-mount-points' checked if "git.exe" was a cygwin flavor of git, instead of the (possibly user customized) value of `magit-git-executable'. Authors ------- 21 Jonas Bernoulli 1 John Mastro 1 Kyle Meyer 1 Noam Postavsky magit-2.90.1/Documentation/RelNotes/2.7.0.txt000066400000000000000000000056441337354740400205000ustar00rootroot00000000000000Magit v2.7.0 Release Notes ========================== Released 19 May 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.7.0, representing 116 commits by 7 people over 7 weeks. Also see http://emacsair.me/2016/05/19/magit-2.7. Changes since v2.6.0 -------------------- * Added new popup `magit-subtree-popup' and bound "O" to it. * Added new popup `magit-branch-config-popup' and made it available from the popups `magit-branch-popup', `magit-pull-and-fetch-popup', `magit-pull-popup', `magit-fetch-popup', and `magit-push-popup'. With a prefix argument it reads a branch to be configured in the minibuffer instead of using the current branch. * Added new option `magit-branch-popup-show-variables', defaulting to t to avoid changing key bindings. When set to nil, no variables are displayed directly in the `magit-branch-popup', instead the subpopup `magit-branch-config-popup' has to be used. * Added new popup command `magit-log-buffer-file-popup'. * Added new command `magit-diff-buffer-file' and new option `magit-diff-buffer-file-locked'. When the value of the option is non-nil, the default, then the command uses a dedicated buffer. * Added new option `magit-log-buffer-file-locked'. When its value is non-nil, the default, then `magit-log-buffer-file' uses a dedicated buffer. * Added new commands `magit-worktree-checkout', `magit-worktree-branch', `magit-worktree-delete', and `magit-worktree-status'. * Added new section inserter `magit-insert-worktrees' * The command `magit-clone' now runs asynchronously, which avoids blocking Emacs and allows handling password prompts. * The command `magit-stage' learned to stage an untracked file while leaving its content unstaged (i.e. `git add --intent-to-add') when called with a prefix argument. * The command `magit-reverse' learned to use `--reject' to ensure that non-conflicting hunks are applied and that conflicting hunks are put into reject files. * When the command `magit-discard' is used on staged changes, then that is done by first reversing the changes in the index and then in the working tree. The second step could fail due to conflicts. Now the `--reject' argument is used, which ensures that non-conflicting hunks are applied and that conflicting hunks are put into reject files. * The command `magit-rebase-continue' learned to reuse the old commit message as-is when called with a prefix argument. * In the refs buffer symbolic refs, such as "remotes/origin/HEAD", are no longer omitted from the lists of local and remote branches. This release also contains the fixes described in the v2.6.1 and v2.6.2 release notes, as well as various other documentation fixes, code clean-ups, bug fixes, and other small to medium improvements. Authors ------- 95 Jonas Bernoulli 10 Kyle Meyer 7 Noam Postavsky 1 Bart Bakker 1 Fritz Grabo 1 Ingo Lohmar 1 John Mastro magit-2.90.1/Documentation/RelNotes/2.8.0.txt000066400000000000000000000104001337354740400204630ustar00rootroot00000000000000Magit v2.8.0 Release Notes ========================== Released 21 August 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.8.0, representing 124 commits by 11 people over 3 months. Also see http://emacsair.me/2016/08/21/magit-2.8. Changes since v2.7.0 -------------------- * Added several new functions that are suitable values for `magit-display-buffer-function': `magit-display-buffer-same-window-except-diff-v1', `magit-display-buffer-fullframe-status-v1', `magit-display-buffer-fullframe-status-topleft-v1', and `magit-display-buffer-fullcolumn-most-v1'. * Added new commands `magit-list-repositories' and related new option `magit-repolist-columns'. * Added new commands `magit-list-submodules and related new option `magit-submodule-list-columns'. * Added new command `magit-branch-orphan'. * Added new command `magit-log-move-to-parent'. * Added support for globbing in file arguments of diff and log commands. * Added support for showing and copying bad commit identified by git bisect. * Added new option `magit-log-output-coding-system'. * Added new option `magit-no-message', which can be used to suppress certain messages whose usefulness are being disputed. * Taught `magit-find-file-noselect' and `magit-find-index-noselect' to use Emacs' encoding detection, and enable `revert-buffer' to work in those buffers. This makes `magit-ediff-*' commands more useful for files with non-standard encoding. * Taught `magit-insert-bisect-rest' to show the log graph by default. The new option `magit-bisect-show-graph' controls this. * Taught `magit-insert-submodules' to display more information. * When a refresh causes the previously current hunk section to disappear, which happens when it was applied in some way, then we attempt to move to a sibling hunk. When that succeeds, then that is now considered a proper move and `magit-section-movement-hook' is called, which in turn may cause the current hunk to be recentered. * In addition to the directory, each member of the value of option `magit-repository-directories' can now specify the depth to look for repositories inside that directory, overriding the default depth specified using the option `magit-repository-directories-depth'. * Blob visiting buffers can now be reverted, which is useful when they visit a reference. * Command `magit-stage' can now be used outside of Magit buffers. * Commands that read a branch or commit from the user now also offer tags as completion candidates. * Taught `magit-insert-worktrees' to use relative filenames. Fixes since v2.7.0 ------------------ * Function `magit-get-all' did split multi-line values into multiple values. * Function `magit-subtree-read-prefix' which is used in order to read the `--prefix' argument from the subtree popup was missing. * Command `magit-blame' failed when run in a blob buffer for a file located in a subdirectory. * Command `magit-diff-visit-file' didn't visit a blob when called inside a `magit-stash-mode' buffer. * Command `magit-submodule-add' did not allow picking a path that does not exist yet and read the path before the url. * Command `magit-submodule-setup' did update existing modules, which can cause them to become detached. * Command `magit-popup-describe-function' could create an extra window on wide frames. * Commands `magit-diff-show-or-scroll-{up,down}' failed to scroll stash buffers. * Mode `git-rebase-mode' did not respect the Git variable `core.commentChar'. * Sections in the process buffer sometimes had invalid parent sections, causing movement and visibility commands to fail, and expected Git errors not to be handled gracefully in some cases. * Merges where not performed asynchronously, which made it impossible to read a passphrase from the user, needed for commit signing. * In bare repositories tracked files were listed as deleted. This release also contains typofixes, documentation updates, code clean-ups, bug fixes, and other small to medium improvements. Authors ------- 59 Jonas Bernoulli 33 Noam Postavsky 23 Kyle Meyer 2 Mario Rodas 1 Andriy Kmit' 1 Basil L. Contovounesios 1 Chris Shoemaker 1 Ivan Brennan 1 Laverne Schrock 1 Samuel W. Flint 1 Wilfred Hughes magit-2.90.1/Documentation/RelNotes/2.9.0.txt000066400000000000000000000465511337354740400205040ustar00rootroot00000000000000It's Magit! A Git Porcelain inside Emacs ========================================= 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. For more information about Magit, see https://magit.vc. If Magit helps you be more productive, then please consider donating at https://magit.vc/donate/. Magit v2.9.0 Release Notes ========================== Released 7 December 2016 by Jonas Bernoulli. We are pleased to announce the release of Magit version 2.9.0, representing 250 commits by 18 people over 15 weeks. Also see https://emacsair.me/2016/12/07/magit-2.9. Breaking changes since v2.8.0 ----------------------------- * For historic reasons "RET" behaved differently in `magit-refs-mode' than anywhere else. "RET" is one of Magit's most essential key bindings and users quickly learn that regardless of what is actually at point, it always shows more information about that thing in another buffer. It can be very confusing if the references buffer breaks this convention. Now `magit-visit-ref' behaves just like `magit-show-commit' even in `magit-refs-mode' buffers. By default at least; you can easily revert this change using: (setq magit-visit-ref-behavior '(checkout-any focus-on-ref)) However we recommend that you instead press "b b RET" to checkout the reference at point, just like you always had to do in other buffers. And "C-u y o RET" to make commit counts and lists of cherries commits relative to the reference at point. Furthermore the option `magit-visit-ref-create' was removed. If you previously had that set to `t', then you can achieve the same using: (add-to-list 'magit-visit-ref-behavior 'create-branch) However we recommend that you instead press "b c RET RET", just like you always had to do in other buffers. #2868 * The option `magit-popup-show-common-commands' now defaults to `nil'. This was done to make popups less noisy but increases the odds that some users will never become aware of the common commands. To counter that, the usage instructions displayed in the echo area now also mention the key that can be used to show these commands temporarily. #2868 You can easily revert this change using: (setq magit-popup-show-common-commands t) * The option `magit-popup-use-prefix-argument' defaults to `default' now, meaning that the use of a prefix argument causes the popup's default action to be invoked directly without the popup being shown first. Previously the use of a prefix argument did not invoke the popup or its default action, and instead informed users that they had to choose what behavior they wanted and that they had to set the option accordingly. Doing that was necessary three years ago, when the default behavior changed when "magit-key-mode.el" was replaced with "magit-popup.el". Now we don't need that safety net anymore. #2868 * If, and only if, point is on a removed line in a diff, then "RET" now jumps to the last commit which still had that line, not the commit which removed that line. Staged changes are excluded from this new behavior because in that case it seems favorable to always visit the file in the working tree to make further changes. #2755 You can easily revert this change using: (setq magit-diff-visit-previous-blob nil) * The margin that by default is displayed in pure log buffers and optionally in some other buffers that contain logs is now more flexible and easier to customize and to change on the fly. The popup that "L" is bound to now features three commands that for changing the appearance of the margin: `magit-toggle-margin', `magit-toggle-margin-details' and `magit-cycle-margin-style'. The binding for `magit-toggle-margin' has changed from "L t" to the simpler "L L". You can easily revert this change using: (magit-change-popup-key 'magit-log-refresh-popup :action ?L ?t) (magit-change-popup-key 'magit-margin-popup :action ?L ?t) For each mode that supports the margin there now exists a dedicated option named `magit-*-margin', which controls whether the margin is shown initially, whether the author name is displayed in addition to the committer date, and how that committer date is formatted. All of these options can be found in the new `magit-margin' Custom group. It is now possible to show the actual committer date, using a time format of your choosing. Previously the only option was to display the age of the commit. The old options that were previously used to configure the margin have been removed. If you have customized `magit-log-show-margin', `magit-reflog-show-margin' and/or `magit-refs-show-margin', then you now have to customize the respective new variable whose names do not contain "-show". The same applies if you have previously changed the value of `magit-log-margin-spec'. Unfortunately this cannot be automated because the format of the values has changed and because the old customizations do not unambiguously map to the new options. You might also want to customize the options `magit-status-margin', `magit-stashes-margin' and `magit-log-select-margin', for all of which no corresponding `magit-*-show-margin' used to exist. Another new option is `magit-refs-margin-for-tags'. If you choose to display the commit dates instead of the commit ages in all supported modes, then you should set `magit-log-margin' before loading `magit'. If you do that then the default values of the other `magit-*-margin' options will use the same commit date style without you having to customize each option individually. #2885, #2792 * By default Git-Commit no longer complains about a summary line that is too long by some standards. You can easily revert this change using: 2f115d51 (add-to-list 'git-commit-style-convention-checks 'overlong-summary-line) * In buffers used to write commit messages `fill-column' is no longer set to 72. Instead the default value 70 is used (or whatever local or global value is set up through other means). You can easily revert this change using: #2848, #2852 (setq git-commit-fill-column 72) * When it takes too long to parse diffs, then Magit used to stop expanding diff sections after one second. This was a constant source of confusion and one second is a very long time anyway, so this did not really help hiding the slowness, so this kludge was effectively dropped. You can easily revert this change using: (setq magit-diff-expansion-threshold 1.0) By the way, improving performance will soon be a priority again. #2886 Changes since v2.8.0 -------------------- * Magit has a new shiny logo! It was created by Dmitriy A. from Prospect One. Thanks a lot! https://prospectone.io/portfolio/magit * The new option `magit-branch-adjust-remote-upstream-alist' can be used to configure what branch to use as upstream when branching a remote branch. Without setting this option the upstream ends up being the same branch as the one referred to by the push-remote. 85c3053d * The per-refresh cache, which is used to save calls to git because that is surprisingly slow on Windows, has been improved for calls to `git config'. Instead of just avoiding identical calls to `git config' as for other sub-commands, we now call `git config --list' only once per refresh to obtain a list of all variables and their values. #2743 * When visiting a file or blob buffer by pressing "RET" while point is inside a diff, then the position this jumps to is now accurate (even when jumping to the file in the working tree from a diff that wasn't about changes in the working tree). #2828 * When visiting a file or blob buffer by pressing "RET" while point is inside a diff, then the buffer may be widened but only if necessary. If it isn't necessary to widen the buffer to jump to the appropriate location, because that position falls into the narrowed region, then that the buffer isn't widened. #2804, #2818 * Hunk refinement is now faster. Users who previously set `magit-diff-refine-hunk' to `nil' due to performance issues may find that it now works well even when set to `all'. #2834 * The new options `magit-diff-highlight-hunk-region-functions' and `magit-diff-unmarked-lines-keep-foreground' (which was previously defined as an undocumented variable) allow tuning the appearance of the hunk-internal region. The new function `magit-diff-highlight-hunk-region-using-face', provides a new style; it makes the hunk-internal region bold (or italic). I recommend you customize the above option to use this function instead of one of the functions mentioned below. The new functions `magit-diff-highlight-hunk-region-using-overlays' and `magit-diff-highlight-hunk-region-using-underline' draw one-pixel lines before and after the hunk-internal region. Both of these functions have (different) glitches and due to limitations of Emacs' display engine it is not possible to fix those. #2293, #2758, #2791 * Added command `magit-find-git-config-file' and variants to make it easier to open a file located in the git directory when ".git" is a regular file whose contents describe the location of the real git directory. 8664223c * Added command `magit-emacs-Q-command' to make troubleshooting and bug reporting easier for users not installing from the git repository. #2856 * The command `magit-branch-spinoff' learned to remove only a subset of commits from the previously current branch, instead of resetting it to its upstream, when the region selects commits reachable from HEAD. 1e652b87 * The command `magit-branch-delete' now falls back to deleting the tracking branch when the user attempts to delete a remote branch which does not actually exist on the remote anymore. #2778 * The command `magit-diff-dwim' learned about additional cases. On a non-current branch it now shows the diff for "CURRENT...BRANCH" (instead of "BRANCH..CURRENT") and inside a stash buffer it shows the diff for the commit at point. #2812 * The command `magit-push', which "o" is bound to in the push popup, now offers the push-branch as default choice. Only if that is not set does it default to the upstream as before. And when pushing a commit that is reachable from HEAD, then it offers to push to the push-branch or upstream of the current branch (which still has to be forced explicitly). #2820 * Log commands now support completion of refs in the "refs/tags" and "refs/pull" namespaces. #2878 * Added option `magit-no-confirm-default' to allow specifying commands which should just use the default choice instead of having the user confirm that by pressing RET. I recommend you don't use this, but if you think that the defaults are so good that you always want to use them, then this might make it a bit easier for you. #2741 * Added option `magit-slow-confirm' for users who are afraid they would answer `y-or-n-p' questions to quickly. One action, deleting all stashes, now defaults to having to be confirmed with "yes RET". #2752 * Added option `magit-view-git-manual-method' to allow following links to the Git Info manual by visiting the respective manpage instead. de38266a * The option `magit-branch-prefer-remote-upstream' now also supports regexps as members instead of only complete branch names. #2823 * The option `magit-branch-read-upstream-first' used to be a boolean. Now it supports a third value `fallback', which means to read the upstream first like `t', but if the value provided by the user does not reference an existing revision, then it is treated as the name of the new branch and the upstream is read using the second prompt, as if the value of this option were `nil'. #2741 * When deleting a stash, the hash is now logged to the process log buffer in addition to *Messages*, making it more likely that a user who accidentally deleted a stash would find the information required to undo that. #2746 * The environment variable `INSIDE_EMACS' is now set when calling git. #2789 * `magit-define-popup' now allows specifying `:max-action-columns' per section by using a function that returns a different value based on the heading, which is passed as argument. 964fcbe0 * Added support for new gpg status letters X, Y, R, and E. #2845 * Added `hl-line-mode' to `magit-repolist-hook' and `magit-submodule-list-hook' and defined those hooks explicitly. 9f806732 * Added the `--gpg-sign=' option to the revert popup. 916e4599 * Added the `--sort=' option to the show-refs popup. (Use "C-u y" to show the popup instead of invoking its default action as "y" does.) 8ab81f06 * Added new faces `git-rebase-comment-heading' and `git-rebase-comment-hash'. #2769 * `whitespace-mode' is not compatible with Magit buffers, where it is now actively prevented from being turned on by the user. #2821 Fixes since v2.8.0 ------------------ * The command `magit-list-repositories' failed on empty repositories. 09fac022 * The Git variable `pull.rebase' was ignored when determining whether the current branch is being rebased onto its upstream in order to display that information in the status buffer. 9c946ee3 * On 32-bit systems `magit-format-log-margin' failed because it tried to truncate a time float that was too large for that. #2765 * On Emacs v25.1 the hunk-internal region flashed briefly on mouse-down-1 events and the delimiting horizontal lines could end up having the height of a regular line instead of just a single pixel. #2758 * On Windows, when using a `windows-nt' Emacs together with a cygwin Git, we failed to instruct Emacs to not use dos shell quoting when calling git. And if Git wasn't available, then that caused an error, which prevented Magit from being loaded. #2842 * The encoding of commit messages is controlled by the Git variable `i18n.logOutputEncoding' but we failed to take that into account. Fixes by setting `i18n.logOutputEncoding' to UTF-8, but only inside Magit and only for `window-nt'. #2738, #2813 * It wasn't taken into account, until a few days after the release, that as of Git v2.11, the default abbreviation size is no longer hardcoded as 7 but instead scales with the repository size. #2880 * File and directory local variables were not honored in the buffers used to write commit messages. #2852 * The caching mechanism that is supposed to ensure that sections of unpulled and unpushed commits remain collapsed even when they disappear was broken for a while. 0ad041c4 * Process sentinels did not in all cases ensure that the correct buffer was current before doing something that assumes that this is the case. Almost always that did not matter because it was the case anyway, but if other timers are running then it is possible that those make the wrong buffer current. #2836 * Process sentinels and filters used when blaming assumed that the `exit' process status indicates success. #2836 * The commands `magit-clone' and `magit-init' did not work over Tramp. #2806, #2807 * The commands `magit-worktree-checkout' and `magit-worktree-branch' did not expand the path they pass to git, which is necessary because git does not know the meaning of "~/". #2796 * The commands which create fixup/squash commands and then immediately squash them into the target commit did not remove `--gpg-sign' or add `--no-gpg-sign'. Signing such commits is not only unnecessary; unless the passphrase was cached earlier, trying to sign resulted in the process indefinitely waiting for the passphrase to arrive with no way for the user to actually provide it. #2799 * Depending on the value of `magit-save-repository-buffers' the user might have been asked whether s/he wants to save "git-rebase-todo", which is never necessary and just a distraction. #2770, #2771 * The function `magit-save-repository-buffers' did not follow symlinks. #2843 * Directories whose names begin with a period were filtered out when using `magit-repository-directories' to calculate a list of repos. #2830 * The user name and email, which are displayed when reading a gpg key from the user, were not stripped from the chosen value before being handed off to git. #2761 * When the upstream of the current branch is a remote whose url isn't configured then that caused an error when refreshing the status buffer. #2858 * Buffers visiting a blob used the file's `default-directory' even when that directory did not exist in the working tree. The top-level directory is now used as `default-directory' when the subdirectory does not exist. cfe46766 * When visiting a directory by displaying a Dired buffer, we used to display a buffer for the parent of the directory in question and placed point on the name of the directory. But the intention always was to show the Dired buffer for the directory itself. 5665ba94 * Visiting or deleting a submodule listed inside "Modules" failed. The latter is now done by de-initalizing the module. c26b746e * In the list of commits that are being rebased in the status buffer, HEAD was sometimes prefixed with "same" when "stop" would have been correct. #2877 * The highlighting of a non-empty second line in a commit message was not automatically updated. #2777 * When `--force-with-lease' was added to the `magit-push-popup', `--force' was removed, but sometimes the former just isn't enough. be39a9ba * The face `magit-diff-file-heading-highlight' used to inherit from `magit-diff-file-heading', which by default makes text bold. That resulted in the complete current heading to be bold, but only the file-name part is supposed to be bold. a4b52516 * The manual stated that "DEL" in Git Rebase mode was bound to `magit-diff-show-or-scroll-down', which was not the case. A new command `git-rebase-show-or-scroll-down` has been added and bound to "DEL" to provide this functionality. #2863 * The function `magit-repolist-status' did not expand the filename which may be necessary when listing submodules. cc8c1385 * The macro `magit-with-temp-index' did honor the refresh cache, even though its BODY may contain calls to git that are identical to outside calls during the same refresh, but which are expected to return a different value due to the use of a different index. #2883 * The log margin did not show the author of stashes. #2846 * The status header about the upstream did not take `branch.NAME.rebase' into account. e65f15d0 * Highlighting overlays could not be garbage collected until after a refresh. #2888 This release also contains typofixes, documentation updates, code clean-ups, and other small bug fixes and improvements. Authors ------- 196 Jonas Bernoulli 21 Kyle Meyer 12 Noam Postavsky 4 Alexander Gramiak 2 Adam Porter 2 Marco Wahl 2 Sean Allred 1 Allen 1 Basil L. Contovounesios 1 Chillar Anand 1 Graham Dobbins 1 Joakim Jalap 1 Josiah Schwab 1 Keshav Kini 1 Marian Schubert 1 Philipp Stephani 1 Tunc Uzlu 1 York Zhao magit-2.90.1/Documentation/RelNotes/2.90.0.org000066400000000000000000000437351337354740400205350ustar00rootroot00000000000000* It's Magit! A Git Porcelain inside Emacs Magit is a text-based Git user interface that puts an unmatched focus on streamlining workflows. Commands are invoked using short mnemonic key sequences that take the cursor’s position in the highly actionable interface into account to provide context-sensitive behavior. With Magit you can do nearly everything that you can do when using Git on the command-line, but at greater speed and while taking advantage of advanced features that previously seemed too daunting to use on a daily basis. Many users will find that by using Magit they can become more effective Git user. For more information about Magit, see https://magit.vc. * Magit v2.90.0 Release Notes Released 8th November 2018 by Jonas Bernoulli. I am pleased to announce the release of Magit version 2.90.0, representing 395 commits by 18 contributors over five months. Also see https://emacsair.me/2018/11/08/magit-2.90. ** Breaking changes - Dropped support for Emacs 24.4. At least Emacs 25.1 is required now. - Dropped support for Git 1. At least Git 2.0.0 is required now. The reason 2.0.0 is the new minimal version isn't its roundness but the discovery that some parts of Magit already depended on that release for two years. Since we will soon drop support for versions before (probably) 2.4.0 anyway, we don't add a backward compatibility kludge for the feature that already requires 2.0.0 but instead bump the minimal version a first time. - Many commands were renamed, making their names longer. The old names are defined as aliases for now. This is part one of a two part change. In this release we rename, for example, ~magit-tag~ to ~magit-tag-create~ and in a later release ~magit-tag-popup~ will be renamed to ~magit-tag~. #3619 - Removed many obsolete variable and function aliases. - Removed many obsolete variables that are not mere aliases. - Removed ~magit-section~ accessor functions. Use the ~oref~ and ~oset~ functions instead. - The function ~magit-section-when~ has been deprecated in favor of ~magit-section-match~ or the new ~magit-section-value-if~. The signatures of some related low-level functions have changed. #3590 - The ~submodule~ section type has been renamed to ~module~, same for the plural variant and the related section-specific keymaps. 35f803c9c, 59e3891fd - Added a new function ~magit-completing-read-multiple*~, which is more like ~magit-completing-read~ than ~magit-completing-read-multiple~. Authors of extension should use the new function, which eventually will replace the old one. cb4d59190 ** Changes since v2.13.0 - Added a new mode ~magit-wip-mode~, which enables automatic committing to work-in-progress refs whenever that makes sense. Previously multiple ~magit-wip-*~ modes had to be enabled to accomplish the same. These modes still exist, the new mode is implemented on top of them, but their explicit use by the user is discouraged. #3534 - Added a new option ~magit-wip-merge-branch~, which causes the current branch to be merged into its wip refs after creating a new commit on the current branch. This isn't enabled by default yet because some additional tooling is required to deal with the fact that this prevents the wip refs from ever being garbage collected, and results in unwieldy commit graphs when history manipulation is involved. #3534 - Added new commands ~magit-wip-log-index~ and ~magit-wip-log-worktree~. #3534 - It is now possible to specify the major-mode used to edit commit messages on a per-repository basis. The same major-mode is also used to prettify commit messages when displaying existing commit messages in ~magit-revision-mode~ buffers. To set the major-mode to be used for commit messages add an entry to the appropriate ~.dir-locals.el~ file using ~git-commit-mode~ as the key, as if that mode were a major-mode. This can also be used to set other variables in the buffers used to /edit/ commit messages. If ~$GIT_WORK_TREE/.git~ is a file, then ~$GIT_WORK_TREE/.dir-locals.el~ would normally not apply when editing a file inside ~$GIT_DIR~. Magit uses it anyway unless ~$GIT_DIR/.dir-locals.el~ exists. 55ba0534c, d7412da32, c5269547a - Added a new major-mode ~git-commit-elisp-text-mode~ intended to be used when editing commit messages for Elisp projects. It derives from ~text-mode~ and additionally highlights ~`symbols'~ and "strings". d7fa6632b - Changed the order and the initial visibility of log sections in the status buffer to optimize for "usefulness". Previously the focus was on making it more likely that the user did not ignore the less frequently useful logs, but that was quite annoying because it got in the way of the more frequently performed tasks. #3518 - Added new option ~magit-status-initial-section~, which controls which section point is placed on when a status buffer is created. The new default is to place point on the section that follows the headers, i.e. the second section. This is quite flexible, you might want to read the doc-string. 87de83da8, #3562, #3518 - Added new commands ~magit-commit-absorb~ and ~magit-commit-absorb-popup~. These commands depend on the ~git-autofixup~ script, which is available from https://github.com/torbiak/git-autofixup. #3053 - Began migrating from using section "types" to using section classes that can inherit from other classes. #3590 - Removed many backward compatibility hacks, which are no longer necessary. - Began to use features and many convenience functions that we couldn't use before because we still supported Emacs 24.4. - ~magit-file-rename~ now reads the target from the same directory as the source. This is more convenient because removing parts of the path is easier than adding them again. - Added new ~magit-gitignore-popup~ and bound ~I~ to it, making it possible to use ~i~ for the ~magit-imerge-popup~ from the ~magit-imerge~ package. - Renamed the existing command ~magit-describe-section~ to ~magit-describe-section-briefly~ and added a new command ~magit-describe-section~, which pops up a ~*Help*~ buffer, which contains information about the function and hook used to insert the section. #3539 - Added new ~magit-refname-pullreq~ face and a corresponding entry to ~magit-ref-namespaces~. - Added new option ~magit-log-trace-definition-function~, which allows specifying the function that ~magit-log-trace-definition~ should use to determine the function at point. The default is ~which-function~. Previously the less complete ~add-log-current-defun~ was used. #3483, 9ff266358 - fixup! and squash! are now highlighted like [keywords] in logs. 426773040 - Added new stub commands ~magit-browse-thing~ and ~magit-edit-thing~. Like other ~magit-*-thing~ functions they are intend to be replaced in section-specific keymaps. The ~forge~ package will use do so for these commands. 56fccaca6, 0fa3092eb - In case they are bound when Magit is loaded then ~$GIT_DIR~ and ~$GIT_WORK_TREE~ are unset now. Magit breaks if these variables are set and the most likely cause for them to be set is a user error. 2d7d5d840 - ~magit-merge-into~ now only offers local branches for completion and defaults to the upstream. If the upstream is a remote branch then it defaults to the respective local branch. a52d70198 - It is now possible to set the face used to highlight the headings of certain sections using the new ~heading-highlight-face~ slot. 2319a1e0e - The summary line of a commit message and the first line of notes are now emphasized more to make it more obvious what text is part of the commit message and what text was added by a note. fda4b936c - Detection of the branch at point was improved. #3530 - Added new shortstat margin style for logs. Performance isn't good yet, so you might want to avoid this for long logs. #3035 - Added new variable ~magit-perl-executable~ for platforms that put ~perl~ in unusual places. We use ~perl~ for some one-liners that are embedded in lisp because we known that it is available because ~git~ depends on it. #3538 - Added new command ~magit-reset-worktree~. The existing ~magit-reset-*~ commands already implemented the variants supported by ~git reset~, now Magit also implements the variant missing from that. b4d5c2bee - Improved ~magit-process-password-auth-source~'s entry matching. 60a335e5c - Added new hook ~magit-create-buffer~ hook. 2113dfc3d - When the user "discards" a file with conflicts then they are asked which side of the conflict they want to keep. When multiple files are selected, then it is now possible to decide for all of them at once. #3553 - Added option ~--ignore-submodules~ to diff popups. This option does not only affect diffs but also the dedicated module sections and can therefore be used to temporarily hide all information about modules, which can be expensive to calculate. #3555, #3568 - Added ~--graph~ to the default value of ~magit-log-select-arguments~ instead of hard-coding this argument for some of the users of the log-select machinery. #3559 - The upstream of the current branch is no emphasized in logs, by default by making it italic. #3573 - Added new command ~magit-submodule-remove~ and the new related option ~magit-submodule-remove-trash-gitdirs~. The default is to not trash the gitdirs. ~magit-submodule-add~ now offers to reuse an existing gitdir when re-adding a submodule. #3585 - ~magit-submodule-add~ is run asynchronously now. #3585 - Information about the running Git process is now also shown in the mode-line of buffers that were created after the process was started. 43264c873 - Rebase commands that continue a rebase sequence can now use ~git rbr~ instead of ~git rebase~. To initiate a rebase sequence using ~git rbr~ you may use https://github.com/fanatoly/magit-rbr. c2cd780b2 - The manual is now also available in epub format, but it isn't very pretty. #3579 - Added new hooks ~magit-stage-hook~ and ~magit-unstage-hook~. #3496 - Added new hook ~git-commit-post-finish-hook~, a hook that has been requested many times but which I did not implement before because it is impossible to make 100% reliable. When the ~emacsclient~ returns, then that does not mean that the calling process is done too. We avoid a race condition by waiting for ~HEAD~ to point to a different commit than it used to point to, before running the hook. If it takes longer than a second for this to happen, then the hook is not run. A few unsafe commands are also blacklisted because they perform other things after creating the commit and that would lead to another race condition. #3615, d445a3d30, af4bf8df8 This hook is used instead of ~with-editor-post-finish-hook~ (on which the former is build) to merge the current branch into its wip refs when ~magit-wip-merge-branch~ is non-nil. - Added new hook ~magit-post-commit-hook~, which is only run after running a ~magit-commit-*~ command that does not require the user to edit the commit message. #3615 - ~magit-format-patch~ can now be told to only include the changes to certain files in the patch. It now also refreshes Magit buffers. #3601 - The list of related refs in ~magit-revision-mode~ buffers is no longer truncate when it doesn't fit on a single line. Instead users can now specify the kinds of refs that should be inserted in such buffers using the option ~magit-revision-insert-related-refs~. #3487 - Added new function ~magit-gitdir~ scheduled to replace ~magit-git-dir~ eventually because the latter has a really strange signature. 5f407a29a - Created new libraries from existing code. 9efcb1e8b ff - The option ~magit-revision-show-gravatar~ is now easier to customize. Customizing it to only show one of the two images actually works now. f4b8fee66, b82228bc6 - The option ~magit-repository-directories~ has a non-nil default value now. f77d1158b - The list of stashes in the status buffer is initially collapsed now. 4dc1d0593 - The commands ~magit-previous-line~ and ~magit-next-line~ are used by default now. 3ae75c865 - Added support for ~--left-right~ output in logs. #3627 - Added new option ~magit-with-editor-envvar~. Changing its value from ~GIT_EDITOR~ to ~GIT_SEQUENCE_EDITOR~ allows users to continue to use Magit (~git-rebase.el~ actually) to edit rebase sequence but to use another editor to edit commit messages and such. #3629 - Added new option ~magit-clone-default-directory~. #3635 - ~magit-ref-namespaces~ is now taken into account when colorizing branch names in buffers listing refs. #3645 - Added new option ~magit-revision-fill-summary-line~. #3610 ** Fixes since v2.13.0 - A confirmation prompt during rebase was wrong. 37d76f409 - ~magit-rebase-autosquash~ asked for confirmation when the user already confirmed earlier. 02e6c75b6 - ~magit-commit-add-log~ inserted after the diff that gets inserted if ~commit.verbose~ is ~true~. #3480 - ~magit-log-wash-rev~ errored in ~magit-cherry-mode~, starting with Emacs 26.1. - ~magit-dired-jump~ failed, starting with Emacs 26.1. #3469 - Magit used a completion function to make the built-in completion respect the collection's order. Even though that wasn't necessary for Ivy and Helm it did the same here, which became a problem when a change in Helm caused fuzzy completion to break in combination with a completion function. Likewise a change in Ivy caused Magit's sort order to be ignored, which we work around now. #3476, #3477 - In some edge cases ~magit-branch-pull-request~ used to set Git variables to invalid values. #3417 - The section visibility cache used ~eq~ when it should have used ~equal~. It also briefly used ~alist-get~, which we cannot do because that did not take a ~testfn~ argument in Emacs 25. #3495, #3499 - Detecting whether a commit has already been pushed to a "publishing" branch was much slower than it had to be. #3519 - ~magit-gitignore-popup~'s autoload definition was broken. - When using cygwin, then ~git-commit-setup-font-lock~ could end up trying to run git in a non-existent directory. #3505 - ~magit-completion-read~ did not protect the value of ~this-command~ even though there is code that assumes it does. #3529 - ~magit-read-file-trace~ in some cases claimed that valid user input was invalid even though it was valid. Now we don't try to validate it anymore. #3531 - We didn't account for the surprising fact that asking whether the value of a local variable is risky can change point. #3541 - ~magit-merge-into~ signaled an error if the upstream of the current branch isn't configured instead of letting the user pick a target. #3550 - Some of the more complex ~magit-cherry-*~ variants did not abort if the first step failed. #3556 - Trying to visit a commit of a submodule directly from the status buffer of the super-projects resulted in an error. #3563 - ~magit-file-rename~ failed to rename a file that is located at the top-level of the working tree. #3569 - Magit didn't account for ~git rebase -i --root~ corrupting the root commit's author date field, resulting in its output being corrupted too. #3574 - If given one invalid rev, then ~magit-rev-eq~ returned ~nil~, but when both revs are invalid, then it returned ~t~. Now it returns ~nil~ in both cases. - In an edge case ~magit-diff-type~ falsely concluded that the uncommitted changes in a diff buffer already are committed. #2627 - ~magit--github-url-p~ failed to return ~t~ for an url for Github Enterprise instances. #3572 - Trying to insert Gravatar images resulted in an error if the service is not reachable. #3597 - ~magit-display-buffer~ always selected the appropriate frame even if that was already selected. That is undesirable because selecting a frame has side-effects. f07eb85c6 - A key binding was not updated when ~magit-submodule-deinit~ was renamed to ~magit-submodule-unpopulate~. b06845208 - ~magit-submodule-visit~ could end up re-populating the visited module. 3d794cd01 - The third-party ~git-annex~ program converts submodule gitdirs to symlinks, which we did not account for. #3599 - ~magit-bisect-start~ did fail silently when invalid user input, which flipped the good and bad revisions, instead of providing an informative error message. #3604 - ~magit-bisect-start~ did fail silently when there are uncommitted changes instead of providing an informative error message. In some cases it actually is possible to bisect with uncommitted changes but that would be dangerous and we do not try to detect whether that is the case and just always error out. #3604 - When applying changes, then the ~--unidiff-zero~ and ~-C0~ arguments were not automatically used when needed. The former wasn't used because of a bug, the latter because I was not aware that there was an edge case that makes that necessary. #3608 - Backported a fix (from Emacs 27) for an Emacs bug that sometimes caused ~git rebase~ to fail to acquire the ~index.lock~. #2708, https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559 - Autoloading ~magit-submodules~ didn't work. #3618 - Reverting files failed if the selection contained only binary files. c7bbe3e9a - ~magit-read-repository~ failed when ~magit-repository-directories~ is non-nil but no repository can be found in those directories. #3636 - Attempting to reverse changes to binary files failed with an error that wasn't informative enough. #3625 - When a local branch is being renamed, then ~magit-branch-rename~ used to also rename the (remote) push-target, which is unsafe in some cases. Now it always asks the user before doing so. 14c7b1381 * Authors 333 Jonas Bernoulli 31 Kyle Meyer 13 Noam Postavsky 2 Phil Sainty 1 Alex Branham 1 Aria Edmonds 1 Arialdo Martini 1 Basil L. Contovounesios 1 Benjamin Motz 1 Bob Uhl 1 Eric Prud'hommeaux 1 Felix Yan 1 John Morris 1 Jordan Galby 1 Louis Roché 1 Mak Kolybabi 1 Miciah Masters 1 N. Troy de Freitas 1 Pierre Neidhardt 1 Raimon Grau magit-2.90.1/Documentation/RelNotes/2.90.1.org000066400000000000000000000021641337354740400205250ustar00rootroot00000000000000* Magit v2.90.1 Release Notes ** Changes since v2.90.0 - Added ~bug-reference-mode~ to ~git-commit-setup-hook~. e19e8fb1e - The "Version" column in ~magit-submodule-list-mode~ and ~magit-repolist-mode~ buffers now shows when a repository is dirty. 0b86dbfd6 - Added new command ~magit-log-merged~. This command requires ~git-when-merged~ (https://github.com/mhagger/git-when-merged). It isn't bound in ~magit-log-popup~ by default. To add it, you can use something like #+BEGIN_SRC emacs-lisp (magit-define-popup-action 'magit-log-popup ?m "Log commit's merge" 'magit-log-merged) #+END_SRC #3657 ** Fixes since v2.90.0 - Bumped the minimal required version of ~git-commit~ to the correct version. e9bd33758 - Dropped the new "v" prefix that we started to add to release tags starting with the previous release in places where that prefix is undesirable. f441cf6d7 - Staging and unstaging submodules while ~diff.submodule~'s value is ~log~ broke shortly before the v2.90.0 release. #3654 * Authors 10 Jonas Bernoulli 1 Allen Li 1 Kevin Brubeck Unhammer 1 Kyle Meyer magit-2.90.1/Documentation/RelNotes/2.91.0.org000066400000000000000000000020561337354740400205250ustar00rootroot00000000000000* Magit v2.91.0 Release Notes (unreleased) ** Breaking changes ** Changes since v2.90.0 - Added ~bug-reference-mode~ to ~git-commit-setup-hook~. e19e8fb1e - The "Version" column in ~magit-submodule-list-mode~ and ~magit-repolist-mode~ buffers now shows when a repository is dirty. 0b86dbfd6 - Added new command ~magit-log-merged~. This command requires ~git-when-merged~ (https://github.com/mhagger/git-when-merged). It isn't bound in ~magit-log-popup~ by default. To add it, you can use something like #+BEGIN_SRC emacs-lisp (magit-define-popup-action 'magit-log-popup ?m "Log commit's merge" 'magit-log-merged) #+END_SRC #3657 ** Fixes since v2.90.0 - Bumped the minimal required version of ~git-commit~ to the correct version. e9bd33758 - Dropped the new "v" prefix that we started to add to release tags starting with the previous release in places where that prefix is undesirable. f441cf6d7 - Staging and unstaging submodules while ~diff.submodule~'s value is ~log~ broke shortly before the v2.90.0 release. #3654 magit-2.90.1/Documentation/magit.org000066400000000000000000011506111337354740400173460ustar00rootroot00000000000000#+TITLE: Magit User Manual :PREAMBLE: #+AUTHOR: Jonas Bernoulli #+EMAIL: jonas@bernoul.li #+DATE: 2015-2018 #+LANGUAGE: en #+TEXINFO_DIR_CATEGORY: Emacs #+TEXINFO_DIR_TITLE: Magit: (magit). #+TEXINFO_DIR_DESC: Using Git from Emacs with Magit. #+SUBTITLE: for version 2.90.1 #+BIND: ox-texinfo+-before-export-hook ox-texinfo+-update-version-strings #+TEXINFO_DEFFN: t #+OPTIONS: H:4 num:3 toc:2 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. #+TEXINFO: @noindent This manual is for Magit version 2.90.1. #+BEGIN_QUOTE Copyright (C) 2015-2018 Jonas Bernoulli 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. #+END_QUOTE :END: * Introduction 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. Staging and otherwise applying changes is one of the most important features in a Git porcelain and here Magit outshines anything else, including Git itself. Git's own staging interface (~git add --patch~) is so cumbersome that many users only use it in exceptional cases. In Magit staging a hunk or even just part of a hunk is as trivial as staging all changes made to a file. The most visible part of Magit's interface is the status buffer, which displays information about the current repository. Its content is created by running several Git commands and making their output actionable. Among other things, it displays information about the current branch, lists unpulled and unpushed changes and contains sections displaying the staged and unstaged changes. That might sound noisy, but, since sections are collapsible, it's not. To stage or unstage a change one places the cursor on the change and then types ~s~ or ~u~. The change can be a file or a hunk, or when the region is active (i.e. when there is a selection) several files or hunks, or even just part of a hunk. The change or changes that these commands - and many others - would act on are highlighted. Magit also implements several other "apply variants" in addition to staging and unstaging. One can discard or reverse a change, or apply it to the working tree. Git's own porcelain only supports this for staging and unstaging and you would have to do something like ~git diff ... | ??? | git apply ...~ to discard, revert, or apply a single hunk on the command line. In fact that's exactly what Magit does internally (which is what lead to the term "apply variants"). Magit isn't just for Git experts, but it does assume some prior experience with Git as well as Emacs. That being said, many users have reported that using Magit was what finally taught them what Git is capable of and how to use it to its fullest. Other users wished they had switched to Emacs sooner so that they would have gotten their hands on Magit earlier. While one has to know the basic features of Emacs to be able to make full use of Magit, acquiring just enough Emacs skills doesn't take long and is worth it, even for users who prefer other editors. Vim users are advised to give [[https://bitbucket.org/lyro/evil/wiki/Home][Evil]], the "Extensible VI Layer for Emacs", and [[https://github.com/syl20bnr/spacemacs][Spacemacs]], an "Emacs starter-kit focused on Evil" a try. Magit provides a consistent and efficient Git porcelain. After a short learning period, you will be able to perform most of your daily version control tasks faster than you would on the command line. You will likely also start using features that seemed too daunting in the past. Magit fully embraces Git. It exposes many advanced features using a simple but flexible interface instead of only wrapping the trivial ones like many GUI clients do. Of course Magit supports logging, cloning, pushing, and other commands that usually don't fail in spectacular ways; but it also supports tasks that often cannot be completed in a single step. Magit fully supports tasks such as merging, rebasing, cherry-picking, reverting, and blaming by not only providing a command to initiate these tasks but also by displaying context sensitive information along the way and providing commands that are useful for resolving conflicts and resuming the sequence after doing so. Magit wraps and in many cases improves upon at least the following Git porcelain commands: ~add~, ~am~, ~bisect~, ~blame~, ~branch~, ~checkout~, ~cherry~, ~cherry-pick~, ~clean~, ~clone~, ~commit~, ~config~, ~describe~, ~diff~, ~fetch~, ~format-patch~, ~init~, ~log~, ~merge~, ~merge-tree~, ~mv~, ~notes~, ~pull~, ~rebase~, ~reflog~, ~remote~, ~request-pull~, ~reset~, ~revert~, ~rm~, ~show~, ~stash~, ~submodule~, ~subtree~, ~tag~, and ~worktree.~ Many more Magit porcelain commands are implemented on top of Git plumbing commands. * Installation ** _ :ignore: Magit can be installed using Emacs' package manager or manually from its development repository. ** Installing from Melpa Magit is available from Melpa and Melpa-Stable. If you haven't used Emacs' package manager before, then it is high time you familiarize yourself with it by reading the documentation in the Emacs manual, see [[info:emacs#Packages]]. Then add one of the archives to ~package-archives~: - To use Melpa: #+BEGIN_SRC emacs-lisp (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) #+END_SRC - To use Melpa-Stable: #+BEGIN_SRC emacs-lisp (require 'package) (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t) #+END_SRC Once you have added your preferred archive, you need to update the local package list using: #+BEGIN_EXAMPLE M-x package-refresh-contents RET #+END_EXAMPLE Once you have done that, you can install Magit and its dependencies using: #+BEGIN_EXAMPLE M-x package-install RET magit RET #+END_EXAMPLE Now see [[*Post-Installation Tasks]]. ** Installing from the Git Repository Magit depends on the ~dash~, ~ghub~, ~graphql~, ~magit-popup~, ~treepy~ and ~with-editor~ libraries which are available from Melpa and Melpa-Stable. Install them using ~M-x package-install RET RET~. Of course you may also install them manually from their repository. Then clone the Magit repository: #+BEGIN_SRC shell-script $ git clone https://github.com/magit/magit.git ~/.emacs.d/site-lisp/magit $ cd ~/.emacs.d/site-lisp/magit #+END_SRC Then compile the libraries and generate the info manuals: #+BEGIN_SRC shell-script $ make #+END_SRC If you haven't installed ~dash~, ~ghub~, ~graphql~, ~magit-popup~, ~treepy~ and ~with-editor~ from Melpa or at ~/path/to/magit/../~, then you have to tell ~make~ where to find them. To do so create the file ~/path/to/magit/config.mk~ with the following content before running ~make~: #+BEGIN_SRC makefile LOAD_PATH = -L /path/to/magit/lisp LOAD_PATH += -L /path/to/dash LOAD_PATH += -L /path/to/ghub LOAD_PATH += -L /path/to/graphql LOAD_PATH += -L /path/to/magit-popup LOAD_PATH += -L /path/to/treepy LOAD_PATH += -L /path/to/with-editor #+END_SRC Finally add this to your init file: #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "~/.emacs.d/site-lisp/magit/lisp") (require 'magit) (with-eval-after-load 'info (info-initialize) (add-to-list 'Info-directory-list "~/.emacs.d/site-lisp/magit/Documentation/")) #+END_SRC Note that you have to add the ~lisp~ subdirectory to the ~load-path~, not the top-level of the repository, and that elements of ~load-path~ should not end with a slash, while those of ~Info-directory-list~ should. Instead of requiring the feature ~magit~, you could load just the autoload definitions, by loading the file ~magit-autoloads.el~. #+BEGIN_SRC emacs-lisp (load "/path/to/magit/lisp/magit-autoloads") #+END_SRC Instead of running Magit directly from the repository by adding that to the ~load-path~, you might want to instead install it in some other directory using ~sudo make install~ and setting ~load-path~ accordingly. To update Magit use: #+BEGIN_SRC shell-script $ git pull $ make #+END_SRC At times it might be necessary to run ~make clean all~ instead. To view all available targets use ~make help~. Now see [[*Post-Installation Tasks]]. ** Post-Installation Tasks After installing Magit you should verify that you are indeed using the Magit, Git, and Emacs releases you think you are using. It's best to restart Emacs before doing so, to make sure you are not using an outdated value for ~load-path~. #+BEGIN_EXAMPLE M-x magit-version RET #+END_EXAMPLE should display something like #+BEGIN_EXAMPLE Magit 2.8.0, Git 2.10.2, Emacs 25.1.1, gnu/linux #+END_EXAMPLE Then you might also want to read about options that many users likely want to customize. See [[*Essential Settings]]. To be able to follow cross references to Git manpages found in this manual, you might also have to manually install the ~gitman~ info manual, or advice ~Info-follow-nearest-node~ to instead open the actual manpage. See [[*How to install the gitman info manual?]]. If you are completely new to Magit then see [[*Getting Started]]. If you run into problems, then please see the [[*FAQ]]. Also see the [[*Debugging Tools]]. And last but not least please consider making a donation, to ensure that I can keep working on Magit. See https://magit.vc/donations. for various donation options. * Getting Started This short tutorial describes the most essential features that many Magitians use on a daily basis. It only scratches the surface but should be enough to get you started. IMPORTANT: It is safest if you clone some repository just for this tutorial. Alternatively you can use an existing local repository, but if you do that, then you should commit all uncommitted changes before proceeding. To display information about the current Git repository, type ~M-x magit-status RET~. You will be using this command a lot, and should therefore give it a global key binding. This is what we recommend: #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x g") 'magit-status) #+END_SRC Most Magit commands are commonly invoked from the status buffer. It can be considered the primary interface for interacting with Git using Magit. Many other Magit buffers may exist at a given time, but they are often created from this buffer. Depending on what state your repository is in, this buffer may contain sections titled "Staged changes", "Unstaged changes", "Unmerged into origin/master", "Unpushed to origin/master", and many others. Since we are starting from a safe state, which you can easily return to (by doing a ~git reset --hard PRE-MAGIT-STATE~), there currently are not staged or unstaged changes. Edit some files and save the changes. Then go back to the status buffer, while at the same time refreshing it, by typing ~C-x g~. (When the status buffer, or any Magit buffer for that matter, is the current buffer, then you can also use just ~g~ to refresh it). Move between sections using ~p~ and ~n~. Note that the bodies of some sections are hidden. Type ~TAB~ to expand or collapse the section at point. You can also use ~C-tab~ to cycle the visibility of the current section and its children. Move to a file section inside the section named "Unstaged changes" and type ~s~ to stage the changes you have made to that file. That file now appears under "Staged changes". Magit can stage and unstage individual hunks, not just complete files. Move to the file you have just staged, expand it using ~TAB~, move to one of the hunks using ~n~, and unstage just that by typing ~u~. Note how the staging (~s~) and unstaging (~u~) commands operate on the change at point. Many other commands behave the same way. You can also un-/stage just part of a hunk. Inside the body of a hunk section (move there using ~C-n~), set the mark using ~C-SPC~ and move down until some added and/or removed lines fall inside the region but not all of them. Again type ~s~ to stage. It is also possible to un-/stage multiple files at once. Move to a file section, type ~C-SPC~, move to the next file using ~n~, and then ~s~ to stage both files. Note that both the mark and point have to be on the headings of sibling sections for this to work. If the region looks like it does in other buffers, then it doesn't select Magit sections that can be acted on as a unit. And then of course you want to commit your changes. Type ~c~. This shows the committing popup buffer featuring various commit variants and arguments that can be passed to ~git commit~. Do not worry about those for now. We want to create a "normal" commit, which is done by typing ~c~ again. Now two new buffers appear. One is for writing the commit message, the other shows a diff with the changes that you are about to committed. Write a message and then type ~C-c C-c~ to actually create the commit. You probably don't want to push the commit you just created because you just committed some random changes, but if that is not the case you could push it by typing ~P~ to bring up the push popup and then ~p~ to push to a branch with the same name as the local branch onto the remote configured as the push-remote. (If the push-remote is not configured yet, then you would first be prompted for the remote to push to.) So far we have mentioned the commit, push, and log popups. These are probably among the popups you will be using the most, but many others exist. To show a popup that lists all other popups (as well as the various apply commands and some other fundamental commands), type ~h~. Try a few. The key bindings in that popup correspond to the bindings in Magit buffers, including but not limited to the status buffer. So you could type ~h d~ to bring up the diff popup, but once you remember that "d" stands for "diff", you would usually do so by just typing ~d~. But the "popup of popups" is useful even once you have memorized all the bindings, as it can provide easy access to Magit commands from non-Magit buffers. You should create a global key binding for this command too: #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x M-g") 'magit-dispatch-popup) #+END_SRC In the same vein, you might also want to enable ~global-magit-file-mode~ to get some more Magit key bindings in regular file-visiting buffers (see [[*Minor Mode for Buffers Visiting Files]]). It is not necessary that you do so now, but if you stick with Magit, then it is highly recommended that you read the next section too. * Interface Concepts ** Modes and Buffers *** _ :ignore: Magit provides several major-modes. For each of these modes there usually exists only one buffer per repository. Separate modes and thus buffers exist for commits, diffs, logs, and some other things. Besides these special purpose buffers, there also exists an overview buffer, called the *status buffer*. It's usually from this buffer that the user invokes Git commands, or creates or visits other buffers. In this manual we often speak about "Magit buffers". By that we mean buffers whose major-modes derive from ~magit-mode~. - Key: M-x magit-toggle-buffer-lock, magit-toggle-buffer-lock This command locks the current buffer to its value or if the buffer is already locked, then it unlocks it. Locking a buffer to its value prevents it from being reused to display another value. The name of a locked buffer contains its value, which allows telling it apart from other locked buffers and the unlocked buffer. Not all Magit buffers can be locked to their values; for example, it wouldn't make sense to lock a status buffer. There can only be a single unlocked buffer using a certain major-mode per repository. So when a buffer is being unlocked and another unlocked buffer already exists for that mode and repository, then the former buffer is instead deleted and the latter is displayed in its place. *** Switching Buffers - Function: magit-display-buffer buffer This function is a wrapper around ~display-buffer~ and is used to display any Magit buffer. It displays BUFFER in some window and, unlike ~display-buffer~, also selects that window, provided ~magit-display-buffer-noselect~ is ~nil~. It also runs the hooks mentioned below. - Variable: magit-display-buffer-noselect When this is non-nil, then ~magit-display-buffer~ only displays the buffer but forgoes also selecting the window. This variable should not be set globally, it is only intended to be let-bound, by code that automatically updates "the other window". This is used for example when the revision buffer is updated when you move inside the log buffer. - User Option: magit-display-buffer-function The function specified here is called by ~magit-display-buffer~ with one argument, a buffer, to actually display that buffer. This function should call ~display-buffer~ with that buffer as first and a list of display actions as second argument. Magit provides several functions, listed below, that are suitable values for this option. If you want to use different rules, then a good way of doing that is to start with a copy of one of these functions and then adjust it to your needs. Instead of using a wrapper around ~display-buffer~, that function itself can be used here, in which case the display actions have to be specified by adding them to ~display-buffer-alist~ instead. To learn about display actions, see [[info:elisp#Choosing a Window for Display]]. - Function: magit-display-buffer-traditional buffer This function is the current default value of the option ~magit-display-buffer-function~. Before that option and this function were added, the behavior was hard-coded in many places all over the code base but now all the rules are contained in this one function (except for the "noselect" special case mentioned above). - Function: magit-display-buffer-same-window-except-diff-v1 This function displays most buffers in the currently selected window. If a buffer's mode derives from ~magit-diff-mode~ or ~magit-process-mode~, it is displayed in another window. - Function: magit-display-buffer-fullframe-status-v1 This function fills the entire frame when displaying a status buffer. Otherwise, it behaves like ~magit-display-buffer-traditional~. - Function: magit-display-buffer-fullframe-status-topleft-v1 This function fills the entire frame when displaying a status buffer. It behaves like ~magit-display-buffer-fullframe-status-v1~ except that it displays buffers that derive from ~magit-diff-mode~ or ~magit-process-mode~ to the top or left of the current buffer rather than to the bottom or right. As a result, Magit buffers tend to pop up on the same side as they would if ~magit-display-buffer-traditional~ were in use. - Function: magit-display-buffer-fullcolumn-most-v1 This function displays most buffers so that they fill the entire height of the frame. However, the buffer is displayed in another window if (1) the buffer's mode derives from ~magit-process-mode~, or (2) the buffer's mode derives from ~magit-diff-mode~, provided that the mode of the current buffer derives from ~magit-log-mode~ or ~magit-cherry-mode~. - User Option: magit-pre-display-buffer-hook This hook is run by ~magit-display-buffer~ before displaying the buffer. - Function: magit-save-window-configuration This function saves the current window configuration. Later when the buffer is buried, it may be restored by ~magit-restore-window-configuration~. - User Option: magit-post-display-buffer-hook This hook is run by ~magit-display-buffer~ after displaying the buffer. - Function: magit-maybe-set-dedicated This function remembers if a new window had to be created to display the buffer, or whether an existing window was reused. This information is later used by ~magit-mode-quit-window~, to determine whether the window should be deleted when its last Magit buffer is buried. *** Naming Buffers - User Option: magit-generate-buffer-name-function The function used to generate the names of Magit buffers. Such a function should take the options ~magit-uniquify-buffer-names~ as well as ~magit-buffer-name-format~ into account. If it doesn't, then should be clearly stated in the doc-string. And if it supports %-sequences beyond those mentioned in the doc-string of the option ~magit-buffer-name-format~, then its own doc-string should describe the additions. - Function: magit-generate-buffer-name-default-function mode This function returns a buffer name suitable for a buffer whose major-mode is MODE and which shows information about the repository in which ~default-directory~ is located. This function uses ~magit-buffer-name-format~ and supporting all of the %-sequences mentioned the documentation of that option. It also respects the option ~magit-uniquify-buffer-names~. - User Option: magit-buffer-name-format The format string used to name Magit buffers. At least the following %-sequences are supported: - ~%m~ The name of the major-mode, but with the ~-mode~ suffix removed. - ~%M~ Like ~%m~ but abbreviate ~magit-status-mode~ as ~magit~. - ~%v~ The value the buffer is locked to, in parentheses, or an empty string if the buffer is not locked to a value. - ~%V~ Like ~%v~, but the string is prefixed with a space, unless it is an empty string. - ~%t~ The top-level directory of the working tree of the repository, or if ~magit-uniquify-buffer-names~ is non-nil an abbreviation of that. - ~%x~ If ~magit-uniquify-buffer-names~ is nil "*", otherwise the empty string. Due to limitations of the ~uniquify~ package, buffer names must end with the path. - ~%T~ Obsolete, use "%t%x" instead. Like ~%t~, but append an asterisk if and only if ~magit-uniquify-buffer-names~ is nil. The value should always contain ~%m~ or ~%M~, ~%v~ or ~%V~, and ~%t~ (or the obsolete ~%T~). If ~magit-uniquify-buffer-names~ is non-nil, then the value must end with ~%t~ or ~%t%x~ (or the obsolete ~%T~). See issue #2841. - User Option: magit-uniquify-buffer-names This option controls whether the names of Magit buffers are uniquified. If the names are not being uniquified, then they contain the full path of the top-level of the working tree of the corresponding repository. If they are being uniquified, then they end with the basename of the top-level, or if that would conflict with the name used for other buffers, then the names of all these buffers are adjusted until they no longer conflict. This is done using the ~uniquify~ package; customize its options to control how buffer names are uniquified. *** Quitting Windows - Key: q, magit-mode-bury-buffer This command buries the current Magit buffer. With a prefix argument, it instead kills the buffer. - User Option: magit-bury-buffer-function The function used to actually bury or kill the current buffer. ~magit-mode-bury-buffer~ calls this function with one argument. If the argument is non-nil, then the function has to kill the current buffer. Otherwise it has to bury it alive. The default value currently is ~magit-restore-window-configuration~. - Function: magit-restore-window-configuration kill-buffer Bury or kill the current buffer using ~quit-window~, which is called with KILL-BUFFER as first and the selected window as second argument. Then restore the window configuration that existed right before the current buffer was displayed in the selected frame. Unfortunately that also means that point gets adjusted in all the buffers, which are being displayed in the selected frame. - Function: magit-mode-quit-window kill-buffer Bury or kill the current buffer using ~quit-window~, which is called with KILL-BUFFER as first and the selected window as second argument. Then, if the window was originally created to display a Magit buffer and the buried buffer was the last remaining Magit buffer that was ever displayed in the window, then that is deleted. *** Automatic Refreshing of Magit Buffers After running a command which may change the state of the current repository, the current Magit buffer and the corresponding status buffer are refreshed. The status buffer may optionally be automatically refreshed whenever a buffer is saved to a file inside the respective repository. Automatically refreshing Magit buffers ensures that the displayed information is up-to-date most of the time but can lead to a noticeable delay in big repositories. Other Magit buffers are not refreshed to keep the delay to a minimum and also because doing so can sometimes be undesirable. Buffers can also be refreshed explicitly, which is useful in buffers that weren't current during the last refresh and after changes were made to the repository outside of Magit. - Key: g, magit-refresh This command refreshes the current buffer if its major mode derives from ~magit-mode~ as well as the corresponding status buffer. If the option ~magit-revert-buffers~ calls for it, then it also reverts all unmodified buffers that visit files being tracked in the current repository. - Key: G, magit-refresh-all This command refreshes all Magit buffers belonging to the current repository and also reverts all unmodified buffers that visit files being tracked in the current repository. The file-visiting buffers are always reverted, even if ~magit-revert-buffers~ is nil. - User Option: magit-refresh-buffer-hook This hook is run in each Magit buffer that was refreshed during the current refresh - normally the current buffer and the status buffer. - User Option: magit-refresh-status-buffer When this option is non-nil, then the status buffer is automatically refreshed after running git for side-effects, in addition to the current Magit buffer, which is always refreshed automatically. Only set this to nil after exhausting all other options to improve performance. - Function: magit-after-save-refresh-status This function is intended to be added to ~after-save-hook~. After doing that the corresponding status buffer is refreshed whenever a buffer is saved to a file inside a repository. Note that refreshing a Magit buffer is done by re-creating its contents from scratch, which can be slow in large repositories. If you are not satisfied with Magit's performance, then you should obviously not add this function to that hook. *** Automatic Saving of File-Visiting Buffers File-visiting buffers are by default saved at certain points in time. This doesn't guarantee that Magit buffers are always up-to-date, but, provided one only edits files by editing them in Emacs and uses only Magit to interact with Git, one can be fairly confident. When in doubt or after outside changes, type ~g~ (~magit-refresh~) to save and refresh explicitly. - User Option: magit-save-repository-buffers This option controls whether file-visiting buffers are saved before certain events. If this is non-nil then all modified file-visiting buffers belonging to the current repository may be saved before running commands, before creating new Magit buffers, and before explicitly refreshing such buffers. If this is ~dontask~ then this is done without user intervention. If it is ~t~ then the user has to confirm each save. *** Automatic Reverting of File-Visiting Buffers By default Magit automatically reverts buffers that are visiting files that are being tracked in a Git repository, after they have changed on disk. When using Magit one often changes files on disk by running git, i.e. "outside Emacs", making this a rather important feature. For example, if you discard a change in the status buffer, then that is done by running ~git apply --reverse ...~, and Emacs considers the file to have "changed on disk". If Magit did not automatically revert the buffer, then you would have to type ~M-x revert-buffer RET RET~ in the visiting buffer before you could continue making changes. - User Option: magit-auto-revert-mode When this mode is enabled, then buffers that visit tracked files, are automatically reverted after the visited files changed on disk. - User Option: global-auto-revert-mode When this mode is enabled, then any file-visiting buffer is automatically reverted after the visited file changed on disk. If you like buffers that visit tracked files to be automatically reverted, then you might also like any buffer to be reverted, not just those visiting tracked files. If that is the case, then enable this mode /instead of/ ~magit-auto-revert-mode~. - User Option: magit-auto-revert-immediately This option controls 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. - User Option: auto-revert-use-notify This option controls whether file notification functions should be used. Note that this variable unfortunately defaults to ~t~ even on systems on which file notifications cannot be used. - User Option: magit-auto-revert-tracked-only This option controls whether ~magit-auto-revert-mode~ only reverts tracked files or all files that are located inside Git repositories, including untracked files and files located inside Git's control directory. - Command: auto-revert-mode The global mode ~magit-auto-revert-mode~ works by turning on this local mode in the appropriate buffers (but ~global-auto-revert-mode~ is implemented differently). You can also turn it on or off manually, which might be necessary if Magit does not notice that a previously untracked file now is being tracked or vice-versa. - User Option: auto-revert-stop-on-user-input This option controls whether the arrival of user input suspends the automatic reverts for ~auto-revert-interval~ seconds. - User Option: auto-revert-interval This option controls for how many seconds Emacs waits before resuming suspended reverts. - User Option: auto-revert-buffer-list-filter This option specifies an additional filter used by ~auto-revert-buffers~ to determine whether a buffer should be reverted or not. This option is provided by ~magit~, which also redefines ~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-buffers-p~. However the default is nil, to not 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. - User Option: auto-revert-verbose This option controls whether Emacs reports when a buffer has been reverted. The options with the ~auto-revert-~ prefix are located in the Custom group named ~auto-revert~. The other, magit-specific, options are located in the ~magit~ group. **** Risk of Reverting Automatically :PROPERTIES: :TEXINFO-NODE: t :END: For the vast majority users automatically reverting file-visiting buffers after they have changed on disk is harmless. If a buffer is modified (i.e. it contains changes that haven't been saved yet), then Emacs would refuse to automatically revert it. If you save a previously modified buffer, then that results in what is seen by Git as an uncommitted change. Git would then refuse to carry out any commands that would cause these changes to be lost. In other words, if there is anything that could be lost, then either Git or Emacs would refuse to discard the changes. However if you do use file-visiting buffers as a sort of ad hoc "staging area", then the automatic reverts could potentially cause data loss. So far I have only heard from one user who uses such a workflow. An example: You visit some file in a buffer, edit it, and save the changes. Then, outside of Emacs (or at least not using Magit or by saving the buffer) you change the file on disk again. At this point the buffer is the only place where the intermediate version still exists. You have saved the changes to disk, but that has since been overwritten. Meanwhile Emacs considers the buffer to be unmodified (because you have not made any changes to it since you last saved it to the visited file) and therefore would not object to it being automatically reverted. At this point an Auto-Revert mode would kick in. It would check whether the buffer is modified and since that is not the case it would revert it. The intermediate version would be lost. (Actually you could still get it back using the ~undo~ command.) If your workflow depends on Emacs preserving the intermediate version in the buffer, then you have to disable all Auto-Revert modes. But please consider that such a workflow would be dangerous even without using an Auto-Revert mode, and should therefore be avoided. If Emacs crashed or if you quit Emacs by mistake, then you would also lose the buffer content. There would be no autosave file still containing the intermediate version (because that was deleted when you saved the buffer) and you would not be asked whether you want to save the buffer (because it isn't modified). ** Sections *** _ :ignore: Magit buffers are organized into nested sections, which can be collapsed and expanded, similar to how sections are handled in Org mode. Each section also has a type, and some sections also have a value. For each section type there can also be a local keymap, shared by all sections of that type. Taking advantage of the section value and type, many commands operate on the current section, or when the region is active and selects sections of the same type, all of the selected sections. Commands that only make sense for a particular section type (as opposed to just behaving differently depending on the type) are usually bound in section type keymaps. *** Section Movement To move within a section use the usual keys (~C-p~, ~C-n~, ~C-b~, ~C-f~ etc), whose global bindings are not shadowed. To move to another section use the following commands. - Key: p, magit-section-backward When not at the beginning of a section, then move to the beginning of the current section. At the beginning of a section, instead move to the beginning of the previous visible section. - Key: n, magit-section-forward Move to the beginning of the next visible section. - Key: M-p, magit-section-backward-siblings Move to the beginning of the previous sibling section. If there is no previous sibling section, then move to the parent section instead. - Key: M-n, magit-section-forward-siblings Move to the beginning of the next sibling section. If there is no next sibling section, then move to the parent section instead. - Key: ^, magit-section-up Move to the beginning of the parent of the current section. The above commands all call the hook ~magit-section-movement-hook~. Any of the functions listed below can be used as members of this hook. - Variable: magit-section-movement-hook This hook is run by all of the above movement commands, after arriving at the destination. - Function: magit-hunk-set-window-start This hook function ensures that the beginning of the current section is visible, provided it is a ~hunk~ section. Otherwise, it does nothing. This function is a member of the hook's default value. - Function: magit-section-set-window-start This hook function ensures that the beginning of the current section is visible, regardless of the section's type. If you add this to ~magit-section-movement-hook~, then you must remove the hunk-only variant in turn. - Function: magit-log-maybe-show-more-commits This hook function only has an effect in log buffers, and ~point~ is on the "show more" section. If that is the case, then it doubles the number of commits that are being shown. This function is a member of the hook's default value. - Function: magit-log-maybe-update-revision-buffer When moving inside a log buffer, then this function updates the revision buffer, provided it is already being displayed in another window of the same frame. This function is a member of the hook's default value. - Function: magit-log-maybe-update-blob-buffer When moving inside a log buffer and another window of the same frame displays a blob buffer, then this function instead displays the blob buffer for the commit at point in that window. - Function: magit-status-maybe-update-revision-buffer When moving inside a status buffer, then this function updates the revision buffer, provided it is already being displayed in another window of the same frame. - Function: magit-status-maybe-update-blob-buffer When moving inside a status buffer and another window of the same frame displays a blob buffer, then this function instead displays the blob buffer for the commit at point in that window. - User Option: magit-update-other-window-delay Delay before automatically updating the other window. When moving around in certain buffers, then certain other buffers, which are being displayed in another window, may optionally be updated to display information about the section at point. When holding down a key to move by more than just one section, then that would update that buffer for each section on the way. To prevent that, updating the revision buffer is delayed, and this option controls for how long. For optimal experience you might have to adjust this delay and/or the keyboard repeat rate and delay of your graphical environment or operating system. *** Section Visibility Magit provides many commands for changing the visibility of sections, but all you need to get started are the next two. - Key: TAB, magit-section-toggle Toggle the visibility of the body of the current section. - Key: C-, magit-section-cycle Cycle the visibility of current section and its children. - Key: M-, magit-section-cycle-diffs Cycle the visibility of diff-related sections in the current buffer. - Key: S-, magit-section-cycle-global Cycle the visibility of all sections in the current buffer. - Key: 1, magit-section-show-level-1 - Key: 2, magit-section-show-level-2 - Key: 3, magit-section-show-level-3 - Key: 4, magit-section-show-level-4 Show sections surrounding the current section up to level N. - Key: M-1, magit-section-show-level-1-all - Key: M-2, magit-section-show-level-2-all - Key: M-3, magit-section-show-level-3-all - Key: M-4, magit-section-show-level-4-all Show all sections up to level N. Some functions, which are used to implement the above commands, are also exposed as commands themselves. By default no keys are bound to these commands, as they are generally perceived to be much less useful. But your mileage may vary. - Command: magit-section-show Show the body of the current section. - Command: magit-section-hide Hide the body of the current section. - Command: magit-section-show-headings Recursively show headings of children of the current section. Only show the headings. Previously shown text-only bodies are hidden. - Command: magit-section-show-children Recursively show the bodies of children of the current section. With a prefix argument show children down to the level of the current section, and hide deeper children. - Command: magit-section-hide-children Recursively hide the bodies of children of the current section. - Command: magit-section-toggle-children Toggle visibility of bodies of children of the current section. When a buffer is first created then some sections are shown expanded while others are not. This is hard coded. When a buffer is refreshed then the previous visibility is preserved. The initial visibility of certain sections can also be overwritten using the hook ~magit-section-set-visibility-hook~. - User Option: magit-section-initial-visibility-alist This options can be used to override the initial visibility of sections. In the future it will also be used to define the defaults, but currently a section's default is still hardcoded. The value is an alist. Each element maps a section type or lineage to the initial visibility state for such sections. The state has to be one of ~show~ or ~hide~, or a function that returns one of these symbols. A function is called with the section as the only argument. Use the command ~magit-describe-section-briefly~ to determine a section's lineage or type. The vector in the output is the section lineage and the type is the first element of that vector. Wildcards can be used, see ~magit-section-match~. - User Option: magit-section-cache-visibility This option controls for which sections the previous visibility state should be restored if a section disappears and later appears again. The value is a boolean or a list of section types. If t, then the visibility of all sections is cached. Otherwise this is only done for sections whose type matches one of the listed types. This requires that the function ~magit-section-cached-visibility~ is a member of ~magit-section-set-visibility-hook~. - Variable: magit-section-set-visibility-hook This hook is run when first creating a buffer and also when refreshing an existing buffer, and is used to determine the visibility of the section currently being inserted. Each function is called with one argument, the section being inserted. It should return ~hide~ or ~show~, or to leave the visibility undefined ~nil~. If no function decides on the visibility and the buffer is being refreshed, then the visibility is preserved; or if the buffer is being created, then the hard coded default is used. Usually this should only be used to set the initial visibility but not during refreshes. If ~magit-insert-section--oldroot~ is non-nil, then the buffer is being refreshed and these functions should immediately return ~nil~. *** Section Hooks Which sections are inserted into certain buffers is controlled with hooks. This includes the status and the refs buffers. For other buffers, e.g. log and diff buffers, this is not possible. The command ~magit-describe-section~ can be used to see which hook (if any) was responsible for inserting the section at point. For buffers whose sections can be customized by the user, a hook variable called ~magit-TYPE-sections-hook~ exists. This hook should be changed using ~magit-add-section-hook~. Avoid using ~add-hooks~ or the Custom interface. The various available section hook variables are described later in this manual along with the appropriate "section inserter functions". - Function: magit-add-section-hook hook function &optional at append local Add the function FUNCTION to the value of section hook HOOK. Add FUNCTION at the beginning of the hook list unless optional APPEND is non-nil, in which case FUNCTION is added at the end. If FUNCTION already is a member then move it to the new location. If optional AT is non-nil and a member of the hook list, then add FUNCTION next to that instead. Add before or after AT, or replace AT with FUNCTION depending on APPEND. If APPEND is the symbol ~replace~, then replace AT with FUNCTION. For any other non-nil value place FUNCTION right after AT. If nil, then place FUNCTION right before AT. If FUNCTION already is a member of the list but AT is not, then leave FUNCTION where ever it already is. If optional LOCAL is non-nil, then modify the hook's buffer-local value rather than its global value. This makes the hook local by copying the default value. That copy is then modified. HOOK should be a symbol. If HOOK is void, it is first set to nil. HOOK's value must not be a single hook function. FUNCTION should be a function that takes no arguments and inserts one or multiple sections at point, moving point forward. FUNCTION may choose not to insert its section(s), when doing so would not make sense. It should not be abused for other side-effects. To remove a function from a section hook, use ~remove-hook~. *** Section Types and Values Each section has a type, for example ~hunk~, ~file~, and ~commit~. Instances of certain section types also have a value. The value of a section of type ~file~, for example, is a file name. Users usually do not have to worry about a section's type and value, but knowing them can be handy at times. - Key: M-x magit-describe-section-briefly, magit-describe-section-briefly Show information about the section at point in the echo area, as "#". Many commands behave differently depending on the type of the section at point and/or somehow consume the value of that section. But that is only one of the reasons why the same key may do something different, depending on what section is current. Additionally for each section type a keymap *might* be defined, named ~magit-TYPE-section-map~. That keymap is used as text property keymap of all text belonging to any section of the respective type. If such a map does not exist for a certain type, then you can define it yourself, and it will automatically be used. *** Section Options This section describes options that have an effect on more than just a certain type of sections. As you can see there are not many of those. - User Option: magit-section-show-child-count Whether to append the number of children to section headings. This only affects sections that could benefit from this information. ** Popup Buffers and Prefix Commands Many Magit commands are implemented using *popup buffers*. First the user invokes a *popup* or *prefix* command, which causes a popup buffer with the available *infix* arguments and *suffix* commands to be displayed. The user then optionally toggles/sets some arguments and finally invokes one of the suffix commands. This is implemented in the library ~magit-popup~. Earlier releases used the library ~magit-key-mode~. A future release will switch to a yet-to-be-written successor, which will likely be named ~transient~. Because ~magit-popup~ can also be used by other packages without having to depend on all of Magit, it is documented in its own manual. See [[info:magit-popup]]. - Key: C-c C-c, magit-dispatch-popup This popup command shows a buffer featuring all other Magit popup commands as well as some other commands that are not popup commands themselves. This command is also, or especially, useful outside Magit buffers, so you should setup a global binding: #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x M-g") 'magit-dispatch-popup) #+END_SRC Most popups set their initial arguments according to the corresponding ~magit-*-arguments~ variable. Two popups, the log and diff popups (see [[*Logging]] and [[*Diffing]]), may behave a bit differently, depending on the value of ~magit-use-sticky-arguments~. - User Option: magit-use-sticky-arguments This option controls how diff and log commands reuse arguments from existing buffers. When ~t~ (the default value), the log or diff popup reuses the arguments from the current repository's log or diff buffer, respectively. When no log or diff buffer exists for the current repository, these popups use the default value of ~magit-log-arguments~ or ~magit-diff-arguments~. When ~current~, log and diff popups will only reuse the arguments if the current buffer is derived from ~magit-log-mode~ or ~magit-diff-mode~, respectively. When ~nil~, the default value of ~magit-log-arguments~ or ~magit-diff-arguments~ is always used. ** Completion, Confirmation and the Selection *** Action Confirmation By default many actions that could potentially lead to data loss have to be confirmed. This includes many very common actions, so this can quickly become annoying. Many of these actions can be undone and if you have thought about how to undo certain mistakes, then it should be safe to disable confirmation for the respective actions. The option ~magit-no-confirm~ can be used to tell Magit to perform certain actions without the user having to confirm them. Note that while this option can only be used to disable confirmation for a specific set of actions, the next section explains another way of telling Magit to ask fewer questions. - User Option: magit-no-confirm The value of this option is a list of symbols, representing actions that do not have to be confirmed by the user before being carried out. By default many potentially dangerous commands ask the user for confirmation. Each of the below symbols stands for an action which, when invoked unintentionally or without being fully aware of the consequences, could lead to tears. In many cases there are several commands that perform variations of a certain action, so we don't use the command names but more generic symbols. - Applying changes: - ~discard~ Discarding one or more changes (i.e. hunks or the complete diff for a file) loses that change, obviously. - ~reverse~ Reverting one or more changes can usually be undone by reverting the reversion. - ~stage-all-changes~, ~unstage-all-changes~ When there are both staged and unstaged changes, then un-/staging everything would destroy that distinction. Of course that also applies when un-/staging a single change, but then less is lost and one does that so often that having to confirm every time would be unacceptable. - Files: - ~delete~ When a file that isn't yet tracked by Git is deleted, then it is completely lost, not just the last changes. Very dangerous. - ~trash~ Instead of deleting a file it can also be move to the system trash. Obviously much less dangerous than deleting it. Also see option ~magit-delete-by-moving-to-trash~. - ~resurrect~ A deleted file can easily be resurrected by "deleting" the deletion, which is done using the same command that was used to delete the same file in the first place. - ~untrack~ Untracking a file can be undone by tracking it again. - ~rename~ Renaming a file can easily be undone. - Sequences: - ~reset-bisect~ Aborting (known to Git as "resetting") a bisect operation loses all information collected so far. - ~abort-rebase~ Aborting a rebase throws away all already modified commits, but it's possible to restore those from the reflog. - ~abort-merge~ Aborting a merge throws away all conflict resolutions which have already been carried out by the user. - ~merge-dirty~ Merging with a dirty worktree can make it hard to go back to the state before the merge was initiated. - References: - ~delete-unmerged-branch~ Once a branch has been deleted, it can only be restored using low-level recovery tools provided by Git. And even then the reflog is gone. The user always has to confirm the deletion of a branch by accepting the default choice (or selecting another branch), but when a branch has not been merged yet, also make sure the user is aware of that. - ~delete-pr-branch~ When deleting a branch that was created from a pull request and if no other branches still exist on that remote, then `magit-branch-delete' offers to delete the remote as well. This should be safe because it only happens if no other refs exist in the remotes namespace, and you can recreate the remote if necessary. - ~drop-stashes~ Dropping a stash is dangerous because Git stores stashes in the reflog. Once a stash is removed, there is no going back without using low-level recovery tools provided by Git. When a single stash is dropped, then the user always has to confirm by accepting the default (or selecting another). This action only concerns the deletion of multiple stashes at once. - Edit published history: Without adding these symbols here, you will be warned before editing commits that have already been pushed to one of the branches listed in ~magit-published-branches~. - ~amend-published~ Affects most commands that amend to "HEAD". - ~rebase-published~ Affects commands that perform interactive rebases. This includes commands from the commit popup that modify a commit other than "HEAD", namely the various fixup and squash variants. - ~edit-published~ Affects the commands ~magit-edit-line-commit~ and ~magit-diff-edit-hunk-commit~. These two commands make it quite easy to accidentally edit a published commit, so you should think twice before configuring them not to ask for confirmation. To disable confirmation completely, add all three symbols here or set ~magit-published-branches~ to ~nil~. - Various: - ~kill-process~ There seldom is a reason to kill a process. - Global settings: Instead of adding all of the above symbols to the value of this option, you can also set it to the atom `t', which has the same effect as adding all of the above symbols. Doing that most certainly is a bad idea, especially because other symbols might be added in the future. So even if you don't want to be asked for confirmation for any of these actions, you are still better of adding all of the respective symbols individually. When ~magit-wip-before-change-mode~ is enabled, then the following actions can be undone fairly easily: ~discard~, ~reverse~, ~stage-all-changes~, and ~unstage-all-changes~. If and only if this mode is enabled, then ~safe-with-wip~ has the same effect as adding all of these symbols individually. *** Completion and Confirmation Many Magit commands ask the user to select from a list of possible things to act on, while offering the most likely choice as the default. For many of these commands the default is the thing at point, provided that it actually is a valid thing to act on. For many commands that act on a branch, the current branch serves as the default if there is no branch at point. These commands combine asking for confirmation and asking for a target to act on into a single action. The user can confirm the default target using ~RET~ or abort using ~C-g~. This is similar to a ~y-or-n-p~ prompt, but the keys to confirm or abort differ. At the same time the user is also given the opportunity to select another target, which is useful because for some commands and/or in some situations you might want to select the action before selecting the target by moving to it. However you might find that for some commands you always want to use the default target, if any, or even that you want the command to act on the default without requiring any confirmation at all. The option ~magit-dwim-selection~ can be used to configure certain commands to that effect. Note that when the region is active then many commands act on the things that are selected using a mechanism based on the region, in many cases after asking for confirmation. This region-based mechanism is called the "selection" and is described in detail in the next section. When a selection exists that is valid for the invoked command, then that command never offers to act on something else, and whether it asks for confirmation is not controlled by this option. Also note that Magit asks for confirmation of certain actions that are not coupled with completion (or the selection). Such dialogs are also not affected by this option and are described in the previous section. - User Option: magit-dwim-selection This option can be used to tell certain commands to use the thing at point instead of asking the user to select a candidate to act on, with or without confirmation. The value has the form ~((COMMAND nil|PROMPT DEFAULT)...)~. - COMMAND is the command that should not prompt for a choice. To have an effect, the command has to use the function ~magit-completing-read~ or a utility function which in turn uses that function. - If the command uses ~magit-completing-read~ multiple times, then PROMPT can be used to only affect one of these uses. PROMPT, if non-nil, is a regular expression that is used to match against the PROMPT argument passed to ~magit-completing-read~. - DEFAULT specifies how to use the default. If it is ~t~, then the DEFAULT argument passed to ~magit-completing-read~ is used without confirmation. If it is ~ask~, then the user is given a chance to abort. DEFAULT can also be ~nil~, in which case the entry has no effect. *** The Selection If the region is active, then many Magit commands act on the things that are selected using a mechanism based on the region instead of one single thing. When the region is not active, then these commands act on the thing at point or read a single thing to act on. This is described in the previous section — this section only covers how multiple things are selected, how that is visualized, and how certain commands behave when that is the case. Magit's mechanism for selecting multiple things, or rather sections that represent these things, is based on the Emacs region, but the area that Magit considers to be selected is typically larger than the region and additional restrictions apply. Magit makes a distinction between a region that qualifies as forming a valid Magit selection and a region that does not. If the region does not qualify, then it is displayed as it is in other Emacs buffers. If the region does qualify as a Magit selection, then the selection is always visualized, while the region itself is only visualized if it begins and ends on the same line. For a region to qualify as a Magit selection, it must begin in the heading of one section and end in the heading of a sibling section. Note that if the end of the region is at the very beginning of section heading (i.e. at the very beginning of a line) then that section is considered to be *inside* the selection. This is not consistent with how the region is normally treated in Emacs — if the region ends at the beginning of a line, then that line is outside the region. Due to how Magit visualizes the selection, it should be obvious that this difference exists. Not every command acts on every valid selection. Some commands do not even consider the location of point, others may act on the section at point but not support acting on the selection, and even commands that do support the selection of course only do so if it selects things that they can act on. This is the main reason why the selection must include the section at point. Even if a selection exists, the invoked command may disregard it, in which case it may act on the current section only. It is much safer to only act on the current section but not the other selected sections than it is to act on the current section *instead* of the selected sections. The latter would be much more surprising and if the current section always is part of the selection, then that cannot happen. - Variable: magit-keep-region-overlay This variable controls whether the region is visualized as usual even when a valid Magit selection or a hunk-internal region exists. See the doc-string for more information. *** The hunk-internal region Somewhat related to the Magit selection described in the previous section is the hunk-internal region. Like the selection, the hunk-internal region is based on the Emacs region but causes that region to not be visualized as it would in other Emacs buffers, and includes the line on which the region ends even if it ends at the very beginning of that line. Unlike the selection, which is based on a region that must begin in the heading of one section and ends in the section of a sibling section, the hunk-internal region must begin inside the *body* of a hunk section and end in the body of the *same* section. The hunk-internal region is honored by "apply" commands, which can, among other targets, act on a hunk. If the hunk-internal region is active, then such commands act only on the marked part of the hunk instead of on the complete hunk. *** Support for Completion Frameworks The built-in option ~completing-read-function~ specifies the low-level function used by ~completing-read~ to ask a user to select from a list of choices. Its default value is ~completing-read-default~. Alternative completion frameworks typically activate themselves by substituting their own implementation. Mostly for historic reasons Magit provides a similar option named ~magit-completing-read-function~, which only controls the low-level function used by ~magit-completing-read~. This option also makes it possible to use a different completing mechanism for Magit than for the rest of Emacs, but doing that is not recommend. You most likely don't have to customize the magit-specific option to use an alternative completion framework. For example, if you enable ~ivy-mode~, then Magit will respect that, and if you enable ~helm-mode~, then you are done too. However if you want to use Ido, then ~ido-mode~ won't do the trick. You will also have to install the ~ido-completing-read+~ package and use ~magit-ido-completing-read~ as ~magit-completing-read-function~. - User Option: magit-completing-read-function The value of this variable is the low-level function used to perform completion by code that uses ~magit-completing-read~ (as opposed to the built-in ~completing-read~). The default value, ~magit-builtin-completing-read~, is suitable for the standard completion mechanism, ~ivy-mode~, and ~helm-mode~ at least. The built-in ~completing-read~ and ~completing-read-default~ are *not* suitable to be used here. ~magit-builtin-completing-read~ performs some additional work, and any function used in its place has to do the same. - Function: magit-builtin-completing-read prompt choices &optional predicate require-match initial-input hist def This function performs completion using the built-in ~completion-read~ and does some additional magit-specific work. - Function: magit-ido-completing-read prompt choices &optional predicate require-match initial-input hist def This function performs completion using ~ido-completing-read+~ from the package by the same name (which you have to explicitly install) and does some additional magit-specific work. We have to use ~ido-completing-read+~ instead of the ~ido-completing-read~ that comes with Ido itself, because the latter, while intended as a drop-in replacement, cannot serve that purpose because it violates too many of the implicit conventions. - Function: magit-completing-read prompt choices &optional predicate require-match initial-input hist def fallback This is the function that Magit commands use when they need the user to select a single thing to act on. The arguments have the same meaning as for ~completing-read~, except for FALLBACK, which is unique to this function and is described below. Instead of asking the user to choose from a list of possible candidates, this function may just return the default specified by DEF, with or without requiring user confirmation. Whether that is the case depends on PROMPT, ~this-command~ and ~magit-dwim-selection~. See the documentation of the latter for more information. If it does read a value in the minibuffer, then this function acts similar to ~completing-read~, except for the following: - If REQUIRE-MATCH is ~nil~ and the user exits without a choice, then ~nil~ is returned instead of an empty string. - If REQUIRE-MATCH is non-nil and the users exits without a choice, an user-error is raised. - FALLBACK specifies a secondary default that is only used if the primary default DEF is ~nil~. The secondary default is not subject to ~magit-dwim-selection~ — if DEF is ~nil~ but FALLBACK is not, then this function always asks the user to choose a candidate, just as if both defaults were ~nil~. - ": " is appended to PROMPT. - PROMPT is modified to end with \" (default DEF|FALLBACK): \" provided that DEF or FALLBACK is non-nil, that neither ~ivy-mode~ nor ~helm-mode~ is enabled, and that ~magit-completing-read-function~ is set to its default value of ~magit-builtin-completing-read~. *** Additional Completion Options - User Option: magit-list-refs-sortby For many commands that read a ref or refs from the user, the value of this option can be used to control the order of the refs. Valid values include any key accepted by the ~--sort~ flag of ~git for-each-ref~. By default, refs are sorted alphabetically by their full name (e.g., "refs/heads/master"). ** Running Git *** Viewing Git Output Magit runs Git either for side-effects (e.g. when pushing) or to get some value (e.g. the name of the current branch). When Git is run for side-effects, the process output is logged in a per-repository log buffer, which can be consulted using the ~magit-process~ command when things don't go as expected. The output/errors for up to `magit-process-log-max' Git commands are retained. - Key: $, magit-process This commands displays the process buffer for the current repository. Inside that buffer, the usual key bindings for navigating and showing sections are available. There is one additional command. - Key: k, magit-process-kill This command kills the process represented by the section at point. - User Option: magit-git-debug When this is non-nil then the output of all calls to git are logged in the process buffer. This is useful when debugging, otherwise it just negatively affects performance. *** Git Process Status When a Git process is running for side-effects, Magit displays an indicator in the mode line, using the ~magit-mode-line-process~ face. If the Git process exits successfully, the process indicator is removed from the mode line immediately. In the case of a Git error, the process indicator is not removed, but is instead highlighted with the ~magit-mode-line-process-error~ face, and the error details from the process buffer are provided as a tooltip for mouse users. This error indicator persists in the mode line until the next magit buffer refresh. If you do not wish process errors to be indicated in the mode line, customize the ~magit-process-display-mode-line-error~ user option. Process errors are additionally indicated at the top of the status buffer. *** Running Git Manually While Magit provides many Emacs commands to interact with Git, it does not cover everything. In those cases your existing Git knowledge will come in handy. Magit provides some commands for running arbitrary Git commands by typing them into the minibuffer, instead of having to switch to a shell. - Key: !, magit-run-popup Shows the popup buffer featuring the below suffix commands. - Key: ! !, magit-git-command-topdir This command reads a command from the user and executes it in the top-level directory of the current working tree. The string "git " is used as initial input when prompting the user for the command. It can be removed to run another command. - Key: ! p, magit-git-command This command reads a command from the user and executes it in ~default-directory~. With a prefix argument the command is executed in the top-level directory of the current working tree instead. The string "git " is used as initial input when prompting the user for the command. It can be removed to run another command. - Key: ! s, magit-shell-command-topdir This command reads a command from the user and executes it in the top-level directory of the current working tree. - Key: ! S, magit-shell-command This command reads a command from the user and executes it in ~default-directory~. With a prefix argument the command is executed in the top-level directory of the current working tree instead. - User Option: magit-shell-command-verbose-prompt Whether the prompt, used by the the above commands when reading a shell command, shows the directory in which it will be run. These suffix commands start external gui tools. - Key: ! k, magit-run-gitk This command runs ~gitk~ in the current repository. - Key: ! a, magit-run-gitk-all This command runs ~gitk --all~ in the current repository. - Key: ! b, magit-run-gitk-branches This command runs ~gitk --branches~ in the current repository. - Key: ! g, magit-run-git-gui This command runs ~git gui~ in the current repository. *** Git Executable Except on MS Windows, Magit defaults to running Git without specifying the path to the git executable. Instead the first executable found by Emacs on ~exec-path~ is used (whose value in turn is set based on the value of the environment variable ~$PATH~ when Emacs was started). This has the advantage that it continues to work even when using Tramp to connect to a remote machine on which the executable is found in a different place. The downside is that if you have multiple versions of Git installed, then you might end up using another version than the one you think you are using. - Key: M-x magit-version, magit-version This command shows the currently used versions of Magit, Git, and Emacs in the echo area. Non-interactively this just returns the Magit version. When the ~system-type~ is ~windows-nt~, then ~magit-git-executable~ is set to an absolute path when Magit is first loaded. This is necessary because Git on that platform comes with several wrapper scripts for the actual git binary, which are also placed on ~$PATH~, and using one of these wrappers instead of the binary would degrade performance horribly. If Magit doesn't find the correct executable then you *can* work around that by setting ~magit-git-executable~ to an absolute path. But note that doing so is a kludge. It is better to make sure the order in the environment variable ~$PATH~ is correct, and that Emacs is started with that environment in effect. The command ~magit-debug-git-executable~ can be useful to find out where Emacs is searching for git. If you have to connect from Windows to a non-Windows machine, then you must change the value to "git". - User Option: magit-git-executable The git executable used by Magit, either the full path to the executable or the string "git" to let Emacs find the executable itself, using the standard mechanism for doing such things. - Key: M-x magit-debug-git-executable, magit-debug-git-executable Display a buffer with information about ~magit-git-executable~. *** Global Git Arguments - User Option: magit-git-global-arguments The arguments set here are used every time the git executable is run as a subprocess. They are placed right after the executable itself and before the git command - as in ~git HERE... COMMAND REST~. For valid arguments see [[man:git]] Be careful what you add here, especially if you are using Tramp to connect to servers with ancient Git versions. Never remove anything that is part of the default value, unless you really know what you are doing. And think very hard before adding something; it will be used every time Magit runs Git for any purpose. * Inspecting ** _ :ignore: The functionality provided by Magit can be roughly divided into three groups: inspecting existing data, manipulating existing data or adding new data, and transferring data. Of course that is a rather crude distinction that often falls short, but it's more useful than no distinction at all. This section is concerned with inspecting data, the next two with manipulating and transferring it. Then follows a section about miscellaneous functionality, which cannot easily be fit into this distinction. Of course other distinctions make sense too, e.g. Git's distinction between porcelain and plumbing commands, which for the most part is equivalent to Emacs' distinction between interactive commands and non-interactive functions. All of the sections mentioned before are mainly concerned with the porcelain -- Magit's plumbing layer is described later. ** Status Buffer *** _ :ignore: While other Magit buffers contain e.g. one particular diff or one particular log, the status buffer contains the diffs for staged and unstaged changes, logs for unpushed and unpulled commits, lists of stashes and untracked files, and information related to the current branch. During certain incomplete operations -- for example when a merge resulted in a conflict -- additional information is displayed that helps proceeding with or aborting the operation. The command ~magit-status~ displays the status buffer belonging to the current repository in another window. This command is used so often that it should be bound globally. We recommend using ~C-x g~: #+BEGIN_SRC emacs-lisp (global-set-key (kbd "C-x g") 'magit-status) #+END_SRC - Key: C-x g, magit-status Show the status of the current Git repository in a buffer. With a prefix argument prompt for a repository to be shown. With two prefix arguments prompt for an arbitrary directory. If that directory isn't the root of an existing repository, then offer to initialize it as a new repository. - User Option: magit-repository-directories List of directories that are Git repositories 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. - User Option: magit-repository-directories-depth The maximum depth to look for Git repositories. This option is obsolete and only used for elements of the option ~magit-repository-directories~ (which see) that don't specify the depth directly. - Command: ido-enter-magit-status From an Ido prompt used to open a file, instead drop into ~magit-status~. This is similar to ~ido-magic-delete-char~, which, despite its name, usually causes a Dired buffer to be created. To make this command available, use something like: #+BEGIN_SRC emacs-lisp (add-hook 'ido-setup-hook (lambda () (define-key ido-completion-map (kbd \"C-x g\") 'ido-enter-magit-status))) #+END_SRC 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: #+BEGIN_SRC emacs-lisp (define-key ido-common-completion-map (kbd \"C-x g\") 'ido-enter-magit-status) #+END_SRC *** Status Sections The contents of status buffers is controlled using the hook ~magit-status-sections-hook~. See [[*Section Hooks]] to learn about such hooks and how to customize them. - User Option: magit-status-sections-hook Hook run to insert sections into a status buffer. The first function on that hook by default is ~magit-insert-status-headers~; it is described in the next section. By default the following functions are also members of that hook: - Function: 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. - Function: magit-insert-rebase-sequence Insert section for the on-going rebase sequence. If no such sequence is in progress, do nothing. - Function: magit-insert-am-sequence Insert section for the on-going patch applying sequence. If no such sequence is in progress, do nothing. - Function: magit-insert-sequencer-sequence Insert section for the on-going cherry-pick or revert sequence. If no such sequence is in progress, do nothing. - Function: magit-insert-bisect-output While bisecting, insert section with output from ~git bisect~. - Function: magit-insert-bisect-rest While bisecting, insert section visualizing the bisect state. - Function: magit-insert-bisect-log While bisecting, insert section logging bisect progress. - Function: 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~. - Function: magit-insert-unstaged-changes Insert section showing unstaged changes. - Function: magit-insert-staged-changes Insert section showing staged changes. - Function: magit-insert-stashes &optional ref heading Insert the ~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:". - Function: magit-insert-unpulled-from-upstream Insert section showing commits that haven't been pulled from the upstream branch yet. - Function: magit-insert-unpulled-from-pushremote Insert section showing commits that haven't been pulled from the push-remote branch yet. - Function: magit-insert-unpushed-to-upstream Insert section showing commits that haven't been pushed to the upstream yet. - Function: magit-insert-unpushed-to-pushremote Insert section showing commits that haven't been pushed to the push-remote yet. The following functions can also be added to the above hook: - Function: magit-insert-tracked-files Insert a tree of tracked files. - Function: magit-insert-ignored-files Insert a tree of ignored files. If the first element of ~magit-diff-section-arguments~ is a directory, then limit the list to files below that. The value of that variable can be set using ~D = f RET g~. - Function: magit-insert-unpulled-or-recent-commits Insert section showing unpulled or recent commits. If an upstream is configured for the current branch and it is ahead of the current branch, then show the missing commits. Otherwise, show the last ~magit-log-section-commit-count~ commits. - Function: magit-insert-recent-commits Insert section showing the last ~magit-log-section-commit-count~ commits. - User Option: magit-log-section-commit-count How many recent commits ~magit-insert-recent-commits~ and ~magit-insert-unpulled-or-recent-commits~ (provided there are no unpulled commits) show. - Function: magit-insert-unpulled-cherries Insert section showing unpulled commits. Like ~magit-insert-unpulled-commits~ but prefix each commit that has not been applied yet (i.e. a commit with a patch-id not shared with any local commit) with "+", and all others with "-". - Function: magit-insert-unpushed-cherries Insert section showing unpushed commits. Like ~magit-insert-unpushed-commits~ but prefix each commit which has not been applied to upstream yet (i.e. a commit with a patch-id not shared with any upstream commit) with "+" and all others with "-". See [[*References Buffer]] for some more section inserters, which could be used here. *** Status Header Sections The contents of status buffers is controlled using the hook ~magit-status-sections-hook~ (see [[*Status Sections]]). By default ~magit-insert-status-headers~ is the first member of that hook variable. - Function: magit-insert-status-headers Insert headers sections appropriate for ~magit-status-mode~ buffers. The sections are inserted by running the functions on the hook ~magit-status-headers-hook~. - User Option: magit-status-headers-hook Hook run to insert headers sections 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. By default the following functions are members of the above hook: - Function: magit-insert-error-header Insert a header line showing 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. - Function: magit-insert-diff-filter-header Insert a header line showing the effective diff filters. - Function: magit-insert-head-branch-header Insert a header line about the current branch or detached ~HEAD~. - Function: magit-insert-upstream-branch-header Insert a header line about the branch that is usually pulled into the current branch. - Function: magit-insert-push-branch-header Insert a header line about the branch that the current branch is usually pushed to. - Function: magit-insert-tags-header Insert a header line about the current and/or next tag, along with the number of commits between the tag and ~HEAD~. The following functions can also be added to the above hook: - Function: magit-insert-repo-header Insert a header line showing the path to the repository top-level. - Function: 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. - Function: magit-insert-user-header Insert a header line about the current user. *** Status Module Sections The contents of status buffers is controlled using the hook ~magit-status-sections-hook~ (see [[*Status Sections]]). By default ~magit-insert-modules~ is /not/ a member of that hook variable. - Function: 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. - User Option: magit-module-sections-hook Hook run by ~magit-insert-modules~. - User Option: magit-module-sections-nested This option controls whether ~magit-insert-modules~ wraps inserted sections in an additional section. 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. - Function: magit-insert-modules-overview Insert sections for all submodules. For each section insert the path, the branch, and the output of ~git describe --tags~, or, failing that, the abbreviated HEAD commit hash. Press ~RET~ on such a submodule section to show its own status buffer. Press ~RET~ on the "Modules" section to display a list of submodules in a separate buffer. This shows additional information not displayed in the super-repository's status buffer. - Function: magit-insert-modules-unpulled-from-upstream Insert sections for modules that haven't been pulled from the upstream yet. These sections can be expanded to show the respective commits. - Function: magit-insert-modules-unpulled-from-pushremote Insert sections for modules that haven't been pulled from the push-remote yet. These sections can be expanded to show the respective commits. - Function: magit-insert-modules-unpushed-to-upstream Insert sections for modules that haven't been pushed to the upstream yet. These sections can be expanded to show the respective commits. - Function: magit-insert-modules-unpushed-to-pushremote Insert sections for modules that haven't been pushed to the push-remote yet. These sections can be expanded to show the respective commits. *** Status Options - User Option: magit-status-refresh-hook Hook run after a status buffer has been refreshed. - User Option: magit-status-margin This option specifies whether the margin is initially shown in Magit-Status mode buffers and how it is formatted. 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 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. - 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. - User Option: magit-log-section-args Additional Git arguments used when creating log sections. Only ~--graph~, ~--decorate~, and ~--show-signature~ are supported. This option is only a temporary kludge and will be removed. Note that due to an issue in Git the use of ~--graph~ is very slow with long histories, so you probably don't want to add this here. Also see the proceeding section for more options concerning status buffers. ** Repository List - Command: magit-list-repositories This command displays a list of repositories in a separate buffer. The options ~magit-repository-directories~ and ~magit-repository-directories-depth~ control which repositories are displayed. - User Option: magit-repolist-columns This option controls what columns are displayed by the command ~magit-list-repositories~ and how they are displayed. 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~. The following functions can be added to the above option: - Function: magit-repolist-column-ident This function inserts the identification of the repository. Usually this is just its basename. - Function: magit-repolist-column-path This function inserts the absolute path of the repository. - Function: magit-repolist-column-version This function inserts a description of the repository's ~HEAD~ revision. - Function: magit-repolist-column-unpulled-from-upstream This function inserts the number of upstream commits not in the current branch. - Function: magit-repolist-column-unpulled-from-pushremote This function inserts the number of commits in the push branch but not the current branch. - Function: magit-repolist-column-unpushed-to-upstream This function inserts the number of commits in the current branch but not its upstream. - Function: magit-repolist-column-unpushed-to-pushremote This function inserts the number of commits in the current branch but not its push branch. ** Logging *** _ :ignore: The status buffer contains logs for the unpushed and unpulled commits, but that obviously isn't enough. The prefix command ~magit-log-popup~, on ~l~, features several suffix commands, which show a specific log in a separate log buffer. Like other popups, the log popup also features several arguments that can be changed before invoking one of the suffix commands. However, in the case of the log popup, these arguments may be taken from those currently in use in the current repository's log buffer, depending on the value of ~magit-use-sticky-arguments~ (see [[*Popup Buffers and Prefix Commands]]). For information about the various arguments, see [[man:git-log]] The switch ~++order=VALUE~ is converted to one of ~--author-date-order~, ~--date-order~, or ~--topo-order~ before being passed to ~git log~. The log popup also features several reflog commands. See [[*Reflog]]. - Key: l, magit-log-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: l l, magit-log-current Show log for the current branch. When ~HEAD~ is detached or with a prefix argument, show log for one or more revs read from the minibuffer. - Key: l o, magit-log-other Show log for one or more revs read from the minibuffer. The user can input any revision or revisions separated by a space, or even ranges, but only branches, tags, and a representation of the commit at point are available as completion candidates. - Key: l h, magit-log-head Show log for ~HEAD~. - Key: l L, magit-log-branches Show log for all local branches and ~HEAD~. - Key: l b, magit-log-all-branches Show log for all local and remote branches and ~HEAD~. - Key: l a, magit-log-all Show log for all references and ~HEAD~. Two additional commands that show the log for the file or blob that is being visited in the current buffer exists, see [[*Minor Mode for Buffers Visiting Files]]. The command ~magit-cherry~ also shows a log, see [[*Cherries]]. *** Refreshing Logs The prefix command ~magit-log-refresh-popup~, on ~L~, can be used to change the log arguments used in the current buffer, without changing which log is shown. This works in dedicated log buffers, but also in the status buffer. - Key: L, magit-log-refresh-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: L g, magit-log-refresh This suffix command sets the local log arguments for the current buffer. - Key: L s, magit-log-set-default-arguments This suffix command sets the default log arguments for buffers of the same type as that of the current buffer. Other existing buffers of the same type are not affected because their local values have already been initialized. - Key: L w, magit-log-save-default-arguments This suffix command sets the default log arguments for buffers of the same type as that of the current buffer, and saves the value for future sessions. Other existing buffers of the same type are not affected because their local values have already been initialized. - Key: L t, magit-toggle-margin Show or hide the margin. *** Log Buffer - Key: L, magit-log-refresh-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. See [[*Refreshing Logs]]. - Key: q, magit-log-bury-buffer Bury the current buffer or the revision buffer in the same frame. Like ~magit-mode-bury-buffer~ (which see) but with a negative prefix argument instead bury the revision buffer, provided it is displayed in the current frame. - Key: C-c C-b, magit-go-backward Move backward in current buffer's history. - Key: C-c C-f, magit-go-forward Move forward in current buffer's history. - Key: C-c C-n, magit-log-move-to-parent Move to a parent of the current commit. By default, this is the first parent, but a numeric prefix can be used to specify another parent. - Key: SPC, magit-diff-show-or-scroll-up Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer up. If there is no commit or stash at point, then prompt for a commit. - Key: DEL, magit-diff-show-or-scroll-down Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer down. If there is no commit or stash at point, then prompt for a commit. - Key: =, magit-log-toggle-commit-limit Toggle the number of commits the current log buffer is limited to. If the number of commits is currently limited, then remove that limit. Otherwise set it to 256. - Key: +, magit-log-double-commit-limit Double the number of commits the current log buffer is limited to. - Key: -, magit-log-half-commit-limit Half the number of commits the current log buffer is limited to. - User Option: magit-log-auto-more Insert more log entries automatically when moving past the last entry. Only considered when moving past the last entry with ~magit-goto-*-section~ commands. - User Option: magit-log-show-refname-after-summary Whether to show the refnames after the commit summaries. This is useful if you use really long branch names. Magit displays references in logs a bit differently from how Git does it. Local branches are blue and remote branches are green. Of course that depends on the used theme, as do the colors used for other types of references. The current branch has a box around it, as do remote branches that are their respective remote's ~HEAD~ branch. If a local branch and its push-target point at the same commit, then their names are combined to preserve space and to make that relationship visible. For example: #+BEGIN_EXAMPLE origin/feature [green][blue-] instead of feature origin/feature [blue-] [green-------] #+END_EXAMPLE Also note that while the popup features the ~--show-signature~ argument, that won't actually be used when enabled, because Magit defaults to use just one line per commit. Instead the commit colorized to indicate the validity of the signed commit object, using the faces named ~magit-signature-*~ (which see). For a description of ~magit-log-margin~ see [[*Log Margin]]. *** Log Margin In buffers which show one or more logs, it is possible to show additional information about each commit in the margin. The options used to configure the margin are named ~magit-INFIX-margin~, where INFIX is the same as in the respective major-mode ~magit-INFIX-mode~. In regular log buffers that would be ~magit-log-margin~. - User Option: magit-log-margin This option specifies whether the margin is initially shown in Magit-Log mode buffers and how it is formatted. 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 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. - 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. You can change the STYLE and AUTHOR-WIDTH of all ~magit-INFIX-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 INIT in ~magit-log-margin~ 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. - Key: L, magit-margin-popup This prefix command features the following commands for changing the appearance of the margin. In some buffers that support the margin, "L" is bound to ~magit-log-refresh-popup~, but that popup features the same commands, and then some other unrelated commands. - Key: L L, magit-toggle-margin This command shows or hides the margin. - Key: L l, magit-cycle-margin-style This command cycles the style used for the margin. - Key: L d, magit-toggle-margin-details This command shows or hides details in the margin. *** Select from Log When the user has to select a recent commit that is reachable from ~HEAD~, using regular completion would be inconvenient (because most humans cannot remember hashes or "HEAD~5", at least not without double checking). Instead a log buffer is used to select the commit, which has the advantage that commits are presented in order and with the commit message. Such selection logs are used when selecting the beginning of a rebase and when selecting the commit to be squashed into. In addition to the key bindings available in all log buffers, the following additional key bindings are available in selection log buffers: - Key: C-c C-c, magit-log-select-pick Select the commit at point and act on it. Call ~magit-log-select-pick-function~ with the selected commit as argument. - Key: C-c C-k, magit-log-select-quit Abort selecting a commit, don't act on any commit. - User Option: magit-log-select-margin This option specifies whether the margin is initially shown in Magit-Log-Select mode buffers and how it is formatted. 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 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. - 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. *** Reflog Also see [[man:git-reflog]] These reflog commands are available from the log popup. See [[*Logging]]. - Key: l r, magit-reflog-current Display the reflog of the current branch. - Key: l O, magit-reflog-other Display the reflog of a branch or another ref. - Key: l H, magit-reflog-head Display the ~HEAD~ reflog. - User Option: magit-reflog-margin This option specifies whether the margin is initially shown in Magit-Reflog mode buffers and how it is formatted. 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 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. - 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. *** Cherries Cherries are commits that haven't been applied upstream (yet), and are usually visualized using a log. Each commit is prefixed with ~-~ if it has an equivalent in the upstream and ~+~ if it does not, i.e. if it is a cherry. The command ~magit-cherry~ shows cherries for a single branch, but the references buffer (see [[*References Buffer]]) can show cherries for multiple "upstreams" at once. Also see [[man:git-reflog]] - Key: Y, magit-cherry Show commits that are in a certain branch but that have not been merged in the upstream branch. - User Option: magit-cherry-margin This option specifies whether the margin is initially shown in Magit-Cherry mode buffers and how it is formatted. 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 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. - 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. ** Diffing *** _ :ignore: The status buffer contains diffs for the staged and unstaged commits, but that obviously isn't enough. The prefix command ~magit-diff-popup~, on ~d~, features several suffix commands, which show a specific diff in a separate diff buffer. Like other popups, the diff popup also features several arguments that can be changed before invoking one of the suffix commands. However, in the case of the diff popup, these arguments may be taken from those currently in use in the current repository's log buffer, depending on the value of ~magit-use-sticky-arguments~ (see [[*Popup Buffers and Prefix Commands]]). Also see [[man:git-diff]] - Key: d, magit-diff-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: d d, magit-diff-dwim Show changes for the thing at point. - Key: d r, magit-diff-range Show differences between two commits. RANGE should be a range (A..B or A...B) but can also be a single commit. If one side of the range is omitted, then it defaults to ~HEAD~. If just a commit is given, then changes in the working tree relative to that commit are shown. 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). - Key: d w, magit-diff-working-tree Show changes between the current working tree and the ~HEAD~ commit. With a prefix argument show changes between the working tree and a commit read from the minibuffer. - Key: d s, magit-diff-staged Show changes between the index and the ~HEAD~ commit. With a prefix argument show changes between the index and a commit read from the minibuffer. - Key: d u, magit-diff-unstaged Show changes between the working tree and the index. - Key: d p, magit-diff-paths Show changes between any two files on disk. All of the above suffix commands update the repository's diff buffer. The diff popup also features two commands which show differences in another buffer: - Key: d c, magit-show-commit Show the commit at point. If there is no commit at point or with a prefix argument, prompt for a commit. - Key: d t, magit-stash-show Show all diffs of a stash in a buffer. Two additional commands that show the diff for the file or blob that is being visited in the current buffer exists, see [[*Minor Mode for Buffers Visiting Files]]. *** Refreshing Diffs The prefix command ~magit-diff-refresh-popup~, on ~D~, can be used to change the diff arguments used in the current buffer, without changing which diff is shown. This works in dedicated diff buffers, but also in the status buffer. - Key: D, magit-diff-refresh-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: D g, magit-diff-refresh This suffix command sets the local diff arguments for the current buffer. - Key: D s, magit-diff-set-default-arguments This suffix command sets the default diff arguments for buffers of the same type as that of the current buffer. Other existing buffers of the same type are not affected because their local values have already been initialized. - Key: D w, magit-diff-save-default-arguments This suffix command sets the default diff arguments for buffers of the same type as that of the current buffer, and saves the value for future sessions. Other existing buffers of the same type are not affected because their local values have already been initialized. - Key: D t, magit-diff-toggle-refine-hunk This command toggles hunk refinement on or off. - Key: D r, magit-diff-switch-range-type This command converts the diff range type from "revA..revB" to "revB...revA", or vice versa. - Key: D f, magit-diff-flip-revs This command swaps revisions in the diff range from "revA..revB" to "revB..revA", or vice versa. - Key: D F, magit-diff-toggle-file-filter This command toggles the file restriction of the diffs in the current buffer, allowing you to quickly switch between viewing all the changes in the commit and the restricted subset. As a special case, when this command is called from a log buffer, it toggles the file restriction in the repository's revision buffer, which is useful when you display a revision from a log buffer that is restricted to a file or files. In addition to the above popup, which allows changing any of the supported arguments, there also exist some commands which change a particular argument. - Key: -, magit-diff-less-context This command decreases the context for diff hunks by COUNT lines. - Key: +, magit-diff-more-context This command increases the context for diff hunks by COUNT lines. - Key: 0, magit-diff-default-context This command resets the context for diff hunks to the default height. The following commands quickly change what diff is being displayed without having to using one of the diff popups. - Key: C-c C-d, magit-diff-while-committing While committing, this command shows the changes that are about to be committed. While amending, invoking the command again toggles between showing just the new changes or all the changes that will be committed. This binding is available in the diff buffer as well as the commit message buffer. - Key: C-c C-b, magit-go-backward This command moves backward in current buffer's history. - Key: C-c C-f, magit-go-forward This command moves forward in current buffer's history. *** Diff Buffer These commands are available in diff buffers. - Key: RET, magit-diff-visit-file From a diff, visit the corresponding file at the appropriate position. If the diff shows changes in the worktree, the index, or ~HEAD~, then visit the actual file. Otherwise, when the diff is about an older commit or a range, then visit the appropriate blob. If point is on a removed line, then visit the blob for the first parent of the commit which removed that line, i.e. the last commit where that line still existed. Otherwise visit the blob for the commit whose changes are being shown. Interactively, when the file or blob to be displayed is already being displayed in another window of the same frame, then just select that window and adjust point. Otherwise, or with a prefix argument, display the buffer in another window. The meaning of the prefix argument can be inverted or further modified using the option ~magit-display-file-buffer-function~. Non-interactively the optional OTHER-WINDOW argument is taken literally. DISPLAY-FN can be used to specify the display function explicitly, in which case OTHER-WINDOW is ignored. The optional FORCE-WORKTREE means to force visiting the worktree version of the file. To do this interactively use the command ~magit-diff-visit-file-worktree~ instead. - User Option: magit-diff-visit-previous-blob This option controls whether ~magit-diff-visit-file~ may visit the previous blob. When this is ~t~ and point is on a removed line in a diff for a committed change, then ~magit-diff-visit-file~ visits the blob from the last revision which still had that line. Currently this is only supported for committed changes, for staged and unstaged changes ~magit-diff-visit-file~ always visits the file in the working tree. - Key: C-, magit-diff-visit-file-worktree From a diff, visit the corresponding file at the appropriate position. When the file is already being displayed in another window of the same frame, then just select that window and adjust point. With a prefix argument also display in another window. The actual file in the worktree is visited. The positions in the hunk headers get less useful the "older" the changes are, and as a result, jumping to the appropriate position gets less reliable. Also see ~magit-diff-visit-file~, which visits the respective blob, unless the diff shows changes in the worktree, the index, or ~HEAD~. - Command: magit-diff-visit-file-other-window From a diff, visit the corresponding file at the appropriate position in another window. - Key: C-c C-t, magit-diff-trace-definition From a diff, show log for the definition at point. - User Option: magit-log-trace-definition-function The function used by ~magit-log-trace-definition~ to determine the function at point. For major-modes that have special needs, you could set that using the mode's hook. - Key: C-c C-e, magit-diff-edit-hunk-commit 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. - Key: j, magit-jump-to-diffstat-or-diff Jump to the diffstat or diff. When point is on a file inside the diffstat section, then jump to the respective diff section. Otherwise, jump to the diffstat section or a child thereof. - Key: SPC, scroll-up Scroll text upward. - Key: DEL, scroll-down Scroll text downward. *** Diff Options - User Option: magit-diff-refine-hunk Whether to show word-granularity differences within diff hunks. - ~nil~ never show fine differences. - ~t~ show fine differences for the current diff hunk only. - ~all~ show fine differences for all displayed diff hunks. - User Option: magit-diff-adjust-tab-width Whether to adjust the width of tabs in diffs. Determining the correct width can be expensive if it requires opening large and/or many files, so the widths are cached in the variable ~magit-diff--tab-width-cache~. Set that to nil to invalidate the cache. - ~nil~ Never adjust tab width. Use `tab-width's value from the Magit buffer itself instead. - ~t~ If the corresponding file-visiting buffer exits, then use ~tab-width~'s value from that buffer. Doing this is cheap, so this value is used even if a corresponding cache entry exists. - ~always~ If there is no such buffer, then temporarily visit the file to determine the value. - NUMBER Like ~always~, but don't visit files larger than NUMBER bytes. - User Option: magit-diff-paint-whitespace Specify where to highlight whitespace errors. See ~magit-diff-highlight-trailing~, ~magit-diff-highlight-indentation~. The symbol ~t~ means in all diffs, ~status~ means only in the status buffer, and nil means nowhere. - User Option: magit-diff-highlight-trailing Whether to highlight whitespace at the end of a line in diffs. Used only when ~magit-diff-paint-whitespace~ is non-nil. - User Option: magit-diff-highlight-indentation Highlight the "wrong" indentation style. Used only when ~magit-diff-paint-whitespace~ is non-nil. The value is a list of cons cells. The car is a regular expression, and the cdr is the value that applies to repositories whose directory matches the regular expression. If more than one element matches, then the *last* element in the list applies. The default value should therefore come first in the list. If the value is ~tabs~, highlight indentation with tabs. If the value is an integer, highlight indentation with at least that many spaces. Otherwise, highlight neither. - User Option: magit-diff-hide-trailing-cr-characters Whether to hide ^M characters at the end of a line in diffs. - User Option: magit-diff-highlight-hunk-region-functions This option specifies the functions used to highlight the hunk-internal region. ~magit-diff-highlight-hunk-region-dim-outside~ overlays the outside of the hunk internal selection with a face that causes the added and removed lines to have the same background color as context lines. This function should not be removed from the value of this option. ~magit-diff-highlight-hunk-region-using-overlays~ and ~magit-diff-highlight-hunk-region-using-underline~ emphasize the region by placing delimiting horizontal lines before and after it. Both of these functions have glitches which cannot be fixed due to limitations of Emacs' display engine. For more information see https://github.com/magit/magit/issues/2758 ff. Instead of, or in addition to, using delimiting horizontal lines, to emphasize the boundaries, you may which to emphasize the text itself, using ~magit-diff-highlight-hunk-region-using-face~. In terminal frames it's not possible to draw lines as the overlay and underline variants normally do, so there they fall back to calling the face function instead. - User Option: magit-diff-unmarked-lines-keep-foreground This option controls whether added and removed lines outside the hunk-internal region only lose their distinct background color or also the foreground color. Whether the outside of the region is dimmed at all depends on ~magit-diff-highlight-hunk-region-functions~. *** Revision Buffer - User Option: magit-revision-insert-related-refs Whether to show related branches in revision buffers. - ~nil~ Don't show any related branches. - ~t~ Show related local branches. - ~all~ Show related local and remote branches. - ~mixed~ Show all containing branches and local merged branches. - User Option: magit-revision-show-gravatars Whether to show gravatar images in revision buffers. If ~nil~, then don't insert any gravatar images. If ~t~, then insert both images. If ~author~ or ~committer~, then insert only the respective image. If you have customized the option ~magit-revision-header-format~ and want to insert the images then you might also have to specify where to do so. In that case the value has to be a cons-cell of two regular expressions. The car specifies where to insert the author's image. The top half of the image is inserted right after the matched text, the bottom half on the next line in the same column. The cdr specifies where to insert the committer's image, accordingly. Either the car or the cdr may be nil." - User Option: magit-revision-use-hash-sections Whether to turn hashes inside the commit message into sections. If non-nil, then hashes inside the commit message are turned into ~commit~ sections. There is a trade off to be made between performance and reliability: - ~slow~ calls git for every word to be absolutely sure. - ~quick~ skips words less than seven characters long. - ~quicker~ additionally skips words that don't contain a number. - ~quickest~ uses all words that are at least seven characters long and which contain at least one number as well as at least one letter. If nil, then no hashes are turned into sections, but you can still visit the commit at point using "RET". The diffs shown in the revision buffer may be automatically restricted to a subset of the changed files. If the revision buffer is displayed from a log buffer, the revision buffer will share the same file restriction as that log buffer (also see the command ~magit-diff-toggle-file-filter~). Note, however, that the log's file restriction will be ignored when ~magit-log-arguments~ includes ~--follow~. In this case, the ~-u~ argument of the log popup can be used to show the file-restricted diffs inline. If the revision buffer is not displayed from a log buffer, the file restriction is determined by the file restriction in the repository's diff buffer, if it exists, and the value of the option ~magit-use-sticky-arguments~. ** Ediffing This section describes how to enter Ediff from Magit buffers. For information on how to use Ediff itself, see info:ediff. - Key: e, 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/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. - Key: E, magit-ediff-popup This prefix command shows the following suffix commands in a popup buffer. - Key: E r, magit-ediff-compare Compare two revisions of a file using Ediff. 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). - Key: E m, magit-ediff-resolve Resolve outstanding conflicts in a file using Ediff, defaulting to the file at point. Provided that the value of ~merge.conflictstyle~ is ~diff3~, you can view the file's merge-base revision using ~/~ in the Ediff control buffer. In the rare event that you want to manually resolve all conflicts, including those already resolved by Git, use ~ediff-merge-revisions-with-ancestor~. - Key: E s, magit-ediff-stage Stage and unstage changes to a file using Ediff, defaulting to the file at point. - Key: E u, magit-ediff-show-unstaged Show unstaged changes to a file using Ediff. - Key: E i, magit-ediff-show-staged Show staged changes to a file using Ediff. - Key: E w, magit-ediff-show-working-tree Show changes in a file between ~HEAD~ and working tree using Ediff. - Key: E c, magit-ediff-show-commit Show changes to a file introduced by a commit using Ediff. - Key: E z, magit-ediff-show-stash Show changes to a file introduced by a stash using Ediff. - User Option: magit-ediff-dwim-show-on-hunks This option controls what command ~magit-ediff-dwim~ calls when point is on uncommitted hunks. When nil, always run ~magit-ediff-stage~. Otherwise, use ~magit-ediff-show-staged~ and ~magit-ediff-show-unstaged~ to show staged and unstaged changes, respectively. - User Option: magit-ediff-show-stash-with-index This option controls whether ~magit-ediff-show-stash~ includes a buffer containing the file's state in the index at the time the stash was created. This makes it possible to tell which changes in the stash were staged. - User Option: magit-ediff-quit-hook This hook is run after quitting an Ediff session that was created using a Magit command. The hook functions are run inside the Ediff control buffer, and should not change the current buffer. This is similar to ~ediff-quit-hook~ but takes the needs of Magit into account. The regular ~ediff-quit-hook~ is ignored by Ediff sessions that were created using a Magit command. ** References Buffer *** _ :ignore: - Key: y, magit-show-refs-popup List and compare references in a dedicated buffer. By default all refs are compared with ~HEAD~, but with a prefix argument this command instead acts as a prefix command and shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: y y, magit-show-refs-head List and compare references in a dedicated buffer. Refs are compared with ~HEAD~. - Key: y c, magit-show-refs-current List and compare references in a dedicated buffer. Refs are compared with the current branch or ~HEAD~ if it is detached. - Key: y o, magit-show-refs List and compare references in a dedicated buffer. Refs are compared with a branch read from the user. - User Option: magit-refs-show-commit-count 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. The default is ~nil~ because anything else can be very expensive. - User Option: magit-refs-pad-commit-counts Whether to pad all commit 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. - User Option: magit-refs-show-remote-prefix Whether to show the remote prefix in lists of remote branches. Showing the prefix is redundant because the name of the remote is already shown in the heading preceding the list of its branches. - User Option: magit-refs-primary-column-width Width of the primary 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.) - User Option: magit-refs-focus-column-width 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. - User Option: magit-refs-margin This option specifies whether the margin is initially shown in Magit-Refs mode buffers and how it is formatted. 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 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. - 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. - User Option: magit-refs-margin-for-tags This option specifies whether to show information about tags in the margin. This is disabled by default because it is slow if there are many tags. The following variables control how individual refs are displayed. If you change one of these variables (especially the "%c" part), then you should also change the others to keep things aligned. The following %-sequences are supported: - ~%a~ Number of commits this ref has over the one we compare to. - ~%b~ Number of commits the ref we compare to has over this one. - ~%c~ Number of commits this ref has over the one we compare to. For the ref which all other refs are compared this is instead "@", if it is the current branch, or "#" otherwise. - ~%C~ For the ref which all other refs are compared this is "@", if it is the current branch, or "#" otherwise. For all other refs " ". - ~%h~ Hash of this ref's tip. - ~%m~ Commit summary of the tip of this ref. - ~%n~ Name of this ref. - ~%u~ Upstream of this local branch. - ~%U~ Upstream of this local branch and additional local vs. upstream information. - User Option: magit-refs-filter-alist This alist controls which tags and branches are omitted from being displayed in ~magit-refs-mode~ buffers. If it is ~nil~, then all refs are displayed (subject to ~magit-refs-sections-hook~). 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. Contrary to how they are displayed in the buffer, for comparison each tag begins with "tags/" and each remote branch with "/". - Key: RET, magit-visit-ref This command visits the reference or revision at point in another buffer. If there is no revision at point or with a prefix argument then it prompts for a revision. This command behaves just like ~magit-show-commit~ as described above, except if point is on a reference in a ~magit-refs-mode~ buffer, in which case the behavior may be different, but only if you have customized the option ~magit-visit-ref-behavior~. - User Option: magit-visit-ref-behavior This option controls 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've grown accustomed this behavior, you can restore it 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. *** References Sections The contents of references buffers is controlled using the hook ~magit-refs-sections-hook~. See [[*Section Hooks]] to learn about such hooks and how to customize them. All of the below functions are members of the default value. Note that it makes much less sense to customize this hook than it does for the respective hook used for the status buffer. - User Option: magit-refs-sections-hook Hook run to insert sections into a references buffer. - Function: magit-insert-local-branches Insert sections showing all local branches. - Function: magit-insert-remote-branches Insert sections showing all remote-tracking branches. - Function: magit-insert-tags Insert sections showing all tags. ** Bisecting Also see [[man:git-bisect]] - Key: B, magit-bisect-popup This prefix command shows the following suffix commands in a popup buffer. When bisecting is not in progress, then the popup buffer features the following commands. - Key: B B, magit-bisect-start 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 known good and a bad commit. - Key: B s, magit-bisect-run Bisect automatically by running commands after each step. When bisecting is in progress, then the popup buffer features these commands instead. - Key: B b, magit-bisect-bad Mark the current commit as bad. Use this after you have asserted that the commit does contain the bug in question. - Key: B g, magit-bisect-good Mark the current commit as good. Use this after you have asserted that the commit does not contain the bug in question. - Key: B k, magit-bisect-skip 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. - Key: B r, magit-bisect-reset After bisecting, cleanup bisection state and return to original ~HEAD~. By default the status buffer shows information about the ongoing bisect session. - User Option: magit-bisect-show-graph This option controls whether a graph is displayed for the log of commits that still have to be bisected. ** Visiting Blobs - Key: M-x magit-find-file, magit-find-file View FILE from REV. Switch to a buffer visiting blob REV:FILE, creating one if none already exists. - Key: M-x magit-find-file-other-window, magit-find-file-other-window View FILE from REV, in another window. Like ~magit-find-file~, but create a new window or reuse an existing one. ** Blaming Also see [[man:git-blame]] To start blaming you can use ~M-x~ in a file-visiting buffer to invoke one of the following commands. You can also invoke these commands using the blame popup, which is available on ~b~ in file-visiting buffers that already contain blame information and, also on ~b~, in all blob-visiting buffers. You can also enter the blame popup from the file popup, which is available on ~C-c M-g~, provided ~magit-file-mode~ is enabled, see [[*Minor Mode for Buffers Visiting Files]]. - Command: magit-blame-addition This command augments each line or chunk of lines in the current file- or blob-visiting buffer with information about what commits last touched these lines. If the buffer visits a revision of that file, then history up to that revision is considered. Otherwise, the file's full history is considered, including uncommitted changes. If Magit-Blame mode is already turned on in the current buffer then blaming is done recursively, by visiting REVISION:FILE (using ~magit-find-file~), where REVISION is a parent of the revision that added the current line or chunk of lines. - Command: magit-blame-echo This command is like ~magit-blame-addition~ except that it doesn't turn on ~read-only-mode~ and that it initially uses the visualization style specified by option ~magit-blame-echo-style~. - Command: magit-blame-removal This command augments each line or chunk of lines in the current blob-visiting buffer with information about the revision that removes it. It cannot be used in file-visiting buffers. Like ~magit-blame-addition~, this command can be used recursively. - Command: magit-blame-reverse This command augments each line or chunk of lines in the current file- or blob-visiting buffer with information about the last revision in which a line still existed. Like ~magit-blame-addition~, this command can be used recursively. The following key bindings are available when Magit-Blame mode is enabled and Read-Only mode is not enabled. These commands are also available in other buffers; here only the behavior is described that is relevant in file-visiting buffers that are being blamed. - Key: RET, magit-show-commit This command shows the commit that last touched the line at point. - Key: SPC, magit-diff-show-or-scroll-up This command updates the commit buffer. This either shows the commit that last touched the line at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and if that buffer contains information about that commit, then the buffer is scrolled up instead. - Key: DEL, magit-diff-show-or-scroll-down This command updates the commit buffer. This either shows the commit that last touched the line at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and if that buffer contains information about that commit, then the buffer is scrolled down instead. The following key bindings are available when Magit-Blame mode is enabled and Read-Only mode is not enabled. - Key: b, magit-blame-popup This prefix command shows the above suffix command along with the appropriate infix arguments in a popup buffer. - Key: n, magit-blame-next-chunk This command moves to the next chunk. - Key: N, magit-blame-next-chunk-same-commit This command moves to the next chunk from the same commit. - Key: p, magit-blame-previous-chunk This command moves to the previous chunk. - Key: P, magit-blame-previous-chunk-same-commit This command moves to the previous chunk from the same commit. - Key: q, magit-blame-quit This command turns off Magit-Blame mode. If the buffer was created during a recursive blame, then it also kills the buffer. - Key: M-w, magit-blame-copy-hash This command saves the hash of the current chunk's commit to the kill ring. When the region is active, the command saves the region's content instead of the hash, like ~kill-ring-save~ would. - Key: c, magit-blame-cycle-style This command changes how blame information is visualized in the current buffer by cycling through the styles specified using the option ~magit-blame-styles~. Blaming is also controlled using the following options. - User Option: magit-blame-styles This option defines a list of styles used to visualize blame information. For now see its doc-string to learn more. - User Option: magit-blame-echo-style This option specifies the blame visualization style used by the command ~magit-blame-echo~. This must be a symbol that is used as the identifier for one of the styles defined in ~magit-blame-styles~. - User Option: magit-blame-time-format This option specifies the format string used to display times when showing blame information. - User Option: magit-blame-read-only This option controls whether blaming a buffer also makes temporarily read-only. - User Option: magit-blame-disable-modes This option lists incompatible minor-modes that should be disabled temporarily when a buffer contains blame information. They are enabled again when the buffer no longer shows blame information. - User Option: magit-blame-goto-chunk-hook This hook is run when moving between chunks. * Manipulating ** Repository Setup - Key: M-x magit-init, magit-init This command initializes a repository and then shows the status buffer for the new repository. 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. - Key: M-x magit-clone, magit-clone This command clones a repository and then shows the status buffer for the new repository. The user is queried for a remote url and a local directory. - User Option: magit-clone-set-remote.pushDefault 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 the user every time she clones a repository. ** Staging and Unstaging *** _ :ignore: Like Git, Magit can of course stage and unstage complete files. Unlike Git, it also allows users to gracefully un-/stage individual hunks and even just part of a hunk. To stage individual hunks and parts of hunks using Git directly, one has to use the very modal and rather clumsy interface of a ~git add --interactive~ session. With Magit, on the other hand, one can un-/stage individual hunks by just moving point into the respective section inside a diff displayed in the status buffer or a separate diff buffer and typing ~s~ or ~u~. To operate on just parts of a hunk, mark the changes that should be un-/staged using the region and then press the same key that would be used to un-/stage. To stage multiple files or hunks at once use a region that starts inside the heading of such a section and ends inside the heading of a sibling section of the same type. Besides staging and unstaging, Magit also provides several other "apply variants" that can also operate on a file, multiple files at once, a hunk, multiple hunks at once, and on parts of a hunk. These apply variants are described in the next section. You can also use Ediff to stage and unstage. See [[*Ediffing]]. - Key: s, magit-stage Add the change at point to the staging area. With a prefix argument and an untracked file (or files) at point, stage the file but not its content. This makes it possible to stage only a subset of the new file's changes. - Key: S, magit-stage-modified 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. - Key: u, magit-unstage Remove the change at point from the staging area. Only staged changes can be unstaged. But by default this command performs an action that is somewhat similar to unstaging, when it is called on a committed change: it reverses the change in the index but not in the working tree. - Key: U, magit-unstage-all Remove all changes from the staging area. - User Option: magit-unstage-committed This option controls whether ~magit-unstage~ "unstages" committed changes by reversing them in the index but not the working tree. The alternative is to raise an error. - Key: M-x magit-reverse-in-index, magit-reverse-in-index This command reverses the committed change at point in the index but not the working tree. By default no key is bound directly to this command, but it is indirectly called when ~u~ (~magit-unstage~) is pressed on a committed change. This allows extracting 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. - Key: M-x magit-reset-index, magit-reset-index Reset the index to some commit. The commit is read from the user and defaults to the commit at point. If there is no commit at point, then it defaults to ~HEAD~. *** Staging from File-Visiting Buffers Fine-grained un-/staging has to be done from the status or a diff buffer, but it's also possible to un-/stage all changes made to the file visited in the current buffer right from inside that buffer. - Key: M-x magit-stage-file, magit-stage-file When invoked inside a file-visiting buffer, then stage all changes to that file. In a Magit buffer, stage the file at point if any. Otherwise prompt for a file to be staged. With a prefix argument always prompt the user for a file, even in a file-visiting buffer or when there is a file section at point. - Key: M-x magit-unstage-file, magit-unstage-file When invoked inside a file-visiting buffer, then unstage all changes to that file. In a Magit buffer, unstage the file at point if any. Otherwise prompt for a file to be unstaged. With a prefix argument always prompt the user for a file, even in a file-visiting buffer or when there is a file section at point. ** Applying Magit provides several "apply variants": stage, unstage, discard, reverse, and "regular apply". At least when operating on a hunk they are all implemented using ~git apply~, which is why they are called "apply variants". - Stage. Apply a change from the working tree to the index. The change also remains in the working tree. - Unstage. Remove a change from the index. The change remains in the working tree. - Discard. On a staged change, remove it from the working tree and the index. On an unstaged change, remove it from the working tree only. - Reverse. Reverse a change in the working tree. Both committed and staged changes can be reversed. Unstaged changes cannot be reversed. Discard them instead. - Apply. Apply a change to the working tree. Both committed and staged changes can be applied. Unstaged changes cannot be applied - as they already have been applied. The previous section described the staging and unstaging commands. What follows are the commands which implement the remaining apply variants. - Key: a, magit-apply 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. - Key: k, magit-discard Remove the change at point from the working tree. - Key: v, magit-reverse 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. With a prefix argument all apply variants attempt a 3-way merge when appropriate (i.e. when ~git apply~ is used internally). ** Committing *** _ :ignore: When the user initiates a commit, Magit calls ~git commit~ without any arguments, so Git has to get it from the user. It creates the file ~.git/COMMIT_EDITMSG~ and then opens that file in an editor. Magit arranges for that editor to be the Emacsclient. Once the user finishes the editing session, the Emacsclient exits and Git creates the commit using the file's content as message. *** Initiating a Commit Also see [[man:git-commit]] - Key: c, magit-commit-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: c c, magit-commit-create Create a new commit on ~HEAD~. With a prefix argument amend to the commit at ~HEAD~ instead. - Key: c a, magit-commit-amend Amend the last commit. - Key: c e, magit-commit-extend 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. Non-interactively respect the optional OVERRIDE-DATE argument and ignore the option. - Key: c w, magit-commit-reword 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. - Key: c f, magit-commit-fixup 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~. - Key: c F, magit-commit-instant-fixup Create a fixup commit and instantly rebase. - Key: c s, magit-commit-squash 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~. - Key: c S, magit-commit-instant-squash Create a squash commit and instantly rebase. - Key: c A, magit-commit-augment 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~. - User Option: magit-commit-ask-to-stage Whether to ask to stage all unstaged changes when committing and nothing is staged. - User Option: magit-commit-extend-override-date Whether using ~magit-commit-extend~ changes the committer date. - User Option: magit-commit-reword-override-date Whether using ~magit-commit-reword~ changes the committer date. - User Option: magit-commit-squash-confirm 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. *** Editing Commit Messages After initiating a commit as described in the previous section, two new buffers appear. One shows the changes that are about to committed, while the other is used to write the message. All regular editing commands are available in the commit message buffer. This section only describes the additional commands. Commit messages are edited in an edit session - in the background Git is waiting for the editor, in our case the Emacsclient, to save the commit message in a file (in most cases ~.git/COMMIT_EDITMSG~) and then return. If the Emacsclient returns with a non-zero exit status then Git does not create the commit. So the most important commands are those for finishing and aborting the commit. - Key: C-c C-c, with-editor-finish Finish the current editing session by returning with exit code 0. Git then creates the commit using the message it finds in the file. - Key: C-c C-k, with-editor-cancel Cancel the current editing session by returning with exit code 1. Git then cancels the commit, but leaves the file untouched. In addition to being used by Git, these messages may also be stored in a ring that persists until Emacs is closed. By default the message is stored at the beginning and the end of an edit session (regardless of whether the session is finished successfully or was canceled). It is sometimes useful to bring back messages from that ring. - Key: C-c M-s, git-commit-save-message Save the current buffer content to the commit message ring. - Key: M-p, git-commit-prev-message Cycle backward through the commit message ring, after saving the current message to the ring. With a numeric prefix ARG, go back ARG comments. - Key: M-n, git-commit-next-message Cycle forward through the commit message ring, after saving the current message to the ring. With a numeric prefix ARG, go back ARG comments. By default the diff for the changes that are about to be committed are automatically shown when invoking the commit. When amending to an existing commit it may be useful to show either the changes that are about to be added to that commit or to show those changes together with those that are already committed. - Key: C-c C-d, magit-diff-while-committing While committing, show the changes that are about to be committed. While amending, invoking the command again toggles between showing just the new changes or all the changes that will be committed. - Key: C-c C-w, magit-pop-revision-stack This command inserts a representation of a revision into the current buffer. It can be used inside buffers used to write commit messages but also in other buffers such as buffers used to edit emails or ChangeLog files. By default this command pops the revision which was last added to the ~magit-revision-stack~ and inserts 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 it instead reads 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. - User Option: magit-pop-revision-stack-format This option controls how the command ~magit-pop-revision-stack~ inserts a revision into the current buffer. 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). Some projects use pseudo headers in commit messages. Magit colorizes such headers and provides some commands to insert such headers. - User Option: git-commit-known-pseudo-headers A list of Git pseudo headers to be highlighted. - Key: C-c C-a, git-commit-ack Insert a header acknowledging that you have looked at the commit. - Key: C-c C-r, git-commit-review Insert a header acknowledging that you have reviewed the commit. - Key: C-c C-s, git-commit-signoff Insert a header to sign off the commit. - Key: C-c C-t, git-commit-test Insert a header acknowledging that you have tested the commit. - Key: C-c C-o, git-commit-cc Insert a header mentioning someone who might be interested. - Key: C-c C-p, git-commit-reported Insert a header mentioning the person who reported the issue being fixed by the commit. - Key: C-c C-i, git-commit-suggested Insert a header mentioning the person who suggested the change. ~git-commit-mode~ is a minor mode that is only used to establish the above key bindings. This allows using an arbitrary major mode when editing the commit message. It's even possible to use a different major mode in different repositories, which is useful when different projects impose different commit message conventions. - User Option: git-commit-major-mode The value of this option is the major mode used to edit Git commit messages. Because ~git-commit-mode~ is a minor mode, we don't use its mode hook to setup the buffer, except for the key bindings. All other setup happens in the function ~git-commit-setup~, which among other things runs the hook ~git-commit-setup-hook~. The following functions are suitable for that hook. - User Option: git-commit-setup-hook Hook run at the end of ~git-commit-setup~. - Function: magit-revert-buffers &optional force Revert unmodified file-visiting buffers of the current repository. If either ~magit-revert-buffers~ is non-nil and ~inhibit-magit-revert~ is nil, or if optional FORCE is non-nil, then revert all unmodified buffers that visit files being tracked in the current repository. - Function: git-commit-save-message Save the current buffer content to the commit message ring. - Function: git-commit-setup-changelog-support After this function is called, ChangeLog entries are treated as paragraphs. - Function: git-commit-turn-on-auto-fill Turn on ~auto-fill-mode~ and set ~fill-column~ to the value of ~git-commit-fill-column~. - Function: git-commit-turn-on-flyspell Turn on Flyspell mode. Also prevent comments from being checked and finally check current non-comment text. - Function: git-commit-propertize-diff Propertize the diff shown inside the commit message buffer. Git inserts such diffs into the commit message template when the ~--verbose~ argument is used. Magit's commit popup by default does not offer that argument because the diff that is shown in a separate buffer is more useful. But some users disagree, which is why this function exists. - Function: with-editor-usage-message Show usage information in the echo area. Magit also helps with writing *good* commit messages by complaining when certain rules are violated. - User Option: git-commit-summary-max-length The intended maximal length of the summary line of commit messages. Characters beyond this column are colorized to indicate that this preference has been violated. - User Option: git-commit-fill-column Column beyond which automatic line-wrapping should happen in commit message buffers. - User Option: git-commit-finish-query-functions List of functions called to query before performing commit. The commit message buffer is current while the functions are called. If any of them returns nil, then the commit is not performed and the buffer is not killed. The user should then fix the issue and try again. The functions are called with one argument. If it is non-nil then that indicates that the user used a prefix argument to force finishing the session despite issues. Functions should usually honor this wish and return non-nil. - Function: git-commit-check-style-conventions Check for violations of certain basic style conventions. For each violation ask the user if she wants to proceed anyway. This makes sure the summary line isn't too long and that the second line is empty. To show no diff while committing remove ~magit-commit-diff~ from ~server-switch-hook~. ** Branching *** The Two Remotes The upstream branch of some local branch is the branch into which the commits on that local branch should eventually be merged, usually something like ~origin/master~. For the ~master~ branch itself the upstream branch and the branch it is being pushed to, are usually the same remote branch. But for a feature branch the upstream branch and the branch it is being pushed to should differ. The commits on feature branches too should /eventually/ end up in a remote branch such as ~origin/master~ or ~origin/maint~. Such a branch should therefore be used as the upstream. But feature branches shouldn't be pushed directly to such branches. Instead a feature branch ~my-feature~ is usually pushed to ~my-fork/my-feature~ or if you are a contributor ~origin/my-feature~. After the new feature has been reviewed, the maintainer merges the feature into ~master~. And finally ~master~ (not ~my-feature~ itself) is pushed to ~origin/master~. But new features seldom are perfect on the first try, and so feature branches usually have to be reviewed, improved, and re-pushed several times. Pushing should therefore be easy to do, and for that reason many Git users have concluded that it is best to use the remote branch to which the local feature branch is being pushed as its upstream. But luckily Git has long ago gained support for a push-remote which can be configured separately from the upstream branch, using the variables ~branch..pushRemote~ and ~remote.pushDefault~. So we no longer have to choose which of the two remotes should be used as "the remote". Each of the fetching, pulling, and pushing popups features three commands that act on the current branch and some other branch. Of these, ~p~ is bound to a command which acts on the push-remote, ~u~ is bound to a command which acts on the upstream, and ~e~ is bound to a command which acts on any other branch. The status buffer shows unpushed and unpulled commits for both the push-remote and the upstream. It's fairly simple to configure these two remotes. The values of all the variables that are related to fetching, pulling, and pushing (as well as some other branch-related variables) can be inspected and changed using the popup ~magit-branch-config-popup~, which is a sub-popup of many popups that deal with branches. It is also possible to set the push-remote or upstream while pushing (see [[*Pushing]]). *** The Branch Popup The popup ~magit-branch-popup~ is used to create and checkout branches, and to make changes to existing branches. It is not used to fetch, pull, merge, rebase, or push branches, i.e. this popup deals with branches themselves, not with the commits reachable from them. Those features are available from separate popups. - Key: b, magit-branch-popup This prefix command shows the following suffix commands in a popup buffer. By default it also displays the values of some branch-related Git variables and allows changing their values, just like the specialized ~magit-branch-config-popup~ does. - User Option: magit-branch-popup-show-variables Whether the ~magit-branch-popup~ shows Git variables. This defaults to t to avoid changing key bindings. When set to nil, no variables are displayed directly in this popup, and the sub-popup ~magit-branch-config-popup~ has to be used instead to view and change branch related variables. - Key: b C, magit-branch-config-popup This command shows branch related variables in a separate popup. By default this asks the user for which branch the variables should be shown. When ~magit-branch-popup-show-variables~ is ~nil~, then it shows the variables for the current branch, unless a prefix argument is used. - Key: b b, magit-checkout Checkout a revision read in the minibuffer and defaulting to the branch or arbitrary revision at point. If the 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. - Key: b n, magit-branch-create Create a new branch. The user is asked for a branch or arbitrary revision to use as the starting point of the new branch. When a branch name is provided, then that becomes the upstream branch of the new branch. The name of the new branch is also read in the minibuffer. Also see option ~magit-branch-prefer-remote-upstream~. - Key: b c, magit-branch-and-checkout This command creates a new branch like ~magit-branch~, but then also checks it out. Also see option ~magit-branch-prefer-remote-upstream~. - Key: b l, magit-branch-checkout This command checks out an existing or new local branch. It reads a branch name from the user offering all local branches and a subset of remote branches as candidates. Remote branches for which a local branch by the same name exists are omitted from the list of candidates. The user can also enter a completely new branch name. - If the user selects an existing local branch, then that is checked out. - If the user selects a remote branch, then it creates and checks out a new local branch with the same name, and configures the selected remote branch as the push target. - If the user enters a new branch name, then it creates and checks 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 starting point or something else depends on the value of ~magit-branch-adjust-remote-upstream-alist~. - Key: b s, magit-branch-spinoff This command creates and checks out 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. - Key: b Y, magit-branch-pull-request This command creates and configures a new branch from a Github pull-request, creating and configuring a new remote if necessary. The name of the local branch is the same as the name of the remote branch that you are being asked to merge, unless the contributor could not be bother to properly name the branch before opening the pull-request. The most likely such case is when you are being asked to merge something like "fork/master" into "origin/master". In such cases the local branch will be named "pr-N", where ~N~ is the pull-request number. These variables are always set by this command: - ~branch..pullRequest~ is set to the pull-request number. - ~branch..pullRequestRemote~ is set to the remote on which the pull-request branch is located. - ~branch..pushRemote~ is set to the same remote as ~branch..pullRequestRemote~ if that is possible, otherwise it is set to the upstream remote. - ~branch..description~ is set to the pull-request title. - ~branch..rebase~ is set to ~true~ because there should be no merge commits among the commits in a pull-request. This command also configures the upstream and the push-remote of the local branch that it creates. The branch against which the pull-request was opened, is always used as the upstream. This makes it easy to see what commits you are being asked to merge in the section titled something like "Unmerged into origin/master". Like for other commands that create a branch it depends on the option ~magit-branch-prefer-remote-upstream~ whether the remote branch itself or the respective local branch is used as the upstream, so this section may also be titled e.g. "Unmerged into master". When necessary and possible, then the remote pull-request branch is configured to be used as the push-target. This makes it easy to see what further changes the contributor has made since you last reviewed their changes in the section titled something like "Unpulled from origin/new-feature" or "Unpulled from fork/new-feature". - If the pull-request branch is located in the upstream repository, then you probably have set ~remote.pushDefault~ to that repository. However some users like to set that variable to their personal fork, even if they have push access to the upstream, so ~branch..pushRemote~ is set anyway. - If the pull-request branch is located inside a fork, then you are usually able to push to that branch, because Github by default allows the recipient of a pull-request to push to the remote pull-request branch even if it is located in a fork. The contributor has to explicitly disable this. - If you are not allowed to push to the pull-request branch on the fork, then a branch by the same name located in the upstream repository is configured as the push-target. - A — sadly rather common — special case is when the contributor didn't bother to use a dedicated branch for the pull-request. The most likely such case is when you are being asked to merge something like "fork/master" into "origin/master". The special push permission mentioned above is never granted for the branch that is the repository's default branch, and that would almost certainly be the case in this scenario. To enable you to easily push somewhere anyway, the local branch is named "pr-N" (where ~N~ is the pull-request number) and the upstream repository is used as the push-remote. - Finally, if you are allowed to push to the pull-request branch and the contributor had the foresight to use a dedicated branch, then the fork is configured as the push-remote. The push-remote is configured using ~branch..pushRemote~, even if the used value is identical to that of ~remote.pushDefault~, just in case you change the value of the latter later on. Additionally the variable ~branch..pullRequestRemote~ is set to the remote on which the pull-request branch is located. When you later delete the local pull-request branch, then you are offered to also delete the corresponding remote, provided it is not the upstream remote and that the tracking branch that corresponds to the deleted branch is the only remaining tracked branch. If you don't confirm, then only the tracking branch itself is deleted in addition to the local branch. Do not delete the tracking branch instead of the local branch. The cleanup mentioned in the previous paragraph is not performed if you do that. - Key: b y, magit-checkout-pull-request This command creates and configures a new branch from a pull request, the same way ~magit-branch-pull-request~ does. Additionally it checks out the new branch. - Key: b x, magit-branch-reset This command resets a branch, defaulting to the branch at point, to the tip of another branch or any other commit. When the branch being reset is the current branch, then a hard reset is performed. 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 the target branch is set as the upstream of the branch that is being reset. - Key: b k, magit-branch-delete 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. - Key: b r, magit-branch-rename Rename a branch. The branch and the new name are read in the minibuffer. With prefix argument the branch is renamed even if that name conflicts with an existing branch. - User Option: magit-branch-read-upstream-first When creating a branch, whether to read the upstream branch before the name of the branch that is to be created. The default is ~nil~, and I recommend you leave it at that. - User Option: magit-branch-prefer-remote-upstream This option specifies whether remote upstreams are favored over local upstreams when creating new branches. When a new branch is created, then the branch, commit, or stash at point is suggested as the 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.: #+BEGIN_SRC text feature --upstream--> origin/master #+END_SRC instead of #+BEGIN_SRC text feature --upstream--> master --upstream--> origin/master #+END_SRC 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. - User Option: magit-branch-adjust-remote-upstream-alist The value of this option is an alist of branches to be used as the upstream when branching a remote branch. 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: #+BEGIN_SRC emacs-lisp (("origin/master" "master" "next" "maint")) #+END_SRC Or if the names of all your ephemeral branches contain a slash, at least in some repositories, then a good value could be: #+BEGIN_SRC emacs-lisp (("origin/master" . "/")) #+END_SRC Of course you can also fine-tune: #+BEGIN_SRC emacs-lisp (("origin/maint" . "\\`hotfix/") ("origin/master" . "\\`feature/")) #+END_SRC - Command: magit-branch-orphan This command creates and checks out a new orphan branch with contents from a given revision. - Command: magit-branch-or-checkout This command is a hybrid between ~magit-checkout~ and ~magit-branch-and-checkout~ and is intended as a replacement for the former in ~magit-branch-popup~. It first asks the user for an existing branch or revision. If the user input actually can be resolved as a branch or revision, then it checks that out, just like ~magit-checkout~ would. Otherwise it creates and checks out a new branch using the input as its name. Before doing so it reads the starting-point for the new branch. This is similar to what ~magit-branch-and-checkout~ does. To use this command instead of ~magit-checkout~ add this to your init file: #+BEGIN_SRC emacs-lisp (magit-remove-popup-key 'magit-branch-popup :action ?b) (magit-define-popup-action 'magit-branch-popup ?b "Checkout" 'magit-branch-or-checkout 'magit-branch t) #+END_SRC *** The Branch Config Popup - Command: magit-branch-config-popup This prefix command shows the following branch-related Git variables in a popup buffer. The values can be changed from that buffer. This popup is a sub-popup of several popups that deal with branches, including ~magit-branch-popup~, ~magit-pull-popup~, ~magit-fetch-popup~, ~magit-pull-and-fetch-popup~, and ~magit-push-popup~. In all of these popups "C" is bound to this popup. The following variables are used to configure a specific branch. The values are being displayed for the current branch (if any). To change the value for another branch invoke ~magit-branch-config-popup~ with a prefix argument. - Variable: branch.NAME.merge Together with ~branch.NAME.remote~ this variable defines the upstream branch of the local branch named NAME. The value of this variable is the full reference of the upstream /branch/. - Variable: branch.NAME.remote Together with ~branch.NAME.merge~ this variable defines the upstream branch of the local branch named NAME. The value of this variable is the name of the upstream /remote/. - Variable: branch.NAME.rebase This variable controls whether pulling into the branch named NAME is done by rebasing or by merging the fetched branch. - When ~true~ then pulling is done by rebasing. - When ~false~ then pulling is done by merging. - When undefined then the value of ~pull.rebase~ is used. The default of that variable is ~false~. - Variable: branch.NAME.pushRemote This variable specifies the remote that the branch named NAME is usually pushed to. The value has to be the name of an existing remote. It is not possible to specify the name of /branch/ to push the local branch to. The name of the remote branch is always the same as the name of the local branch. If this variable is undefined but ~remote.pushDefault~ is defined, then the value of the latter is used. By default ~remote.pushDefault~ is undefined. - Variable: branch.NAME.description This variable can be used to describe the branch named NAME. That description is used e.g. when turning the branch into a series of patches. The following variables specify defaults which are used if the above branch-specific variables are not set. - Variable: pull.rebase This variable specifies whether pulling is done by rebasing or by merging. It can be overwritten using ~branch.NAME.rebase~. - When ~true~ then pulling is done by rebasing. - When ~false~ (the default) then pulling is done by merging. Since it is never a good idea to merge the upstream branch into a feature or hotfix branch and most branches are such branches, you should consider setting this to ~true~, and ~branch.master.rebase~ to ~false~. - Variable: remote.pushDefault This variable specifies what remote the local branches are usually pushed to. This can be overwritten per branch using ~branch.NAME.pushRemote~. The following variables are used during the creation of a branch and control whether the various branch-specific variables are automatically set at this time. - Variable: branch.autoSetupMerge This variable specifies under what circumstances creating a branch NAME should result in the variables ~branch.NAME.merge~ and ~branch.NAME.remote~ being set according to the starting point used to create the branch. If the starting point isn't a branch, then these variables are never set. - When ~always~ then the variables are set regardless of whether the starting point is a local or a remote branch. - When ~true~ (the default) then the variables are set when the starting point is a remote branch, but not when it is a local branch. - When ~false~ then the variables are never set. - Variable: branch.autoSetupRebase This variable specifies whether creating a branch NAME should result in the variable ~branch.NAME.rebase~ being set to ~true~. - When ~always~ then the variable is set regardless of whether the starting point is a local or a remote branch. - When ~local~ then the variable are set when the starting point is a local branch, but not when it is a remote branch. - When ~remote~ then the variable are set when the starting point is a remote branch, but not when it is a local branch. - When ~never~ (the default) then the variable is never set. Note that the respective commands always change the repository-local values. If you want to change the global value, which is used when the local value is undefined, then you have to do so on the command line, e.g.: #+BEGIN_SRC shell-script git config --global remote.autoSetupMerge always #+END_SRC For more information about these variables you should also see man:git-config Also see [[man:git-branch]], [[man:git-checkout]] and [[*Pushing]]. - User Option: magit-prefer-remote-upstream This option controls whether commands that read a branch from the user and then set it as the upstream branch, offer a local or a remote branch as default completion candidate, when they have the choice. This affects all commands that use ~magit-read-upstream-branch~ or ~magit-read-starting-point~, which includes all commands that change the upstream and many which create new branches. *** Auxiliary Branch Commands These commands are not available from the branch popup by default. - Command: magit-branch-shelve This command shelves a branch. This is done by deleting the branch, and creating a new reference "refs/shelved/BRANCH-NAME" pointing at the same commit as the branch pointed at. If the deleted branch had a reflog, then that is preserved as the reflog of the new reference. This is useful if you want to move a branch out of sight, but are not ready to completely discard it yet. - Command: magit-branch-unshelve This command unshelves a branch that was previously shelved using ~magit-branch-shelve~. This is done by deleting the reference "refs/shelved/BRANCH-NAME" and creating a branch "BRANCH-NAME" pointing at the same commit as the deleted reference pointed at. If the deleted reference had a reflog, then that is restored as the reflog of the branch. ** Merging Also see [[man:git-merge]] For information on how to resolve merge conflicts see the next section. - Key: m, magit-merge-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. When no merge is in progress, then the popup buffer features the following commands. - Key: m m, magit-merge-plain This command merges another branch or an arbitrary revision into the current branch. The branch or revision to be merged is read in the minibuffer and defaults to the branch at point. Unless there are conflicts or a prefix argument is used, then the resulting merge commit uses a generic commit message, and the user does not get a chance to inspect or change it before the commit is created. With a prefix argument this does not actually create the merge commit, which makes it possible to inspect how conflicts were resolved and to adjust the commit message. - Key: m e, magit-merge-editmsg This command merges another branch or an arbitrary revision into the current branch and opens a commit message buffer, so that the user can make adjustments. The commit is not actually created until the user finishes with ~C-c C-c~. - Key: m n, magit-merge-nocommit This command merges another branch or an arbitrary revision into the current branch, but does not actually create the merge commit. The user can then further adjust the merge, even when automatic conflict resolution succeeded and/or adjust the commit message. - Key: m a, magit-merge-absorb This command merges another local branch into the current branch and then removes the former. Before the source branch is merged, it is first force pushed to its push-remote, provided the respective remote branch already exists. This ensures that the respective pull-request (if any) won't get stuck on some obsolete version of the commits that are being merged. Finally, if ~magit-branch-pull-request~ was used to create the merged branch, then the respective remote branch is also removed. - Key: m i, magit-merge-into This command merges the current branch into another local branch and then removes the former. The latter becomes the new current branch. Before the source branch is merged, it is first force pushed to its push-remote, provided the respective remote branch already exists. This ensures that the respective pull-request (if any) won't get stuck on some obsolete version of the commits that are being merged. Finally, if ~magit-branch-pull-request~ was used to create the merged branch, then the respective remote branch is also removed. - Key: m s, magit-merge-squash This command squashes the changes introduced by another branch or an arbitrary revision into the current branch. This only applies the changes made by the squashed commits. No information is preserved that would allow creating an actual merge commit. Instead of this command you should probably use a command from the apply popup. - Key: m p, magit-merge-preview This command shows a preview of merging another branch or an arbitrary revision into the current branch. When a merge is in progress, then the popup buffer features these commands instead. - Key: m m, magit-merge After the user resolved conflicts, this command proceeds with the merge. If some conflicts weren't resolved, then this command fails. - Key: m a, magit-merge-abort This command aborts the current merge operation. ** Resolving Conflicts When merging branches (or otherwise combining or changing history) conflicts can occur. If you edited two completely different parts of the same file in two branches and then merge one of these branches into the other, then Git can resolve that on its own, but if you edit the same area of a file, then a human is required to decide how the two versions, or "sides of the conflict", are to be combined into one. Here we can only provide a brief introduction to the subject and point you toward some tools that can help. If you are new to this, then please also consult Git's own documentation as well as other resources. If a file has conflicts and Git cannot resolve them by itself, then it puts both versions into the affected file along with special markers whose purpose is to denote the boundaries of the unresolved part of the file and between the different versions. These boundary lines begin with the strings consisting of six times the same character, one of ~<~, ~|~, ~=~ and ~>~ and are followed by information about the source of the respective versions, e.g.: #+BEGIN_EXAMPLE <<<<<<< HEAD Take the blue pill. ======= Take the red pill. >>>>>>> feature #+END_EXAMPLE In this case you have chosen to take the red pill on one branch and on another you picked the blue pill. Now that you are merging these two diverging branches, Git cannot possibly know which pill you want to take. To resolve that conflict you have to create a version of the affected area of the file by keeping only one of the sides, possibly by editing it in order to bring in the changes from the other side, remove the other versions as well as the markers, and then stage the result. A possible resolution might be: #+BEGIN_EXAMPLE Take both pills. #+END_EXAMPLE Often it is useful to see not only the two sides of the conflict but also the "original" version from before the same area of the file was modified twice on different branches. Instruct Git to insert that version as well by running this command once: #+BEGIN_SRC shell-script git config --global merge.conflictStyle diff3 #+END_SRC The above conflict might then have looked like this: #+BEGIN_EXAMPLE <<<<<<< HEAD Take the blue pill. ||||||| merged common ancestors Take either the blue or the red pill, but not both. ======= Take the red pill. >>>>>>> feature #+END_EXAMPLE If that were the case, then the above conflict resolution would not have been correct, which demonstrates why seeing the original version alongside the conflicting versions can be useful. You can perform the conflict resolution completely by hand, but Emacs also provides some packages that help in the process: Smerge, Ediff (info:ediff), and Emerge (info:emacs#Emerge). Magit does not provide its own tools for conflict resolution, but it does make using Smerge and Ediff more convenient. (Ediff supersedes Emerge, so you probably don't want to use the latter anyway.) In the Magit status buffer, files with unresolved conflicts are listed in the "Unstaged changes" and/or "Staged changes" sections. They are prefixed with the word "unmerged", which in this context essentially is a synonym for "unresolved". Pressing ~RET~ while point is on such a file section shows a buffer visiting that file, turns on ~smerge-mode~ in that buffer, and places point inside the first area with conflicts. You should then resolve that conflict using regular edit commands and/or Smerge commands. Unfortunately Smerge does not have a manual, but you can get a list of commands and binding ~C-c ^ C-h~ and press ~RET~ while point is on a command name to read its documentation. Normally you would edit one version and then tell Smerge to keep only that version. Use ~C-c ^ m~ (~smerge-keep-mine~) to keep the ~HEAD~ version or ~C-c ^ o~ (~smerge-keep-other~) to keep the version that follows "|||||||". Then use ~C-c ^ n~ to move to the next conflicting area in the same file. Once you are done resolving conflicts, return to the Magit status buffer. The file should now be shown as "modified", no longer as "unmerged", because Smerge automatically stages the file when you save the buffer after resolving the last conflict. Alternatively you could use Ediff, which uses separate buffers for the different versions of the file. To resolve conflicts in a file using Ediff press ~e~ while point is on such a file in the status buffer. Ediff can be used for other purposes as well. For more information on how to enter Ediff from Magit, see [[*Ediffing]]. Explaining how to use Ediff is beyond the scope of this manual, instead see info:ediff. If you are unsure whether you should Smerge or Ediff, then use the former. It is much easier to understand and use, and except for truly complex conflicts, the latter is usually overkill. ** Rebasing *** _ :ignore: Also see [[man:git-rebase]] For information on how to resolve conflicts that occur during rebases see the preceding section. - Key: r, magit-rebase-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. When no rebase is in progress, then the popup buffer features the following commands. Using one of these commands /starts/ a rebase sequence. Git might then stop somewhere along the way, either because you told it to do so, or because applying a commit failed due to a conflict. When that happens, then the status buffer shows information about the rebase sequence which is in progress in a section similar to a log section. See [[*Information About In-Progress Rebase]]. - Key: r p, magit-rebase-onto-pushremote Rebase the current branch onto ~branch..pushRemote~. If that variable is unset, then rebase onto ~remote.pushDefault~. - Key: r u, magit-rebase-onto-upstream Rebase the current branch onto its upstream branch. - Key: r e, magit-rebase-branch Rebase the current branch onto a branch read in the minibuffer. All commits that are reachable from head but not from the selected branch TARGET are being rebased." - Key: r s, magit-rebase-subset Start a non-interactive rebase sequence with commits from START to ~HEAD~ onto NEWBASE. START has to be selected from a list of recent commits. By default Magit uses the ~--autostash~ argument, which causes uncommitted changes to be stored in a stash before the rebase begins. These changes are restored after the rebase completes and if possible the stash is removed. If the stash does not apply cleanly, then the stash is not removed. In case something goes wrong when resolving the conflicts, this allows you to start over. Even though one of the actions is dedicated to interactive rebases, the popup also features the infix argument ~--interactive~. This can be used to turn one of the other, non-interactive rebase variants into an interactive rebase. For example if you want to clean up a feature branch and at the same time rebase it onto ~master~, then you could use ~r-iu~. But we recommend that you instead do that in two steps. First use ~ri~ to cleanup the feature branch, and then in a second step ~ru~ to rebase it onto ~master~. That way if things turn out to be more complicated than you thought and/or you make a mistake and have to start over, then you only have to redo half the work. Explicitly enabling ~--interactive~ won't have an effect on the following commands as they always use that argument anyway, even if it is not enabled in the popup. - Key: r i, magit-rebase-interactive Start an interactive rebase sequence. - Key: r f, magit-rebase-autosquash Combine squash and fixup commits with their intended targets. - Key: r m, magit-rebase-edit-commit Edit a single older commit using rebase. - Key: r w, magit-rebase-reword-commit Reword a single older commit using rebase. - Key: r k, magit-rebase-remove-commit Remove a single older commit using rebase. When a rebase is in progress, then the popup buffer features these commands instead. - Key: r r, magit-rebase-continue Restart the current rebasing operation. In some cases this pops up a commit message buffer for you do edit. With a prefix argument the old message is reused as-is. - Key: r s, magit-rebase-skip Skip the current commit and restart the current rebase operation. - Key: r e, magit-rebase-edit Edit the todo list of the current rebase operation. - Key: r a, magit-rebase-abort Abort the current rebase operation, restoring the original branch. *** Editing Rebase Sequences - Key: C-c C-c, with-editor-finish Finish the current editing session by returning with exit code 0. Git then uses the rebase instructions it finds in the file. - Key: C-c C-k, with-editor-cancel Cancel the current editing session by returning with exit code 1. Git then forgoes starting the rebase sequence. - Key: RET, git-rebase-show-commit Show the commit on the current line in another buffer and select that buffer. - Key: SPC, git-rebase-show-or-scroll-up Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window up. - Key: DEL, git-rebase-show-or-scroll-down Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window down. - Key: p, git-rebase-backward-line Move to previous line. - Key: n, forward-line Move to next line. - Key: M-p, git-rebase-move-line-up Move the current commit (or command) up. - Key: M-n, git-rebase-move-line-down Move the current commit (or command) down. - Key: r, git-rebase-reword Edit message of commit on current line. - Key: e, git-rebase-edit Stop at the commit on the current line. - Key: s, git-rebase-squash Meld commit on current line into previous commit, and edit message. - Key: f, git-rebase-fixup Meld commit on current line into previous commit, discarding the current commit's message. - Key: k, git-rebase-kill-line Kill the current action line. - Key: c, git-rebase-pick Use commit on current line. - Key: x, git-rebase-exec Insert a shell command to be run after the proceeding 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. - Key: y, git-rebase-insert Read an arbitrary commit and insert it below current line. - Key: C-x u, git-rebase-undo Undo some previous changes. Like ~undo~ but works in read-only buffers. - User Option: git-rebase-auto-advance Whether to move to next line after changing a line. - User Option: git-rebase-show-instructions Whether to show usage instructions inside the rebase buffer. - User Option: git-rebase-confirm-cancel Whether confirmation is required to cancel. *** Information About In-Progress Rebase While a rebase sequence is in progress, the status buffer features a section that lists the commits that have already been applied as well as the commits that still have to be applied. The commits are split in two halves. When rebase stops at a commit, either because the user has to deal with a conflict or because s/he explicitly requested that rebase stops at that commit, then point is placed on the commit that separates the two groups, i.e. on ~HEAD~. The commits above it have not been applied yet, while the ~HEAD~ and the commits below it have already been applied. In between these two groups of applied and yet-to-be applied commits, there sometimes is a commit which has been dropped. Each commit is prefixed with a word and these words are additionally shown in different colors to indicate the status of the commits. The following colors are used: - Yellow commits have not been applied yet. - Gray commits have already been applied. - The blue commit is the ~HEAD~ commit. - The green commit is the commit the rebase sequence stopped at. If this is the same commit as ~HEAD~ (e.g. because you haven't done anything yet after rebase stopped at the commit, then this commit is shown in blue, not green). There can only be a green *and* a blue commit at the same time, if you create one or more new commits after rebase stops at a commit. - Red commits have been dropped. They are shown for reference only, e.g. to make it easier to diff. Of course these colors are subject to the color-theme in use. The following words are used: - Commits prefixed with ~pick~, ~reword~, ~edit~, ~squash~, and ~fixup~ have not been applied yet. These words have the same meaning here as they do in the buffer used to edit the rebase sequence. See [[*Editing Rebase Sequences]]. - Commits prefixed with ~done~ and ~onto~ have already been applied. It is possible for such a commit to be the ~HEAD~, in which case it is blue. Otherwise it is grey. - The commit prefixed with ~onto~ is the commit on top of which all the other commits are being re-applied. This commit itself did not have to be re-applied, it is the commit rebase did rewind to before starting to re-apply other commits. - Commits prefixed with ~done~ have already been re-applied. This includes commits that have been re-applied but also new commits that you have created during the rebase. - All other commits, those not prefixed with any of the above words, are in some way related to the commit at which rebase stopped. To determine whether a commit is related to the stopped-at commit their hashes, trees and patch-ids [fn:patch-id] are being compared. The commit message is not used for this purpose. Generally speaking commits that are related to the stopped-at commit can have any of the used colors, though not all color/word combinations are possible. Words used for stopped-at commits are: - When a commit is prefixed with ~void~, then that indicates that Magit knows for sure that all the changes in that commit have been applied using several new commits. This commit is no longer reachable from ~HEAD~, and it also isn't one of the commits that will be applied when resuming the session. - When a commit is prefixed with ~join~, then that indicates that the rebase sequence stopped at that commit due to a conflict - you now have to join (merge) the changes with what has already been applied. In a sense this is the commit rebase stopped at, but while its effect is already in the index and in the worktree (with conflict markers), the commit itself has not actually been applied yet (it isn't the ~HEAD~). So it is shown in yellow, like the other commits that still have to be applied. - When a commit is prefixed with ~stop~ or a /blue/ or /green/ ~same~, then that indicates that rebase stopped at this commit, that it is still applied or has been applied again, and that at least its patch-id is unchanged. - When a commit is prefixed with ~stop~, then that indicates that rebase stopped at that commit because you requested that earlier, and its patch-id is unchanged. It might even still be the exact same commit. - When a commit is prefixed with a /blue/ or /green/ ~same~, then that indicates that while its tree or hash changed, its patch-id did not. If it is blue, then it is the ~HEAD~ commit (as always for blue). When it is green, then it no longer is ~HEAD~ because other commit have been created since (but before continuing the rebase). - When a commit is prefixed with ~goal~, a /yellow/ ~same,~ or ~work~, then that indicates that rebase applied that commit but that you then reset ~HEAD~ to an earlier commit (likely to split it up into multiple commits), and that there are some uncommitted changes remaining which likely (but not necessarily) originate from that commit. - When a commit is prefixed with ~goal~, then that indicates that it is still possible to create a new commit with the exact same tree (the "goal") without manually editing any files, by committing the index, or by staging all changes and then committing that. This is the case when the original tree still exists in the index or worktree in untainted form. - When a commit is prefixed with a yellow ~same~, then that indicates that it is no longer possible to create a commit with the exact same tree, but that it is still possible to create a commit with the same patch-id. This would be the case if you created a new commit with other changes, but the changes from the original commit still exist in the index or working tree in untainted form. - When a commit is prefixed with ~work~, then that indicates that you reset ~HEAD~ to an earlier commit, and that there are some staged and/or unstaged changes (likely, but not necessarily) originating from that commit. However it is no longer possible to create a new commit with the same tree or at least the same patch-id because you have already made other changes. - When a commit is prefixed with ~poof~ or ~gone~, then that indicates that rebase applied that commit but that you then reset ~HEAD~ to an earlier commit (likely to split it up into multiple commits), and that there are no uncommitted changes. - When a commit is prefixed with ~poof~, then that indicates that it is no longer reachable from ~HEAD~, but that it has been replaced with one or more commits, which together have the exact same effect. - When a commit is prefixed with ~gone~, then that indicates that it is no longer reachable from ~HEAD~ and that we also cannot determine whether its changes are still in effect in one or more new commits. They might be, but if so, then there must also be other changes which makes it impossible to know for sure. Do not worry if you do not fully understand the above. That's okay, you will acquire a good enough understanding through practice. For other sequence operations such as cherry-picking, a similar section is displayed, but they lack some of the features described above, due to limitations in the git commands used to implement them. Most importantly these sequences only support "picking" a commit but not other actions such as "rewording", and they do not keep track of the commits which have already been applied. [fn:patch-id] The patch-id is a hash of the /changes/ introduced by a commit. It differs from the hash of the commit itself, which is a hash of the result of applying that change (i.e. the resulting trees and blobs) as well as author and committer information, the commit message, and the hashes of the parents of the commit. The patch-id hash on the other hand is created only from the added and removed lines, even line numbers and whitespace changes are ignored when calculating this hash. The patch-ids of two commits can be used to answer the question "Do these commits make the same change?". ** Cherry Picking *** _ :ignore: Also see [[man:git-cherry-pick]] - Key: A, magit-cherry-pick-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. When no cherry-pick or revert is in progress, then the popup buffer features the following commands. - Key: A A, magit-cherry-copy This command copies COMMITS from another branch onto the current branch. If the region selects multiple commits, then those are copied, without prompting. Otherwise the user is prompted for a commit or range, defaulting to the commit at point. - Key: A a, magit-cherry-apply This command applies the changes in COMMITS from another branch onto the current branch. If the region selects multiple commits, then those are used, without prompting. Otherwise the user is prompted for a commit or range, defaulting to the commit at point. This command also has a top-level binding, which can be invoked without using the popup by typing ~a~ at the top-level. The following commands not only apply some commits to some branch, but also remove them from some other branch. The removal is performed using either ~git-update-ref~ or if necessary ~git-rebase~. Both applying commits as well as removing them using ~git-rebase~ can lead to conflicts. If that happens, then these commands abort and you not only have to resolve the conflicts but also finish the process the same way you would have to if these commands didn't exist at all. - Key: A h, magit-cherry-harvest This command moves the selected COMMITS that must be located on another BRANCH onto the current branch instead, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the current branch or removing them from the other branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. - Key: A d, magit-cherry-donate This command moves the selected COMMITS from the current branch onto another existing BRANCH, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. - Key: A n, magit-cherry-spinout This command moves the selected COMMITS from the current branch onto a new branch BRANCH, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. - Key: A s, magit-cherry-spinoff This command moves the selected COMMITS from the current branch onto a new branch BRANCH, removing them from the former. When this command succeeds, then the new branch is checked out. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. When a cherry-pick or revert is in progress, then the popup buffer features these commands instead. - Key: A A, magit-sequence-continue Resume the current cherry-pick or revert sequence. - Key: A s, magit-sequence-skip Skip the stopped at commit during a cherry-pick or revert sequence. - Key: A a, magit-sequence-abort Abort the current cherry-pick or revert sequence. This discards all changes made since the sequence started. *** Reverting - Key: V, magit-revert-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. When no cherry-pick or revert is in progress, then the popup buffer features the following commands. - Key: V V, magit-revert-and-commit Revert a commit by creating a new commit. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting. - Key: V v, magit-revert-no-commit Revert a commit by applying it in reverse to the working tree. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting. When a cherry-pick or revert is in progress, then the popup buffer features these commands instead. - Key: V A, magit-sequence-continue Resume the current cherry-pick or revert sequence. - Key: V s, magit-sequence-skip Skip the stopped at commit during a cherry-pick or revert sequence. - Key: V a, magit-sequence-abort Abort the current cherry-pick or revert sequence. This discards all changes made since the sequence started. ** Resetting Also see [[man:git-reset]] - Key: x, magit-reset-quickly Reset the ~HEAD~ and index to some commit read from the user and defaulting to the commit at point, and possibly also reset the working tree. With a prefix argument reset the working tree otherwise don't. - Key: X m, magit-reset-mixed Reset the ~HEAD~ and index to some commit read from the user and defaulting to the commit at point. The working tree is kept as-is. - Key: X s, magit-reset-soft Reset the ~HEAD~ to some commit read from the user and defaulting to the commit at point. The index and the working tree are kept as-is. - Key: X h, magit-reset-hard Reset the ~HEAD~, index, and working tree to some commit read from the user and defaulting to the commit at point. - Key: X i, magit-reset-index Reset the index to some commit read from the user and defaulting to the commit at point. Keep the ~HEAD~ and working tree as-is, so if the commit refers to the ~HEAD~, then this effectively unstages all changes. - Key: X w, magit-reset-worktree Reset the working tree to some commit read from the user and defaulting to the commit at point. Keep the ~HEAD~ and index as-is. - Key: X f, magit-file-checkout Update file in the working tree and index to the contents from a revision. Both the revision and file are read from the user. ** Stashing Also see [[man:git-stash]] - Key: z, magit-stash-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: z z, magit-stash-both Create a stash of the index and working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to ~--include-untracked~ while two prefix arguments are equivalent to ~--all~. - Key: z i, magit-stash-index Create a stash of the index only. Unstaged and untracked changes are not stashed. - Key: z w, magit-stash-worktree Create a stash of unstaged changes in the working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to ~--include-untracked~ while two prefix arguments are equivalent to ~--all~. - Key: z x, magit-stash-keep-index Create a stash of the index and working tree, keeping index intact. Untracked files are included according to popup arguments. One prefix argument is equivalent to ~--include-untracked~ while two prefix arguments are equivalent to ~--all~. - Key: z Z, magit-snapshot-both Create a snapshot of the index and working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to ~--include-untracked~ while two prefix arguments are equivalent to ~--all~. - Key: z I, magit-snapshot-index Create a snapshot of the index only. Unstaged and untracked changes are not stashed. - Key: z W, magit-snapshot-worktree Create a snapshot of unstaged changes in the working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to ~--include-untracked~ while two prefix arguments are equivalent to ~--all~-. - Key: z a, magit-stash-apply 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. - Key: z p, magit-stash-pop 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. - Key: z k, magit-stash-drop Remove a stash from the stash list. When the region is active, offer to drop all contained stashes. - Key: z v, magit-stash-show Show all diffs of a stash in a buffer. - Key: z b, magit-stash-branch Create and checkout a new BRANCH from STASH. The branch starts at the commit that was current when the stash was created. - Key: z B, magit-stash-branch-here Create and checkout a new BRANCH using ~magit-branch~ with the current branch or ~HEAD~ as the starting-point. Then apply STASH, dropping it if it applies cleanly. - Key: z f, magit-stash-format-patch Create a patch from STASH. - Key: k, magit-stash-clear Remove all stashes saved in REF's reflog by deleting REF. - Key: z l, magit-stash-list List all stashes in a buffer. - User Option: magit-stashes-margin This option specifies whether the margin is initially shown in stashes buffers and how it is formatted. 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 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. - 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. * Transferring ** Remotes *** The Remote Popup The popup ~magit-remote-popup~ is used to add remotes and to make changes to existing remotes. This popup only deals with remotes themselves, not with branches or the transfer of commits. Those features are available from separate popups. Also see [[man:git-remote]] - Key: M, magit-remote-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - User Option: magit-remote-popup-show-variables This option controls whether the ~magit-remote-popup~ shows remote related Git variables. When set to nil, no variables are displayed directly in this popup, and the sub-popup ~magit-remote-config-popup~ has to be used instead to view and change remote related variables. - Key: M C, magit-remote-config-popup This command shows remote related variables in a separate popup. By default this asks the user for which remote the variables should be shown. When ~magit-remote-popup-show-variables~ is ~nil~, then it shows the variables for the upstream of the current branch or "origin" it that branch has no remote upstream. To select another remote use a prefix argument. - Key: M a, magit-remote-add This command add a remote and fetches it. The remote name and url are read in the minibuffer. - Key: M r, magit-remote-rename This command renames a remote. Both the old and the new names are read in the minibuffer. - Key: M u, magit-remote-set-url This command changes the url of a remote. Both the remote and the new url are read in the minibuffer. - Key: M k, magit-remote-remove This command deletes a remote, read in the minibuffer. - Key: M p, magit-remote-prune This command removes stale remote-tracking branches for a remote read in the minibuffer. - Key: M P, magit-remote-prune-refspecs This command removes stale refspecs for a remote read in the minibuffer. 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 this command offers to either delete the remote or to replace the stale refspecs with the default refspec ("+refs/heads/*:refs/remotes/REMOTE/*"). This command also removes the remote-tracking branches that were created due to the now stale refspecs. Other stale branches are not removed. - User Option: magit-remote-add-set-remote.pushDefault This option controls whether the user is asked whether they want to set ~remote.pushDefault~ after adding a remote. If ~ask~, then users is always ask. If ~ask-if-unset~, then the user is only if the variable isn't set already. If ~nil~, then the user isn't asked and the variable isn't set. If the value is a string, then the variable is set without the user being asked, provided that the name of the added remote is equal to that string and the variable isn't already set. *** The Remote Config Popup - Command: magit-remote-config-popup This prefix command shows the following remote-related Git variables in a popup buffer. The values can be changed from that buffer. This popup is a sub-popup of the ~magit-remote-popup~ in which "C" is bound to this popup. The following variables are used to configure a specific remote. The values are being displayed for the upstream remote of the current branch. To change the value for another remote invoke ~magit-remote-config-popup~ with a prefix argument. - Variable: remote.NAME.url This variable specifies the url of the remote named NAME. It can have multiple values. - Variable: remote.NAME.fetch The refspec used when fetching from the remote named NAME. It can have multiple values. - Variable: remote.NAME.pushurl This variable specifies the url used for fetching from the remote named NAME. If it is not specified, then ~remote.NAME.url~ is used instead. It can have multiple values. - Variable: remote.NAME.push The refspec used when pushing to the remote named NAME. It can have multiple values. - Variable: remote.NAME.tagOpts This variable specifies what tags are fetched by default. If the value is ~--no-tags~ then no tags are fetched. If the value is ~--tags~, then all tags are fetched. If this variable has not value, then only tags are fetched that are reachable from fetched branches. ** Fetching For information about the differences between the /upstream/ and the /push-remote/, see [[*Branching]]. Also see [[man:git-fetch]] - Key: f, magit-fetch-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: f p, magit-fetch-from-pushremote Fetch from the push-remote of the current branch. - Key: f u, magit-fetch-from-upstream Fetch from the upstream of the current branch. - Key: f e, magit-fetch-other Fetch from another repository. - Key: f o, magit-fetch-branch Fetch a branch from a remote, both of which are read from the minibuffer. - Key: f r, magit-fetch-refspec Fetch from a remote using an explicit refspec, both of which are read from the minibuffer. - Key: f a, magit-fetch-all Fetch from all remotes. - Key: f m, magit-submodule-fetch Fetch all submodules. With a prefix argument fetch all remotes of all submodules. Instead of using one popup for fetching and another for pulling, you could also use ~magit-pull-and-fetch-popup~. See its doc-string for more information. ** Pulling For information about the differences between the /upstream/ and the /push-remote/, see [[*Branching]]. Also see [[man:git-pull]] - Key: F, magit-pull-popup This prefix command shows the following suffix commands in a popup buffer. - Key: F p, magit-pull-from-pushremote Pull from the push-remote of the current branch. - Key: F u, magit-pull-from-upstream Pull from the upstream of the current branch. - Key: F e, magit-pull-branch Pull from a branch read in the minibuffer. Instead of using one popup for fetching and another for pulling, you could also use ~magit-pull-and-fetch-popup~. See its doc-string for more information. ** Pushing For information about the differences between the /upstream/ and the /push-remote/, see [[*Branching]]. Also see [[man:git-push]] - Key: P, magit-push-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: P p, magit-push-current-to-pushremote Push the current branch to ~branch..pushRemote~ or if that is unset to ~remote.pushDefault~. When ~magit-push-current-set-remote-if-missing~ is non-nil and 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. - Key: P u, magit-push-current-to-upstream Push the current branch to its upstream branch. When ~magit-push-current-set-remote-if-missing~ is non-nil and the push-remote is not configured, then read the upstream from the user, set it, and then push to it. With a prefix argument the push-remote can be changed before pushed to it. - Key: P e, magit-push-current Push the current branch to a branch read in the minibuffer. - Key: P o, magit-push-other Push an arbitrary branch or commit somewhere. Both the source and the target are read in the minibuffer. - Key: P r, magit-push-refspecs Push one or multiple refspecs to a remote, both of which 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. - Key: P m, magit-push-matching Push all matching branches to another repository. If multiple remotes exit, then read one from the user. If just one exists, use that without requiring confirmation. - Key: P t, magit-push-tags 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. - Key: P T, magit-push-tag Push a tag to another repository. Two more push commands exist, which by default are not available from the push popup. See their doc-strings for instructions on how to add them to the popup. - Command: 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..pushRemote~, ~branch..remote~, ~branch..merge~, and ~remote..push~. - Command: magit-push-to-remote remote args Push to the remote 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..pushRemote~, ~branch..remote~, ~branch..merge~, and ~remote..push~. - User Option: magit-push-current-set-remote-if-missing This option controls whether missing remotes are configured before pushing. When ~nil~, then the command ~magit-push-current-to-pushremote~ and ~magit-push-current-to-upstream~ do not appear in the push popup if the push-remote resp. upstream is not configured. If the user invokes one of these commands anyway, then it raises an error. When ~non-nil~, then these commands always appear in the push popup. But if the required configuration is missing, then they do appear in a way that indicates that this is the case. If the user invokes one of them, then it asks for the necessary configuration, stores the configuration, and then uses it to push a first time. This option also affects whether the argument ~--set-upstream~ is available in the popup. If the value is ~non-nil~, then that argument is redundant. But note that changing the value of this option does not take affect immediately, the argument will only be added or removed after restarting Emacs. ** Creating and Sending Patches - Key: W, magit-patch-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: W p, magit-format-patch Create patches for a set commits. If the region marks commits, then create patches for those. Otherwise prompt for a range or a single commit, defaulting to the commit at point. - Key: W r, magit-request-pull Request that upstream pulls from your public repository. It is also possible to save a plain patch file by using ~C-x C-w~ inside a ~magit-diff-mode~ or ~magit-revision-mode~ buffer. ** Applying Patches Also see [[man:git-am]] and [[man:git-apply]] - Key: w, magit-am-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: w w, magit-am-apply-patches Apply one or more patches. If the region marks files, then apply those patches. Otherwise read a file name in the minibuffer defaulting to the file at point. - Key: w m, magit-am-apply-maildir Apply the patches from a maildir. When an "am" operation is in progress, then the popup buffer features these commands instead. - Key: w w, magit-am-continue Resume the current patch applying sequence. - Key: w s, magit-am-skip Skip the stopped at patch during a patch applying sequence. - Key: w a, magit-am-abort Abort the current patch applying sequence. This discards all changes made since the sequence started. In addition to the commands listed at the top, the "am" popup also has a binding for the related "patch" popup. - Key: w a, magit-patch-apply-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: w a a, magit-patch-apply This command applies a simple patch file, which may not contain any Git metadata in addition to the actual diff. * Miscellaneous ** Tagging Also see [[man:git-tag]] - Key: t, magit-tag-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: t t, magit-tag-create Create a new tag with the given NAME at REV. With a prefix argument annotate the tag. - Key: t k, magit-tag-delete 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. - Key: t p, magit-tag-prune Offer to delete tags missing locally from REMOTE, and vice versa. - Command: magit-tag-release Create an opinionated release tag. Assume version tags that match "\\`v?[0-9]\\(\\.[0-9]\\)*\\'". Prompt for the name of the new tag using the highest existing tag as initial input and call "git tag --annotate --sign -m MSG" TAG, regardless of whether these arguments are enabled in the popup. Given a TAG "v1.2.3" and a repository "/path/to/foo-bar", the MESSAGE would be "Foo-Bar 1.2.3". Because it is so opinionated, this command is not available from the tag popup by default. ** Notes Also see [[man:git-notes]] - Key: T, magit-notes-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. - Key: T T, magit-notes-edit Edit the note attached to a commit, defaulting to the commit at point. By default use the value of Git variable ~core.notesRef~ or "refs/notes/commits" if that is undefined. - Key: T r, magit-notes-remove Remove the note attached to a commit, defaulting to the commit at point. By default use the value of Git variable ~core.notesRef~ or "refs/notes/commits" if that is undefined. - Key: T p, magit-notes-prune Remove notes about unreachable commits. It is possible to merge one note ref into another. That may result in conflicts which have to resolved in the temporary worktree ".git/NOTES_MERGE_WORKTREE". - Key: T m, magit-notes-merge Merge the notes of a ref read from the user 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 a notes merge is in progress then the popup features the following suffix commands, instead of those listed above. - Key: T c, magit-notes-merge-commit Commit the current notes ref merge, after manually resolving conflicts. - Key: T a, magit-notes-merge-abort Abort the current notes ref merge. The following variables control what notes reference ~magit-notes-*~, ~git notes~ and ~git show~ act on and display. Both the local and global values are displayed and can be modified. - Variable: core.notesRef This variable specifies the notes ref that is displayed by default and which commands act on by default. - Variable: notes.displayRef This variable specifies additional notes ref to be displayed in addition to the ref specified by ~core.notesRef~. It can have multiple values and may end with ~*~ to display all refs in the ~refs/notes/~ namespace (or ~**~ if some names contain slashes). ** Submodules *** _ :ignore: Also see [[man:git-submodule]] *** Listing Submodules The command ~magit-list-submodules~ displays a list of the current repository's submodules in a separate buffer. It's also possible to display information about submodules directly in the status buffer of the super-repository by adding ~magit-insert-submodules~ to the hook ~magit-status-sections-hook~ as described in [[*Status Module Sections]]. - Command: magit-list-submodules This command displays a list of the current repository's submodules in a separate buffer. It can be invoked by pressing ~RET~ on the section titled "Modules". - User Option: magit-submodule-list-columns This option controls what columns are displayed by the command ~magit-list-submodules~ and how they are displayed. 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~. - Function: magit-insert-submodules Insert sections for all submodules. For each section insert the path, the branch, and the output of ~git describe --tags~, or, failing that, the abbreviated HEAD commit hash. Press ~RET~ on such a submodule section to show its own status buffer. Press ~RET~ on the "Modules" section to display a list of submodules in a separate buffer. This shows additional information not displayed in the super-repository's status buffer. *** Submodule Popup - Key: o, magit-submodule-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. Some of the below commands default to act on the modules that are selected using the region. For brevity their description talk about "the selected modules", but if no modules are selected, then they act on the current module instead, or if point isn't on a module, then the read a single module to act on. With a prefix argument these commands ignore the selection and the current module and instead act on all suitable modules. - Key: o a, magit-submodule-add This commands adds the repository at URL as a module. Optional PATH is the path to the module relative to the root of the super-project. If it is nil then the path is determined based on URL. - Key: o r, magit-submodule-register This command registers the selected modules by copying their urls from ".gitmodules" to "$GIT_DIR/config". These values can then be edited before running ~magit-submodule-populate~. If you don't need to edit any urls, then use the latter directly. - Key: o p, magit-submodule-populate This command creates the working directory or directories of the selected modules, checking out the recorded commits. - Key: o u, magit-submodule-update This command updates the selected modules checking out the recorded commits. - Key: o s, magit-submodule-synchronize This command synchronizes the urls of the selected modules, copying the values from ".gitmodules" to the ".git/config" of the super-project as well those of the modules. - Key: o d, magit-submodule-unpopulate This command removes the working directory of the selected modules. - Key: o l, magit-list-submodules This command displays a list of the current repository's modules. - Key: o f, magit-fetch-modules This command fetches all modules. 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. ** Subtree Also see [[man:git-subtree]] - Key: O, magit-tree-popup This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. Most infix arguments only apply to some of the ~git subtree~ subcommands. When an argument that does not apply to the invoked command is set, then it is silently ignored. When the ~--prefix~ argument is set in the popup buffer, then that is used. Otherwise the prefix is read in the minibuffer. - Key: O a, magit-subtree-add Add COMMIT from REPOSITORY as a new subtree at PREFIX. - Key: O c, magit-subtree-add-commit Add COMMIT as a new subtree at PREFIX. - Key: O m, magit-subtree-merge Merge COMMIT into the PREFIX subtree. - Key: O f, magit-subtree-pull Pull COMMIT from REPOSITORY into the PREFIX subtree. - Key: O p, magit-subtree-push Extract the history of the subtree PREFIX and push it to REF on REPOSITORY. - Key: O s, magit-subtree-split Extract the history of the subtree PREFIX. ** Worktree Also see [[man:git-worktree]] - Key: %, magit-worktree-popup This prefix command shows the following suffix commands in a popup buffer. - Key: % b, magit-worktree-checkout Checkout BRANCH in a new worktree at PATH. - Key: % c, magit-worktree-branch Create a new BRANCH and check it out in a new worktree at PATH. - Key: % p, magit-worktree-checkout-pull-request Create, configure and checkout a new worktree from a pull-request. This is like ~magit-checkout-pull-request~ (which see) except that it also creates a new worktree. - Key: % k, magit-worktree-delete Delete a worktree, defaulting to the worktree at point. The primary worktree cannot be deleted. - Key: % g, magit-worktree-status 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. ** Common Commands These are some of the commands that can be used in all buffers whose major-modes derive from ~magit-mode~. There are other common commands beside the ones below, but these didn't fit well anywhere else. - Key: M-w, magit-copy-section-value This command saves the value of the current section to the ~kill-ring~, and, provided that the current section is a commit, branch, or tag section, it also pushes the (referenced) revision to the ~magit-revision-stack~. When the current section is a branch or a tag, and a prefix argument is used, then it saves the revision at its tip to the ~kill-ring~ instead of the reference name. - Key: C-w, magit-copy-buffer-revision This command saves the revision being displayed in the current buffer to the ~kill-ring~ and also pushes it to the ~magit-revision-stack~. It 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. Outside of Magit ~M-w~ and ~C-w~ are usually bound to ~kill-ring-save~ and ~kill-region~, and these commands would also be useful in Magit buffers. Therefore when the region is active, then both of these commands behave like ~kill-ring-save~ instead of as described above. ** Wip Modes *** _ :ignore: Git keeps *committed* changes around long enough for users to recover changes they have accidentally deleted. It does so by not garbage collecting any committed but no longer referenced objects for a certain period of time, by default 30 days. But Git does *not* keep track of *uncommitted* changes in the working tree and not even the index (the staging area). Because Magit makes it so convenient to modify uncommitted changes, it also makes it easy to shoot yourself in the foot in the process. For that reason Magit provides a global mode that saves *tracked* files to work-in-progress references after or before certain actions. (At present untracked files are never saved and for technical reasons nothing is saved before the first commit has been created). Two separate work-in-progress references are used to track the state of the index and of the working tree: ~refs/wip/index/~ and ~refs/wip/wtree/~, where ~~ is the full ref of the current branch, e.g. ~refs/heads/master~. When the ~HEAD~ is detached then ~HEAD~ is used in place of ~~. Checking out another branch (or detaching ~HEAD~) causes the use of different wip refs for subsequent changes. - User Option: magit-wip-mode When this mode is enabled, then uncommitted changes are committed to dedicated work-in-progress refs whenever appropriate (i.e. when dataloss would be a possibility otherwise). Setting this variable directly does not take effect; either use the Custom interface to do so or call the respective mode function. 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. See [[*Legacy Wip Modes]]. To view the log for a branch and its wip refs use the commands ~magit-wip-log~ and ~magit-wip-log-current~. You should use ~--graph~ when using these commands. - Command: magit-wip-log This command shows the log for a branch and its wip refs. With a negative prefix argument only the worktree wip ref is shown. The absolute numeric value of the prefix argument controls how many "branches" of each wip ref are shown. This is only relevant if the value of ~magit-wip-merge-branch~ is ~nil~. - Command: magit-wip-log-current This command shows the log for the current branch and its wip refs. With a negative prefix argument only the worktree wip ref is shown. The absolute numeric value of the prefix argument controls how many "branches" of each wip ref are shown. This is only relevant if the value of ~magit-wip-merge-branch~ is ~nil~. - Key: X w, magit-reset-worktree This command resets the working tree to some commit read from the user and defaulting to the commit at point, while keeping the ~HEAD~ and index as-is. This can be used to restore files to the state committed to a wip ref. Note that this will discard any unstaged changes that might have existed before invoking this command (but of course only after committing that to the working tree wip ref). Note that even if you enable ~magit-wip-mode~ this won't give you perfect protection. The most likely scenario for losing changes despite the use of ~magit-wip-mode~ is making a change outside Emacs and then destroying it also outside Emacs. In some such a scenario, Magit, being an Emacs package, didn't get the opportunity to keep you from shooting yourself in the foot. When you are unsure whether Magit did commit a change to the wip refs, then you can explicitly request that all changes to all tracked files are being committed. - Key: M-x magit-wip-commit, magit-wip-commit This command commits all changes to all tracked files to the index and working tree work-in-progress refs. Like the modes described above, it does not commit untracked files, but it does check all tracked files for changes. Use this command when you suspect that the modes might have overlooked a change made outside Emacs/Magit. - User Option: magit-wip-namespace The namespace used for work-in-progress refs. It has to end with a slash. The wip refs are named ~index/~ and ~wtree/~. When snapshots are created while the ~HEAD~ is detached then ~HEAD~ is used in place of ~~. - User Option: magit-wip-mode-lighter Mode-line lighter for ~magit-wip--mode~. *** Wip Graph - User Option: magit-wip-merge-branch This option controls whether the current branch is merged into the wip refs after a new commit was created on the branch. 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. When ~magit-wip-merge-branch~ is ~t~, then the history looks like this: #+BEGIN_EXAMPLE ,*--*--*--*--*--* refs/wip/index/refs/heads/master / / / A-----B-----C refs/heads/master #+END_EXAMPLE When ~magit-wip-merge-branch~ is ~nil~, then creating a commit on the real branch and then making a change causes the wip refs to be recreated to fork from the new commit. But the old commits on the wip refs are not lost. They are still available from the reflog. To make it easier to see when the fork point of a wip ref was changed, an additional commit with the message "restart autosaving" is created on it (~xxO~ commits below are such boundary commits). Starting with #+BEGIN_EXAMPLE BI0---BI1 refs/wip/index/refs/heads/master / A---B refs/heads/master \ BW0---BW1 refs/wip/wtree/refs/heads/master #+END_EXAMPLE and committing the staged changes and editing and saving a file would result in #+BEGIN_EXAMPLE BI0---BI1 refs/wip/index/refs/heads/master / A---B---C refs/heads/master \ \ \ CW0---CW1 refs/wip/wtree/refs/heads/master \ BW0---BW1 refs/wip/wtree/refs/heads/master@{2} #+END_EXAMPLE The fork-point of the index wip ref is not changed until some change is being staged. Likewise just checking out a branch or creating a commit does not change the fork-point of the working tree wip ref. The fork-points are not adjusted until there actually is a change that should be committed to the respective wip ref. *** Legacy Wip Modes It is recommended that you use the mode ~magit-wip-mode~ (which see) and ignore the existence of the following modes, which are preserved for historic reasons. Setting the following variables directly does not take effect; either use the Custom interface to do so or call the respective mode functions. - User Option: magit-wip-after-save-mode When this mode is enabled, then saving a buffer that visits a file tracked in a Git repository causes its current state to be committed to the working tree wip ref for the current branch. - User Option: magit-wip-after-apply-mode When this mode is enabled, then applying (i.e. staging, unstaging, discarding, reversing, and regularly applying) a change to a file tracked in a Git repository causes its current state to be committed to the index and/or working tree wip refs for the current branch. If you only ever edit files using Emacs and only ever interact with Git using Magit, then the above two modes should be enough to protect each and every change from accidental loss. In practice nobody does that. Two additional modes exists that do commit to the wip refs before making changes that could cause the loss of earlier changes. - User Option: magit-wip-before-change-mode When this mode is enabled, then certain commands commit the existing changes to the files they are about to make changes to. - User Option: magit-wip-initial-backup-mode When this mode is enabled, then the current version of a file is committed to the worktree wip ref before the buffer visiting that file is saved for the first time since the buffer was created. This backs up the same version of the file that ~backup-buffer~ would save. While ~backup-buffer~ uses a backup file, this mode uses the same worktree wip ref as used by the other Magit Wip modes. Like ~backup-buffer~, it only does this once; unless you kill the buffer and visit the file again only one backup will be created per Emacs session. This mode ignores the variables that affect ~backup-buffer~ and can be used along-side that function, which is recommended because it only backs up files that are tracked in a Git repository. - User Option: magit-wip-after-save-local-mode-lighter Mode-line lighter for ~magit-wip-after-save-local-mode~. - User Option: magit-wip-after-apply-mode-lighter Mode-line lighter for ~magit-wip-after-apply-mode~. - User Option: magit-wip-before-change-mode-lighter Mode-line lighter for ~magit-wip-before-change-mode~. - User Option: magit-wip-initial-backup-mode-lighter Mode-line lighter for ~magit-wip-initial-backup-mode~. ** Minor Mode for Buffers Visiting Files The ~magit-file-mode~ enables certain Magit features in file-visiting buffers belonging to a Git repository. It should be enabled globally using ~global-magit-file-mode~. Currently this mode only establishes a few key bindings, but this might be extended in the future. - User Option: magit-file-mode Whether to establish certain Magit key bindings in all file-visiting buffers belonging to a Git repository. This establishes the bindings suggested in [[*Getting Started]] (but only for file-visiting buffers), and additionally binds ~C-c M-g~ to ~magit-file-popup~. - Key: C-c M-g, magit-file-popup This prefix command shows a popup buffer featuring suffix commands that operate on the file being visited in the current buffer. - Key: C-c M-g s, magit-stage-file Stage all changes to the file being visited in the current buffer. - Key: C-c M-g u, magit-unstage-file Unstage all changes to the file being visited in the current buffer. - Key: C-c M-g c, magit-commit-popup This prefix command shows suffix commands along with the appropriate infix arguments in a popup buffer. See [[*Initiating a Commit]]. - Key: C-c M-g D, magit-diff-buffer-file-popup This prefix command shows the same suffix commands and infix arguments in a popup buffer as ~magit-diff-popup~. But this variant has to be called from a file-visiting buffer and the visited file is automatically used in the popup to limit the diff to that file. - Key: C-c M-g d, magit-diff-buffer-file This command shows the diff for the file of blob that the current buffer visits. - User Option: magit-diff-buffer-file-locked This option controls whether ~magit-diff-buffer-file~ uses a dedicated buffer. See [[*Modes and Buffers]]. - Key: C-c M-g L, magit-log-buffer-file-popup This prefix command shows the same suffix commands and infix arguments in a popup buffer as ~magit-log-popup~. But this variant has to be called from a file-visiting buffer and the visited file is automatically used in the popup to limit the log to that file. - Key: C-c M-g l, magit-log-buffer-file This command shows the log for the file of blob that the current buffer visits. Renames are followed when a prefix argument is used or when ~--follow~ is part of ~magit-log-arguments~. When the region is active, the log is restricted to the selected line range. - Key: C-c M-g t, magit-log-trace-definition This command shows the log for the definition at point. - User Option: magit-log-buffer-file-locked This option controls whether ~magit-log-buffer-file~ uses a dedicated buffer. See [[*Modes and Buffers]]. - Key: C-c M-g B, magit-blame-popup This prefix command shows all blaming suffix command along with the appropriate infix arguments in a popup buffer. See [[*Blaming]]. - Key: C-c M-g b, magit-blame-addition This command shows for each line the revision in which it was added. - Key: C-c M-g r, magit-blame-removal This command shows for each line the revision in which it was removed. This command is only available in blob-visiting buffers. - Key: C-c M-g f, magit-blame-reverse This command shows for each line the last revision in which it still exists. This command is only available in blob-visiting buffers. - Key: C-c M-g e, magit-edit-line-commit This command makes the commit editable that added the current line. With a prefix argument it makes the commit editable 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. - Key: C-c M-g p, magit-blob-previous Visit the previous blob which modified the current file. There are a few additional commands that operate on a single file but are not available from the file popup by default: - Command: magit-file-rename This command renames a file read from the user. - Command: magit-file-delete This command deletes a file read from the user. - Command: magit-file-untrack This command untracks a file read from the user. - Command: magit-file-checkout This command updates a file in the working tree and index to the contents from a revision. Both the revision and file are read from the user. You could add them to the popup like so: #+BEGIN_SRC emacs-lisp (magit-define-popup-action 'magit-file-popup ?R "Rename file" 'magit-file-rename) (magit-define-popup-action 'magit-file-popup ?K "Delete file" 'magit-file-delete) (magit-define-popup-action 'magit-file-popup ?U "Untrack file" 'magit-file-untrack) (magit-define-popup-action 'magit-file-popup ?C "Checkout file" 'magit-file-checkout) #+END_SRC ** Minor Mode for Buffers Visiting Blobs The ~magit-blob-mode~ enables certain Magit features in blob-visiting buffers. Such buffers can be created using ~magit-find-file~ and some of the commands mentioned below, which also take care of turning on this minor mode. Currently this mode only establishes a few key bindings, but this might be extended. - Key: p, magit-blob-previous Visit the previous blob which modified the current file. - Key: n, magit-blob-next Visit the next blob which modified the current file. - Key: q, magit-kill-this-buffer Kill the current buffer. * Customizing ** _ :ignore: Both Git and Emacs are highly customizable. Magit is both a Git porcelain as well as an Emacs package, so it makes sense to customize it using both Git variables as well as Emacs options. However this flexibility doesn't come without problems, including but not limited to the following. - Some Git variables automatically have an effect in Magit without requiring any explicit support. Sometimes that is desirable - in other cases, it breaks Magit. When a certain Git setting breaks Magit but you want to keep using that setting on the command line, then that can be accomplished by overriding the value for Magit only by appending something like ~("-c" "some.variable=compatible-value")~ to ~magit-git-global-arguments~. - Certain settings like ~fetch.prune=true~ are respected by Magit commands (because they simply call the respective Git command) but their value is not reflected in the respective popup buffers. In this case the ~--prune~ argument in ~magit-fetch-popup~ might be active or inactive depending on the value of ~magit-fetch-arguments~ only, but that doesn't keep the Git variable from being honored by the suffix commands anyway. So pruning might happen despite the ~--prune~ arguments being displayed in a way that seems to indicate that no pruning will happen. I intend to address these and similar issues in a future release. ** Per-Repository Configuration Magit can be configured on a per-repository level using both Git variables as well as Emacs options. To set a Git variable for one repository only, simply set it in ~/path/to/repo/.git/config~ instead of ~$HOME/.gitconfig~ or ~/etc/gitconfig~. See [[man:git-config]] Similarly, Emacs options can be set for one repository only by editing ~/path/to/repo/.dir-locals.el~. See [[info:emacs#Directory Variables]]. For example to disable automatic refreshes of file-visiting buffers in just one huge repository use this: - ~/path/to/huge/repo/.dir-locals.el~ #+BEGIN_SRC emacs-lisp ((nil . ((magit-refresh-buffers . nil)))) #+END_SRC If you want to apply the same settings to several, but not all, repositories then keeping the repository-local config files in sync would quickly become annoying. To avoid that you can create config files for certain classes of repositories (e.g. "huge repositories") and then include those files in the per-repository config files. For example: - ~/path/to/huge/repo/.git/config~ #+BEGIN_SRC conf [include] path = /path/to/huge-gitconfig #+END_SRC - ~/path/to/huge-gitconfig~ #+BEGIN_SRC conf [status] showUntrackedFiles = no #+END_SRC - ~$HOME/.emacs.d/init.el~ #+BEGIN_SRC emacs-lisp (dir-locals-set-class-variables 'huge-git-repository '((nil . ((magit-refresh-buffers . nil))))) (dir-locals-set-directory-class "/path/to/huge/repo/" 'huge-git-repository) #+END_SRC ** Essential Settings *** _ :ignore: The next two sections list and discuss several variables that many users might want to customize, for safety and/or performance reasons. *** Safety This section discusses various variables that you might want to change (or *not* change) for safety reasons. Git keeps *committed* changes around long enough for users to recover changes they have accidentally been deleted. It does not do the same for *uncommitted* changes in the working tree and not even the index (the staging area). Because Magit makes it so easy to modify uncommitted changes, it also makes it easy to shoot yourself in the foot in the process. For that reason Magit provides three global modes that save *tracked* files to work-in-progress references after or before certain actions. See [[*Wip Modes]]. These modes are not enabled by default because of performance concerns. Instead a lot of potentially destructive commands require confirmation every time they are used. In many cases this can be disabled by adding a symbol to ~magit-no-confirm~ (see [[*Completion and Confirmation]]). If you enable the various wip modes then you should add ~safe-with-wip~ to this list. Similarly it isn't necessary to require confirmation before moving a file to the system trash - if you trashed a file by mistake then you can recover it from the there. Option ~magit-delete-by-moving-to-trash~ controls whether the system trash is used, which is the case by default. Nevertheless, ~trash~ isn't a member of ~magit-no-confirm~ - you might want to change that. By default buffers visiting files are automatically reverted when the visited file changes on disk. This isn't as risky as it might seem, but to make an informed decision you should see [[*Risk of Reverting Automatically]]. *** Performance **** _ :ignore: After Magit has run ~git~ for side-effects, it also refreshes the current Magit buffer and the respective status buffer. This is necessary because otherwise outdated information might be displayed without the user noticing. Magit buffers are updated by recreating their content from scratch, which makes updating simpler and less error-prone, but also more costly. Keeping it simple and just re-creating everything from scratch is an old design decision and departing from that will require major refactoring. I plan to do that in time for the next major release. I also intend to create logs and diffs asynchronously, which should also help a lot but also requires major refactoring. Meanwhile you can tell Magit to only automatically refresh the current Magit buffer, but not the status buffer. If you do that, then the status buffer is only refreshed automatically if it is the current buffer. #+BEGIN_SRC emacs-lisp (setq magit-refresh-status-buffer nil) #+END_SRC You should also check whether any third-party packages have added anything to ~magit-refresh-buffer-hook~, ~magit-status-refresh-hook~, ~magit-pre-refresh-hook~, and ~magit-post-refresh-hook~. If so, then check whether those additions impact performance significantly. Setting ~magit-refresh-verbose~ and then inspecting the output in the ~*Messages*~ buffer, should help doing so. Magit also reverts buffers for visited files located inside the current repository when the visited file changes on disk. That is implemented on top of ~auto-revert-mode~ from the built-in library ~autorevert~. To figure out whether that impacts performance, check whether performance is significantly worse, when many buffers exist and/or when some buffers visit files using TRAMP. If so, then this should help. #+BEGIN_SRC emacs-lisp (setq auto-revert-buffer-list-filter 'magit-auto-revert-repository-buffers-p) #+END_SRC For alternative approaches see [[*Automatic Reverting of File-Visiting Buffers]]. If you have enabled any features that are disabled by default, then you should check whether they impact performance significantly. It's likely that they were not enabled by default because it is known that they reduce performance at least in large repositories. If performance is only slow inside certain unusually large repositories, then you might want to disable certain features on a per-repository or per-repository-class basis only. See [[*Per-Repository Configuration]]. **** Log Performance :PROPERTIES: :NONODE: t :END: When showing logs, Magit limits the number of commits initially shown in the hope that this avoids unnecessary work. When using ~--graph~ is used, then this unfortunately does not have the desired effect for large histories. Junio, Git's maintainer, said on the git mailing list (http://www.spinics.net/lists/git/msg232230.html): "~--graph~ wants to compute the whole history and the max-count only affects the output phase after ~--graph~ does its computation". In other words, it's not that Git is slow at outputting the differences, or that Magit is slow at parsing the output - the problem is that Git first goes outside and has a smoke. We actually work around this issue by limiting the number of commits not only by using ~-~ but by also using a range. But unfortunately that's not always possible. In repositories with more than a few thousand commits ~--graph~ should never be a member of ~magit-log-section-arguments~. That variable is used in the status buffer which is refreshed every time you run any Magit command. Using ~--color --graph~ is even slower. Magit uses code that is part of Emacs to turn control characters into faces. That code is pretty slow and this is quite noticeable when showing a log with many branches and merges. For that reason ~--color~ is not enabled by default anymore. Consider leaving it at that. **** Diff Performance :PROPERTIES: :NONODE: t :END: If diffs are slow, then consider turning off some optional diff features by setting all or some of the following variables to ~nil~: ~magit-diff-highlight-indentation~, ~magit-diff-highlight-trailing~, ~magit-diff-paint-whitespace~, ~magit-diff-highlight-hunk-body~, and ~magit-diff-refine-hunk~. When showing a commit instead of some arbitrary diff, then some additional information is displayed. Calculating this information can be quite expensive given certain circumstances. If looking at a commit using ~magit-revision-mode~ takes considerably more time than looking at the same commit in ~magit-diff-mode~, then consider setting ~magit-revision-insert-related-refs~ to ~nil~. **** Refs Buffer Performance :PROPERTIES: :NONODE: t :END: When refreshing the "references buffer" is slow, then that's usually because several hundred refs are being displayed. The best way to address that is to display fewer refs, obviously. If you are not, or only mildly, interested in seeing the list of tags, then start by not displaying them: #+BEGIN_SRC emacs-lisp (remove-hook 'magit-refs-sections-hook 'magit-insert-tags) #+END_SRC Then you should also make sure that the listed remote branches actually all exist. You can do so by pruning branches which no longer exist using ~f-pa~. **** Committing Performance :PROPERTIES: :NONODE: t :END: When you initiate a commit, then Magit by default automatically shows a diff of the changes you are about to commit. For large commits this can take a long time, which is especially distracting when you are committing large amounts of generated data which you don't actually intend to inspect before committing. This behavior can be turned off using: #+BEGIN_SRC emacs-lisp (remove-hook 'server-switch-hook 'magit-commit-diff) #+END_SRC Then you can type ~C-c C-d~ to show the diff when you actually want to see it, but only then. Alternatively you can leave the hook alone and just type ~C-g~ in those cases when it takes too long to generate the diff. If you do that, then you will end up with a broken diff buffer, but doing it this way has the advantage that you usually get to see the diff, which is useful because it increases the odds that you spot potential issues. **** The Built-In VC Package :PROPERTIES: :NONODE: t :END: Emacs comes with a version control interface called "VC", see [[info:emacs#Version Control]]. It is enabled be default, and if you don't use it in addition to Magit, then you should disable it to keep it from performing unnecessary work: #+BEGIN_SRC emacs-lisp (setq vc-handled-backends nil) #+END_SRC You can also disable its use for Git but keep using it when using another version control system: #+BEGIN_SRC emacs-lisp (setq vc-handled-backends (delq 'Git vc-handled-backends)) #+END_SRC **** Microsoft Windows Performance In order to update the status buffer, ~git~ has to be run a few dozen times. That is problematic on Microsoft Windows, because that operating system is exceptionally slow at starting processes. Sadly this is an issue that can only be fixed by Microsoft itself, and they don't appear to be particularly interested in doing so. Beside the subprocess issue, there are also other Windows-specific performance issues. Some of these have workarounds. The maintainers of "Git for Windows" try to improve performance on Windows. Always use the latest release in order to benefit from the latest performance tweaks. Magit too tries to work around some Windows-specific issues. According to some sources, setting the following Git variables can also help. #+BEGIN_SRC shell-script git config --global core.preloadindex true # default since v2.1 git config --global core.fscache true # default since v2.8 git config --global gc.auto 256 #+END_SRC You should also check whether an anti-virus program is affecting performance. **** MacOS Performance On macOS Emacs currently creates child processes using ~fork~. It appears that this also copies GUI resources. The result is that forking takes about 30 times as long on Darwin than on Linux. And because Magit starts many ~git~ processes even when doing simple things, that makes quite a difference. On the ~master~ branch Emacs now uses ~vfork~ when possible, like this was already done on Linux, and now child creation only takes about twice as long on Darwin. See [fn:mac1] for more information. Nobody knows when the changes on the ~master~ branch will be released as ~26.1~, but it is still a long way off. You might want to get your hands on this change before then. The easiest way to get a patched Emacs is to install the ~emacs-plus~ formula [fn:mac2] using ~homebrew~. The change has been backported, so you get it not only when using ~--HEAD~, but also when using ~--devel~ or when installing the latest release (by not using a version argument). Alternatively you can apply the backport [fn:mac3] manually. [fn:mac1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-04/msg00201.html [fn:mac2] https://github.com/d12frosted/homebrew-emacs-plus [fn:mac3] https://gist.githubusercontent.com/aaronjensen/f45894ddf431ecbff78b1bcf533d3e6b/raw/6a5cd7f57341aba673234348d8b0d2e776f86719/Emacs-25-OS-X-use-vfork.patch * Plumbing ** _ :ignore: The following sections describe how to use several of Magit's core abstractions to extend Magit itself or implement a separate extension. A few of the low-level features used by Magit have been factored out into separate libraries/packages, so that they can be used by other packages, without having to depend on Magit. These libraries are described in separate manuals, see [[info:with-editor]] and [[info:magit-popup]]. If you are trying to find an unused key that you can bind to a command provided by your own Magit extension, then checkout https://github.com/magit/magit/wiki/Plugin-Dispatch-Key-Registry. ** Calling Git *** _ :ignore: Magit provides many specialized functions for calling Git. All of these functions are defined in either ~magit-git.el~ or ~magit-process.el~ and have one of the prefixes ~magit-run-~, ~magit-call-~, ~magit-start-~, or ~magit-git-~ (which is also used for other things). All of these functions accept an indefinite number of arguments, which are strings that specify command line arguments for Git (or in some cases an arbitrary executable). These arguments are flattened before being passed on to the executable; so instead of strings they can also be lists of strings and arguments that are ~nil~ are silently dropped. Some of these functions also require a single mandatory argument before these command line arguments. Roughly speaking, these functions run Git either to get some value or for side-effects. The functions that return a value are useful to collect the information necessary to populate a Magit buffer, while the others are used to implement Magit commands. The functions in the value-only group always run synchronously, and they never trigger a refresh. The function in the side-effect group can be further divided into subgroups depending on whether they run Git synchronously or asynchronously, and depending on whether they trigger a refresh when the executable has finished. *** Getting a Value from Git These functions run Git in order to get a value, an exit status, or output. Of course you could also use them to run Git commands that have side-effects, but that should be avoided. - Function: magit-git-exit-code &rest args Executes git with ARGS and returns its exit code. - Function: magit-git-success &rest args Executes git with ARGS and returns ~t~ if the exit code is ~0~, ~nil~ otherwise. - Function: magit-git-failure &rest args Executes git with ARGS and returns ~t~ if the exit code is ~1~, ~nil~ otherwise. - Function: magit-git-true &rest args Executes git with ARGS and returns ~t~ if the first line printed by git is the string "true", ~nil~ otherwise. - Function: magit-git-false &rest args Executes git with ARGS and returns ~t~ if the first line printed by git is the string "false", ~nil~ otherwise. - Function: magit-git-insert &rest args Executes git with ARGS and inserts its output at point. - Function: magit-git-string &rest args Executes git with ARGS and returns the first line of its output. If there is no output or if it begins with a newline character, then this returns ~nil~. - Function: magit-git-lines &rest args Executes git with ARGS and returns its output as a list of lines. Empty lines anywhere in the output are omitted. - Function: magit-git-items &rest args Executes git with ARGS and returns its null-separated output as a list. Empty items anywhere in the output are omitted. If the value of option ~magit-git-debug~ is non-nil and git exits with a non-zero exit status, then warn about that in the echo area and add a section containing git's standard error in the current repository's process buffer. If an error occurs when using one of the above functions, then that is usually due to a bug, i.e. using an argument which is not actually supported. Such errors are usually not reported, but when they occur we need to be able to debug them. - User Option: magit-git-debug Whether to report errors that occur when using ~magit-git-insert~, ~magit-git-string~, ~magit-git-lines~, or ~magit-git-items~. This does not actually raise an error. Instead a message is shown in the echo area, and git's standard error is insert into a new section in the current repository's process buffer. - Function: magit-git-str &rest args This is a variant of ~magit-git-string~ that ignores the option ~magit-git-debug~. It is mainly intended to be used while handling errors in functions that do respect that option. Using such a function while handing an error could cause yet another error and therefore lead to an infinite recursion. You probably won't ever need to use this function. *** Calling Git for Effect These functions are used to run git to produce some effect. Most Magit commands that actually run git do so by using such a function. Because we do not need to consume git's output when using these functions, their output is instead logged into a per-repository buffer, which can be shown using ~$~ from a Magit buffer or ~M-x magit-process~ elsewhere. These functions can have an effect in two distinct ways. Firstly, running git may change something, i.e. create or push a new commit. Secondly, that change may require that Magit buffers are refreshed to reflect the changed state of the repository. But refreshing isn't always desirable, so only some of these functions do perform such a refresh after git has returned. Sometimes it is useful to run git asynchronously. For example, when the user has just initiated a push, then there is no reason to make her wait until that has completed. In other cases it makes sense to wait for git to complete before letting the user do something else. For example after staging a change it is useful to wait until after the refresh because that also automatically moves to the next change. - Function: magit-call-git &rest args Calls git synchronously with ARGS. - Function: magit-call-process program &rest args Calls PROGRAM synchronously with ARGS. - Function: magit-run-git &rest args Calls git synchronously with ARGS and then refreshes. - Function: magit-run-git-with-input input &rest args Calls git synchronously with ARGS and sends it INPUT on standard input. INPUT should be a buffer or the name of an existing buffer. The content of that buffer is used as the process' standard input. After the process returns a refresh is performed. As a special case, INPUT may also be nil. In that case the content of the current buffer is used as standard input and *no* refresh is performed. This function actually runs git asynchronously. But then it waits for the process to return, so the function itself is synchronous. - Function: magit-run-git-with-logfile file &rest args Calls git synchronously with ARGS. The process' output is saved in FILE. This is rarely useful and so this function might be removed in the future. This function actually runs git asynchronously. But then it waits for the process to return, so the function itself is synchronous. - Function: magit-git &rest args Calls git synchronously with ARGS for side-effects only. This function does not refresh the buffer. - Function: magit-git-wash washer &rest args Execute Git with ARGS, inserting washed output at point. Actually first insert the raw output at point. If there is no output call ~magit-cancel-section~. Otherwise temporarily narrow the buffer to the inserted text, move to its beginning, and then call function WASHER with ARGS as its sole argument. And now for the asynchronous variants. - Function: magit-run-git-async &rest args Start Git, prepare for refresh, and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if ~magit-revert-buffers~ is non-nil. - Function: magit-run-git-with-editor &rest args Export GIT_EDITOR and start Git. Also prepare for refresh and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. - Function: magit-start-git &rest args Start Git, prepare for refresh, and return the process object. If INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. Option ~magit-git-executable~ specifies the Git executable and option ~magit-git-global-arguments~ specifies constant arguments. The remaining arguments ARGS specify arguments to Git. They are flattened before use. After Git returns, some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if ~magit-revert-buffers~ is non-nil. - Function: magit-start-process &rest args Start PROGRAM, prepare for refresh, and return the process object. If optional argument INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. The process is started using ~start-file-process~ and then setup to use the sentinel ~magit-process-sentinel~ and the filter ~magit-process-filter~. Information required by these functions is stored in the process object. When this function returns the process has not started to run yet so it is possible to override the sentinel and filter. After the process returns, ~magit-process-sentinel~ refreshes the buffer that was current when ~magit-start-process~ was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if ~magit-revert-buffers~ is non-nil. - Variable: magit-this-process The child process which is about to start. This can be used to change the filter and sentinel. - Variable: magit-process-raise-error When this is non-nil, then ~magit-process-sentinel~ raises an error if git exits with a non-zero exit status. For debugging purposes. ** Section Plumbing *** Creating Sections - Macro: magit-insert-section &rest args Insert a section at point. TYPE is the section type, a symbol. Many commands that act on the current section behave differently depending on that type. Also if a variable ~magit-TYPE-section-map~ exists, then use that as the text-property ~keymap~ of all text belonging to the section (but this may be overwritten in subsections). TYPE can also have the form ~(eval FORM)~ in which case FORM is evaluated at runtime. Optional VALUE is the value of the section, usually a string that is required when acting on the section. When optional HIDE is non-nil collapse the section body by default, i.e. when first creating the section, but not when refreshing the buffer. Otherwise, expand it by default. This can be overwritten using ~magit-section-set-visibility-hook~. When a section is recreated during a refresh, then the visibility of predecessor is inherited and HIDE is ignored (but the hook is still honored). BODY is any number of forms that actually insert the section's heading and body. Optional NAME, if specified, has to be a symbol, which is then bound to the struct of the section being inserted. Before BODY is evaluated the ~start~ of the section object is set to the value of ~point~ and after BODY was evaluated its ~end~ is set to the new value of ~point~; BODY is responsible for moving ~point~ forward. If it turns out inside BODY that the section is empty, then ~magit-cancel-section~ can be used to abort and remove all traces of the partially inserted section. This can happen when creating a section by washing Git's output and Git didn't actually output anything this time around. - Function: magit-insert-heading &rest args Insert the heading for the section currently being inserted. This function should only be used inside ~magit-insert-section~. When called without any arguments, then just set the ~content~ slot of the object representing the section being inserted to a marker at ~point~. The section should only contain a single line when this function is used like this. When called with arguments ARGS, which have to be strings, then insert those strings at point. The section should not contain any text before this happens and afterwards it should again only contain a single line. If the ~face~ property is set anywhere inside any of these strings, then insert all of them unchanged. Otherwise use the ~magit-section-heading~ face for all inserted text. The ~content~ property of the section struct is the end of the heading (which lasts from ~start~ to ~content~) and the beginning of the body (which lasts from ~content~ to ~end~). If the value of ~content~ is nil, then the section has no heading and its body cannot be collapsed. If a section does have a heading then its height must be exactly one line, including a trailing newline character. This isn't enforced; you are responsible for getting it right. The only exception is that this function does insert a newline character if necessary. - Function: magit-cancel-section Cancel the section currently being inserted. This exits the innermost call to ~magit-insert-section~ and removes all traces of what has already happened inside that call. - Function: magit-define-section-jumper sym title &optional value Define an interactive function to go to section SYM. TITLE is the displayed title of the section. *** Section Selection - Function: magit-current-section Return the section at point. - Function: magit-region-sections &optional condition multiple Return a list of the selected sections. When the region is active and constitutes a valid section selection, then return a list of all selected sections. This is the case when the region begins in the heading of a section and ends in the heading of the same section or in that of a sibling section. If optional MULTIPLE is non-nil, then the region cannot begin and end in the same section. When the selection is not valid, then return nil. In this case, most commands that can act on the selected sections will instead act on the section at point. When the region looks like it would in any other buffer then the selection is invalid. When the selection is valid then the region uses the ~magit-section-highlight~ face. This does not apply to diffs where things get a bit more complicated, but even here if the region looks like it usually does, then that's not a valid selection as far as this function is concerned. If optional CONDITION is non-nil, then the selection not only has to be valid; all selected sections additionally have to match CONDITION, or nil is returned. See ~magit-section-match~ for the forms CONDITION can take. - Function: magit-region-values &optional condition multiple Return a list of the values of the selected sections. Return the values that themselves would be returned by ~magit-region-sections~ (which see). *** Matching Sections - Key: M-x magit-describe-section-briefly, magit-describe-section-briefly Show information about the section at point. This command is intended for debugging purposes. - Function: magit-section-ident section Return an unique identifier for SECTION. The return value has the form ~((TYPE . VALUE)...)~. - Function: magit-get-section ident &optional root Return the section identified by IDENT. IDENT has to be a list as returned by ~magit-section-ident~. - Function: magit-section-match condition &optional section Return ~t~ if SECTION matches CONDITION. SECTION defaults to the section at point. If SECTION is not specified and there also is no section at point, then return ~nil~. CONDITION can take the following forms: - ~(CONDITION...)~ matches if any of the CONDITIONs matches. - ~[CLASS...]~ matches if the section's class is the same as the first CLASS or a subclass of that; the section's parent class matches the second CLASS; and so on. - ~[* CLASS...]~ matches sections that match ~[CLASS...]~ and also recursively all their child sections. - ~CLASS~ matches if the section's class is the same as CLASS or a subclass of that; regardless of the classes of the parent sections. Each CLASS should be a class symbol, identifying a class that derives from ~magit-section~. For backward compatibility CLASS can also be a "type symbol". A section matches such a symbol if the value of its ~type~ slot is ~eq~. If a type symbol has an entry in ~magit--section-type-alist~, then a section also matches that type if its class is a subclass of the class that corresponds to the type as per that alist. Note that it is not necessary to specify the complete section lineage as printed by ~magit-describe-section-briefly~, unless of course you want to be that precise. - Function: magit-section-value-if condition &optional section If the section at point matches CONDITION, then return its value. If optional SECTION is non-nil then test whether that matches instead. If there is no section at point and SECTION is nil, then return nil. If the section does not match, then return nil. See ~magit-section-match~ for the forms CONDITION can take. - Function: magit-section-case &rest clauses Choose among clauses on the type of the section at point. Each clause looks like (CONDITION BODY...). The type of the section is compared against each CONDITION; the BODY forms of the first match are evaluated sequentially and the value of the last form is returned. Inside BODY the symbol ~it~ is bound to the section at point. If no clause succeeds or if there is no section at point return nil. See ~magit-section-match~ for the forms CONDITION can take. Additionally a CONDITION of t is allowed in the final clause and matches if no other CONDITION match, even if there is no section at point. - Variable: magit-root-section The root section in the current buffer. All other sections are descendants of this section. The value of this variable is set by ~magit-insert-section~ and you should never modify it. For diff related sections a few additional tools exist. - Function: magit-diff-type &optional section Return the diff type of SECTION. The returned type is one of the symbols ~staged~, ~unstaged~, ~committed~, or ~undefined~. This type serves a similar purpose as the general type common to all sections (which is stored in the ~type~ slot of the corresponding ~magit-section~ struct) but takes additional information into account. When the SECTION isn't related to diffs and the buffer containing it also isn't a diff-only buffer, then return nil. Currently the type can also be one of ~tracked~ and ~untracked~, but these values are not handled explicitly in every place they should be. A possible fix could be to just return nil here. The section has to be a ~diff~ or ~hunk~ section, or a section whose children are of type ~diff~. If optional SECTION is nil, return the diff type for the current section. In buffers whose major mode is ~magit-diff-mode~ SECTION is ignored and the type is determined using other means. In ~magit-revision-mode~ buffers the type is always ~committed~. - Function: magit-diff-scope &optional section strict Return the diff scope of SECTION or the selected section(s). A diff's "scope" describes what part of a diff is selected, it is a symbol, one of ~region~, ~hunk~, ~hunks~, ~file~, ~files~, or ~list~. Do not confuse this with the diff "type", as returned by ~magit-diff-type~. If optional SECTION is non-nil, then return the scope of that, ignoring the sections selected by the region. Otherwise return the scope of the current section, or if the region is active and selects a valid group of diff related sections, the type of these sections, i.e. ~hunks~ or ~files~. If SECTION (or if the current section that is nil) is a ~hunk~ section and the region starts and ends inside the body of a that section, then the type is ~region~. If optional STRICT is non-nil then return nil if the diff type of the section at point is ~untracked~ or the section at point is not actually a ~diff~ but a ~diffstat~ section. ** Refreshing Buffers All commands that create a new Magit buffer or change what is being displayed in an existing buffer do so by calling ~magit-mode-setup~. Among other things, that function sets the buffer local values of ~default-directory~ (to the top-level of the repository), ~magit-refresh-function~, and ~magit-refresh-args~. Buffers are refreshed by calling the function that is the local value of ~magit-refresh-function~ (a function named ~magit-*-refresh-buffer~, where ~*~ may be something like ~diff~) with the value of ~magit-refresh-args~ as arguments. - Macro: magit-mode-setup buffer switch-func mode refresh-func &optional refresh-args This function displays and selects BUFFER, turns on MODE, and refreshes a first time. This function displays and optionally selects BUFFER by calling ~magit-mode-display-buffer~ with BUFFER, MODE and SWITCH-FUNC as arguments. Then it sets the local value of ~magit-refresh-function~ to REFRESH-FUNC and that of ~magit-refresh-args~ to REFRESH-ARGS. Finally it creates the buffer content by calling REFRESH-FUNC with REFRESH-ARGS as arguments. All arguments are evaluated before switching to BUFFER. - Function: magit-mode-display-buffer buffer mode &optional switch-function This function display BUFFER in some window and select it. BUFFER may be a buffer or a string, the name of a buffer. The buffer is returned. Unless BUFFER is already displayed in the selected frame, store the previous window configuration as a buffer local value, so that it can later be restored by ~magit-mode-bury-buffer~. The buffer is displayed and selected using SWITCH-FUNCTION. If that is ~nil~ then ~pop-to-buffer~ is used if the current buffer's major mode derives from ~magit-mode~. Otherwise ~switch-to-buffer~ is used. - Variable: magit-refresh-function The value of this buffer-local variable is the function used to refresh the current buffer. It is called with ~magit-refresh-args~ as arguments. - Variable: magit-refresh-args The list of arguments used by ~magit-refresh-function~ to refresh the current buffer. ~magit-refresh-function~ is called with these arguments. The value is usually set using ~magit-mode-setup~, but in some cases it's also useful to provide commands which can change the value. For example, the ~magit-diff-refresh-popup~ can be used to change any of the arguments used to display the diff, without having to specify again which differences should be shown. ~magit-diff-more-context~, ~magit-diff-less-context~, and ~magit-diff-default-context~ change just the ~-U~ argument. In both case this is done by changing the value of this variable and then calling this ~magit-refresh-function~. ** Conventions *** _ :ignore: Also see [[*Completion and Confirmation]]. *** Theming Faces The default theme uses blue for local branches, green for remote branches, and goldenrod (brownish yellow) for tags. When creating a new theme, you should probably follow that example. If your theme already uses other colors, then stick to that. In older releases these reference faces used to have a background color and a box around them. The basic default faces no longer do so, to make Magit buffers much less noisy, and you should follow that example at least with regards to boxes. (Boxes were used in the past to work around a conflict between the highlighting overlay and text property backgrounds. That's no longer necessary because highlighting no longer causes other background colors to disappear.) Alternatively you can keep the background color and/or box, but then have to take special care to adjust ~magit-branch-current~ accordingly. By default it looks mostly like ~magit-branch-local~, but with a box (by default the former is the only face that uses a box, exactly so that it sticks out). If the former also uses a box, then you have to make sure that it differs in some other way from the latter. The most difficult faces to theme are those related to diffs, headings, highlighting, and the region. There are faces that fall into all four groups - expect to spend some time getting this right. The ~region~ face in the default theme, in both the light and dark variants, as well as in many other themes, distributed with Emacs or by third-parties, is very ugly. It is common to use a background color that really sticks out, which is ugly but if that were the only problem then it would be acceptable. Unfortunately many themes also set the foreground color, which ensures that all text within the region is readable. Without doing that there might be cases where some foreground color is too close to the region background color to still be readable. But it also means that text within the region loses all syntax highlighting. I consider the work that went into getting the ~region~ face right to be a good indicator for the general quality of a theme. My recommendation for the ~region~ face is this: use a background color slightly different from the background color of the ~default~ face, and do not set the foreground color at all. So for a light theme you might use a light (possibly tinted) gray as the background color of ~default~ and a somewhat darker gray for the background of ~region~. That should usually be enough to not collide with the foreground color of any other face. But if some other faces also set a light gray as background color, then you should also make sure it doesn't collide with those (in some cases it might be acceptable though). Magit only uses the ~region~ face when the region is "invalid" by its own definition. In a Magit buffer the region is used to either select multiple sibling sections, so that commands which support it act on all of these sections instead of just the current section, or to select lines within a single hunk section. In all other cases, the section is considered invalid and Magit won't act on it. But such invalid sections happen, either because the user has not moved point enough yet to make it valid or because she wants to use a non-magit command to act on the region, e.g. ~kill-region~. So using the regular ~region~ face for invalid sections is a feature. It tells the user that Magit won't be able to act on it. It's acceptable if that face looks a bit odd and even (but less so) if it collides with the background colors of section headings and other things that have a background color. Magit highlights the current section. If a section has subsections, then all of them are highlighted. This is done using faces that have "highlight" in their names. For most sections, ~magit-section-highlight~ is used for both the body and the heading. Like the ~region~ face, it should only set the background color to something similar to that of ~default~. The highlight background color must be different from both the ~region~ background color and the ~default~ background color. For diff related sections Magit uses various faces to highlight different parts of the selected section(s). Note that hunk headings, unlike all other section headings, by default have a background color, because it is useful to have very visible separators between hunks. That face ~magit-diff-hunk-heading~, should be different from both ~magit-diff-hunk-heading-highlight~ and ~magit-section-highlight~, as well as from ~magit-diff-context~ and ~magit-diff-context-highlight~. By default we do that by changing the foreground color. Changing the background color would lead to complications, and there are already enough we cannot get around. (Also note that it is generally a good idea for section headings to always be bold, but only for sections that have subsections). When there is a valid region selecting diff-related sibling sections, i.e. multiple files or hunks, then the bodies of all these sections use the respective highlight faces, but additionally the headings instead use one of the faces ~magit-diff-file-heading-selection~ or ~magit-diff-hunk-heading-selection~. These faces have to be different from the regular highlight variants to provide explicit visual indication that the region is active. When theming diff related faces, start by setting the option ~magit-diff-refine-hunk~ to ~all~. You might personally prefer to only refine the current hunk or not use hunk refinement at all, but some of the users of your theme want all hunks to be refined, so you have to cater to that. (Also turn on ~magit-diff-highlight-indentation~, ~magit-diff-highlight-trailing~, and ~magit-diff-paint-whitespace~; and insert some whitespace errors into the code you use for testing.) For e.g. "added lines" you have to adjust three faces: ~magit-diff-added~, ~magit-diff-added-highlight~, and ~smerge-refined-added~. Make sure that the latter works well with both of the former, as well as ~smerge-other~ and ~diff-added~. Then do the same for the removed lines, context lines, lines added by us, and lines added by them. Also make sure the respective added, removed, and context faces use approximately the same saturation for both the highlighted and unhighlighted variants. Also make sure the file and diff headings work nicely with context lines (e.g. make them look different). Line faces should set both the foreground and the background color. For example, for added lines use two different greens. It's best if the foreground color of both the highlighted and the unhighlighted variants are the same, so you will need to have to find a color that works well on the highlight and unhighlighted background, the refine background, and the highlight context background. When there is an hunk internal region, then the added- and removed-lines background color is used only within that region. Outside the region the highlighted context background color is used. This makes it easier to see what is being staged. With an hunk internal region the hunk heading is shown using ~magit-diff-hunk-heading-selection~, and so are the thin lines that are added around the lines that fall within the region. The background color of that has to be distinct enough from the various other involved background colors. Nobody said this would be easy. If your theme restricts itself to a certain set of colors, then you should make an exception here. Otherwise it would be impossible to make the diffs look good in each and every variation. Actually you might want to just stick to the default definitions for these faces. You have been warned. Also please note that if you do not get this right, this will in some cases look to users like bugs in Magit - so please do it right or not at all. * FAQ :PROPERTIES: :APPENDIX: t :END: ** _ :ignore: The next two nodes lists frequently asked questions. For a list of frequently *and recently* asked questions, i.e. questions that haven't made it into the manual yet, see https://github.com/magit/magit/wiki/FAQ. Please also use the [[*Debugging Tools]]. ** FAQ - How to ...? *** How to show git's output? To show the output of recently run git commands, press ~$~ (or, if that isn't available, ~M-x magit-process-buffer~). This will show a buffer containing a section per git invocation; as always press ~TAB~ to expand or collapse them. By default, git's output is only inserted into the process buffer if it is run for side-effects. When the output is consumed in some way, also inserting it into the process buffer would be too expensive. For debugging purposes, it's possible to do so anyway by setting ~magit-git-debug~ to ~t~. *** How to install the gitman info manual? Git's manpages can be exported as an info manual called ~gitman~. Magit's own info manual links to nodes in that manual instead of the actual manpages because Info doesn't support linking to manpages. Unfortunately some distributions do not install the ~gitman~ manual by default and you will have to install a separate documentation package to get it. Magit patches Info adding the ability to visit links to the ~gitman~ Info manual by instead viewing the respective manpage. If you prefer that approach, then set the value of ~magit-view-git-manual-method~ to one of the supported packages ~man~ or ~woman~, e.g.: #+BEGIN_SRC emacs-lisp (setq magit-view-git-manual-method 'man) #+END_SRC *** How to show diffs for gpg-encrypted files? Git supports showing diffs for encrypted files, but has to be told to do so. Since Magit just uses Git to get the diffs, configuring Git also affects the diffs displayed inside Magit. #+BEGIN_SRC shell-script git config --global diff.gpg.textconv "gpg --no-tty --decrypt" echo "*.gpg filter=gpg diff=gpg" > .gitattributes #+END_SRC *** How does branching and pushing work? Please see [[*Branching]] and http://emacsair.me/2016/01/17/magit-2.4 *** Can Magit be used as ~ediff-version-control-package~? No, it cannot. For that to work the functions ~ediff-magit-internal~ and ~ediff-magit-merge-internal~ would have to be implemented, and they are not. These two functions are only used by the three commands ~ediff-revision~, ~ediff-merge-revisions-with-ancestor~, and ~ediff-merge-revisions~. These commands only delegate the task of populating buffers with certain revisions to the "internal" functions. The equally important task of determining which revisions are to be compared/merged is not delegated. Instead this is done without any support whatsoever from the version control package/system - meaning that the user has to enter the revisions explicitly. Instead of implementing ~ediff-magit-internal~ we provide ~magit-ediff-compare~, which handles both tasks like it is 2005. The other commands ~ediff-merge-revisions~ and ~ediff-merge-revisions-with-ancestor~ are normally not what you want when using a modern version control system like Git. Instead of letting the user resolve only those conflicts which Git could not resolve on its own, they throw away all work done by Git and then expect the user to manually merge all conflicts, including those that had already been resolved. That made sense back in the days when version control systems couldn't merge (or so I have been told), but not anymore. Once in a blue moon you might actually want to see all conflicts, in which case you *can* use these commands, which then use ~ediff-vc-merge-internal~. So we don't actually have to implement ~ediff-magit-merge-internal~. Instead we provide the more useful command ~magit-ediff-resolve~ which only shows yet-to-be resolved conflicts. ** FAQ - Issues and Errors *** Magit is slow See [[*Performance]]. *** I changed several thousand files at once and now Magit is unusable Magit is *currently* not expected to work under such conditions. It sure would be nice if it did, and v2.5 will hopefully be a big step into that direction. But it might take until v3.1 to accomplish fully satisfactory performance, because that requires some heavy refactoring. But for now we recommend you use the command line to complete this one commit. Also see [[*Performance]]. *** I am having problems committing That likely means that Magit is having problems finding an appropriate emacsclient executable. See [[info:with-editor#Configuring With-Editor]] and [[info:with-editor#Debugging]]. *** I am using MS Windows and cannot push with Magit It's almost certain that Magit is only incidental to this issue. It is much more likely that this is a configuration issue, even if you can push on the command line. Detailed setup instructions can be found at https://github.com/magit/magit/wiki/Pushing-with-Magit-from-Windows. *** I am using OS X and SOMETHING works in shell, but not in Magit This usually occurs because Emacs doesn't have the same environment variables as your shell. Try installing and configuring https://github.com/purcell/exec-path-from-shell. By default it synchronizes ~$PATH~, which helps Magit find the same ~git~ as the one you are using on the shell. If SOMETHING is "passphrase caching with gpg-agent for commit and/or tag signing", then you'll also need to synchronize ~$GPG_AGENT_INFO~. *** Diffs contain control sequences This happens when you configure Git to always color diffs and/or all of its output. The valid values for relevant Git variables ~color.ui~ and ~color.diff~ are ~false~, ~true~ and ~always~, and the default is ~true~. You should leave it that way because then you get colorful output in terminals by default but when git's output is consumed by something else, then no color control sequences are used. If you actually use some other tool that requires setting ~color.ui~ and/or ~color.diff~ to ~always~ (which is highly unlikely), then you can override these settings just for Magit by using: #+BEGIN_SRC emacs-lisp (setq magit-git-global-arguments (nconc magit-git-global-arguments '("-c" "color.ui=false" "-c" "color.diff=false"))) #+END_SRC *** Expanding a file to show the diff causes it to disappear This is probably caused by a change of a ~diff.*~ Git variable. You probably set that variable for a reason, and should therefore only undo that setting in Magit by customizing ~magit-git-global-arguments~. *** Point is wrong in the ~COMMIT_EDITMSG~ buffer Neither Magit nor `git-commit` fiddle with point in the buffer used to write commit messages, so something else must be doing it. You have probably globally enabled a mode which does restore point in file-visiting buffers. It might be a bit surprising, but when you write a commit message, then you are actually editing a file. So you have to figure out which package is doing. ~saveplace~, ~pointback~, and ~session~ are likely candidates. These snippets might help: #+BEGIN_SRC emacs-lisp (setq session-name-disable-regexp "\\(?:\\`'\\.git/[A-Z_]+\\'\\)") (with-eval-after-load 'pointback (lambda () (when (or git-commit-mode git-rebase-mode) (pointback-mode -1)))) #+END_SRC *** The mode-line information isn't always up-to-date Magit is not responsible for the version control information that is being displayed in the mode-line and looks something like ~Git-master~. The built-in "Version Control" package, also known as "VC", updates that information, and can be told to do so more often: #+BEGIN_SRC emacs-lisp (setq auto-revert-check-vc-info t) #+END_SRC But doing so isn't good for performance. For more (overly optimistic) information see [[info:emacs#VC Mode Line]]. If you don't really care about seeing that information in the mode-line, but just don't want to see /incorrect/ information, then consider disabling VC when using Git: #+BEGIN_SRC emacs-lisp (setq vc-handled-backends (delq 'Git vc-handled-backends)) #+END_SRC Or to disable it completely: #+BEGIN_SRC emacs-lisp (setq vc-handled-backends nil) #+END_SRC *** A branch and tag sharing the same name breaks SOMETHING Or more generally, ambiguous refnames break SOMETHING. Magit assumes that refs are named non-ambiguously across the "refs/heads/", "refs/tags/", and "refs/remotes/" namespaces (i.e., all the names remain unique when those prefixes are stripped). We consider ambiguous refnames unsupported and recommend that you use a non-ambiguous naming scheme. However, if you do work with a repository that has ambiguous refnames, please report any issues you encounter so that we can investigate whether there is a simple fix. *** My Git hooks work on the command-line but not inside Magit When Magit calls ~git~ it adds a few global arguments including ~--literal-pathspecs~ and the ~git~ process started by Magit then passes that setting on to other ~git~ process it starts itself. It does so by setting the environment variable ~GIT_LITERAL_PATHSPECS~, not by calling subprocesses with the ~--literal-pathspecs~. You can therefore override this setting in hook scripts using ~unset GIT_LITERAL_PATHSPECS~. *** ~git-commit-mode~ isn't used when committing from the command-line The reason for this is that ~git-commit.el~ has not been loaded yet and/or that the server has not been started yet. These things have always already been taken care of when you commit from Magit because in order to do so, Magit has to be loaded and doing that involves loading ~git-commit~ and starting the server. If you want to commit from the command-line, then you have to take care of these things yourself. Your ~init.el~ file should contain: #+BEGIN_SRC emacs-lisp (require 'git-commit) (server-mode) #+END_SRC Instead of `(require 'git-commit)` you may also use: #+BEGIN_SRC emacs-lisp (load "/path/to/magit-autoloads.el") #+END_SRC You might want to do that because loading ~git-commit~ causes large parts of Magit to be loaded. There are also some variations of ~(server-mode)~ that you might want to try. Personally I use: #+BEGIN_SRC emacs-lisp (use-package server :config (or (server-running-p) (server-mode))) #+END_SRC Now you can use: #+BEGIN_SRC shell-script $ emacs& $ EDITOR=emacsclient git commit #+END_SRC However you cannot use: #+BEGIN_SRC shell-script $ killall emacs $ EDITOR="emacsclient --alternate-editor emacs" git commit #+END_SRC This will actually end up using ~emacs~, not ~emacsclient~. If you do this, then can still edit the commit message but ~git-commit-mode~ won't be used and you have to exit ~emacs~ to finish the process. Tautology ahead. If you want to be able to use ~emacsclient~ to connect to a running ~emacs~ instance, even though no ~emacs~ instance is running, then you cannot use ~emacsclient~ directly. Instead you have to create a script that does something like this: Try to use ~emacsclient~ (without using ~--alternate-editor~). If that succeeds, do nothing else. Otherwise start ~emacs &~ (and ~init.el~ must call ~server-start~) and try to use ~emacsclient~ again. *** Point ends up inside invisible text when jumping to a file-visiting buffer This can happen when you type ~RET~ on a hunk to visit the respective file at the respective position. One solution to this problem is to use ~global-reveal-mode~. It makes sure that text around point is always visible. If that is too drastic for your taste, then you may instead use ~magit-diff-visit-file-hook~ to reveal the text, possibly using ~reveal-post-command~ or for Org buffers ~org-reveal~. * Debugging Tools Magit and its dependencies provide a few debugging tools, and we appreciate it very much if you use those tools before reporting an issue. Please include all relevant output when reporting an issue. - Key: M-x magit-version, magit-version This command shows the currently used versions of Magit, Git, and Emacs in the echo area. Non-interactively this just returns the Magit version. - Key: M-x magit-emacs-Q-command, magit-emacs-Q-command This command shows a debugging shell command in the echo area and adds it to the kill ring. Paste that command into a shell and run it. This shell command starts ~emacs~ with only ~magit~ and its dependencies loaded. Neither your configuration nor other installed packages are loaded. This makes it easier to determine whether some issue lays with Magit or something else. If you run Magit from its Git repository, then you should be able to use ~make emacs-Q~ instead of the output of this command. - Key: M-x magit-debug-git-executable, magit-debug-git-executable This command displays a buffer containing information about the available and used ~git~ executable(s), and can be useful when investigating ~exec-path~ issues. Also see [[*Git Executable]]. - Key: M-x with-editor-debug, with-editor-debug This command displays a buffer containing information about the available and used ~~emacsclient~ executable(s), and can be useful when investigating why Magit (or rather ~with-editor~) cannot find an appropriate ~emacsclient~ executable. Also see [[info:with-editor#Debugging]]. Please also see the [[*FAQ]]. * Keystroke Index :PROPERTIES: :APPENDIX: t :INDEX: ky :COOKIE_DATA: recursive :END: * Command Index :PROPERTIES: :APPENDIX: t :INDEX: cp :END: * Function Index :PROPERTIES: :APPENDIX: t :INDEX: fn :END: * Variable Index :PROPERTIES: :APPENDIX: t :INDEX: vr :END: * _ Copying :PROPERTIES: :COPYING: t :END: #+BEGIN_QUOTE Copyright (C) 2015-2018 Jonas Bernoulli 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. #+END_QUOTE * _ :ignore: # LocalWords: ARG ARGS CONDITIONs ChangeLog DNS Dired Ediff Ediffing # LocalWords: Elpa Emacsclient FUNC Flyspell Git Git's Gitk HOOK's # LocalWords: IDENT Ido Junio LocalWords Magit Magit's Magitian Magitians # LocalWords: Melpa Propertize REF REF's RET Reflog SPC SYM Spacemacs # LocalWords: Submodules TODO TYPEs Theming Unpulled Unpushed Unstaged # LocalWords: Untracked WORKTREE Wip ack args async autoloads autosaving # LocalWords: autosquash backport basename branchref builtin # LocalWords: cdr changelog committer config customizable diff's diffstat # LocalWords: dwim ediff ediffing editmsg emacsclient filename fixup # LocalWords: flyspell func git's gitk gitman gitmodule gitmodules goto # LocalWords: gpg gui ident ido init inserter inserters keymap keymaps # LocalWords: logfile magit maildir manpage manpages minibuffer multi mv # LocalWords: namespace newbase nocommit notesRef popup popups posix prev # LocalWords: propertize rebase rebased rebasing reflog repo signoff str # LocalWords: struct subcommand submodule submodule's submodules subprocess # LocalWords: sym texinfo theming todo topdir un unhighlighted unpulled # LocalWords: unpushed unstage unstaged unstages unstaging untracked url # LocalWords: versa whitespace wip workflow worktree wtree # LocalWords: backported macOS # IMPORTANT: Also update ORG_ARGS and ORG_EVAL in the Makefile. # Local Variables: # eval: (require 'magit-utils nil t) # eval: (require 'org-man nil t) # eval: (require 'ox-extra nil t) # eval: (require 'ox-texinfo+ nil t) # eval: (and (featurep 'ox-extra) (ox-extras-activate '(ignore-headlines))) # indent-tabs-mode: nil # org-src-preserve-indentation: nil # End: magit-2.90.1/Documentation/magit.texi000066400000000000000000013167651337354740400175460ustar00rootroot00000000000000\input texinfo @c -*- texinfo -*- @c %**start of header @setfilename magit.info @settitle Magit User Manual @documentencoding UTF-8 @documentlanguage en @c %**end of header @copying @quotation Copyright (C) 2015-2018 Jonas Bernoulli 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. @end quotation @end copying @dircategory Emacs @direntry * Magit: (magit). Using Git from Emacs with Magit. @end direntry @finalout @titlepage @title Magit User Manual @subtitle for version 2.90.1 @author Jonas Bernoulli @page @vskip 0pt plus 1filll @insertcopying @end titlepage @contents @ifnottex @node Top @top Magit User Manual 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. @noindent This manual is for Magit version 2.90.1. @quotation Copyright (C) 2015-2018 Jonas Bernoulli 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. @end quotation @end ifnottex @menu * Introduction:: * Installation:: * Getting Started:: * Interface Concepts:: * Inspecting:: * Manipulating:: * Transferring:: * Miscellaneous:: * Customizing:: * Plumbing:: * FAQ:: * Debugging Tools:: * Keystroke Index:: * Command Index:: * Function Index:: * Variable Index:: @detailmenu --- The Detailed Node Listing --- Installation * Installing from Melpa:: * Installing from the Git Repository:: * Post-Installation Tasks:: Interface Concepts * Modes and Buffers:: * Sections:: * Popup Buffers and Prefix Commands:: * Completion, Confirmation and the Selection: Completion Confirmation and the Selection. * Running Git:: Modes and Buffers * Switching Buffers:: * Naming Buffers:: * Quitting Windows:: * Automatic Refreshing of Magit Buffers:: * Automatic Saving of File-Visiting Buffers:: * Automatic Reverting of File-Visiting Buffers:: Sections * Section Movement:: * Section Visibility:: * Section Hooks:: * Section Types and Values:: * Section Options:: Completion, Confirmation and the Selection * Action Confirmation:: * Completion and Confirmation:: * The Selection:: * The hunk-internal region:: * Support for Completion Frameworks:: * Additional Completion Options:: Running Git * Viewing Git Output:: * Git Process Status:: * Running Git Manually:: * Git Executable:: * Global Git Arguments:: Inspecting * Status Buffer:: * Repository List:: * Logging:: * Diffing:: * Ediffing:: * References Buffer:: * Bisecting:: * Visiting Blobs:: * Blaming:: Status Buffer * Status Sections:: * Status Header Sections:: * Status Module Sections:: * Status Options:: Logging * Refreshing Logs:: * Log Buffer:: * Log Margin:: * Select from Log:: * Reflog:: * Cherries:: Diffing * Refreshing Diffs:: * Diff Buffer:: * Diff Options:: * Revision Buffer:: References Buffer * References Sections:: Manipulating * Repository Setup:: * Staging and Unstaging:: * Applying:: * Committing:: * Branching:: * Merging:: * Resolving Conflicts:: * Rebasing:: * Cherry Picking:: * Resetting:: * Stashing:: Staging and Unstaging * Staging from File-Visiting Buffers:: Committing * Initiating a Commit:: * Editing Commit Messages:: Branching * The Two Remotes:: * The Branch Popup:: * The Branch Config Popup:: * Auxiliary Branch Commands:: Rebasing * Editing Rebase Sequences:: * Information About In-Progress Rebase:: Cherry Picking * Reverting:: Transferring * Remotes:: * Fetching:: * Pulling:: * Pushing:: * Creating and Sending Patches:: * Applying Patches:: Remotes * The Remote Popup:: * The Remote Config Popup:: Miscellaneous * Tagging:: * Notes:: * Submodules:: * Subtree:: * Worktree:: * Common Commands:: * Wip Modes:: * Minor Mode for Buffers Visiting Files:: * Minor Mode for Buffers Visiting Blobs:: Submodules * Listing Submodules:: * Submodule Popup:: Wip Modes * Wip Graph:: * Legacy Wip Modes:: Customizing * Per-Repository Configuration:: * Essential Settings:: Essential Settings * Safety:: * Performance:: Plumbing * Calling Git:: * Section Plumbing:: * Refreshing Buffers:: * Conventions:: Calling Git * Getting a Value from Git:: * Calling Git for Effect:: Section Plumbing * Creating Sections:: * Section Selection:: * Matching Sections:: Conventions * Theming Faces:: FAQ * FAQ - How to @dots{}?:: * FAQ - Issues and Errors:: FAQ - How to @dots{}? * How to show git's output?:: * How to install the gitman info manual?:: * How to show diffs for gpg-encrypted files?:: * How does branching and pushing work?:: * Can Magit be used as @code{ediff-version-control-package}?:: FAQ - Issues and Errors * Magit is slow:: * I changed several thousand files at once and now Magit is unusable:: * I am having problems committing:: * I am using MS Windows and cannot push with Magit:: * I am using OS X and SOMETHING works in shell, but not in Magit: I am using OS X and SOMETHING works in shell but not in Magit. * Diffs contain control sequences:: * Expanding a file to show the diff causes it to disappear:: * Point is wrong in the @code{COMMIT_EDITMSG} buffer:: * The mode-line information isn't always up-to-date:: * A branch and tag sharing the same name breaks SOMETHING:: * My Git hooks work on the command-line but not inside Magit:: * @code{git-commit-mode} isn't used when committing from the command-line:: * Point ends up inside invisible text when jumping to a file-visiting buffer:: @end detailmenu @end menu @node Introduction @chapter Introduction 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. Staging and otherwise applying changes is one of the most important features in a Git porcelain and here Magit outshines anything else, including Git itself. Git's own staging interface (@code{git add --patch}) is so cumbersome that many users only use it in exceptional cases. In Magit staging a hunk or even just part of a hunk is as trivial as staging all changes made to a file. The most visible part of Magit's interface is the status buffer, which displays information about the current repository. Its content is created by running several Git commands and making their output actionable. Among other things, it displays information about the current branch, lists unpulled and unpushed changes and contains sections displaying the staged and unstaged changes. That might sound noisy, but, since sections are collapsible, it's not. To stage or unstage a change one places the cursor on the change and then types @code{s} or @code{u}. The change can be a file or a hunk, or when the region is active (i.e. when there is a selection) several files or hunks, or even just part of a hunk. The change or changes that these commands - and many others - would act on are highlighted. Magit also implements several other "apply variants" in addition to staging and unstaging. One can discard or reverse a change, or apply it to the working tree. Git's own porcelain only supports this for staging and unstaging and you would have to do something like @code{git diff ... | ??? | git apply ...} to discard, revert, or apply a single hunk on the command line. In fact that's exactly what Magit does internally (which is what lead to the term "apply variants"). Magit isn't just for Git experts, but it does assume some prior experience with Git as well as Emacs. That being said, many users have reported that using Magit was what finally taught them what Git is capable of and how to use it to its fullest. Other users wished they had switched to Emacs sooner so that they would have gotten their hands on Magit earlier. While one has to know the basic features of Emacs to be able to make full use of Magit, acquiring just enough Emacs skills doesn't take long and is worth it, even for users who prefer other editors. Vim users are advised to give @uref{https://bitbucket.org/lyro/evil/wiki/Home, Evil}, the "Extensible VI Layer for Emacs", and @uref{https://github.com/syl20bnr/spacemacs, Spacemacs}, an "Emacs starter-kit focused on Evil" a try. Magit provides a consistent and efficient Git porcelain. After a short learning period, you will be able to perform most of your daily version control tasks faster than you would on the command line. You will likely also start using features that seemed too daunting in the past. Magit fully embraces Git. It exposes many advanced features using a simple but flexible interface instead of only wrapping the trivial ones like many GUI clients do. Of course Magit supports logging, cloning, pushing, and other commands that usually don't fail in spectacular ways; but it also supports tasks that often cannot be completed in a single step. Magit fully supports tasks such as merging, rebasing, cherry-picking, reverting, and blaming by not only providing a command to initiate these tasks but also by displaying context sensitive information along the way and providing commands that are useful for resolving conflicts and resuming the sequence after doing so. Magit wraps and in many cases improves upon at least the following Git porcelain commands: @code{add}, @code{am}, @code{bisect}, @code{blame}, @code{branch}, @code{checkout}, @code{cherry}, @code{cherry-pick}, @code{clean}, @code{clone}, @code{commit}, @code{config}, @code{describe}, @code{diff}, @code{fetch}, @code{format-patch}, @code{init}, @code{log}, @code{merge}, @code{merge-tree}, @code{mv}, @code{notes}, @code{pull}, @code{rebase}, @code{reflog}, @code{remote}, @code{request-pull}, @code{reset}, @code{revert}, @code{rm}, @code{show}, @code{stash}, @code{submodule}, @code{subtree}, @code{tag}, and @code{worktree.} Many more Magit porcelain commands are implemented on top of Git plumbing commands. @node Installation @chapter Installation Magit can be installed using Emacs' package manager or manually from its development repository. @menu * Installing from Melpa:: * Installing from the Git Repository:: * Post-Installation Tasks:: @end menu @node Installing from Melpa @section Installing from Melpa Magit is available from Melpa and Melpa-Stable. If you haven't used Emacs' package manager before, then it is high time you familiarize yourself with it by reading the documentation in the Emacs manual, see @ref{Packages,,,emacs,}. Then add one of the archives to @code{package-archives}: @itemize @item To use Melpa: @end itemize @lisp (require 'package) (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t) @end lisp @itemize @item To use Melpa-Stable: @end itemize @lisp (require 'package) (add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t) @end lisp Once you have added your preferred archive, you need to update the local package list using: @example M-x package-refresh-contents RET @end example Once you have done that, you can install Magit and its dependencies using: @example M-x package-install RET magit RET @end example Now see @ref{Post-Installation Tasks}. @node Installing from the Git Repository @section Installing from the Git Repository Magit depends on the @code{dash}, @code{ghub}, @code{graphql}, @code{magit-popup}, @code{treepy} and @code{with-editor} libraries which are available from Melpa and Melpa-Stable. Install them using @code{M-x package-install RET RET}. Of course you may also install them manually from their repository. Then clone the Magit repository: @example $ git clone https://github.com/magit/magit.git ~/.emacs.d/site-lisp/magit $ cd ~/.emacs.d/site-lisp/magit @end example Then compile the libraries and generate the info manuals: @example $ make @end example If you haven't installed @code{dash}, @code{ghub}, @code{graphql}, @code{magit-popup}, @code{treepy} and @code{with-editor} from Melpa or at @code{/path/to/magit/../}, then you have to tell @code{make} where to find them. To do so create the file @code{/path/to/magit/config.mk} with the following content before running @code{make}: @example LOAD_PATH = -L /path/to/magit/lisp LOAD_PATH += -L /path/to/dash LOAD_PATH += -L /path/to/ghub LOAD_PATH += -L /path/to/graphql LOAD_PATH += -L /path/to/magit-popup LOAD_PATH += -L /path/to/treepy LOAD_PATH += -L /path/to/with-editor @end example Finally add this to your init file: @lisp (add-to-list 'load-path "~/.emacs.d/site-lisp/magit/lisp") (require 'magit) (with-eval-after-load 'info (info-initialize) (add-to-list 'Info-directory-list "~/.emacs.d/site-lisp/magit/Documentation/")) @end lisp Note that you have to add the @code{lisp} subdirectory to the @code{load-path}, not the top-level of the repository, and that elements of @code{load-path} should not end with a slash, while those of @code{Info-directory-list} should. Instead of requiring the feature @code{magit}, you could load just the autoload definitions, by loading the file @code{magit-autoloads.el}. @lisp (load "/path/to/magit/lisp/magit-autoloads") @end lisp Instead of running Magit directly from the repository by adding that to the @code{load-path}, you might want to instead install it in some other directory using @code{sudo make install} and setting @code{load-path} accordingly. To update Magit use: @example $ git pull $ make @end example At times it might be necessary to run @code{make clean all} instead. To view all available targets use @code{make help}. Now see @ref{Post-Installation Tasks}. @node Post-Installation Tasks @section Post-Installation Tasks After installing Magit you should verify that you are indeed using the Magit, Git, and Emacs releases you think you are using. It's best to restart Emacs before doing so, to make sure you are not using an outdated value for @code{load-path}. @example M-x magit-version RET @end example should display something like @example Magit 2.8.0, Git 2.10.2, Emacs 25.1.1, gnu/linux @end example Then you might also want to read about options that many users likely want to customize. See @ref{Essential Settings}. To be able to follow cross references to Git manpages found in this manual, you might also have to manually install the @code{gitman} info manual, or advice @code{Info-follow-nearest-node} to instead open the actual manpage. See @ref{How to install the gitman info manual?}. If you are completely new to Magit then see @ref{Getting Started}. If you run into problems, then please see the @ref{FAQ}. Also see the @ref{Debugging Tools}. And last but not least please consider making a donation, to ensure that I can keep working on Magit. See @uref{https://magit.vc/donations}. for various donation options. @node Getting Started @chapter Getting Started This short tutorial describes the most essential features that many Magitians use on a daily basis. It only scratches the surface but should be enough to get you started. IMPORTANT: It is safest if you clone some repository just for this tutorial. Alternatively you can use an existing local repository, but if you do that, then you should commit all uncommitted changes before proceeding. To display information about the current Git repository, type @code{M-x magit-status RET}. You will be using this command a lot, and should therefore give it a global key binding. This is what we recommend: @lisp (global-set-key (kbd "C-x g") 'magit-status) @end lisp Most Magit commands are commonly invoked from the status buffer. It can be considered the primary interface for interacting with Git using Magit. Many other Magit buffers may exist at a given time, but they are often created from this buffer. Depending on what state your repository is in, this buffer may contain sections titled "Staged changes", "Unstaged changes", "Unmerged into origin/master", "Unpushed to origin/master", and many others. Since we are starting from a safe state, which you can easily return to (by doing a @code{git reset --hard PRE-MAGIT-STATE}), there currently are not staged or unstaged changes. Edit some files and save the changes. Then go back to the status buffer, while at the same time refreshing it, by typing @code{C-x g}. (When the status buffer, or any Magit buffer for that matter, is the current buffer, then you can also use just @code{g} to refresh it). Move between sections using @code{p} and @code{n}. Note that the bodies of some sections are hidden. Type @code{TAB} to expand or collapse the section at point. You can also use @code{C-tab} to cycle the visibility of the current section and its children. Move to a file section inside the section named "Unstaged changes" and type @code{s} to stage the changes you have made to that file. That file now appears under "Staged changes". Magit can stage and unstage individual hunks, not just complete files. Move to the file you have just staged, expand it using @code{TAB}, move to one of the hunks using @code{n}, and unstage just that by typing @code{u}. Note how the staging (@code{s}) and unstaging (@code{u}) commands operate on the change at point. Many other commands behave the same way. You can also un-/stage just part of a hunk. Inside the body of a hunk section (move there using @code{C-n}), set the mark using @code{C-SPC} and move down until some added and/or removed lines fall inside the region but not all of them. Again type @code{s} to stage. It is also possible to un-/stage multiple files at once. Move to a file section, type @code{C-SPC}, move to the next file using @code{n}, and then @code{s} to stage both files. Note that both the mark and point have to be on the headings of sibling sections for this to work. If the region looks like it does in other buffers, then it doesn't select Magit sections that can be acted on as a unit. And then of course you want to commit your changes. Type @code{c}. This shows the committing popup buffer featuring various commit variants and arguments that can be passed to @code{git commit}. Do not worry about those for now. We want to create a "normal" commit, which is done by typing @code{c} again. Now two new buffers appear. One is for writing the commit message, the other shows a diff with the changes that you are about to committed. Write a message and then type @code{C-c C-c} to actually create the commit. You probably don't want to push the commit you just created because you just committed some random changes, but if that is not the case you could push it by typing @code{P} to bring up the push popup and then @code{p} to push to a branch with the same name as the local branch onto the remote configured as the push-remote. (If the push-remote is not configured yet, then you would first be prompted for the remote to push to.) So far we have mentioned the commit, push, and log popups. These are probably among the popups you will be using the most, but many others exist. To show a popup that lists all other popups (as well as the various apply commands and some other fundamental commands), type @code{h}. Try a few. The key bindings in that popup correspond to the bindings in Magit buffers, including but not limited to the status buffer. So you could type @code{h d} to bring up the diff popup, but once you remember that "d" stands for "diff", you would usually do so by just typing @code{d}. But the "popup of popups" is useful even once you have memorized all the bindings, as it can provide easy access to Magit commands from non-Magit buffers. You should create a global key binding for this command too: @lisp (global-set-key (kbd "C-x M-g") 'magit-dispatch-popup) @end lisp In the same vein, you might also want to enable @code{global-magit-file-mode} to get some more Magit key bindings in regular file-visiting buffers (see @ref{Minor Mode for Buffers Visiting Files}). It is not necessary that you do so now, but if you stick with Magit, then it is highly recommended that you read the next section too. @node Interface Concepts @chapter Interface Concepts @menu * Modes and Buffers:: * Sections:: * Popup Buffers and Prefix Commands:: * Completion, Confirmation and the Selection: Completion Confirmation and the Selection. * Running Git:: @end menu @node Modes and Buffers @section Modes and Buffers Magit provides several major-modes. For each of these modes there usually exists only one buffer per repository. Separate modes and thus buffers exist for commits, diffs, logs, and some other things. Besides these special purpose buffers, there also exists an overview buffer, called the @strong{status buffer}. It's usually from this buffer that the user invokes Git commands, or creates or visits other buffers. In this manual we often speak about "Magit buffers". By that we mean buffers whose major-modes derive from @code{magit-mode}. @table @asis @kindex M-x magit-toggle-buffer-lock @cindex magit-toggle-buffer-lock @item @kbd{M-x magit-toggle-buffer-lock} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-buffer-lock}) This command locks the current buffer to its value or if the buffer is already locked, then it unlocks it. Locking a buffer to its value prevents it from being reused to display another value. The name of a locked buffer contains its value, which allows telling it apart from other locked buffers and the unlocked buffer. Not all Magit buffers can be locked to their values; for example, it wouldn't make sense to lock a status buffer. There can only be a single unlocked buffer using a certain major-mode per repository. So when a buffer is being unlocked and another unlocked buffer already exists for that mode and repository, then the former buffer is instead deleted and the latter is displayed in its place. @end table @menu * Switching Buffers:: * Naming Buffers:: * Quitting Windows:: * Automatic Refreshing of Magit Buffers:: * Automatic Saving of File-Visiting Buffers:: * Automatic Reverting of File-Visiting Buffers:: @end menu @node Switching Buffers @subsection Switching Buffers @defun magit-display-buffer buffer This function is a wrapper around @code{display-buffer} and is used to display any Magit buffer. It displays BUFFER in some window and, unlike @code{display-buffer}, also selects that window, provided @code{magit-display-buffer-noselect} is @code{nil}. It also runs the hooks mentioned below. @end defun @defvar magit-display-buffer-noselect When this is non-nil, then @code{magit-display-buffer} only displays the buffer but forgoes also selecting the window. This variable should not be set globally, it is only intended to be let-bound, by code that automatically updates "the other window". This is used for example when the revision buffer is updated when you move inside the log buffer. @end defvar @defopt magit-display-buffer-function The function specified here is called by @code{magit-display-buffer} with one argument, a buffer, to actually display that buffer. This function should call @code{display-buffer} with that buffer as first and a list of display actions as second argument. Magit provides several functions, listed below, that are suitable values for this option. If you want to use different rules, then a good way of doing that is to start with a copy of one of these functions and then adjust it to your needs. Instead of using a wrapper around @code{display-buffer}, that function itself can be used here, in which case the display actions have to be specified by adding them to @code{display-buffer-alist} instead. To learn about display actions, see @ref{Choosing a Window for Display,,,elisp,}. @end defopt @defun magit-display-buffer-traditional buffer This function is the current default value of the option @code{magit-display-buffer-function}. Before that option and this function were added, the behavior was hard-coded in many places all over the code base but now all the rules are contained in this one function (except for the "noselect" special case mentioned above). @end defun @defun magit-display-buffer-same-window-except-diff-v1 This function displays most buffers in the currently selected window. If a buffer's mode derives from @code{magit-diff-mode} or @code{magit-process-mode}, it is displayed in another window. @end defun @defun magit-display-buffer-fullframe-status-v1 This function fills the entire frame when displaying a status buffer. Otherwise, it behaves like @code{magit-display-buffer-traditional}. @end defun @defun magit-display-buffer-fullframe-status-topleft-v1 This function fills the entire frame when displaying a status buffer. It behaves like @code{magit-display-buffer-fullframe-status-v1} except that it displays buffers that derive from @code{magit-diff-mode} or @code{magit-process-mode} to the top or left of the current buffer rather than to the bottom or right. As a result, Magit buffers tend to pop up on the same side as they would if @code{magit-display-buffer-traditional} were in use. @end defun @defun magit-display-buffer-fullcolumn-most-v1 This function displays most buffers so that they fill the entire height of the frame. However, the buffer is displayed in another window if (1) the buffer's mode derives from @code{magit-process-mode}, or (2) the buffer's mode derives from @code{magit-diff-mode}, provided that the mode of the current buffer derives from @code{magit-log-mode} or @code{magit-cherry-mode}. @end defun @defopt magit-pre-display-buffer-hook This hook is run by @code{magit-display-buffer} before displaying the buffer. @end defopt @defun magit-save-window-configuration This function saves the current window configuration. Later when the buffer is buried, it may be restored by @code{magit-restore-window-configuration}. @end defun @defopt magit-post-display-buffer-hook This hook is run by @code{magit-display-buffer} after displaying the buffer. @end defopt @defun magit-maybe-set-dedicated This function remembers if a new window had to be created to display the buffer, or whether an existing window was reused. This information is later used by @code{magit-mode-quit-window}, to determine whether the window should be deleted when its last Magit buffer is buried. @end defun @node Naming Buffers @subsection Naming Buffers @defopt magit-generate-buffer-name-function The function used to generate the names of Magit buffers. Such a function should take the options @code{magit-uniquify-buffer-names} as well as @code{magit-buffer-name-format} into account. If it doesn't, then should be clearly stated in the doc-string. And if it supports %-sequences beyond those mentioned in the doc-string of the option @code{magit-buffer-name-format}, then its own doc-string should describe the additions. @end defopt @defun magit-generate-buffer-name-default-function mode This function returns a buffer name suitable for a buffer whose major-mode is MODE and which shows information about the repository in which @code{default-directory} is located. This function uses @code{magit-buffer-name-format} and supporting all of the %-sequences mentioned the documentation of that option. It also respects the option @code{magit-uniquify-buffer-names}. @end defun @defopt magit-buffer-name-format The format string used to name Magit buffers. At least the following %-sequences are supported: @itemize @item @code{%m} The name of the major-mode, but with the @code{-mode} suffix removed. @item @code{%M} Like @code{%m} but abbreviate @code{magit-status-mode} as @code{magit}. @item @code{%v} The value the buffer is locked to, in parentheses, or an empty string if the buffer is not locked to a value. @item @code{%V} Like @code{%v}, but the string is prefixed with a space, unless it is an empty string. @item @code{%t} The top-level directory of the working tree of the repository, or if @code{magit-uniquify-buffer-names} is non-nil an abbreviation of that. @item @code{%x} If @code{magit-uniquify-buffer-names} is nil "*", otherwise the empty string. Due to limitations of the @code{uniquify} package, buffer names must end with the path. @item @code{%T} Obsolete, use "%t%x" instead. Like @code{%t}, but append an asterisk if and only if @code{magit-uniquify-buffer-names} is nil. @end itemize The value should always contain @code{%m} or @code{%M}, @code{%v} or @code{%V}, and @code{%t} (or the obsolete @code{%T}). If @code{magit-uniquify-buffer-names} is non-nil, then the value must end with @code{%t} or @code{%t%x} (or the obsolete @code{%T}). See issue #2841. @end defopt @defopt magit-uniquify-buffer-names This option controls whether the names of Magit buffers are uniquified. If the names are not being uniquified, then they contain the full path of the top-level of the working tree of the corresponding repository. If they are being uniquified, then they end with the basename of the top-level, or if that would conflict with the name used for other buffers, then the names of all these buffers are adjusted until they no longer conflict. This is done using the @code{uniquify} package; customize its options to control how buffer names are uniquified. @end defopt @node Quitting Windows @subsection Quitting Windows @table @asis @kindex q @cindex magit-mode-bury-buffer @item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-mode-bury-buffer}) This command buries the current Magit buffer. With a prefix argument, it instead kills the buffer. @end table @defopt magit-bury-buffer-function The function used to actually bury or kill the current buffer. @code{magit-mode-bury-buffer} calls this function with one argument. If the argument is non-nil, then the function has to kill the current buffer. Otherwise it has to bury it alive. The default value currently is @code{magit-restore-window-configuration}. @end defopt @defun magit-restore-window-configuration kill-buffer Bury or kill the current buffer using @code{quit-window}, which is called with KILL-BUFFER as first and the selected window as second argument. Then restore the window configuration that existed right before the current buffer was displayed in the selected frame. Unfortunately that also means that point gets adjusted in all the buffers, which are being displayed in the selected frame. @end defun @defun magit-mode-quit-window kill-buffer Bury or kill the current buffer using @code{quit-window}, which is called with KILL-BUFFER as first and the selected window as second argument. Then, if the window was originally created to display a Magit buffer and the buried buffer was the last remaining Magit buffer that was ever displayed in the window, then that is deleted. @end defun @node Automatic Refreshing of Magit Buffers @subsection Automatic Refreshing of Magit Buffers After running a command which may change the state of the current repository, the current Magit buffer and the corresponding status buffer are refreshed. The status buffer may optionally be automatically refreshed whenever a buffer is saved to a file inside the respective repository. Automatically refreshing Magit buffers ensures that the displayed information is up-to-date most of the time but can lead to a noticeable delay in big repositories. Other Magit buffers are not refreshed to keep the delay to a minimum and also because doing so can sometimes be undesirable. Buffers can also be refreshed explicitly, which is useful in buffers that weren't current during the last refresh and after changes were made to the repository outside of Magit. @table @asis @kindex g @cindex magit-refresh @item @kbd{g} @tie{}@tie{}@tie{}@tie{}(@code{magit-refresh}) This command refreshes the current buffer if its major mode derives from @code{magit-mode} as well as the corresponding status buffer. If the option @code{magit-revert-buffers} calls for it, then it also reverts all unmodified buffers that visit files being tracked in the current repository. @kindex G @cindex magit-refresh-all @item @kbd{G} @tie{}@tie{}@tie{}@tie{}(@code{magit-refresh-all}) This command refreshes all Magit buffers belonging to the current repository and also reverts all unmodified buffers that visit files being tracked in the current repository. The file-visiting buffers are always reverted, even if @code{magit-revert-buffers} is nil. @end table @defopt magit-refresh-buffer-hook This hook is run in each Magit buffer that was refreshed during the current refresh - normally the current buffer and the status buffer. @end defopt @defopt magit-refresh-status-buffer When this option is non-nil, then the status buffer is automatically refreshed after running git for side-effects, in addition to the current Magit buffer, which is always refreshed automatically. Only set this to nil after exhausting all other options to improve performance. @end defopt @defun magit-after-save-refresh-status This function is intended to be added to @code{after-save-hook}. After doing that the corresponding status buffer is refreshed whenever a buffer is saved to a file inside a repository. Note that refreshing a Magit buffer is done by re-creating its contents from scratch, which can be slow in large repositories. If you are not satisfied with Magit's performance, then you should obviously not add this function to that hook. @end defun @node Automatic Saving of File-Visiting Buffers @subsection Automatic Saving of File-Visiting Buffers File-visiting buffers are by default saved at certain points in time. This doesn't guarantee that Magit buffers are always up-to-date, but, provided one only edits files by editing them in Emacs and uses only Magit to interact with Git, one can be fairly confident. When in doubt or after outside changes, type @code{g} (@code{magit-refresh}) to save and refresh explicitly. @defopt magit-save-repository-buffers This option controls whether file-visiting buffers are saved before certain events. If this is non-nil then all modified file-visiting buffers belonging to the current repository may be saved before running commands, before creating new Magit buffers, and before explicitly refreshing such buffers. If this is @code{dontask} then this is done without user intervention. If it is @code{t} then the user has to confirm each save. @end defopt @node Automatic Reverting of File-Visiting Buffers @subsection Automatic Reverting of File-Visiting Buffers By default Magit automatically reverts buffers that are visiting files that are being tracked in a Git repository, after they have changed on disk. When using Magit one often changes files on disk by running git, i.e. "outside Emacs", making this a rather important feature. For example, if you discard a change in the status buffer, then that is done by running @code{git apply --reverse ...}, and Emacs considers the file to have "changed on disk". If Magit did not automatically revert the buffer, then you would have to type @code{M-x revert-buffer RET RET} in the visiting buffer before you could continue making changes. @defopt magit-auto-revert-mode When this mode is enabled, then buffers that visit tracked files, are automatically reverted after the visited files changed on disk. @end defopt @defopt global-auto-revert-mode When this mode is enabled, then any file-visiting buffer is automatically reverted after the visited file changed on disk. If you like buffers that visit tracked files to be automatically reverted, then you might also like any buffer to be reverted, not just those visiting tracked files. If that is the case, then enable this mode @emph{instead of} @code{magit-auto-revert-mode}. @end defopt @defopt magit-auto-revert-immediately This option controls whether Magit reverts buffers immediately. If this is non-nil and either @code{global-auto-revert-mode} or @code{magit-auto-revert-mode} is enabled, then Magit immediately reverts buffers by explicitly calling @code{auto-revert-buffers} after running git for side-effects. If @code{auto-revert-use-notify} is non-nil (and file notifications are actually supported), then @code{magit-auto-revert-immediately} does not have to be non-nil, because the reverts happen immediately anyway. If @code{magit-auto-revert-immediately} and @code{auto-revert-use-notify} are both @code{nil}, then reverts happen after @code{auto-revert-interval} seconds of user inactivity. That is not desirable. @end defopt @defopt auto-revert-use-notify This option controls whether file notification functions should be used. Note that this variable unfortunately defaults to @code{t} even on systems on which file notifications cannot be used. @end defopt @defopt magit-auto-revert-tracked-only This option controls whether @code{magit-auto-revert-mode} only reverts tracked files or all files that are located inside Git repositories, including untracked files and files located inside Git's control directory. @end defopt @cindex auto-revert-mode @deffn Command auto-revert-mode The global mode @code{magit-auto-revert-mode} works by turning on this local mode in the appropriate buffers (but @code{global-auto-revert-mode} is implemented differently). You can also turn it on or off manually, which might be necessary if Magit does not notice that a previously untracked file now is being tracked or vice-versa. @end deffn @defopt auto-revert-stop-on-user-input This option controls whether the arrival of user input suspends the automatic reverts for @code{auto-revert-interval} seconds. @end defopt @defopt auto-revert-interval This option controls for how many seconds Emacs waits before resuming suspended reverts. @end defopt @defopt auto-revert-buffer-list-filter This option specifies an additional filter used by @code{auto-revert-buffers} to determine whether a buffer should be reverted or not. This option is provided by @code{magit}, which also redefines @code{auto-revert-buffers} to respect it. Magit users who do not turn on the local mode @code{auto-revert-mode} themselves, are best served by setting the value to @code{magit-auto-revert-repository-buffers-p}. However the default is nil, to not 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 @code{auto-revert-mode} in buffers in which Magit doesn't do that for them, should likely not use any filter. Users who turn on @code{global-auto-revert-mode}, do not have to worry about this option, because it is disregarded if the global mode is enabled. @end defopt @defopt auto-revert-verbose This option controls whether Emacs reports when a buffer has been reverted. @end defopt The options with the @code{auto-revert-} prefix are located in the Custom group named @code{auto-revert}. The other, magit-specific, options are located in the @code{magit} group. @menu * Risk of Reverting Automatically:: @end menu @node Risk of Reverting Automatically @unnumberedsubsubsec Risk of Reverting Automatically For the vast majority users automatically reverting file-visiting buffers after they have changed on disk is harmless. If a buffer is modified (i.e. it contains changes that haven't been saved yet), then Emacs would refuse to automatically revert it. If you save a previously modified buffer, then that results in what is seen by Git as an uncommitted change. Git would then refuse to carry out any commands that would cause these changes to be lost. In other words, if there is anything that could be lost, then either Git or Emacs would refuse to discard the changes. However if you do use file-visiting buffers as a sort of ad hoc "staging area", then the automatic reverts could potentially cause data loss. So far I have only heard from one user who uses such a workflow. An example: You visit some file in a buffer, edit it, and save the changes. Then, outside of Emacs (or at least not using Magit or by saving the buffer) you change the file on disk again. At this point the buffer is the only place where the intermediate version still exists. You have saved the changes to disk, but that has since been overwritten. Meanwhile Emacs considers the buffer to be unmodified (because you have not made any changes to it since you last saved it to the visited file) and therefore would not object to it being automatically reverted. At this point an Auto-Revert mode would kick in. It would check whether the buffer is modified and since that is not the case it would revert it. The intermediate version would be lost. (Actually you could still get it back using the @code{undo} command.) If your workflow depends on Emacs preserving the intermediate version in the buffer, then you have to disable all Auto-Revert modes. But please consider that such a workflow would be dangerous even without using an Auto-Revert mode, and should therefore be avoided. If Emacs crashed or if you quit Emacs by mistake, then you would also lose the buffer content. There would be no autosave file still containing the intermediate version (because that was deleted when you saved the buffer) and you would not be asked whether you want to save the buffer (because it isn't modified). @node Sections @section Sections Magit buffers are organized into nested sections, which can be collapsed and expanded, similar to how sections are handled in Org mode. Each section also has a type, and some sections also have a value. For each section type there can also be a local keymap, shared by all sections of that type. Taking advantage of the section value and type, many commands operate on the current section, or when the region is active and selects sections of the same type, all of the selected sections. Commands that only make sense for a particular section type (as opposed to just behaving differently depending on the type) are usually bound in section type keymaps. @menu * Section Movement:: * Section Visibility:: * Section Hooks:: * Section Types and Values:: * Section Options:: @end menu @node Section Movement @subsection Section Movement To move within a section use the usual keys (@code{C-p}, @code{C-n}, @code{C-b}, @code{C-f} etc), whose global bindings are not shadowed. To move to another section use the following commands. @table @asis @kindex p @cindex magit-section-backward @item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-backward}) When not at the beginning of a section, then move to the beginning of the current section. At the beginning of a section, instead move to the beginning of the previous visible section. @kindex n @cindex magit-section-forward @item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-forward}) Move to the beginning of the next visible section. @kindex M-p @cindex magit-section-backward-siblings @item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-backward-siblings}) Move to the beginning of the previous sibling section. If there is no previous sibling section, then move to the parent section instead. @kindex M-n @cindex magit-section-forward-siblings @item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-forward-siblings}) Move to the beginning of the next sibling section. If there is no next sibling section, then move to the parent section instead. @kindex ^ @cindex magit-section-up @item @kbd{^} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-up}) Move to the beginning of the parent of the current section. @end table The above commands all call the hook @code{magit-section-movement-hook}. Any of the functions listed below can be used as members of this hook. @defvar magit-section-movement-hook This hook is run by all of the above movement commands, after arriving at the destination. @end defvar @defun magit-hunk-set-window-start This hook function ensures that the beginning of the current section is visible, provided it is a @code{hunk} section. Otherwise, it does nothing. This function is a member of the hook's default value. @end defun @defun magit-section-set-window-start This hook function ensures that the beginning of the current section is visible, regardless of the section's type. If you add this to @code{magit-section-movement-hook}, then you must remove the hunk-only variant in turn. @end defun @defun magit-log-maybe-show-more-commits This hook function only has an effect in log buffers, and @code{point} is on the "show more" section. If that is the case, then it doubles the number of commits that are being shown. This function is a member of the hook's default value. @end defun @defun magit-log-maybe-update-revision-buffer When moving inside a log buffer, then this function updates the revision buffer, provided it is already being displayed in another window of the same frame. This function is a member of the hook's default value. @end defun @defun magit-log-maybe-update-blob-buffer When moving inside a log buffer and another window of the same frame displays a blob buffer, then this function instead displays the blob buffer for the commit at point in that window. @end defun @defun magit-status-maybe-update-revision-buffer When moving inside a status buffer, then this function updates the revision buffer, provided it is already being displayed in another window of the same frame. @end defun @defun magit-status-maybe-update-blob-buffer When moving inside a status buffer and another window of the same frame displays a blob buffer, then this function instead displays the blob buffer for the commit at point in that window. @end defun @defopt magit-update-other-window-delay Delay before automatically updating the other window. When moving around in certain buffers, then certain other buffers, which are being displayed in another window, may optionally be updated to display information about the section at point. When holding down a key to move by more than just one section, then that would update that buffer for each section on the way. To prevent that, updating the revision buffer is delayed, and this option controls for how long. For optimal experience you might have to adjust this delay and/or the keyboard repeat rate and delay of your graphical environment or operating system. @end defopt @node Section Visibility @subsection Section Visibility Magit provides many commands for changing the visibility of sections, but all you need to get started are the next two. @table @asis @kindex TAB @cindex magit-section-toggle @item @kbd{TAB} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-toggle}) Toggle the visibility of the body of the current section. @kindex C- @cindex magit-section-cycle @item @kbd{C-} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle}) Cycle the visibility of current section and its children. @kindex M- @cindex magit-section-cycle-diffs @item @kbd{M-} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle-diffs}) Cycle the visibility of diff-related sections in the current buffer. @kindex S- @cindex magit-section-cycle-global @item @kbd{S-} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-cycle-global}) Cycle the visibility of all sections in the current buffer. @kindex 1 @cindex magit-section-show-level-1 @item @kbd{1} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-1}) @kindex 2 @cindex magit-section-show-level-2 @item @kbd{2} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-2}) @kindex 3 @cindex magit-section-show-level-3 @item @kbd{3} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-3}) @kindex 4 @cindex magit-section-show-level-4 @item @kbd{4} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-4}) Show sections surrounding the current section up to level N@. @kindex M-1 @cindex magit-section-show-level-1-all @item @kbd{M-1} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-1-all}) @kindex M-2 @cindex magit-section-show-level-2-all @item @kbd{M-2} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-2-all}) @kindex M-3 @cindex magit-section-show-level-3-all @item @kbd{M-3} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-3-all}) @kindex M-4 @cindex magit-section-show-level-4-all @item @kbd{M-4} @tie{}@tie{}@tie{}@tie{}(@code{magit-section-show-level-4-all}) Show all sections up to level N@. @end table Some functions, which are used to implement the above commands, are also exposed as commands themselves. By default no keys are bound to these commands, as they are generally perceived to be much less useful. But your mileage may vary. @cindex magit-section-show @deffn Command magit-section-show Show the body of the current section. @end deffn @cindex magit-section-hide @deffn Command magit-section-hide Hide the body of the current section. @end deffn @cindex magit-section-show-headings @deffn Command magit-section-show-headings Recursively show headings of children of the current section. Only show the headings. Previously shown text-only bodies are hidden. @end deffn @cindex magit-section-show-children @deffn Command magit-section-show-children Recursively show the bodies of children of the current section. With a prefix argument show children down to the level of the current section, and hide deeper children. @end deffn @cindex magit-section-hide-children @deffn Command magit-section-hide-children Recursively hide the bodies of children of the current section. @end deffn @cindex magit-section-toggle-children @deffn Command magit-section-toggle-children Toggle visibility of bodies of children of the current section. @end deffn When a buffer is first created then some sections are shown expanded while others are not. This is hard coded. When a buffer is refreshed then the previous visibility is preserved. The initial visibility of certain sections can also be overwritten using the hook @code{magit-section-set-visibility-hook}. @defopt magit-section-initial-visibility-alist This options can be used to override the initial visibility of sections. In the future it will also be used to define the defaults, but currently a section's default is still hardcoded. The value is an alist. Each element maps a section type or lineage to the initial visibility state for such sections. The state has to be one of @code{show} or @code{hide}, or a function that returns one of these symbols. A function is called with the section as the only argument. Use the command @code{magit-describe-section-briefly} to determine a section's lineage or type. The vector in the output is the section lineage and the type is the first element of that vector. Wildcards can be used, see @code{magit-section-match}. @end defopt @defopt magit-section-cache-visibility This option controls for which sections the previous visibility state should be restored if a section disappears and later appears again. The value is a boolean or a list of section types. If t, then the visibility of all sections is cached. Otherwise this is only done for sections whose type matches one of the listed types. This requires that the function @code{magit-section-cached-visibility} is a member of @code{magit-section-set-visibility-hook}. @end defopt @defvar magit-section-set-visibility-hook This hook is run when first creating a buffer and also when refreshing an existing buffer, and is used to determine the visibility of the section currently being inserted. Each function is called with one argument, the section being inserted. It should return @code{hide} or @code{show}, or to leave the visibility undefined @code{nil}. If no function decides on the visibility and the buffer is being refreshed, then the visibility is preserved; or if the buffer is being created, then the hard coded default is used. Usually this should only be used to set the initial visibility but not during refreshes. If @code{magit-insert-section--oldroot} is non-nil, then the buffer is being refreshed and these functions should immediately return @code{nil}. @end defvar @node Section Hooks @subsection Section Hooks Which sections are inserted into certain buffers is controlled with hooks. This includes the status and the refs buffers. For other buffers, e.g. log and diff buffers, this is not possible. The command @code{magit-describe-section} can be used to see which hook (if any) was responsible for inserting the section at point. For buffers whose sections can be customized by the user, a hook variable called @code{magit-TYPE-sections-hook} exists. This hook should be changed using @code{magit-add-section-hook}. Avoid using @code{add-hooks} or the Custom interface. The various available section hook variables are described later in this manual along with the appropriate "section inserter functions". @defun magit-add-section-hook hook function &optional at append local Add the function FUNCTION to the value of section hook HOOK@. Add FUNCTION at the beginning of the hook list unless optional APPEND is non-nil, in which case FUNCTION is added at the end. If FUNCTION already is a member then move it to the new location. If optional AT is non-nil and a member of the hook list, then add FUNCTION next to that instead. Add before or after AT, or replace AT with FUNCTION depending on APPEND@. If APPEND is the symbol @code{replace}, then replace AT with FUNCTION@. For any other non-nil value place FUNCTION right after AT@. If nil, then place FUNCTION right before AT@. If FUNCTION already is a member of the list but AT is not, then leave FUNCTION where ever it already is. If optional LOCAL is non-nil, then modify the hook's buffer-local value rather than its global value. This makes the hook local by copying the default value. That copy is then modified. HOOK should be a symbol. If HOOK is void, it is first set to nil. HOOK's value must not be a single hook function. FUNCTION should be a function that takes no arguments and inserts one or multiple sections at point, moving point forward. FUNCTION may choose not to insert its section(s), when doing so would not make sense. It should not be abused for other side-effects. @end defun To remove a function from a section hook, use @code{remove-hook}. @node Section Types and Values @subsection Section Types and Values Each section has a type, for example @code{hunk}, @code{file}, and @code{commit}. Instances of certain section types also have a value. The value of a section of type @code{file}, for example, is a file name. Users usually do not have to worry about a section's type and value, but knowing them can be handy at times. @table @asis @kindex M-x magit-describe-section-briefly @cindex magit-describe-section-briefly @item @kbd{M-x magit-describe-section-briefly} @tie{}@tie{}@tie{}@tie{}(@code{magit-describe-section-briefly}) Show information about the section at point in the echo area, as "#". @end table Many commands behave differently depending on the type of the section at point and/or somehow consume the value of that section. But that is only one of the reasons why the same key may do something different, depending on what section is current. Additionally for each section type a keymap @strong{might} be defined, named @code{magit-TYPE-section-map}. That keymap is used as text property keymap of all text belonging to any section of the respective type. If such a map does not exist for a certain type, then you can define it yourself, and it will automatically be used. @node Section Options @subsection Section Options This section describes options that have an effect on more than just a certain type of sections. As you can see there are not many of those. @defopt magit-section-show-child-count Whether to append the number of children to section headings. This only affects sections that could benefit from this information. @end defopt @node Popup Buffers and Prefix Commands @section Popup Buffers and Prefix Commands Many Magit commands are implemented using @strong{popup buffers}. First the user invokes a @strong{popup} or @strong{prefix} command, which causes a popup buffer with the available @strong{infix} arguments and @strong{suffix} commands to be displayed. The user then optionally toggles/sets some arguments and finally invokes one of the suffix commands. This is implemented in the library @code{magit-popup}. Earlier releases used the library @code{magit-key-mode}. A future release will switch to a yet-to-be-written successor, which will likely be named @code{transient}. Because @code{magit-popup} can also be used by other packages without having to depend on all of Magit, it is documented in its own manual. See @ref{Top,,,magit-popup,}. @table @asis @kindex C-c C-c @cindex magit-dispatch-popup @item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{magit-dispatch-popup}) This popup command shows a buffer featuring all other Magit popup commands as well as some other commands that are not popup commands themselves. @end table This command is also, or especially, useful outside Magit buffers, so you should setup a global binding: @lisp (global-set-key (kbd "C-x M-g") 'magit-dispatch-popup) @end lisp Most popups set their initial arguments according to the corresponding @code{magit-*-arguments} variable. Two popups, the log and diff popups (see @ref{Logging} and @ref{Diffing}), may behave a bit differently, depending on the value of @code{magit-use-sticky-arguments}. @defopt magit-use-sticky-arguments This option controls how diff and log commands reuse arguments from existing buffers. When @code{t} (the default value), the log or diff popup reuses the arguments from the current repository's log or diff buffer, respectively. When no log or diff buffer exists for the current repository, these popups use the default value of @code{magit-log-arguments} or @code{magit-diff-arguments}. When @code{current}, log and diff popups will only reuse the arguments if the current buffer is derived from @code{magit-log-mode} or @code{magit-diff-mode}, respectively. When @code{nil}, the default value of @code{magit-log-arguments} or @code{magit-diff-arguments} is always used. @end defopt @node Completion Confirmation and the Selection @section Completion, Confirmation and the Selection @menu * Action Confirmation:: * Completion and Confirmation:: * The Selection:: * The hunk-internal region:: * Support for Completion Frameworks:: * Additional Completion Options:: @end menu @node Action Confirmation @subsection Action Confirmation By default many actions that could potentially lead to data loss have to be confirmed. This includes many very common actions, so this can quickly become annoying. Many of these actions can be undone and if you have thought about how to undo certain mistakes, then it should be safe to disable confirmation for the respective actions. The option @code{magit-no-confirm} can be used to tell Magit to perform certain actions without the user having to confirm them. Note that while this option can only be used to disable confirmation for a specific set of actions, the next section explains another way of telling Magit to ask fewer questions. @defopt magit-no-confirm The value of this option is a list of symbols, representing actions that do not have to be confirmed by the user before being carried out. By default many potentially dangerous commands ask the user for confirmation. Each of the below symbols stands for an action which, when invoked unintentionally or without being fully aware of the consequences, could lead to tears. In many cases there are several commands that perform variations of a certain action, so we don't use the command names but more generic symbols. @itemize @item Applying changes: @itemize @item @code{discard} Discarding one or more changes (i.e. hunks or the complete diff for a file) loses that change, obviously. @item @code{reverse} Reverting one or more changes can usually be undone by reverting the reversion. @item @code{stage-all-changes}, @code{unstage-all-changes} When there are both staged and unstaged changes, then un-/staging everything would destroy that distinction. Of course that also applies when un-/staging a single change, but then less is lost and one does that so often that having to confirm every time would be unacceptable. @end itemize @item Files: @itemize @item @code{delete} When a file that isn't yet tracked by Git is deleted, then it is completely lost, not just the last changes. Very dangerous. @item @code{trash} Instead of deleting a file it can also be move to the system trash. Obviously much less dangerous than deleting it. Also see option @code{magit-delete-by-moving-to-trash}. @item @code{resurrect} A deleted file can easily be resurrected by "deleting" the deletion, which is done using the same command that was used to delete the same file in the first place. @item @code{untrack} Untracking a file can be undone by tracking it again. @item @code{rename} Renaming a file can easily be undone. @end itemize @item Sequences: @itemize @item @code{reset-bisect} Aborting (known to Git as "resetting") a bisect operation loses all information collected so far. @item @code{abort-rebase} Aborting a rebase throws away all already modified commits, but it's possible to restore those from the reflog. @item @code{abort-merge} Aborting a merge throws away all conflict resolutions which have already been carried out by the user. @item @code{merge-dirty} Merging with a dirty worktree can make it hard to go back to the state before the merge was initiated. @end itemize @item References: @itemize @item @code{delete-unmerged-branch} Once a branch has been deleted, it can only be restored using low-level recovery tools provided by Git. And even then the reflog is gone. The user always has to confirm the deletion of a branch by accepting the default choice (or selecting another branch), but when a branch has not been merged yet, also make sure the user is aware of that. @item @code{delete-pr-branch} When deleting a branch that was created from a pull request and if no other branches still exist on that remote, then `magit-branch-delete' offers to delete the remote as well. This should be safe because it only happens if no other refs exist in the remotes namespace, and you can recreate the remote if necessary. @item @code{drop-stashes} Dropping a stash is dangerous because Git stores stashes in the reflog. Once a stash is removed, there is no going back without using low-level recovery tools provided by Git. When a single stash is dropped, then the user always has to confirm by accepting the default (or selecting another). This action only concerns the deletion of multiple stashes at once. @end itemize @item Edit published history: Without adding these symbols here, you will be warned before editing commits that have already been pushed to one of the branches listed in @code{magit-published-branches}. @itemize @item @code{amend-published} Affects most commands that amend to "HEAD". @item @code{rebase-published} Affects commands that perform interactive rebases. This includes commands from the commit popup that modify a commit other than "HEAD", namely the various fixup and squash variants. @item @code{edit-published} Affects the commands @code{magit-edit-line-commit} and @code{magit-diff-edit-hunk-commit}. These two commands make it quite easy to accidentally edit a published commit, so you should think twice before configuring them not to ask for confirmation. @end itemize To disable confirmation completely, add all three symbols here or set @code{magit-published-branches} to @code{nil}. @item Various: @itemize @item @code{kill-process} There seldom is a reason to kill a process. @end itemize @item Global settings: Instead of adding all of the above symbols to the value of this option, you can also set it to the atom `t', which has the same effect as adding all of the above symbols. Doing that most certainly is a bad idea, especially because other symbols might be added in the future. So even if you don't want to be asked for confirmation for any of these actions, you are still better of adding all of the respective symbols individually. When @code{magit-wip-before-change-mode} is enabled, then the following actions can be undone fairly easily: @code{discard}, @code{reverse}, @code{stage-all-changes}, and @code{unstage-all-changes}. If and only if this mode is enabled, then @code{safe-with-wip} has the same effect as adding all of these symbols individually. @end itemize @end defopt @node Completion and Confirmation @subsection Completion and Confirmation Many Magit commands ask the user to select from a list of possible things to act on, while offering the most likely choice as the default. For many of these commands the default is the thing at point, provided that it actually is a valid thing to act on. For many commands that act on a branch, the current branch serves as the default if there is no branch at point. These commands combine asking for confirmation and asking for a target to act on into a single action. The user can confirm the default target using @code{RET} or abort using @code{C-g}. This is similar to a @code{y-or-n-p} prompt, but the keys to confirm or abort differ. At the same time the user is also given the opportunity to select another target, which is useful because for some commands and/or in some situations you might want to select the action before selecting the target by moving to it. However you might find that for some commands you always want to use the default target, if any, or even that you want the command to act on the default without requiring any confirmation at all. The option @code{magit-dwim-selection} can be used to configure certain commands to that effect. Note that when the region is active then many commands act on the things that are selected using a mechanism based on the region, in many cases after asking for confirmation. This region-based mechanism is called the "selection" and is described in detail in the next section. When a selection exists that is valid for the invoked command, then that command never offers to act on something else, and whether it asks for confirmation is not controlled by this option. Also note that Magit asks for confirmation of certain actions that are not coupled with completion (or the selection). Such dialogs are also not affected by this option and are described in the previous section. @defopt magit-dwim-selection @end defopt This option can be used to tell certain commands to use the thing at point instead of asking the user to select a candidate to act on, with or without confirmation. The value has the form @code{((COMMAND nil|PROMPT DEFAULT)...)}. @itemize @item COMMAND is the command that should not prompt for a choice. To have an effect, the command has to use the function @code{magit-completing-read} or a utility function which in turn uses that function. @item If the command uses @code{magit-completing-read} multiple times, then PROMPT can be used to only affect one of these uses. PROMPT, if non-nil, is a regular expression that is used to match against the PROMPT argument passed to @code{magit-completing-read}. @item DEFAULT specifies how to use the default. If it is @code{t}, then the DEFAULT argument passed to @code{magit-completing-read} is used without confirmation. If it is @code{ask}, then the user is given a chance to abort. DEFAULT can also be @code{nil}, in which case the entry has no effect. @end itemize @node The Selection @subsection The Selection If the region is active, then many Magit commands act on the things that are selected using a mechanism based on the region instead of one single thing. When the region is not active, then these commands act on the thing at point or read a single thing to act on. This is described in the previous section — this section only covers how multiple things are selected, how that is visualized, and how certain commands behave when that is the case. Magit's mechanism for selecting multiple things, or rather sections that represent these things, is based on the Emacs region, but the area that Magit considers to be selected is typically larger than the region and additional restrictions apply. Magit makes a distinction between a region that qualifies as forming a valid Magit selection and a region that does not. If the region does not qualify, then it is displayed as it is in other Emacs buffers. If the region does qualify as a Magit selection, then the selection is always visualized, while the region itself is only visualized if it begins and ends on the same line. For a region to qualify as a Magit selection, it must begin in the heading of one section and end in the heading of a sibling section. Note that if the end of the region is at the very beginning of section heading (i.e. at the very beginning of a line) then that section is considered to be @strong{inside} the selection. This is not consistent with how the region is normally treated in Emacs — if the region ends at the beginning of a line, then that line is outside the region. Due to how Magit visualizes the selection, it should be obvious that this difference exists. Not every command acts on every valid selection. Some commands do not even consider the location of point, others may act on the section at point but not support acting on the selection, and even commands that do support the selection of course only do so if it selects things that they can act on. This is the main reason why the selection must include the section at point. Even if a selection exists, the invoked command may disregard it, in which case it may act on the current section only. It is much safer to only act on the current section but not the other selected sections than it is to act on the current section @strong{instead} of the selected sections. The latter would be much more surprising and if the current section always is part of the selection, then that cannot happen. @defvar magit-keep-region-overlay This variable controls whether the region is visualized as usual even when a valid Magit selection or a hunk-internal region exists. See the doc-string for more information. @end defvar @node The hunk-internal region @subsection The hunk-internal region Somewhat related to the Magit selection described in the previous section is the hunk-internal region. Like the selection, the hunk-internal region is based on the Emacs region but causes that region to not be visualized as it would in other Emacs buffers, and includes the line on which the region ends even if it ends at the very beginning of that line. Unlike the selection, which is based on a region that must begin in the heading of one section and ends in the section of a sibling section, the hunk-internal region must begin inside the @strong{body} of a hunk section and end in the body of the @strong{same} section. The hunk-internal region is honored by "apply" commands, which can, among other targets, act on a hunk. If the hunk-internal region is active, then such commands act only on the marked part of the hunk instead of on the complete hunk. @node Support for Completion Frameworks @subsection Support for Completion Frameworks The built-in option @code{completing-read-function} specifies the low-level function used by @code{completing-read} to ask a user to select from a list of choices. Its default value is @code{completing-read-default}. Alternative completion frameworks typically activate themselves by substituting their own implementation. Mostly for historic reasons Magit provides a similar option named @code{magit-completing-read-function}, which only controls the low-level function used by @code{magit-completing-read}. This option also makes it possible to use a different completing mechanism for Magit than for the rest of Emacs, but doing that is not recommend. You most likely don't have to customize the magit-specific option to use an alternative completion framework. For example, if you enable @code{ivy-mode}, then Magit will respect that, and if you enable @code{helm-mode}, then you are done too. However if you want to use Ido, then @code{ido-mode} won't do the trick. You will also have to install the @code{ido-completing-read+} package and use @code{magit-ido-completing-read} as @code{magit-completing-read-function}. @defopt magit-completing-read-function The value of this variable is the low-level function used to perform completion by code that uses @code{magit-completing-read} (as opposed to the built-in @code{completing-read}). The default value, @code{magit-builtin-completing-read}, is suitable for the standard completion mechanism, @code{ivy-mode}, and @code{helm-mode} at least. The built-in @code{completing-read} and @code{completing-read-default} are @strong{not} suitable to be used here. @code{magit-builtin-completing-read} performs some additional work, and any function used in its place has to do the same. @end defopt @defun magit-builtin-completing-read prompt choices &optional predicate require-match initial-input hist def This function performs completion using the built-in @code{completion-read} and does some additional magit-specific work. @end defun @defun magit-ido-completing-read prompt choices &optional predicate require-match initial-input hist def This function performs completion using @code{ido-completing-read+} from the package by the same name (which you have to explicitly install) and does some additional magit-specific work. We have to use @code{ido-completing-read+} instead of the @code{ido-completing-read} that comes with Ido itself, because the latter, while intended as a drop-in replacement, cannot serve that purpose because it violates too many of the implicit conventions. @end defun @defun magit-completing-read prompt choices &optional predicate require-match initial-input hist def fallback This is the function that Magit commands use when they need the user to select a single thing to act on. The arguments have the same meaning as for @code{completing-read}, except for FALLBACK, which is unique to this function and is described below. Instead of asking the user to choose from a list of possible candidates, this function may just return the default specified by DEF, with or without requiring user confirmation. Whether that is the case depends on PROMPT, @code{this-command} and @code{magit-dwim-selection}. See the documentation of the latter for more information. If it does read a value in the minibuffer, then this function acts similar to @code{completing-read}, except for the following: @itemize @item If REQUIRE-MATCH is @code{nil} and the user exits without a choice, then @code{nil} is returned instead of an empty string. @item If REQUIRE-MATCH is non-nil and the users exits without a choice, an user-error is raised. @item FALLBACK specifies a secondary default that is only used if the primary default DEF is @code{nil}. The secondary default is not subject to @code{magit-dwim-selection} — if DEF is @code{nil} but FALLBACK is not, then this function always asks the user to choose a candidate, just as if both defaults were @code{nil}. @item ": " is appended to PROMPT@. @item PROMPT is modified to end with \" (default DEF|FALLBACK): \" provided that DEF or FALLBACK is non-nil, that neither @code{ivy-mode} nor @code{helm-mode} is enabled, and that @code{magit-completing-read-function} is set to its default value of @code{magit-builtin-completing-read}. @end itemize @end defun @node Additional Completion Options @subsection Additional Completion Options @defopt magit-list-refs-sortby For many commands that read a ref or refs from the user, the value of this option can be used to control the order of the refs. Valid values include any key accepted by the @code{--sort} flag of @code{git for-each-ref}. By default, refs are sorted alphabetically by their full name (e.g., "refs/heads/master"). @end defopt @node Running Git @section Running Git @menu * Viewing Git Output:: * Git Process Status:: * Running Git Manually:: * Git Executable:: * Global Git Arguments:: @end menu @node Viewing Git Output @subsection Viewing Git Output Magit runs Git either for side-effects (e.g. when pushing) or to get some value (e.g. the name of the current branch). When Git is run for side-effects, the process output is logged in a per-repository log buffer, which can be consulted using the @code{magit-process} command when things don't go as expected. The output/errors for up to `magit-process-log-max' Git commands are retained. @table @asis @kindex $ @cindex magit-process @item @kbd{$} @tie{}@tie{}@tie{}@tie{}(@code{magit-process}) This commands displays the process buffer for the current repository. @end table Inside that buffer, the usual key bindings for navigating and showing sections are available. There is one additional command. @table @asis @kindex k @cindex magit-process-kill @item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-process-kill}) This command kills the process represented by the section at point. @end table @defopt magit-git-debug When this is non-nil then the output of all calls to git are logged in the process buffer. This is useful when debugging, otherwise it just negatively affects performance. @end defopt @node Git Process Status @subsection Git Process Status When a Git process is running for side-effects, Magit displays an indicator in the mode line, using the @code{magit-mode-line-process} face. If the Git process exits successfully, the process indicator is removed from the mode line immediately. In the case of a Git error, the process indicator is not removed, but is instead highlighted with the @code{magit-mode-line-process-error} face, and the error details from the process buffer are provided as a tooltip for mouse users. This error indicator persists in the mode line until the next magit buffer refresh. If you do not wish process errors to be indicated in the mode line, customize the @code{magit-process-display-mode-line-error} user option. Process errors are additionally indicated at the top of the status buffer. @node Running Git Manually @subsection Running Git Manually While Magit provides many Emacs commands to interact with Git, it does not cover everything. In those cases your existing Git knowledge will come in handy. Magit provides some commands for running arbitrary Git commands by typing them into the minibuffer, instead of having to switch to a shell. @table @asis @kindex ! @cindex magit-run-popup @item @kbd{!} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-popup}) Shows the popup buffer featuring the below suffix commands. @kindex ! ! @cindex magit-git-command-topdir @item @kbd{! !} @tie{}@tie{}@tie{}@tie{}(@code{magit-git-command-topdir}) This command reads a command from the user and executes it in the top-level directory of the current working tree. The string "git " is used as initial input when prompting the user for the command. It can be removed to run another command. @kindex ! p @cindex magit-git-command @item @kbd{! p} @tie{}@tie{}@tie{}@tie{}(@code{magit-git-command}) This command reads a command from the user and executes it in @code{default-directory}. With a prefix argument the command is executed in the top-level directory of the current working tree instead. The string "git " is used as initial input when prompting the user for the command. It can be removed to run another command. @kindex ! s @cindex magit-shell-command-topdir @item @kbd{! s} @tie{}@tie{}@tie{}@tie{}(@code{magit-shell-command-topdir}) This command reads a command from the user and executes it in the top-level directory of the current working tree. @kindex ! S @cindex magit-shell-command @item @kbd{! S} @tie{}@tie{}@tie{}@tie{}(@code{magit-shell-command}) This command reads a command from the user and executes it in @code{default-directory}. With a prefix argument the command is executed in the top-level directory of the current working tree instead. @end table @defopt magit-shell-command-verbose-prompt Whether the prompt, used by the the above commands when reading a shell command, shows the directory in which it will be run. @end defopt These suffix commands start external gui tools. @table @asis @kindex ! k @cindex magit-run-gitk @item @kbd{! k} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk}) This command runs @code{gitk} in the current repository. @kindex ! a @cindex magit-run-gitk-all @item @kbd{! a} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk-all}) This command runs @code{gitk --all} in the current repository. @kindex ! b @cindex magit-run-gitk-branches @item @kbd{! b} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-gitk-branches}) This command runs @code{gitk --branches} in the current repository. @kindex ! g @cindex magit-run-git-gui @item @kbd{! g} @tie{}@tie{}@tie{}@tie{}(@code{magit-run-git-gui}) This command runs @code{git gui} in the current repository. @end table @node Git Executable @subsection Git Executable Except on MS Windows, Magit defaults to running Git without specifying the path to the git executable. Instead the first executable found by Emacs on @code{exec-path} is used (whose value in turn is set based on the value of the environment variable @code{$PATH} when Emacs was started). This has the advantage that it continues to work even when using Tramp to connect to a remote machine on which the executable is found in a different place. The downside is that if you have multiple versions of Git installed, then you might end up using another version than the one you think you are using. @table @asis @kindex M-x magit-version @cindex magit-version @item @kbd{M-x magit-version} @tie{}@tie{}@tie{}@tie{}(@code{magit-version}) This command shows the currently used versions of Magit, Git, and Emacs in the echo area. Non-interactively this just returns the Magit version. @end table When the @code{system-type} is @code{windows-nt}, then @code{magit-git-executable} is set to an absolute path when Magit is first loaded. This is necessary because Git on that platform comes with several wrapper scripts for the actual git binary, which are also placed on @code{$PATH}, and using one of these wrappers instead of the binary would degrade performance horribly. If Magit doesn't find the correct executable then you @strong{can} work around that by setting @code{magit-git-executable} to an absolute path. But note that doing so is a kludge. It is better to make sure the order in the environment variable @code{$PATH} is correct, and that Emacs is started with that environment in effect. The command @code{magit-debug-git-executable} can be useful to find out where Emacs is searching for git. If you have to connect from Windows to a non-Windows machine, then you must change the value to "git". @defopt magit-git-executable The git executable used by Magit, either the full path to the executable or the string "git" to let Emacs find the executable itself, using the standard mechanism for doing such things. @end defopt @table @asis @kindex M-x magit-debug-git-executable @cindex magit-debug-git-executable @item @kbd{M-x magit-debug-git-executable} @tie{}@tie{}@tie{}@tie{}(@code{magit-debug-git-executable}) Display a buffer with information about @code{magit-git-executable}. @end table @node Global Git Arguments @subsection Global Git Arguments @defopt magit-git-global-arguments The arguments set here are used every time the git executable is run as a subprocess. They are placed right after the executable itself and before the git command - as in @code{git HERE... COMMAND REST}. For valid arguments see @ifinfo @ref{git,,,gitman,}. @end ifinfo @ifhtml @html the git(1) manpage. @end html @end ifhtml @iftex the git(1) manpage. @end iftex Be careful what you add here, especially if you are using Tramp to connect to servers with ancient Git versions. Never remove anything that is part of the default value, unless you really know what you are doing. And think very hard before adding something; it will be used every time Magit runs Git for any purpose. @end defopt @node Inspecting @chapter Inspecting The functionality provided by Magit can be roughly divided into three groups: inspecting existing data, manipulating existing data or adding new data, and transferring data. Of course that is a rather crude distinction that often falls short, but it's more useful than no distinction at all. This section is concerned with inspecting data, the next two with manipulating and transferring it. Then follows a section about miscellaneous functionality, which cannot easily be fit into this distinction. Of course other distinctions make sense too, e.g. Git's distinction between porcelain and plumbing commands, which for the most part is equivalent to Emacs' distinction between interactive commands and non-interactive functions. All of the sections mentioned before are mainly concerned with the porcelain -- Magit's plumbing layer is described later. @menu * Status Buffer:: * Repository List:: * Logging:: * Diffing:: * Ediffing:: * References Buffer:: * Bisecting:: * Visiting Blobs:: * Blaming:: @end menu @node Status Buffer @section Status Buffer While other Magit buffers contain e.g. one particular diff or one particular log, the status buffer contains the diffs for staged and unstaged changes, logs for unpushed and unpulled commits, lists of stashes and untracked files, and information related to the current branch. During certain incomplete operations -- for example when a merge resulted in a conflict -- additional information is displayed that helps proceeding with or aborting the operation. The command @code{magit-status} displays the status buffer belonging to the current repository in another window. This command is used so often that it should be bound globally. We recommend using @code{C-x g}: @lisp (global-set-key (kbd "C-x g") 'magit-status) @end lisp @table @asis @kindex C-x g @cindex magit-status @item @kbd{C-x g} @tie{}@tie{}@tie{}@tie{}(@code{magit-status}) Show the status of the current Git repository in a buffer. With a prefix argument prompt for a repository to be shown. With two prefix arguments prompt for an arbitrary directory. If that directory isn't the root of an existing repository, then offer to initialize it as a new repository. @end table @defopt magit-repository-directories List of directories that are Git repositories or contain Git repositories. Each element has the form @code{(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. @end defopt @defopt magit-repository-directories-depth The maximum depth to look for Git repositories. This option is obsolete and only used for elements of the option @code{magit-repository-directories} (which see) that don't specify the depth directly. @end defopt @cindex ido-enter-magit-status @deffn Command ido-enter-magit-status From an Ido prompt used to open a file, instead drop into @code{magit-status}. This is similar to @code{ido-magic-delete-char}, which, despite its name, usually causes a Dired buffer to be created. To make this command available, use something like: @lisp (add-hook 'ido-setup-hook (lambda () (define-key ido-completion-map (kbd \"C-x g\") 'ido-enter-magit-status))) @end lisp 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: @lisp (define-key ido-common-completion-map (kbd \"C-x g\") 'ido-enter-magit-status) @end lisp @end deffn @menu * Status Sections:: * Status Header Sections:: * Status Module Sections:: * Status Options:: @end menu @node Status Sections @subsection Status Sections The contents of status buffers is controlled using the hook @code{magit-status-sections-hook}. See @ref{Section Hooks} to learn about such hooks and how to customize them. @defopt magit-status-sections-hook Hook run to insert sections into a status buffer. @end defopt The first function on that hook by default is @code{magit-insert-status-headers}; it is described in the next section. By default the following functions are also members of that hook: @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. @end defun @defun magit-insert-rebase-sequence Insert section for the on-going rebase sequence. If no such sequence is in progress, do nothing. @end defun @defun magit-insert-am-sequence Insert section for the on-going patch applying sequence. If no such sequence is in progress, do nothing. @end defun @defun magit-insert-sequencer-sequence Insert section for the on-going cherry-pick or revert sequence. If no such sequence is in progress, do nothing. @end defun @defun magit-insert-bisect-output While bisecting, insert section with output from @code{git bisect}. @end defun @defun magit-insert-bisect-rest While bisecting, insert section visualizing the bisect state. @end defun @defun magit-insert-bisect-log While bisecting, insert section logging bisect progress. @end defun @defun magit-insert-untracked-files Maybe insert a list or tree of untracked files. Do so depending on the value of @code{status.showUntrackedFiles}. Note that even if the value is @code{all}, Magit still initially only shows directories. But the directory sections can then be expanded using @code{TAB}. @end defun @defun magit-insert-unstaged-changes Insert section showing unstaged changes. @end defun @defun magit-insert-staged-changes Insert section showing staged changes. @end defun @defun magit-insert-stashes &optional ref heading Insert the @code{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:". @end defun @defun magit-insert-unpulled-from-upstream Insert section showing commits that haven't been pulled from the upstream branch yet. @end defun @defun magit-insert-unpulled-from-pushremote Insert section showing commits that haven't been pulled from the push-remote branch yet. @end defun @defun magit-insert-unpushed-to-upstream Insert section showing commits that haven't been pushed to the upstream yet. @end defun @defun magit-insert-unpushed-to-pushremote Insert section showing commits that haven't been pushed to the push-remote yet. @end defun The following functions can also be added to the above hook: @defun magit-insert-tracked-files Insert a tree of tracked files. @end defun @defun magit-insert-ignored-files Insert a tree of ignored files. If the first element of @code{magit-diff-section-arguments} is a directory, then limit the list to files below that. The value of that variable can be set using @code{D = f RET g}. @end defun @defun magit-insert-unpulled-or-recent-commits Insert section showing unpulled or recent commits. If an upstream is configured for the current branch and it is ahead of the current branch, then show the missing commits. Otherwise, show the last @code{magit-log-section-commit-count} commits. @end defun @defun magit-insert-recent-commits Insert section showing the last @code{magit-log-section-commit-count} commits. @end defun @defopt magit-log-section-commit-count How many recent commits @code{magit-insert-recent-commits} and @code{magit-insert-unpulled-or-recent-commits} (provided there are no unpulled commits) show. @end defopt @defun magit-insert-unpulled-cherries Insert section showing unpulled commits. Like @code{magit-insert-unpulled-commits} but prefix each commit that has not been applied yet (i.e. a commit with a patch-id not shared with any local commit) with "+", and all others with "-". @end defun @defun magit-insert-unpushed-cherries Insert section showing unpushed commits. Like @code{magit-insert-unpushed-commits} but prefix each commit which has not been applied to upstream yet (i.e. a commit with a patch-id not shared with any upstream commit) with "+" and all others with "-". @end defun See @ref{References Buffer} for some more section inserters, which could be used here. @node Status Header Sections @subsection Status Header Sections The contents of status buffers is controlled using the hook @code{magit-status-sections-hook} (see @ref{Status Sections}). By default @code{magit-insert-status-headers} is the first member of that hook variable. @defun magit-insert-status-headers Insert headers sections appropriate for @code{magit-status-mode} buffers. The sections are inserted by running the functions on the hook @code{magit-status-headers-hook}. @end defun @defopt magit-status-headers-hook Hook run to insert headers sections into the status buffer. This hook is run by @code{magit-insert-status-headers}, which in turn has to be a member of @code{magit-status-sections-hook} to be used at all. @end defopt By default the following functions are members of the above hook: @defun magit-insert-error-header Insert a header line showing 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. @end defun @defun magit-insert-diff-filter-header Insert a header line showing the effective diff filters. @end defun @defun magit-insert-head-branch-header Insert a header line about the current branch or detached @code{HEAD}. @end defun @defun magit-insert-upstream-branch-header Insert a header line about the branch that is usually pulled into the current branch. @end defun @defun magit-insert-push-branch-header Insert a header line about the branch that the current branch is usually pushed to. @end defun @defun magit-insert-tags-header Insert a header line about the current and/or next tag, along with the number of commits between the tag and @code{HEAD}. @end defun The following functions can also be added to the above hook: @defun magit-insert-repo-header Insert a header line showing the path to the repository top-level. @end defun @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. @end defun @defun magit-insert-user-header Insert a header line about the current user. @end defun @node Status Module Sections @subsection Status Module Sections The contents of status buffers is controlled using the hook @code{magit-status-sections-hook} (see @ref{Status Sections}). By default @code{magit-insert-modules} is @emph{not} a member of that hook variable. @defun magit-insert-modules Insert submodule sections. Hook @code{magit-module-sections-hook} controls which module sections are inserted, and option @code{magit-module-sections-nested} controls whether they are wrapped in an additional section. @end defun @defopt magit-module-sections-hook Hook run by @code{magit-insert-modules}. @end defopt @defopt magit-module-sections-nested This option controls whether @code{magit-insert-modules} wraps inserted sections in an additional section. If this is non-nil, then only a single top-level section is inserted. If it is nil, then all sections listed in @code{magit-module-sections-hook} become top-level sections. @end defopt @defun magit-insert-modules-overview Insert sections for all submodules. For each section insert the path, the branch, and the output of @code{git describe --tags}, or, failing that, the abbreviated HEAD commit hash. Press @code{RET} on such a submodule section to show its own status buffer. Press @code{RET} on the "Modules" section to display a list of submodules in a separate buffer. This shows additional information not displayed in the super-repository's status buffer. @end defun @defun magit-insert-modules-unpulled-from-upstream Insert sections for modules that haven't been pulled from the upstream yet. These sections can be expanded to show the respective commits. @end defun @defun magit-insert-modules-unpulled-from-pushremote Insert sections for modules that haven't been pulled from the push-remote yet. These sections can be expanded to show the respective commits. @end defun @defun magit-insert-modules-unpushed-to-upstream Insert sections for modules that haven't been pushed to the upstream yet. These sections can be expanded to show the respective commits. @end defun @defun magit-insert-modules-unpushed-to-pushremote Insert sections for modules that haven't been pushed to the push-remote yet. These sections can be expanded to show the respective commits. @end defun @node Status Options @subsection Status Options @defopt magit-status-refresh-hook Hook run after a status buffer has been refreshed. @end defopt @defopt magit-status-margin This option specifies whether the margin is initially shown in Magit-Status mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @defopt magit-log-section-args Additional Git arguments used when creating log sections. Only @code{--graph}, @code{--decorate}, and @code{--show-signature} are supported. This option is only a temporary kludge and will be removed. Note that due to an issue in Git the use of @code{--graph} is very slow with long histories, so you probably don't want to add this here. @end defopt Also see the proceeding section for more options concerning status buffers. @node Repository List @section Repository List @cindex magit-list-repositories @deffn Command magit-list-repositories This command displays a list of repositories in a separate buffer. The options @code{magit-repository-directories} and @code{magit-repository-directories-depth} control which repositories are displayed. @end deffn @defopt magit-repolist-columns This option controls what columns are displayed by the command @code{magit-list-repositories} and how they are displayed. Each element has the form @code{(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 @code{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 @code{:right-align} and @code{:pad-right}. @end defopt The following functions can be added to the above option: @defun magit-repolist-column-ident This function inserts the identification of the repository. Usually this is just its basename. @end defun @defun magit-repolist-column-path This function inserts the absolute path of the repository. @end defun @defun magit-repolist-column-version This function inserts a description of the repository's @code{HEAD} revision. @end defun @defun magit-repolist-column-unpulled-from-upstream This function inserts the number of upstream commits not in the current branch. @end defun @defun magit-repolist-column-unpulled-from-pushremote This function inserts the number of commits in the push branch but not the current branch. @end defun @defun magit-repolist-column-unpushed-to-upstream This function inserts the number of commits in the current branch but not its upstream. @end defun @defun magit-repolist-column-unpushed-to-pushremote This function inserts the number of commits in the current branch but not its push branch. @end defun @node Logging @section Logging The status buffer contains logs for the unpushed and unpulled commits, but that obviously isn't enough. The prefix command @code{magit-log-popup}, on @code{l}, features several suffix commands, which show a specific log in a separate log buffer. Like other popups, the log popup also features several arguments that can be changed before invoking one of the suffix commands. However, in the case of the log popup, these arguments may be taken from those currently in use in the current repository's log buffer, depending on the value of @code{magit-use-sticky-arguments} (see @ref{Popup Buffers and Prefix Commands}). For information about the various arguments, see @ifinfo @ref{git-log,,,gitman,}. @end ifinfo @ifhtml @html the git-log(1) manpage. @end html @end ifhtml @iftex the git-log(1) manpage. @end iftex The switch @code{++order=VALUE} is converted to one of @code{--author-date-order}, @code{--date-order}, or @code{--topo-order} before being passed to @code{git log}. The log popup also features several reflog commands. See @ref{Reflog}. @table @asis @kindex l @cindex magit-log-popup @item @kbd{l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex l l @cindex magit-log-current @item @kbd{l l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-current}) Show log for the current branch. When @code{HEAD} is detached or with a prefix argument, show log for one or more revs read from the minibuffer. @kindex l o @cindex magit-log-other @item @kbd{l o} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-other}) Show log for one or more revs read from the minibuffer. The user can input any revision or revisions separated by a space, or even ranges, but only branches, tags, and a representation of the commit at point are available as completion candidates. @kindex l h @cindex magit-log-head @item @kbd{l h} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-head}) Show log for @code{HEAD}. @kindex l L @cindex magit-log-branches @item @kbd{l L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-branches}) Show log for all local branches and @code{HEAD}. @kindex l b @cindex magit-log-all-branches @item @kbd{l b} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-all-branches}) Show log for all local and remote branches and @code{HEAD}. @kindex l a @cindex magit-log-all @item @kbd{l a} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-all}) Show log for all references and @code{HEAD}. @end table Two additional commands that show the log for the file or blob that is being visited in the current buffer exists, see @ref{Minor Mode for Buffers Visiting Files}. The command @code{magit-cherry} also shows a log, see @ref{Cherries}. @menu * Refreshing Logs:: * Log Buffer:: * Log Margin:: * Select from Log:: * Reflog:: * Cherries:: @end menu @node Refreshing Logs @subsection Refreshing Logs The prefix command @code{magit-log-refresh-popup}, on @code{L}, can be used to change the log arguments used in the current buffer, without changing which log is shown. This works in dedicated log buffers, but also in the status buffer. @table @asis @kindex L @cindex magit-log-refresh-popup @item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex L g @cindex magit-log-refresh @item @kbd{L g} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh}) This suffix command sets the local log arguments for the current buffer. @kindex L s @cindex magit-log-set-default-arguments @item @kbd{L s} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-set-default-arguments}) This suffix command sets the default log arguments for buffers of the same type as that of the current buffer. Other existing buffers of the same type are not affected because their local values have already been initialized. @kindex L w @cindex magit-log-save-default-arguments @item @kbd{L w} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-save-default-arguments}) This suffix command sets the default log arguments for buffers of the same type as that of the current buffer, and saves the value for future sessions. Other existing buffers of the same type are not affected because their local values have already been initialized. @kindex L t @cindex magit-toggle-margin @item @kbd{L t} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin}) Show or hide the margin. @end table @node Log Buffer @subsection Log Buffer @table @asis @kindex L @cindex magit-log-refresh-popup @item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-refresh-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. See @ref{Refreshing Logs}. @kindex q @cindex magit-log-bury-buffer @item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-bury-buffer}) Bury the current buffer or the revision buffer in the same frame. Like @code{magit-mode-bury-buffer} (which see) but with a negative prefix argument instead bury the revision buffer, provided it is displayed in the current frame. @kindex C-c C-b @cindex magit-go-backward @item @kbd{C-c C-b} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-backward}) Move backward in current buffer's history. @kindex C-c C-f @cindex magit-go-forward @item @kbd{C-c C-f} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-forward}) Move forward in current buffer's history. @kindex C-c C-n @cindex magit-log-move-to-parent @item @kbd{C-c C-n} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-move-to-parent}) Move to a parent of the current commit. By default, this is the first parent, but a numeric prefix can be used to specify another parent. @kindex SPC @cindex magit-diff-show-or-scroll-up @item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-up}) Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer up. If there is no commit or stash at point, then prompt for a commit. @kindex DEL @cindex magit-diff-show-or-scroll-down @item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-down}) Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer down. If there is no commit or stash at point, then prompt for a commit. @kindex = @cindex magit-log-toggle-commit-limit @item @kbd{=} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-toggle-commit-limit}) Toggle the number of commits the current log buffer is limited to. If the number of commits is currently limited, then remove that limit. Otherwise set it to 256. @kindex + @cindex magit-log-double-commit-limit @item @kbd{+} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-double-commit-limit}) Double the number of commits the current log buffer is limited to. @kindex - @cindex magit-log-half-commit-limit @item @kbd{-} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-half-commit-limit}) Half the number of commits the current log buffer is limited to. @end table @defopt magit-log-auto-more Insert more log entries automatically when moving past the last entry. Only considered when moving past the last entry with @code{magit-goto-*-section} commands. @end defopt @defopt magit-log-show-refname-after-summary Whether to show the refnames after the commit summaries. This is useful if you use really long branch names. @end defopt Magit displays references in logs a bit differently from how Git does it. Local branches are blue and remote branches are green. Of course that depends on the used theme, as do the colors used for other types of references. The current branch has a box around it, as do remote branches that are their respective remote's @code{HEAD} branch. If a local branch and its push-target point at the same commit, then their names are combined to preserve space and to make that relationship visible. For example: @example origin/feature [green][blue-] instead of feature origin/feature [blue-] [green-------] @end example Also note that while the popup features the @code{--show-signature} argument, that won't actually be used when enabled, because Magit defaults to use just one line per commit. Instead the commit colorized to indicate the validity of the signed commit object, using the faces named @code{magit-signature-*} (which see). For a description of @code{magit-log-margin} see @ref{Log Margin}. @node Log Margin @subsection Log Margin In buffers which show one or more logs, it is possible to show additional information about each commit in the margin. The options used to configure the margin are named @code{magit-INFIX-margin}, where INFIX is the same as in the respective major-mode @code{magit-INFIX-mode}. In regular log buffers that would be @code{magit-log-margin}. @defopt magit-log-margin This option specifies whether the margin is initially shown in Magit-Log mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt You can change the STYLE and AUTHOR-WIDTH of all @code{magit-INFIX-margin} options to the same values by customizing @code{magit-log-margin} @strong{before} @code{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 INIT in @code{magit-log-margin} to @code{nil}, then that is used in the default of all other options. But setting it to @code{t}, i.e. re-enforcing the default for that option, does not carry to other options. @table @asis @kindex L @cindex magit-margin-popup @item @kbd{L} @tie{}@tie{}@tie{}@tie{}(@code{magit-margin-popup}) This prefix command features the following commands for changing the appearance of the margin. @end table In some buffers that support the margin, "L" is bound to @code{magit-log-refresh-popup}, but that popup features the same commands, and then some other unrelated commands. @table @asis @kindex L L @cindex magit-toggle-margin @item @kbd{L L} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin}) This command shows or hides the margin. @kindex L l @cindex magit-cycle-margin-style @item @kbd{L l} @tie{}@tie{}@tie{}@tie{}(@code{magit-cycle-margin-style}) This command cycles the style used for the margin. @kindex L d @cindex magit-toggle-margin-details @item @kbd{L d} @tie{}@tie{}@tie{}@tie{}(@code{magit-toggle-margin-details}) This command shows or hides details in the margin. @end table @node Select from Log @subsection Select from Log When the user has to select a recent commit that is reachable from @code{HEAD}, using regular completion would be inconvenient (because most humans cannot remember hashes or "HEAD~5", at least not without double checking). Instead a log buffer is used to select the commit, which has the advantage that commits are presented in order and with the commit message. Such selection logs are used when selecting the beginning of a rebase and when selecting the commit to be squashed into. In addition to the key bindings available in all log buffers, the following additional key bindings are available in selection log buffers: @table @asis @kindex C-c C-c @cindex magit-log-select-pick @item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-select-pick}) Select the commit at point and act on it. Call @code{magit-log-select-pick-function} with the selected commit as argument. @kindex C-c C-k @cindex magit-log-select-quit @item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-select-quit}) Abort selecting a commit, don't act on any commit. @end table @defopt magit-log-select-margin This option specifies whether the margin is initially shown in Magit-Log-Select mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @node Reflog @subsection Reflog Also see @ifinfo @ref{git-reflog,,,gitman,}. @end ifinfo @ifhtml @html the git-reflog(1) manpage. @end html @end ifhtml @iftex the git-reflog(1) manpage. @end iftex These reflog commands are available from the log popup. See @ref{Logging}. @table @asis @kindex l r @cindex magit-reflog-current @item @kbd{l r} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-current}) Display the reflog of the current branch. @kindex l O @cindex magit-reflog-other @item @kbd{l O} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-other}) Display the reflog of a branch or another ref. @kindex l H @cindex magit-reflog-head @item @kbd{l H} @tie{}@tie{}@tie{}@tie{}(@code{magit-reflog-head}) Display the @code{HEAD} reflog. @end table @defopt magit-reflog-margin This option specifies whether the margin is initially shown in Magit-Reflog mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @node Cherries @subsection Cherries Cherries are commits that haven't been applied upstream (yet), and are usually visualized using a log. Each commit is prefixed with @code{-} if it has an equivalent in the upstream and @code{+} if it does not, i.e. if it is a cherry. The command @code{magit-cherry} shows cherries for a single branch, but the references buffer (see @ref{References Buffer}) can show cherries for multiple "upstreams" at once. Also see @ifinfo @ref{git-reflog,,,gitman,}. @end ifinfo @ifhtml @html the git-reflog(1) manpage. @end html @end ifhtml @iftex the git-reflog(1) manpage. @end iftex @table @asis @kindex Y @cindex magit-cherry @item @kbd{Y} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry}) Show commits that are in a certain branch but that have not been merged in the upstream branch. @end table @defopt magit-cherry-margin This option specifies whether the margin is initially shown in Magit-Cherry mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @node Diffing @section Diffing The status buffer contains diffs for the staged and unstaged commits, but that obviously isn't enough. The prefix command @code{magit-diff-popup}, on @code{d}, features several suffix commands, which show a specific diff in a separate diff buffer. Like other popups, the diff popup also features several arguments that can be changed before invoking one of the suffix commands. However, in the case of the diff popup, these arguments may be taken from those currently in use in the current repository's log buffer, depending on the value of @code{magit-use-sticky-arguments} (see @ref{Popup Buffers and Prefix Commands}). Also see @ifinfo @ref{git-diff,,,gitman,}. @end ifinfo @ifhtml @html the git-diff(1) manpage. @end html @end ifhtml @iftex the git-diff(1) manpage. @end iftex @table @asis @kindex d @cindex magit-diff-popup @item @kbd{d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex d d @cindex magit-diff-dwim @item @kbd{d d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-dwim}) Show changes for the thing at point. @kindex d r @cindex magit-diff-range @item @kbd{d r} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-range}) Show differences between two commits. RANGE should be a range (A..B or A@dots{}B) but can also be a single commit. If one side of the range is omitted, then it defaults to @code{HEAD}. If just a commit is given, then changes in the working tree relative to that commit are shown. 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 "@dots{}" range). @kindex d w @cindex magit-diff-working-tree @item @kbd{d w} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-working-tree}) Show changes between the current working tree and the @code{HEAD} commit. With a prefix argument show changes between the working tree and a commit read from the minibuffer. @kindex d s @cindex magit-diff-staged @item @kbd{d s} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-staged}) Show changes between the index and the @code{HEAD} commit. With a prefix argument show changes between the index and a commit read from the minibuffer. @kindex d u @cindex magit-diff-unstaged @item @kbd{d u} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-unstaged}) Show changes between the working tree and the index. @kindex d p @cindex magit-diff-paths @item @kbd{d p} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-paths}) Show changes between any two files on disk. @end table All of the above suffix commands update the repository's diff buffer. The diff popup also features two commands which show differences in another buffer: @table @asis @kindex d c @cindex magit-show-commit @item @kbd{d c} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-commit}) Show the commit at point. If there is no commit at point or with a prefix argument, prompt for a commit. @kindex d t @cindex magit-stash-show @item @kbd{d t} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-show}) Show all diffs of a stash in a buffer. @end table Two additional commands that show the diff for the file or blob that is being visited in the current buffer exists, see @ref{Minor Mode for Buffers Visiting Files}. @menu * Refreshing Diffs:: * Diff Buffer:: * Diff Options:: * Revision Buffer:: @end menu @node Refreshing Diffs @subsection Refreshing Diffs The prefix command @code{magit-diff-refresh-popup}, on @code{D}, can be used to change the diff arguments used in the current buffer, without changing which diff is shown. This works in dedicated diff buffers, but also in the status buffer. @table @asis @kindex D @cindex magit-diff-refresh-popup @item @kbd{D} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-refresh-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex D g @cindex magit-diff-refresh @item @kbd{D g} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-refresh}) This suffix command sets the local diff arguments for the current buffer. @kindex D s @cindex magit-diff-set-default-arguments @item @kbd{D s} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-set-default-arguments}) This suffix command sets the default diff arguments for buffers of the same type as that of the current buffer. Other existing buffers of the same type are not affected because their local values have already been initialized. @kindex D w @cindex magit-diff-save-default-arguments @item @kbd{D w} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-save-default-arguments}) This suffix command sets the default diff arguments for buffers of the same type as that of the current buffer, and saves the value for future sessions. Other existing buffers of the same type are not affected because their local values have already been initialized. @kindex D t @cindex magit-diff-toggle-refine-hunk @item @kbd{D t} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-toggle-refine-hunk}) This command toggles hunk refinement on or off. @kindex D r @cindex magit-diff-switch-range-type @item @kbd{D r} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-switch-range-type}) This command converts the diff range type from "revA..revB" to "revB@dots{}revA", or vice versa. @kindex D f @cindex magit-diff-flip-revs @item @kbd{D f} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-flip-revs}) This command swaps revisions in the diff range from "revA..revB" to "revB..revA", or vice versa. @kindex D F @cindex magit-diff-toggle-file-filter @item @kbd{D F} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-toggle-file-filter}) This command toggles the file restriction of the diffs in the current buffer, allowing you to quickly switch between viewing all the changes in the commit and the restricted subset. As a special case, when this command is called from a log buffer, it toggles the file restriction in the repository's revision buffer, which is useful when you display a revision from a log buffer that is restricted to a file or files. @end table In addition to the above popup, which allows changing any of the supported arguments, there also exist some commands which change a particular argument. @table @asis @kindex - @cindex magit-diff-less-context @item @kbd{-} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-less-context}) This command decreases the context for diff hunks by COUNT lines. @kindex + @cindex magit-diff-more-context @item @kbd{+} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-more-context}) This command increases the context for diff hunks by COUNT lines. @kindex 0 @cindex magit-diff-default-context @item @kbd{0} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-default-context}) This command resets the context for diff hunks to the default height. @end table The following commands quickly change what diff is being displayed without having to using one of the diff popups. @table @asis @kindex C-c C-d @cindex magit-diff-while-committing @item @kbd{C-c C-d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-while-committing}) While committing, this command shows the changes that are about to be committed. While amending, invoking the command again toggles between showing just the new changes or all the changes that will be committed. This binding is available in the diff buffer as well as the commit message buffer. @kindex C-c C-b @cindex magit-go-backward @item @kbd{C-c C-b} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-backward}) This command moves backward in current buffer's history. @kindex C-c C-f @cindex magit-go-forward @item @kbd{C-c C-f} @tie{}@tie{}@tie{}@tie{}(@code{magit-go-forward}) This command moves forward in current buffer's history. @end table @node Diff Buffer @subsection Diff Buffer These commands are available in diff buffers. @table @asis @kindex RET @cindex magit-diff-visit-file @item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-visit-file}) From a diff, visit the corresponding file at the appropriate position. If the diff shows changes in the worktree, the index, or @code{HEAD}, then visit the actual file. Otherwise, when the diff is about an older commit or a range, then visit the appropriate blob. If point is on a removed line, then visit the blob for the first parent of the commit which removed that line, i.e. the last commit where that line still existed. Otherwise visit the blob for the commit whose changes are being shown. Interactively, when the file or blob to be displayed is already being displayed in another window of the same frame, then just select that window and adjust point. Otherwise, or with a prefix argument, display the buffer in another window. The meaning of the prefix argument can be inverted or further modified using the option @code{magit-display-file-buffer-function}. Non-interactively the optional OTHER-WINDOW argument is taken literally. DISPLAY-FN can be used to specify the display function explicitly, in which case OTHER-WINDOW is ignored. The optional FORCE-WORKTREE means to force visiting the worktree version of the file. To do this interactively use the command @code{magit-diff-visit-file-worktree} instead. @end table @defopt magit-diff-visit-previous-blob This option controls whether @code{magit-diff-visit-file} may visit the previous blob. When this is @code{t} and point is on a removed line in a diff for a committed change, then @code{magit-diff-visit-file} visits the blob from the last revision which still had that line. Currently this is only supported for committed changes, for staged and unstaged changes @code{magit-diff-visit-file} always visits the file in the working tree. @end defopt @table @asis @kindex C- @cindex magit-diff-visit-file-worktree @item @kbd{C-} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-visit-file-worktree}) From a diff, visit the corresponding file at the appropriate position. When the file is already being displayed in another window of the same frame, then just select that window and adjust point. With a prefix argument also display in another window. The actual file in the worktree is visited. The positions in the hunk headers get less useful the "older" the changes are, and as a result, jumping to the appropriate position gets less reliable. Also see @code{magit-diff-visit-file}, which visits the respective blob, unless the diff shows changes in the worktree, the index, or @code{HEAD}. @end table @cindex magit-diff-visit-file-other-window @deffn Command magit-diff-visit-file-other-window From a diff, visit the corresponding file at the appropriate position in another window. @end deffn @table @asis @kindex C-c C-t @cindex magit-diff-trace-definition @item @kbd{C-c C-t} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-trace-definition}) From a diff, show log for the definition at point. @end table @defopt magit-log-trace-definition-function The function used by @code{magit-log-trace-definition} to determine the function at point. For major-modes that have special needs, you could set that using the mode's hook. @end defopt @table @asis @kindex C-c C-e @cindex magit-diff-edit-hunk-commit @item @kbd{C-c C-e} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-edit-hunk-commit}) 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 @code{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 @code{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 @code{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 @code{magit-rebase-edit-command} instead of this command. @kindex j @cindex magit-jump-to-diffstat-or-diff @item @kbd{j} @tie{}@tie{}@tie{}@tie{}(@code{magit-jump-to-diffstat-or-diff}) Jump to the diffstat or diff. When point is on a file inside the diffstat section, then jump to the respective diff section. Otherwise, jump to the diffstat section or a child thereof. @kindex SPC @cindex scroll-up @item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{scroll-up}) Scroll text upward. @kindex DEL @cindex scroll-down @item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{scroll-down}) Scroll text downward. @end table @node Diff Options @subsection Diff Options @defopt magit-diff-refine-hunk Whether to show word-granularity differences within diff hunks. @itemize @item @code{nil} never show fine differences. @item @code{t} show fine differences for the current diff hunk only. @item @code{all} show fine differences for all displayed diff hunks. @end itemize @end defopt @defopt magit-diff-adjust-tab-width Whether to adjust the width of tabs in diffs. Determining the correct width can be expensive if it requires opening large and/or many files, so the widths are cached in the variable @code{magit-diff--tab-width-cache}. Set that to nil to invalidate the cache. @itemize @item @code{nil} Never adjust tab width. Use `tab-width's value from the Magit buffer itself instead. @item @code{t} If the corresponding file-visiting buffer exits, then use @code{tab-width}'s value from that buffer. Doing this is cheap, so this value is used even if a corresponding cache entry exists. @item @code{always} If there is no such buffer, then temporarily visit the file to determine the value. @item NUMBER Like @code{always}, but don't visit files larger than NUMBER bytes. @end itemize @end defopt @defopt magit-diff-paint-whitespace Specify where to highlight whitespace errors. See @code{magit-diff-highlight-trailing}, @code{magit-diff-highlight-indentation}. The symbol @code{t} means in all diffs, @code{status} means only in the status buffer, and nil means nowhere. @end defopt @defopt magit-diff-highlight-trailing Whether to highlight whitespace at the end of a line in diffs. Used only when @code{magit-diff-paint-whitespace} is non-nil. @end defopt @defopt magit-diff-highlight-indentation Highlight the "wrong" indentation style. Used only when @code{magit-diff-paint-whitespace} is non-nil. The value is a list of cons cells. The car is a regular expression, and the cdr is the value that applies to repositories whose directory matches the regular expression. If more than one element matches, then the @strong{last} element in the list applies. The default value should therefore come first in the list. If the value is @code{tabs}, highlight indentation with tabs. If the value is an integer, highlight indentation with at least that many spaces. Otherwise, highlight neither. @end defopt @defopt magit-diff-hide-trailing-cr-characters Whether to hide ^M characters at the end of a line in diffs. @end defopt @defopt magit-diff-highlight-hunk-region-functions This option specifies the functions used to highlight the hunk-internal region. @code{magit-diff-highlight-hunk-region-dim-outside} overlays the outside of the hunk internal selection with a face that causes the added and removed lines to have the same background color as context lines. This function should not be removed from the value of this option. @code{magit-diff-highlight-hunk-region-using-overlays} and @code{magit-diff-highlight-hunk-region-using-underline} emphasize the region by placing delimiting horizontal lines before and after it. Both of these functions have glitches which cannot be fixed due to limitations of Emacs' display engine. For more information see @uref{https://github.com/magit/magit/issues/2758} ff. Instead of, or in addition to, using delimiting horizontal lines, to emphasize the boundaries, you may which to emphasize the text itself, using @code{magit-diff-highlight-hunk-region-using-face}. In terminal frames it's not possible to draw lines as the overlay and underline variants normally do, so there they fall back to calling the face function instead. @end defopt @defopt magit-diff-unmarked-lines-keep-foreground This option controls whether added and removed lines outside the hunk-internal region only lose their distinct background color or also the foreground color. Whether the outside of the region is dimmed at all depends on @code{magit-diff-highlight-hunk-region-functions}. @end defopt @node Revision Buffer @subsection Revision Buffer @defopt magit-revision-insert-related-refs Whether to show related branches in revision buffers. @itemize @item @code{nil} Don't show any related branches. @item @code{t} Show related local branches. @item @code{all} Show related local and remote branches. @item @code{mixed} Show all containing branches and local merged branches. @end itemize @end defopt @defopt magit-revision-show-gravatars Whether to show gravatar images in revision buffers. If @code{nil}, then don't insert any gravatar images. If @code{t}, then insert both images. If @code{author} or @code{committer}, then insert only the respective image. If you have customized the option @code{magit-revision-header-format} and want to insert the images then you might also have to specify where to do so. In that case the value has to be a cons-cell of two regular expressions. The car specifies where to insert the author's image. The top half of the image is inserted right after the matched text, the bottom half on the next line in the same column. The cdr specifies where to insert the committer's image, accordingly. Either the car or the cdr may be nil." @end defopt @defopt magit-revision-use-hash-sections Whether to turn hashes inside the commit message into sections. If non-nil, then hashes inside the commit message are turned into @code{commit} sections. There is a trade off to be made between performance and reliability: @itemize @item @code{slow} calls git for every word to be absolutely sure. @item @code{quick} skips words less than seven characters long. @item @code{quicker} additionally skips words that don't contain a number. @item @code{quickest} uses all words that are at least seven characters long and which contain at least one number as well as at least one letter. @end itemize If nil, then no hashes are turned into sections, but you can still visit the commit at point using "RET". @end defopt The diffs shown in the revision buffer may be automatically restricted to a subset of the changed files. If the revision buffer is displayed from a log buffer, the revision buffer will share the same file restriction as that log buffer (also see the command @code{magit-diff-toggle-file-filter}). Note, however, that the log's file restriction will be ignored when @code{magit-log-arguments} includes @code{--follow}. In this case, the @code{-u} argument of the log popup can be used to show the file-restricted diffs inline. If the revision buffer is not displayed from a log buffer, the file restriction is determined by the file restriction in the repository's diff buffer, if it exists, and the value of the option @code{magit-use-sticky-arguments}. @node Ediffing @section Ediffing This section describes how to enter Ediff from Magit buffers. For information on how to use Ediff itself, see @ref{Top,,,ediff,}. @table @asis @kindex e @cindex magit-ediff-dwim @item @kbd{e} @tie{}@tie{}@tie{}@tie{}(@code{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/commit, in which case the user is asked about the other. It might not always guess right, in which case the appropriate @code{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. @kindex E @cindex magit-ediff-popup @item @kbd{E} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-popup}) This prefix command shows the following suffix commands in a popup buffer. @kindex E r @cindex magit-ediff-compare @item @kbd{E r} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-compare}) Compare two revisions of a file using Ediff. 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 "@dots{}" range). @kindex E m @cindex magit-ediff-resolve @item @kbd{E m} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-resolve}) Resolve outstanding conflicts in a file using Ediff, defaulting to the file at point. Provided that the value of @code{merge.conflictstyle} is @code{diff3}, you can view the file's merge-base revision using @code{/} in the Ediff control buffer. In the rare event that you want to manually resolve all conflicts, including those already resolved by Git, use @code{ediff-merge-revisions-with-ancestor}. @kindex E s @cindex magit-ediff-stage @item @kbd{E s} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-stage}) Stage and unstage changes to a file using Ediff, defaulting to the file at point. @kindex E u @cindex magit-ediff-show-unstaged @item @kbd{E u} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-unstaged}) Show unstaged changes to a file using Ediff. @kindex E i @cindex magit-ediff-show-staged @item @kbd{E i} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-staged}) Show staged changes to a file using Ediff. @kindex E w @cindex magit-ediff-show-working-tree @item @kbd{E w} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-working-tree}) Show changes in a file between @code{HEAD} and working tree using Ediff. @kindex E c @cindex magit-ediff-show-commit @item @kbd{E c} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-commit}) Show changes to a file introduced by a commit using Ediff. @kindex E z @cindex magit-ediff-show-stash @item @kbd{E z} @tie{}@tie{}@tie{}@tie{}(@code{magit-ediff-show-stash}) Show changes to a file introduced by a stash using Ediff. @end table @defopt magit-ediff-dwim-show-on-hunks This option controls what command @code{magit-ediff-dwim} calls when point is on uncommitted hunks. When nil, always run @code{magit-ediff-stage}. Otherwise, use @code{magit-ediff-show-staged} and @code{magit-ediff-show-unstaged} to show staged and unstaged changes, respectively. @end defopt @defopt magit-ediff-show-stash-with-index This option controls whether @code{magit-ediff-show-stash} includes a buffer containing the file's state in the index at the time the stash was created. This makes it possible to tell which changes in the stash were staged. @end defopt @defopt magit-ediff-quit-hook This hook is run after quitting an Ediff session that was created using a Magit command. The hook functions are run inside the Ediff control buffer, and should not change the current buffer. This is similar to @code{ediff-quit-hook} but takes the needs of Magit into account. The regular @code{ediff-quit-hook} is ignored by Ediff sessions that were created using a Magit command. @end defopt @node References Buffer @section References Buffer @table @asis @kindex y @cindex magit-show-refs-popup @item @kbd{y} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-popup}) List and compare references in a dedicated buffer. By default all refs are compared with @code{HEAD}, but with a prefix argument this command instead acts as a prefix command and shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex y y @cindex magit-show-refs-head @item @kbd{y y} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-head}) List and compare references in a dedicated buffer. Refs are compared with @code{HEAD}. @kindex y c @cindex magit-show-refs-current @item @kbd{y c} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs-current}) List and compare references in a dedicated buffer. Refs are compared with the current branch or @code{HEAD} if it is detached. @kindex y o @cindex magit-show-refs @item @kbd{y o} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-refs}) List and compare references in a dedicated buffer. Refs are compared with a branch read from the user. @end table @defopt magit-refs-show-commit-count Whether to show commit counts in Magit-Refs mode buffers. @itemize @item @code{all} Show counts for branches and tags. @item @code{branch} Show counts for branches only. @item @code{nil} Never show counts. @end itemize The default is @code{nil} because anything else can be very expensive. @end defopt @defopt magit-refs-pad-commit-counts Whether to pad all commit 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 @code{magit-dimmed}. If this is non-nil, then spaces are placed on both sides of all commit counts. @end defopt @defopt magit-refs-show-remote-prefix Whether to show the remote prefix in lists of remote branches. Showing the prefix is redundant because the name of the remote is already shown in the heading preceding the list of its branches. @end defopt @defopt magit-refs-primary-column-width Width of the primary 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.) @end defopt @defopt magit-refs-focus-column-width 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 @code{*} or @code{@@}. For each other reference, this column optionally shows how many commits it is ahead of the focused branch and @code{<}, or if it isn't ahead then the commits it is behind and @code{>}, or if it isn't behind either, then a @code{=}. This column may also display only @code{*} or @code{@@} for the focused branch, in which case this option is ignored. Use @code{L v} to change the verbosity of this column. @end defopt @defopt magit-refs-margin This option specifies whether the margin is initially shown in Magit-Refs mode buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @defopt magit-refs-margin-for-tags This option specifies whether to show information about tags in the margin. This is disabled by default because it is slow if there are many tags. @end defopt The following variables control how individual refs are displayed. If you change one of these variables (especially the "%c" part), then you should also change the others to keep things aligned. The following %-sequences are supported: @itemize @item @code{%a} Number of commits this ref has over the one we compare to. @item @code{%b} Number of commits the ref we compare to has over this one. @item @code{%c} Number of commits this ref has over the one we compare to. For the ref which all other refs are compared this is instead "@@", if it is the current branch, or "#" otherwise. @item @code{%C} For the ref which all other refs are compared this is "@@", if it is the current branch, or "#" otherwise. For all other refs " ". @item @code{%h} Hash of this ref's tip. @item @code{%m} Commit summary of the tip of this ref. @item @code{%n} Name of this ref. @item @code{%u} Upstream of this local branch. @item @code{%U} Upstream of this local branch and additional local vs. upstream information. @end itemize @defopt magit-refs-filter-alist This alist controls which tags and branches are omitted from being displayed in @code{magit-refs-mode} buffers. If it is @code{nil}, then all refs are displayed (subject to @code{magit-refs-sections-hook}). 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. Contrary to how they are displayed in the buffer, for comparison each tag begins with "tags/" and each remote branch with "/". @end defopt @table @asis @kindex RET @cindex magit-visit-ref @item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-visit-ref}) This command visits the reference or revision at point in another buffer. If there is no revision at point or with a prefix argument then it prompts for a revision. This command behaves just like @code{magit-show-commit} as described above, except if point is on a reference in a @code{magit-refs-mode} buffer, in which case the behavior may be different, but only if you have customized the option @code{magit-visit-ref-behavior}. @end table @defopt magit-visit-ref-behavior This option controls how @code{magit-visit-ref} behaves in @code{magit-refs-mode} buffers. By default @code{magit-visit-ref} behaves like @code{magit-show-commit}, in all buffers, including @code{magit-refs-mode} buffers. When the type of the section at point is @code{commit} then "RET" is bound to @code{magit-show-commit}, and when the type is either @code{branch} or @code{tag} then it is bound to @code{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 @code{magit-refs-mode} buffers, doing surprising things, some of which cannot really be described as "visit this thing". If you've grown accustomed this behavior, you can restore it 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 @code{M-x magit-show-commit} to get it back. @code{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. @itemize @item @code{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 @code{HEAD}. Instead of adding this symbol, consider pressing "C-u y o RET". @item @code{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. @item @code{checkout-any} Check out the reference at point. If that reference is a tag or a remote branch, then this results in a detached @code{HEAD}. Instead of adding this symbol, consider pressing "b b RET", like you would do in other buffers. @item @code{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. @end itemize @end defopt @menu * References Sections:: @end menu @node References Sections @subsection References Sections The contents of references buffers is controlled using the hook @code{magit-refs-sections-hook}. See @ref{Section Hooks} to learn about such hooks and how to customize them. All of the below functions are members of the default value. Note that it makes much less sense to customize this hook than it does for the respective hook used for the status buffer. @defopt magit-refs-sections-hook Hook run to insert sections into a references buffer. @end defopt @defun magit-insert-local-branches Insert sections showing all local branches. @end defun @defun magit-insert-remote-branches Insert sections showing all remote-tracking branches. @end defun @defun magit-insert-tags Insert sections showing all tags. @end defun @node Bisecting @section Bisecting Also see @ifinfo @ref{git-bisect,,,gitman,}. @end ifinfo @ifhtml @html the git-bisect(1) manpage. @end html @end ifhtml @iftex the git-bisect(1) manpage. @end iftex @table @asis @kindex B @cindex magit-bisect-popup @item @kbd{B} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-popup}) This prefix command shows the following suffix commands in a popup buffer. @end table When bisecting is not in progress, then the popup buffer features the following commands. @table @asis @kindex B B @cindex magit-bisect-start @item @kbd{B B} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-start}) 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 known good and a bad commit. @kindex B s @cindex magit-bisect-run @item @kbd{B s} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-run}) Bisect automatically by running commands after each step. @end table When bisecting is in progress, then the popup buffer features these commands instead. @table @asis @kindex B b @cindex magit-bisect-bad @item @kbd{B b} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-bad}) Mark the current commit as bad. Use this after you have asserted that the commit does contain the bug in question. @kindex B g @cindex magit-bisect-good @item @kbd{B g} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-good}) Mark the current commit as good. Use this after you have asserted that the commit does not contain the bug in question. @kindex B k @cindex magit-bisect-skip @item @kbd{B k} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-skip}) 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. @kindex B r @cindex magit-bisect-reset @item @kbd{B r} @tie{}@tie{}@tie{}@tie{}(@code{magit-bisect-reset}) After bisecting, cleanup bisection state and return to original @code{HEAD}. @end table By default the status buffer shows information about the ongoing bisect session. @defopt magit-bisect-show-graph This option controls whether a graph is displayed for the log of commits that still have to be bisected. @end defopt @node Visiting Blobs @section Visiting Blobs @table @asis @kindex M-x magit-find-file @cindex magit-find-file @item @kbd{M-x magit-find-file} @tie{}@tie{}@tie{}@tie{}(@code{magit-find-file}) View FILE from REV@. Switch to a buffer visiting blob REV:FILE, creating one if none already exists. @kindex M-x magit-find-file-other-window @cindex magit-find-file-other-window @item @kbd{M-x magit-find-file-other-window} @tie{}@tie{}@tie{}@tie{}(@code{magit-find-file-other-window}) View FILE from REV, in another window. Like @code{magit-find-file}, but create a new window or reuse an existing one. @end table @node Blaming @section Blaming Also see @ifinfo @ref{git-blame,,,gitman,}. @end ifinfo @ifhtml @html the git-blame(1) manpage. @end html @end ifhtml @iftex the git-blame(1) manpage. @end iftex To start blaming you can use @code{M-x} in a file-visiting buffer to invoke one of the following commands. You can also invoke these commands using the blame popup, which is available on @code{b} in file-visiting buffers that already contain blame information and, also on @code{b}, in all blob-visiting buffers. You can also enter the blame popup from the file popup, which is available on @code{C-c M-g}, provided @code{magit-file-mode} is enabled, see @ref{Minor Mode for Buffers Visiting Files}. @cindex magit-blame-addition @deffn Command magit-blame-addition This command augments each line or chunk of lines in the current file- or blob-visiting buffer with information about what commits last touched these lines. If the buffer visits a revision of that file, then history up to that revision is considered. Otherwise, the file's full history is considered, including uncommitted changes. If Magit-Blame mode is already turned on in the current buffer then blaming is done recursively, by visiting REVISION:FILE (using @code{magit-find-file}), where REVISION is a parent of the revision that added the current line or chunk of lines. @end deffn @cindex magit-blame-echo @deffn Command magit-blame-echo This command is like @code{magit-blame-addition} except that it doesn't turn on @code{read-only-mode} and that it initially uses the visualization style specified by option @code{magit-blame-echo-style}. @end deffn @cindex magit-blame-removal @deffn Command magit-blame-removal This command augments each line or chunk of lines in the current blob-visiting buffer with information about the revision that removes it. It cannot be used in file-visiting buffers. Like @code{magit-blame-addition}, this command can be used recursively. @end deffn @cindex magit-blame-reverse @deffn Command magit-blame-reverse This command augments each line or chunk of lines in the current file- or blob-visiting buffer with information about the last revision in which a line still existed. Like @code{magit-blame-addition}, this command can be used recursively. @end deffn The following key bindings are available when Magit-Blame mode is enabled and Read-Only mode is not enabled. These commands are also available in other buffers; here only the behavior is described that is relevant in file-visiting buffers that are being blamed. @table @asis @kindex RET @cindex magit-show-commit @item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{magit-show-commit}) This command shows the commit that last touched the line at point. @kindex SPC @cindex magit-diff-show-or-scroll-up @item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-up}) This command updates the commit buffer. This either shows the commit that last touched the line at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and if that buffer contains information about that commit, then the buffer is scrolled up instead. @kindex DEL @cindex magit-diff-show-or-scroll-down @item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-show-or-scroll-down}) This command updates the commit buffer. This either shows the commit that last touched the line at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and if that buffer contains information about that commit, then the buffer is scrolled down instead. @end table The following key bindings are available when Magit-Blame mode is enabled and Read-Only mode is not enabled. @table @asis @kindex b @cindex magit-blame-popup @item @kbd{b} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-popup}) This prefix command shows the above suffix command along with the appropriate infix arguments in a popup buffer. @kindex n @cindex magit-blame-next-chunk @item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-next-chunk}) This command moves to the next chunk. @kindex N @cindex magit-blame-next-chunk-same-commit @item @kbd{N} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-next-chunk-same-commit}) This command moves to the next chunk from the same commit. @kindex p @cindex magit-blame-previous-chunk @item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-previous-chunk}) This command moves to the previous chunk. @kindex P @cindex magit-blame-previous-chunk-same-commit @item @kbd{P} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-previous-chunk-same-commit}) This command moves to the previous chunk from the same commit. @kindex q @cindex magit-blame-quit @item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-quit}) This command turns off Magit-Blame mode. If the buffer was created during a recursive blame, then it also kills the buffer. @kindex M-w @cindex magit-blame-copy-hash @item @kbd{M-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-copy-hash}) This command saves the hash of the current chunk's commit to the kill ring. When the region is active, the command saves the region's content instead of the hash, like @code{kill-ring-save} would. @kindex c @cindex magit-blame-cycle-style @item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-cycle-style}) This command changes how blame information is visualized in the current buffer by cycling through the styles specified using the option @code{magit-blame-styles}. @end table Blaming is also controlled using the following options. @defopt magit-blame-styles This option defines a list of styles used to visualize blame information. For now see its doc-string to learn more. @end defopt @defopt magit-blame-echo-style This option specifies the blame visualization style used by the command @code{magit-blame-echo}. This must be a symbol that is used as the identifier for one of the styles defined in @code{magit-blame-styles}. @end defopt @defopt magit-blame-time-format This option specifies the format string used to display times when showing blame information. @end defopt @defopt magit-blame-read-only This option controls whether blaming a buffer also makes temporarily read-only. @end defopt @defopt magit-blame-disable-modes This option lists incompatible minor-modes that should be disabled temporarily when a buffer contains blame information. They are enabled again when the buffer no longer shows blame information. @end defopt @defopt magit-blame-goto-chunk-hook This hook is run when moving between chunks. @end defopt @node Manipulating @chapter Manipulating @menu * Repository Setup:: * Staging and Unstaging:: * Applying:: * Committing:: * Branching:: * Merging:: * Resolving Conflicts:: * Rebasing:: * Cherry Picking:: * Resetting:: * Stashing:: @end menu @node Repository Setup @section Repository Setup @table @asis @kindex M-x magit-init @cindex magit-init @item @kbd{M-x magit-init} @tie{}@tie{}@tie{}@tie{}(@code{magit-init}) This command initializes a repository and then shows the status buffer for the new repository. 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. @kindex M-x magit-clone @cindex magit-clone @item @kbd{M-x magit-clone} @tie{}@tie{}@tie{}@tie{}(@code{magit-clone}) This command clones a repository and then shows the status buffer for the new repository. The user is queried for a remote url and a local directory. @end table @defopt magit-clone-set-remote.pushDefault Whether to set the value of @code{remote.pushDefault} after cloning. If @code{t}, then set without asking. If @code{nil}, then don't set. If @code{ask}, then ask the user every time she clones a repository. @end defopt @node Staging and Unstaging @section Staging and Unstaging Like Git, Magit can of course stage and unstage complete files. Unlike Git, it also allows users to gracefully un-/stage individual hunks and even just part of a hunk. To stage individual hunks and parts of hunks using Git directly, one has to use the very modal and rather clumsy interface of a @code{git add --interactive} session. With Magit, on the other hand, one can un-/stage individual hunks by just moving point into the respective section inside a diff displayed in the status buffer or a separate diff buffer and typing @code{s} or @code{u}. To operate on just parts of a hunk, mark the changes that should be un-/staged using the region and then press the same key that would be used to un-/stage. To stage multiple files or hunks at once use a region that starts inside the heading of such a section and ends inside the heading of a sibling section of the same type. Besides staging and unstaging, Magit also provides several other "apply variants" that can also operate on a file, multiple files at once, a hunk, multiple hunks at once, and on parts of a hunk. These apply variants are described in the next section. You can also use Ediff to stage and unstage. See @ref{Ediffing}. @table @asis @kindex s @cindex magit-stage @item @kbd{s} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage}) Add the change at point to the staging area. With a prefix argument and an untracked file (or files) at point, stage the file but not its content. This makes it possible to stage only a subset of the new file's changes. @kindex S @cindex magit-stage-modified @item @kbd{S} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-modified}) 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. @kindex u @cindex magit-unstage @item @kbd{u} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage}) Remove the change at point from the staging area. Only staged changes can be unstaged. But by default this command performs an action that is somewhat similar to unstaging, when it is called on a committed change: it reverses the change in the index but not in the working tree. @kindex U @cindex magit-unstage-all @item @kbd{U} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-all}) Remove all changes from the staging area. @end table @defopt magit-unstage-committed This option controls whether @code{magit-unstage} "unstages" committed changes by reversing them in the index but not the working tree. The alternative is to raise an error. @end defopt @table @asis @kindex M-x magit-reverse-in-index @cindex magit-reverse-in-index @item @kbd{M-x magit-reverse-in-index} @tie{}@tie{}@tie{}@tie{}(@code{magit-reverse-in-index}) This command reverses the committed change at point in the index but not the working tree. By default no key is bound directly to this command, but it is indirectly called when @code{u} (@code{magit-unstage}) is pressed on a committed change. This allows extracting a change from @code{HEAD}, while leaving it in the working tree, so that it can later be committed using a separate commit. A typical workflow would be: @itemize @item Optionally make sure that there are no uncommitted changes. @item Visit the @code{HEAD} commit and navigate to the change that should not have been included in that commit. @item Type @code{u} (@code{magit-unstage}) to reverse it in the index. This assumes that @code{magit-unstage-committed-changes} is non-nil. @item Type @code{c e} to extend @code{HEAD} with the staged changes, including those that were already staged before. @item Optionally stage the remaining changes using @code{s} or @code{S} and then type @code{c c} to create a new commit. @end itemize @kindex M-x magit-reset-index @cindex magit-reset-index @item @kbd{M-x magit-reset-index} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-index}) Reset the index to some commit. The commit is read from the user and defaults to the commit at point. If there is no commit at point, then it defaults to @code{HEAD}. @end table @menu * Staging from File-Visiting Buffers:: @end menu @node Staging from File-Visiting Buffers @subsection Staging from File-Visiting Buffers Fine-grained un-/staging has to be done from the status or a diff buffer, but it's also possible to un-/stage all changes made to the file visited in the current buffer right from inside that buffer. @table @asis @kindex M-x magit-stage-file @cindex magit-stage-file @item @kbd{M-x magit-stage-file} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-file}) When invoked inside a file-visiting buffer, then stage all changes to that file. In a Magit buffer, stage the file at point if any. Otherwise prompt for a file to be staged. With a prefix argument always prompt the user for a file, even in a file-visiting buffer or when there is a file section at point. @kindex M-x magit-unstage-file @cindex magit-unstage-file @item @kbd{M-x magit-unstage-file} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-file}) When invoked inside a file-visiting buffer, then unstage all changes to that file. In a Magit buffer, unstage the file at point if any. Otherwise prompt for a file to be unstaged. With a prefix argument always prompt the user for a file, even in a file-visiting buffer or when there is a file section at point. @end table @node Applying @section Applying Magit provides several "apply variants": stage, unstage, discard, reverse, and "regular apply". At least when operating on a hunk they are all implemented using @code{git apply}, which is why they are called "apply variants". @itemize @item Stage. Apply a change from the working tree to the index. The change also remains in the working tree. @item Unstage. Remove a change from the index. The change remains in the working tree. @item Discard. On a staged change, remove it from the working tree and the index. On an unstaged change, remove it from the working tree only. @item Reverse. Reverse a change in the working tree. Both committed and staged changes can be reversed. Unstaged changes cannot be reversed. Discard them instead. @item Apply. Apply a change to the working tree. Both committed and staged changes can be applied. Unstaged changes cannot be applied - as they already have been applied. @end itemize The previous section described the staging and unstaging commands. What follows are the commands which implement the remaining apply variants. @table @asis @kindex a @cindex magit-apply @item @kbd{a} @tie{}@tie{}@tie{}@tie{}(@code{magit-apply}) 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. @kindex k @cindex magit-discard @item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-discard}) Remove the change at point from the working tree. @kindex v @cindex magit-reverse @item @kbd{v} @tie{}@tie{}@tie{}@tie{}(@code{magit-reverse}) 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. @end table With a prefix argument all apply variants attempt a 3-way merge when appropriate (i.e. when @code{git apply} is used internally). @node Committing @section Committing When the user initiates a commit, Magit calls @code{git commit} without any arguments, so Git has to get it from the user. It creates the file @code{.git/COMMIT_EDITMSG} and then opens that file in an editor. Magit arranges for that editor to be the Emacsclient. Once the user finishes the editing session, the Emacsclient exits and Git creates the commit using the file's content as message. @menu * Initiating a Commit:: * Editing Commit Messages:: @end menu @node Initiating a Commit @subsection Initiating a Commit Also see @ifinfo @ref{git-commit,,,gitman,}. @end ifinfo @ifhtml @html the git-commit(1) manpage. @end html @end ifhtml @iftex the git-commit(1) manpage. @end iftex @table @asis @kindex c @cindex magit-commit-popup @item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex c c @cindex magit-commit-create @item @kbd{c c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-create}) Create a new commit on @code{HEAD}. With a prefix argument amend to the commit at @code{HEAD} instead. @kindex c a @cindex magit-commit-amend @item @kbd{c a} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-amend}) Amend the last commit. @kindex c e @cindex magit-commit-extend @item @kbd{c e} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-extend}) Amend the last commit, without editing the message. With a prefix argument keep the committer date, otherwise change it. The option @code{magit-commit-extend-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. @kindex c w @cindex magit-commit-reword @item @kbd{c w} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-reword}) Reword the last commit, ignoring staged changes. With a prefix argument keep the committer date, otherwise change it. The option @code{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. @kindex c f @cindex magit-commit-fixup @item @kbd{c f} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-fixup}) 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 @code{magit-commit-squash-confirm}. @kindex c F @cindex magit-commit-instant-fixup @item @kbd{c F} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-instant-fixup}) Create a fixup commit and instantly rebase. @kindex c s @cindex magit-commit-squash @item @kbd{c s} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-squash}) 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 @code{magit-commit-squash-confirm}. @kindex c S @cindex magit-commit-instant-squash @item @kbd{c S} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-instant-squash}) Create a squash commit and instantly rebase. @kindex c A @cindex magit-commit-augment @item @kbd{c A} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-augment}) 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 @code{magit-commit-squash-confirm}. @end table @defopt magit-commit-ask-to-stage Whether to ask to stage all unstaged changes when committing and nothing is staged. @end defopt @defopt magit-commit-extend-override-date Whether using @code{magit-commit-extend} changes the committer date. @end defopt @defopt magit-commit-reword-override-date Whether using @code{magit-commit-reword} changes the committer date. @end defopt @defopt magit-commit-squash-confirm 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 @code{magit-commit-squash} and @code{magit-commit-fixup}. The "instant" variants always require confirmation because making an error while using those is harder to recover from. @end defopt @node Editing Commit Messages @subsection Editing Commit Messages After initiating a commit as described in the previous section, two new buffers appear. One shows the changes that are about to committed, while the other is used to write the message. All regular editing commands are available in the commit message buffer. This section only describes the additional commands. Commit messages are edited in an edit session - in the background Git is waiting for the editor, in our case the Emacsclient, to save the commit message in a file (in most cases @code{.git/COMMIT_EDITMSG}) and then return. If the Emacsclient returns with a non-zero exit status then Git does not create the commit. So the most important commands are those for finishing and aborting the commit. @table @asis @kindex C-c C-c @cindex with-editor-finish @item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-finish}) Finish the current editing session by returning with exit code 0. Git then creates the commit using the message it finds in the file. @kindex C-c C-k @cindex with-editor-cancel @item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-cancel}) Cancel the current editing session by returning with exit code 1. Git then cancels the commit, but leaves the file untouched. @end table In addition to being used by Git, these messages may also be stored in a ring that persists until Emacs is closed. By default the message is stored at the beginning and the end of an edit session (regardless of whether the session is finished successfully or was canceled). It is sometimes useful to bring back messages from that ring. @table @asis @kindex C-c M-s @cindex git-commit-save-message @item @kbd{C-c M-s} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-save-message}) Save the current buffer content to the commit message ring. @kindex M-p @cindex git-commit-prev-message @item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-prev-message}) Cycle backward through the commit message ring, after saving the current message to the ring. With a numeric prefix ARG, go back ARG comments. @kindex M-n @cindex git-commit-next-message @item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-next-message}) Cycle forward through the commit message ring, after saving the current message to the ring. With a numeric prefix ARG, go back ARG comments. @end table By default the diff for the changes that are about to be committed are automatically shown when invoking the commit. When amending to an existing commit it may be useful to show either the changes that are about to be added to that commit or to show those changes together with those that are already committed. @table @asis @kindex C-c C-d @cindex magit-diff-while-committing @item @kbd{C-c C-d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-while-committing}) While committing, show the changes that are about to be committed. While amending, invoking the command again toggles between showing just the new changes or all the changes that will be committed. @kindex C-c C-w @cindex magit-pop-revision-stack @item @kbd{C-c C-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-pop-revision-stack}) This command inserts a representation of a revision into the current buffer. It can be used inside buffers used to write commit messages but also in other buffers such as buffers used to edit emails or ChangeLog files. By default this command pops the revision which was last added to the @code{magit-revision-stack} and inserts it into the current buffer according to @code{magit-pop-revision-stack-format}. Revisions can be put on the stack using @code{magit-copy-section-value} and @code{magit-copy-buffer-revision}. If the stack is empty or with a prefix argument it instead reads 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. @end table @defopt magit-pop-revision-stack-format This option controls how the command @code{magit-pop-revision-stack} inserts a revision into the current buffer. The entries on the stack have the format @code{(HASH TOPLEVEL)} and this option has the format @code{(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 @dots{}' 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). @end defopt Some projects use pseudo headers in commit messages. Magit colorizes such headers and provides some commands to insert such headers. @defopt git-commit-known-pseudo-headers A list of Git pseudo headers to be highlighted. @end defopt @table @asis @kindex C-c C-a @cindex git-commit-ack @item @kbd{C-c C-a} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-ack}) Insert a header acknowledging that you have looked at the commit. @kindex C-c C-r @cindex git-commit-review @item @kbd{C-c C-r} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-review}) Insert a header acknowledging that you have reviewed the commit. @kindex C-c C-s @cindex git-commit-signoff @item @kbd{C-c C-s} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-signoff}) Insert a header to sign off the commit. @kindex C-c C-t @cindex git-commit-test @item @kbd{C-c C-t} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-test}) Insert a header acknowledging that you have tested the commit. @kindex C-c C-o @cindex git-commit-cc @item @kbd{C-c C-o} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-cc}) Insert a header mentioning someone who might be interested. @kindex C-c C-p @cindex git-commit-reported @item @kbd{C-c C-p} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-reported}) Insert a header mentioning the person who reported the issue being fixed by the commit. @kindex C-c C-i @cindex git-commit-suggested @item @kbd{C-c C-i} @tie{}@tie{}@tie{}@tie{}(@code{git-commit-suggested}) Insert a header mentioning the person who suggested the change. @end table @code{git-commit-mode} is a minor mode that is only used to establish the above key bindings. This allows using an arbitrary major mode when editing the commit message. It's even possible to use a different major mode in different repositories, which is useful when different projects impose different commit message conventions. @defopt git-commit-major-mode The value of this option is the major mode used to edit Git commit messages. @end defopt Because @code{git-commit-mode} is a minor mode, we don't use its mode hook to setup the buffer, except for the key bindings. All other setup happens in the function @code{git-commit-setup}, which among other things runs the hook @code{git-commit-setup-hook}. The following functions are suitable for that hook. @defopt git-commit-setup-hook Hook run at the end of @code{git-commit-setup}. @end defopt @defun magit-revert-buffers &optional force Revert unmodified file-visiting buffers of the current repository. If either @code{magit-revert-buffers} is non-nil and @code{inhibit-magit-revert} is nil, or if optional FORCE is non-nil, then revert all unmodified buffers that visit files being tracked in the current repository. @end defun @defun git-commit-save-message Save the current buffer content to the commit message ring. @end defun @defun git-commit-setup-changelog-support After this function is called, ChangeLog entries are treated as paragraphs. @end defun @defun git-commit-turn-on-auto-fill Turn on @code{auto-fill-mode} and set @code{fill-column} to the value of @code{git-commit-fill-column}. @end defun @defun git-commit-turn-on-flyspell Turn on Flyspell mode. Also prevent comments from being checked and finally check current non-comment text. @end defun @defun git-commit-propertize-diff Propertize the diff shown inside the commit message buffer. Git inserts such diffs into the commit message template when the @code{--verbose} argument is used. Magit's commit popup by default does not offer that argument because the diff that is shown in a separate buffer is more useful. But some users disagree, which is why this function exists. @end defun @defun with-editor-usage-message Show usage information in the echo area. @end defun Magit also helps with writing @strong{good} commit messages by complaining when certain rules are violated. @defopt git-commit-summary-max-length The intended maximal length of the summary line of commit messages. Characters beyond this column are colorized to indicate that this preference has been violated. @end defopt @defopt git-commit-fill-column Column beyond which automatic line-wrapping should happen in commit message buffers. @end defopt @defopt git-commit-finish-query-functions List of functions called to query before performing commit. The commit message buffer is current while the functions are called. If any of them returns nil, then the commit is not performed and the buffer is not killed. The user should then fix the issue and try again. The functions are called with one argument. If it is non-nil then that indicates that the user used a prefix argument to force finishing the session despite issues. Functions should usually honor this wish and return non-nil. @end defopt @defun git-commit-check-style-conventions Check for violations of certain basic style conventions. For each violation ask the user if she wants to proceed anyway. This makes sure the summary line isn't too long and that the second line is empty. @end defun To show no diff while committing remove @code{magit-commit-diff} from @code{server-switch-hook}. @node Branching @section Branching @menu * The Two Remotes:: * The Branch Popup:: * The Branch Config Popup:: * Auxiliary Branch Commands:: @end menu @node The Two Remotes @subsection The Two Remotes The upstream branch of some local branch is the branch into which the commits on that local branch should eventually be merged, usually something like @code{origin/master}. For the @code{master} branch itself the upstream branch and the branch it is being pushed to, are usually the same remote branch. But for a feature branch the upstream branch and the branch it is being pushed to should differ. The commits on feature branches too should @emph{eventually} end up in a remote branch such as @code{origin/master} or @code{origin/maint}. Such a branch should therefore be used as the upstream. But feature branches shouldn't be pushed directly to such branches. Instead a feature branch @code{my-feature} is usually pushed to @code{my-fork/my-feature} or if you are a contributor @code{origin/my-feature}. After the new feature has been reviewed, the maintainer merges the feature into @code{master}. And finally @code{master} (not @code{my-feature} itself) is pushed to @code{origin/master}. But new features seldom are perfect on the first try, and so feature branches usually have to be reviewed, improved, and re-pushed several times. Pushing should therefore be easy to do, and for that reason many Git users have concluded that it is best to use the remote branch to which the local feature branch is being pushed as its upstream. But luckily Git has long ago gained support for a push-remote which can be configured separately from the upstream branch, using the variables @code{branch..pushRemote} and @code{remote.pushDefault}. So we no longer have to choose which of the two remotes should be used as "the remote". Each of the fetching, pulling, and pushing popups features three commands that act on the current branch and some other branch. Of these, @code{p} is bound to a command which acts on the push-remote, @code{u} is bound to a command which acts on the upstream, and @code{e} is bound to a command which acts on any other branch. The status buffer shows unpushed and unpulled commits for both the push-remote and the upstream. It's fairly simple to configure these two remotes. The values of all the variables that are related to fetching, pulling, and pushing (as well as some other branch-related variables) can be inspected and changed using the popup @code{magit-branch-config-popup}, which is a sub-popup of many popups that deal with branches. It is also possible to set the push-remote or upstream while pushing (see @ref{Pushing}). @node The Branch Popup @subsection The Branch Popup The popup @code{magit-branch-popup} is used to create and checkout branches, and to make changes to existing branches. It is not used to fetch, pull, merge, rebase, or push branches, i.e. this popup deals with branches themselves, not with the commits reachable from them. Those features are available from separate popups. @table @asis @kindex b @cindex magit-branch-popup @item @kbd{b} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-popup}) This prefix command shows the following suffix commands in a popup buffer. By default it also displays the values of some branch-related Git variables and allows changing their values, just like the specialized @code{magit-branch-config-popup} does. @end table @defopt magit-branch-popup-show-variables Whether the @code{magit-branch-popup} shows Git variables. This defaults to t to avoid changing key bindings. When set to nil, no variables are displayed directly in this popup, and the sub-popup @code{magit-branch-config-popup} has to be used instead to view and change branch related variables. @end defopt @table @asis @kindex b C @cindex magit-branch-config-popup @item @kbd{b C} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-config-popup}) This command shows branch related variables in a separate popup. By default this asks the user for which branch the variables should be shown. When @code{magit-branch-popup-show-variables} is @code{nil}, then it shows the variables for the current branch, unless a prefix argument is used. @kindex b b @cindex magit-checkout @item @kbd{b b} @tie{}@tie{}@tie{}@tie{}(@code{magit-checkout}) Checkout a revision read in the minibuffer and defaulting to the branch or arbitrary revision at point. If the revision is a local branch then that becomes the current branch. If it is something else then @code{HEAD} becomes detached. Checkout fails if the working tree or the staging area contain changes. @kindex b n @cindex magit-branch-create @item @kbd{b n} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-create}) Create a new branch. The user is asked for a branch or arbitrary revision to use as the starting point of the new branch. When a branch name is provided, then that becomes the upstream branch of the new branch. The name of the new branch is also read in the minibuffer. Also see option @code{magit-branch-prefer-remote-upstream}. @kindex b c @cindex magit-branch-and-checkout @item @kbd{b c} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-and-checkout}) This command creates a new branch like @code{magit-branch}, but then also checks it out. Also see option @code{magit-branch-prefer-remote-upstream}. @kindex b l @cindex magit-branch-checkout @item @kbd{b l} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-checkout}) This command checks out an existing or new local branch. It reads a branch name from the user offering all local branches and a subset of remote branches as candidates. Remote branches for which a local branch by the same name exists are omitted from the list of candidates. The user can also enter a completely new branch name. @itemize @item If the user selects an existing local branch, then that is checked out. @item If the user selects a remote branch, then it creates and checks out a new local branch with the same name, and configures the selected remote branch as the push target. @item If the user enters a new branch name, then it creates and checks that out, after also reading the starting-point from the user. @end itemize In the latter two cases the upstream is also set. Whether it is set to the chosen starting point or something else depends on the value of @code{magit-branch-adjust-remote-upstream-alist}. @kindex b s @cindex magit-branch-spinoff @item @kbd{b s} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-spinoff}) This command creates and checks out 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 @code{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 @code{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 @code{HEAD} are moved to the new branch. If FROM is not reachable from @code{HEAD} or is reachable from the source branch's upstream, then an error is raised. @kindex b Y @cindex magit-branch-pull-request @item @kbd{b Y} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-pull-request}) This command creates and configures a new branch from a Github pull-request, creating and configuring a new remote if necessary. The name of the local branch is the same as the name of the remote branch that you are being asked to merge, unless the contributor could not be bother to properly name the branch before opening the pull-request. The most likely such case is when you are being asked to merge something like "fork/master" into "origin/master". In such cases the local branch will be named "pr-N", where @code{N} is the pull-request number. These variables are always set by this command: @itemize @item @code{branch..pullRequest} is set to the pull-request number. @item @code{branch..pullRequestRemote} is set to the remote on which the pull-request branch is located. @item @code{branch..pushRemote} is set to the same remote as @code{branch..pullRequestRemote} if that is possible, otherwise it is set to the upstream remote. @item @code{branch..description} is set to the pull-request title. @item @code{branch..rebase} is set to @code{true} because there should be no merge commits among the commits in a pull-request. @end itemize This command also configures the upstream and the push-remote of the local branch that it creates. The branch against which the pull-request was opened, is always used as the upstream. This makes it easy to see what commits you are being asked to merge in the section titled something like "Unmerged into origin/master". Like for other commands that create a branch it depends on the option @code{magit-branch-prefer-remote-upstream} whether the remote branch itself or the respective local branch is used as the upstream, so this section may also be titled e.g. "Unmerged into master". When necessary and possible, then the remote pull-request branch is configured to be used as the push-target. This makes it easy to see what further changes the contributor has made since you last reviewed their changes in the section titled something like "Unpulled from origin/new-feature" or "Unpulled from fork/new-feature". @itemize @item If the pull-request branch is located in the upstream repository, then you probably have set @code{remote.pushDefault} to that repository. However some users like to set that variable to their personal fork, even if they have push access to the upstream, so @code{branch..pushRemote} is set anyway. @item If the pull-request branch is located inside a fork, then you are usually able to push to that branch, because Github by default allows the recipient of a pull-request to push to the remote pull-request branch even if it is located in a fork. The contributor has to explicitly disable this. @itemize @item If you are not allowed to push to the pull-request branch on the fork, then a branch by the same name located in the upstream repository is configured as the push-target. @item A — sadly rather common — special case is when the contributor didn't bother to use a dedicated branch for the pull-request. The most likely such case is when you are being asked to merge something like "fork/master" into "origin/master". The special push permission mentioned above is never granted for the branch that is the repository's default branch, and that would almost certainly be the case in this scenario. To enable you to easily push somewhere anyway, the local branch is named "pr-N" (where @code{N} is the pull-request number) and the upstream repository is used as the push-remote. @item Finally, if you are allowed to push to the pull-request branch and the contributor had the foresight to use a dedicated branch, then the fork is configured as the push-remote. @end itemize The push-remote is configured using @code{branch..pushRemote}, even if the used value is identical to that of @code{remote.pushDefault}, just in case you change the value of the latter later on. Additionally the variable @code{branch..pullRequestRemote} is set to the remote on which the pull-request branch is located. @end itemize When you later delete the local pull-request branch, then you are offered to also delete the corresponding remote, provided it is not the upstream remote and that the tracking branch that corresponds to the deleted branch is the only remaining tracked branch. If you don't confirm, then only the tracking branch itself is deleted in addition to the local branch. Do not delete the tracking branch instead of the local branch. The cleanup mentioned in the previous paragraph is not performed if you do that. @kindex b y @cindex magit-checkout-pull-request @item @kbd{b y} @tie{}@tie{}@tie{}@tie{}(@code{magit-checkout-pull-request}) This command creates and configures a new branch from a pull request, the same way @code{magit-branch-pull-request} does. Additionally it checks out the new branch. @kindex b x @cindex magit-branch-reset @item @kbd{b x} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-reset}) This command resets a branch, defaulting to the branch at point, to the tip of another branch or any other commit. When the branch being reset is the current branch, then a hard reset is performed. 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 the target branch is set as the upstream of the branch that is being reset. @kindex b k @cindex magit-branch-delete @item @kbd{b k} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-delete}) 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. @kindex b r @cindex magit-branch-rename @item @kbd{b r} @tie{}@tie{}@tie{}@tie{}(@code{magit-branch-rename}) Rename a branch. The branch and the new name are read in the minibuffer. With prefix argument the branch is renamed even if that name conflicts with an existing branch. @end table @defopt magit-branch-read-upstream-first When creating a branch, whether to read the upstream branch before the name of the branch that is to be created. The default is @code{nil}, and I recommend you leave it at that. @end defopt @defopt magit-branch-prefer-remote-upstream This option specifies whether remote upstreams are favored over local upstreams when creating new branches. When a new branch is created, then the branch, commit, or stash at point is suggested as the 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.: @example feature --upstream--> origin/master @end example instead of @example feature --upstream--> master --upstream--> origin/master @end example Which you prefer is a matter of personal preference. If you do prefer the former, then you should add branches such as @code{master}, @code{next}, and @code{maint} to the value of this options. @end defopt @defopt magit-branch-adjust-remote-upstream-alist The value of this option is an alist of branches to be used as the upstream when branching a remote branch. 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 @code{((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 @strong{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: @lisp (("origin/master" "master" "next" "maint")) @end lisp Or if the names of all your ephemeral branches contain a slash, at least in some repositories, then a good value could be: @lisp (("origin/master" . "/")) @end lisp Of course you can also fine-tune: @lisp (("origin/maint" . "\\`hotfix/") ("origin/master" . "\\`feature/")) @end lisp @end defopt @cindex magit-branch-orphan @deffn Command magit-branch-orphan This command creates and checks out a new orphan branch with contents from a given revision. @end deffn @cindex magit-branch-or-checkout @deffn Command magit-branch-or-checkout This command is a hybrid between @code{magit-checkout} and @code{magit-branch-and-checkout} and is intended as a replacement for the former in @code{magit-branch-popup}. It first asks the user for an existing branch or revision. If the user input actually can be resolved as a branch or revision, then it checks that out, just like @code{magit-checkout} would. Otherwise it creates and checks out a new branch using the input as its name. Before doing so it reads the starting-point for the new branch. This is similar to what @code{magit-branch-and-checkout} does. To use this command instead of @code{magit-checkout} add this to your init file: @lisp (magit-remove-popup-key 'magit-branch-popup :action ?b) (magit-define-popup-action 'magit-branch-popup ?b "Checkout" 'magit-branch-or-checkout 'magit-branch t) @end lisp @end deffn @node The Branch Config Popup @subsection The Branch Config Popup @cindex magit-branch-config-popup @deffn Command magit-branch-config-popup This prefix command shows the following branch-related Git variables in a popup buffer. The values can be changed from that buffer. This popup is a sub-popup of several popups that deal with branches, including @code{magit-branch-popup}, @code{magit-pull-popup}, @code{magit-fetch-popup}, @code{magit-pull-and-fetch-popup}, and @code{magit-push-popup}. In all of these popups "C" is bound to this popup. @end deffn The following variables are used to configure a specific branch. The values are being displayed for the current branch (if any). To change the value for another branch invoke @code{magit-branch-config-popup} with a prefix argument. @defvar branch.NAME.merge Together with @code{branch.NAME.remote} this variable defines the upstream branch of the local branch named NAME@. The value of this variable is the full reference of the upstream @emph{branch}. @end defvar @defvar branch.NAME.remote Together with @code{branch.NAME.merge} this variable defines the upstream branch of the local branch named NAME@. The value of this variable is the name of the upstream @emph{remote}. @end defvar @defvar branch.NAME.rebase This variable controls whether pulling into the branch named NAME is done by rebasing or by merging the fetched branch. @itemize @item When @code{true} then pulling is done by rebasing. @item When @code{false} then pulling is done by merging. @item When undefined then the value of @code{pull.rebase} is used. The default of that variable is @code{false}. @end itemize @end defvar @defvar branch.NAME.pushRemote This variable specifies the remote that the branch named NAME is usually pushed to. The value has to be the name of an existing remote. It is not possible to specify the name of @emph{branch} to push the local branch to. The name of the remote branch is always the same as the name of the local branch. If this variable is undefined but @code{remote.pushDefault} is defined, then the value of the latter is used. By default @code{remote.pushDefault} is undefined. @end defvar @defvar branch.NAME.description This variable can be used to describe the branch named NAME@. That description is used e.g. when turning the branch into a series of patches. @end defvar The following variables specify defaults which are used if the above branch-specific variables are not set. @defvar pull.rebase This variable specifies whether pulling is done by rebasing or by merging. It can be overwritten using @code{branch.NAME.rebase}. @itemize @item When @code{true} then pulling is done by rebasing. @item When @code{false} (the default) then pulling is done by merging. @end itemize Since it is never a good idea to merge the upstream branch into a feature or hotfix branch and most branches are such branches, you should consider setting this to @code{true}, and @code{branch.master.rebase} to @code{false}. @end defvar @defvar remote.pushDefault This variable specifies what remote the local branches are usually pushed to. This can be overwritten per branch using @code{branch.NAME.pushRemote}. @end defvar The following variables are used during the creation of a branch and control whether the various branch-specific variables are automatically set at this time. @defvar branch.autoSetupMerge This variable specifies under what circumstances creating a branch NAME should result in the variables @code{branch.NAME.merge} and @code{branch.NAME.remote} being set according to the starting point used to create the branch. If the starting point isn't a branch, then these variables are never set. @itemize @item When @code{always} then the variables are set regardless of whether the starting point is a local or a remote branch. @item When @code{true} (the default) then the variables are set when the starting point is a remote branch, but not when it is a local branch. @item When @code{false} then the variables are never set. @end itemize @end defvar @defvar branch.autoSetupRebase This variable specifies whether creating a branch NAME should result in the variable @code{branch.NAME.rebase} being set to @code{true}. @itemize @item When @code{always} then the variable is set regardless of whether the starting point is a local or a remote branch. @item When @code{local} then the variable are set when the starting point is a local branch, but not when it is a remote branch. @item When @code{remote} then the variable are set when the starting point is a remote branch, but not when it is a local branch. @item When @code{never} (the default) then the variable is never set. @end itemize @end defvar Note that the respective commands always change the repository-local values. If you want to change the global value, which is used when the local value is undefined, then you have to do so on the command line, e.g.: @example git config --global remote.autoSetupMerge always @end example For more information about these variables you should also see @ifinfo @ref{git-config,,,gitman,}. @end ifinfo @ifhtml @html the git-config(1) manpage. @end html @end ifhtml @iftex the git-config(1) manpage. @end iftex Also see @ifinfo @ref{git-branch,,,gitman,}. @end ifinfo @ifhtml @html the git-branch(1) manpage. @end html @end ifhtml @iftex the git-branch(1) manpage. @end iftex , @ifinfo @ref{git-checkout,,,gitman,}. @end ifinfo @ifhtml @html the git-checkout(1) manpage. @end html @end ifhtml @iftex the git-checkout(1) manpage. @end iftex and @ref{Pushing}. @defopt magit-prefer-remote-upstream This option controls whether commands that read a branch from the user and then set it as the upstream branch, offer a local or a remote branch as default completion candidate, when they have the choice. This affects all commands that use @code{magit-read-upstream-branch} or @code{magit-read-starting-point}, which includes all commands that change the upstream and many which create new branches. @end defopt @node Auxiliary Branch Commands @subsection Auxiliary Branch Commands These commands are not available from the branch popup by default. @cindex magit-branch-shelve @deffn Command magit-branch-shelve This command shelves a branch. This is done by deleting the branch, and creating a new reference "refs/shelved/BRANCH-NAME" pointing at the same commit as the branch pointed at. If the deleted branch had a reflog, then that is preserved as the reflog of the new reference. This is useful if you want to move a branch out of sight, but are not ready to completely discard it yet. @end deffn @cindex magit-branch-unshelve @deffn Command magit-branch-unshelve This command unshelves a branch that was previously shelved using @code{magit-branch-shelve}. This is done by deleting the reference "refs/shelved/BRANCH-NAME" and creating a branch "BRANCH-NAME" pointing at the same commit as the deleted reference pointed at. If the deleted reference had a reflog, then that is restored as the reflog of the branch. @end deffn @node Merging @section Merging Also see @ifinfo @ref{git-merge,,,gitman,}. @end ifinfo @ifhtml @html the git-merge(1) manpage. @end html @end ifhtml @iftex the git-merge(1) manpage. @end iftex For information on how to resolve merge conflicts see the next section. @table @asis @kindex m @cindex magit-merge-popup @item @kbd{m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table When no merge is in progress, then the popup buffer features the following commands. @table @asis @kindex m m @cindex magit-merge-plain @item @kbd{m m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-plain}) This command merges another branch or an arbitrary revision into the current branch. The branch or revision to be merged is read in the minibuffer and defaults to the branch at point. Unless there are conflicts or a prefix argument is used, then the resulting merge commit uses a generic commit message, and the user does not get a chance to inspect or change it before the commit is created. With a prefix argument this does not actually create the merge commit, which makes it possible to inspect how conflicts were resolved and to adjust the commit message. @kindex m e @cindex magit-merge-editmsg @item @kbd{m e} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-editmsg}) This command merges another branch or an arbitrary revision into the current branch and opens a commit message buffer, so that the user can make adjustments. The commit is not actually created until the user finishes with @code{C-c C-c}. @kindex m n @cindex magit-merge-nocommit @item @kbd{m n} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-nocommit}) This command merges another branch or an arbitrary revision into the current branch, but does not actually create the merge commit. The user can then further adjust the merge, even when automatic conflict resolution succeeded and/or adjust the commit message. @kindex m a @cindex magit-merge-absorb @item @kbd{m a} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-absorb}) This command merges another local branch into the current branch and then removes the former. Before the source branch is merged, it is first force pushed to its push-remote, provided the respective remote branch already exists. This ensures that the respective pull-request (if any) won't get stuck on some obsolete version of the commits that are being merged. Finally, if @code{magit-branch-pull-request} was used to create the merged branch, then the respective remote branch is also removed. @kindex m i @cindex magit-merge-into @item @kbd{m i} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-into}) This command merges the current branch into another local branch and then removes the former. The latter becomes the new current branch. Before the source branch is merged, it is first force pushed to its push-remote, provided the respective remote branch already exists. This ensures that the respective pull-request (if any) won't get stuck on some obsolete version of the commits that are being merged. Finally, if @code{magit-branch-pull-request} was used to create the merged branch, then the respective remote branch is also removed. @kindex m s @cindex magit-merge-squash @item @kbd{m s} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-squash}) This command squashes the changes introduced by another branch or an arbitrary revision into the current branch. This only applies the changes made by the squashed commits. No information is preserved that would allow creating an actual merge commit. Instead of this command you should probably use a command from the apply popup. @kindex m p @cindex magit-merge-preview @item @kbd{m p} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-preview}) This command shows a preview of merging another branch or an arbitrary revision into the current branch. @end table When a merge is in progress, then the popup buffer features these commands instead. @table @asis @kindex m m @cindex magit-merge @item @kbd{m m} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge}) After the user resolved conflicts, this command proceeds with the merge. If some conflicts weren't resolved, then this command fails. @kindex m a @cindex magit-merge-abort @item @kbd{m a} @tie{}@tie{}@tie{}@tie{}(@code{magit-merge-abort}) This command aborts the current merge operation. @end table @node Resolving Conflicts @section Resolving Conflicts When merging branches (or otherwise combining or changing history) conflicts can occur. If you edited two completely different parts of the same file in two branches and then merge one of these branches into the other, then Git can resolve that on its own, but if you edit the same area of a file, then a human is required to decide how the two versions, or "sides of the conflict", are to be combined into one. Here we can only provide a brief introduction to the subject and point you toward some tools that can help. If you are new to this, then please also consult Git's own documentation as well as other resources. If a file has conflicts and Git cannot resolve them by itself, then it puts both versions into the affected file along with special markers whose purpose is to denote the boundaries of the unresolved part of the file and between the different versions. These boundary lines begin with the strings consisting of six times the same character, one of @code{<}, @code{|}, @code{=} and @code{>} and are followed by information about the source of the respective versions, e.g.: @example <<<<<<< HEAD Take the blue pill. ======= Take the red pill. >>>>>>> feature @end example In this case you have chosen to take the red pill on one branch and on another you picked the blue pill. Now that you are merging these two diverging branches, Git cannot possibly know which pill you want to take. To resolve that conflict you have to create a version of the affected area of the file by keeping only one of the sides, possibly by editing it in order to bring in the changes from the other side, remove the other versions as well as the markers, and then stage the result. A possible resolution might be: @example Take both pills. @end example Often it is useful to see not only the two sides of the conflict but also the "original" version from before the same area of the file was modified twice on different branches. Instruct Git to insert that version as well by running this command once: @example git config --global merge.conflictStyle diff3 @end example The above conflict might then have looked like this: @example <<<<<<< HEAD Take the blue pill. ||||||| merged common ancestors Take either the blue or the red pill, but not both. ======= Take the red pill. >>>>>>> feature @end example If that were the case, then the above conflict resolution would not have been correct, which demonstrates why seeing the original version alongside the conflicting versions can be useful. You can perform the conflict resolution completely by hand, but Emacs also provides some packages that help in the process: Smerge, Ediff (@ref{Top,,,ediff,}), and Emerge (@ref{Emerge,,,emacs,}). Magit does not provide its own tools for conflict resolution, but it does make using Smerge and Ediff more convenient. (Ediff supersedes Emerge, so you probably don't want to use the latter anyway.) In the Magit status buffer, files with unresolved conflicts are listed in the "Unstaged changes" and/or "Staged changes" sections. They are prefixed with the word "unmerged", which in this context essentially is a synonym for "unresolved". Pressing @code{RET} while point is on such a file section shows a buffer visiting that file, turns on @code{smerge-mode} in that buffer, and places point inside the first area with conflicts. You should then resolve that conflict using regular edit commands and/or Smerge commands. Unfortunately Smerge does not have a manual, but you can get a list of commands and binding @code{C-c ^ C-h} and press @code{RET} while point is on a command name to read its documentation. Normally you would edit one version and then tell Smerge to keep only that version. Use @code{C-c ^ m} (@code{smerge-keep-mine}) to keep the @code{HEAD} version or @code{C-c ^ o} (@code{smerge-keep-other}) to keep the version that follows "|||||||". Then use @code{C-c ^ n} to move to the next conflicting area in the same file. Once you are done resolving conflicts, return to the Magit status buffer. The file should now be shown as "modified", no longer as "unmerged", because Smerge automatically stages the file when you save the buffer after resolving the last conflict. Alternatively you could use Ediff, which uses separate buffers for the different versions of the file. To resolve conflicts in a file using Ediff press @code{e} while point is on such a file in the status buffer. Ediff can be used for other purposes as well. For more information on how to enter Ediff from Magit, see @ref{Ediffing}. Explaining how to use Ediff is beyond the scope of this manual, instead see @ref{Top,,,ediff,}. If you are unsure whether you should Smerge or Ediff, then use the former. It is much easier to understand and use, and except for truly complex conflicts, the latter is usually overkill. @node Rebasing @section Rebasing Also see @ifinfo @ref{git-rebase,,,gitman,}. @end ifinfo @ifhtml @html the git-rebase(1) manpage. @end html @end ifhtml @iftex the git-rebase(1) manpage. @end iftex For information on how to resolve conflicts that occur during rebases see the preceding section. @table @asis @kindex r @cindex magit-rebase-popup @item @kbd{r} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table When no rebase is in progress, then the popup buffer features the following commands. Using one of these commands @emph{starts} a rebase sequence. Git might then stop somewhere along the way, either because you told it to do so, or because applying a commit failed due to a conflict. When that happens, then the status buffer shows information about the rebase sequence which is in progress in a section similar to a log section. See @ref{Information About In-Progress Rebase}. @table @asis @kindex r p @cindex magit-rebase-onto-pushremote @item @kbd{r p} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-onto-pushremote}) Rebase the current branch onto @code{branch..pushRemote}. If that variable is unset, then rebase onto @code{remote.pushDefault}. @kindex r u @cindex magit-rebase-onto-upstream @item @kbd{r u} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-onto-upstream}) Rebase the current branch onto its upstream branch. @kindex r e @cindex magit-rebase-branch @item @kbd{r e} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-branch}) Rebase the current branch onto a branch read in the minibuffer. All commits that are reachable from head but not from the selected branch TARGET are being rebased." @kindex r s @cindex magit-rebase-subset @item @kbd{r s} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-subset}) Start a non-interactive rebase sequence with commits from START to @code{HEAD} onto NEWBASE@. START has to be selected from a list of recent commits. @end table By default Magit uses the @code{--autostash} argument, which causes uncommitted changes to be stored in a stash before the rebase begins. These changes are restored after the rebase completes and if possible the stash is removed. If the stash does not apply cleanly, then the stash is not removed. In case something goes wrong when resolving the conflicts, this allows you to start over. Even though one of the actions is dedicated to interactive rebases, the popup also features the infix argument @code{--interactive}. This can be used to turn one of the other, non-interactive rebase variants into an interactive rebase. For example if you want to clean up a feature branch and at the same time rebase it onto @code{master}, then you could use @code{r-iu}. But we recommend that you instead do that in two steps. First use @code{ri} to cleanup the feature branch, and then in a second step @code{ru} to rebase it onto @code{master}. That way if things turn out to be more complicated than you thought and/or you make a mistake and have to start over, then you only have to redo half the work. Explicitly enabling @code{--interactive} won't have an effect on the following commands as they always use that argument anyway, even if it is not enabled in the popup. @table @asis @kindex r i @cindex magit-rebase-interactive @item @kbd{r i} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-interactive}) Start an interactive rebase sequence. @kindex r f @cindex magit-rebase-autosquash @item @kbd{r f} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-autosquash}) Combine squash and fixup commits with their intended targets. @kindex r m @cindex magit-rebase-edit-commit @item @kbd{r m} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-edit-commit}) Edit a single older commit using rebase. @kindex r w @cindex magit-rebase-reword-commit @item @kbd{r w} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-reword-commit}) Reword a single older commit using rebase. @kindex r k @cindex magit-rebase-remove-commit @item @kbd{r k} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-remove-commit}) Remove a single older commit using rebase. @end table When a rebase is in progress, then the popup buffer features these commands instead. @table @asis @kindex r r @cindex magit-rebase-continue @item @kbd{r r} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-continue}) Restart the current rebasing operation. In some cases this pops up a commit message buffer for you do edit. With a prefix argument the old message is reused as-is. @kindex r s @cindex magit-rebase-skip @item @kbd{r s} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-skip}) Skip the current commit and restart the current rebase operation. @kindex r e @cindex magit-rebase-edit @item @kbd{r e} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-edit}) Edit the todo list of the current rebase operation. @kindex r a @cindex magit-rebase-abort @item @kbd{r a} @tie{}@tie{}@tie{}@tie{}(@code{magit-rebase-abort}) Abort the current rebase operation, restoring the original branch. @end table @menu * Editing Rebase Sequences:: * Information About In-Progress Rebase:: @end menu @node Editing Rebase Sequences @subsection Editing Rebase Sequences @table @asis @kindex C-c C-c @cindex with-editor-finish @item @kbd{C-c C-c} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-finish}) Finish the current editing session by returning with exit code 0. Git then uses the rebase instructions it finds in the file. @kindex C-c C-k @cindex with-editor-cancel @item @kbd{C-c C-k} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-cancel}) Cancel the current editing session by returning with exit code 1. Git then forgoes starting the rebase sequence. @kindex RET @cindex git-rebase-show-commit @item @kbd{RET} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-commit}) Show the commit on the current line in another buffer and select that buffer. @kindex SPC @cindex git-rebase-show-or-scroll-up @item @kbd{SPC} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-or-scroll-up}) Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window up. @kindex DEL @cindex git-rebase-show-or-scroll-down @item @kbd{DEL} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-show-or-scroll-down}) Show the commit on the current line in another buffer without selecting that buffer. If the revision buffer is already visible in another window of the current frame, then instead scroll that window down. @kindex p @cindex git-rebase-backward-line @item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-backward-line}) Move to previous line. @kindex n @cindex forward-line @item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{forward-line}) Move to next line. @kindex M-p @cindex git-rebase-move-line-up @item @kbd{M-p} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-move-line-up}) Move the current commit (or command) up. @kindex M-n @cindex git-rebase-move-line-down @item @kbd{M-n} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-move-line-down}) Move the current commit (or command) down. @kindex r @cindex git-rebase-reword @item @kbd{r} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-reword}) Edit message of commit on current line. @kindex e @cindex git-rebase-edit @item @kbd{e} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-edit}) Stop at the commit on the current line. @kindex s @cindex git-rebase-squash @item @kbd{s} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-squash}) Meld commit on current line into previous commit, and edit message. @kindex f @cindex git-rebase-fixup @item @kbd{f} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-fixup}) Meld commit on current line into previous commit, discarding the current commit's message. @kindex k @cindex git-rebase-kill-line @item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-kill-line}) Kill the current action line. @kindex c @cindex git-rebase-pick @item @kbd{c} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-pick}) Use commit on current line. @kindex x @cindex git-rebase-exec @item @kbd{x} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-exec}) Insert a shell command to be run after the proceeding 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. @kindex y @cindex git-rebase-insert @item @kbd{y} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-insert}) Read an arbitrary commit and insert it below current line. @kindex C-x u @cindex git-rebase-undo @item @kbd{C-x u} @tie{}@tie{}@tie{}@tie{}(@code{git-rebase-undo}) Undo some previous changes. Like @code{undo} but works in read-only buffers. @end table @defopt git-rebase-auto-advance Whether to move to next line after changing a line. @end defopt @defopt git-rebase-show-instructions Whether to show usage instructions inside the rebase buffer. @end defopt @defopt git-rebase-confirm-cancel Whether confirmation is required to cancel. @end defopt @node Information About In-Progress Rebase @subsection Information About In-Progress Rebase While a rebase sequence is in progress, the status buffer features a section that lists the commits that have already been applied as well as the commits that still have to be applied. The commits are split in two halves. When rebase stops at a commit, either because the user has to deal with a conflict or because s/he explicitly requested that rebase stops at that commit, then point is placed on the commit that separates the two groups, i.e. on @code{HEAD}. The commits above it have not been applied yet, while the @code{HEAD} and the commits below it have already been applied. In between these two groups of applied and yet-to-be applied commits, there sometimes is a commit which has been dropped. Each commit is prefixed with a word and these words are additionally shown in different colors to indicate the status of the commits. The following colors are used: @itemize @item Yellow commits have not been applied yet. @item Gray commits have already been applied. @item The blue commit is the @code{HEAD} commit. @item The green commit is the commit the rebase sequence stopped at. If this is the same commit as @code{HEAD} (e.g. because you haven't done anything yet after rebase stopped at the commit, then this commit is shown in blue, not green). There can only be a green @strong{and} a blue commit at the same time, if you create one or more new commits after rebase stops at a commit. @item Red commits have been dropped. They are shown for reference only, e.g. to make it easier to diff. @end itemize Of course these colors are subject to the color-theme in use. The following words are used: @itemize @item Commits prefixed with @code{pick}, @code{reword}, @code{edit}, @code{squash}, and @code{fixup} have not been applied yet. These words have the same meaning here as they do in the buffer used to edit the rebase sequence. See @ref{Editing Rebase Sequences}. @item Commits prefixed with @code{done} and @code{onto} have already been applied. It is possible for such a commit to be the @code{HEAD}, in which case it is blue. Otherwise it is grey. @itemize @item The commit prefixed with @code{onto} is the commit on top of which all the other commits are being re-applied. This commit itself did not have to be re-applied, it is the commit rebase did rewind to before starting to re-apply other commits. @item Commits prefixed with @code{done} have already been re-applied. This includes commits that have been re-applied but also new commits that you have created during the rebase. @end itemize @item All other commits, those not prefixed with any of the above words, are in some way related to the commit at which rebase stopped. To determine whether a commit is related to the stopped-at commit their hashes, trees and patch-ids @footnote{The patch-id is a hash of the @emph{changes} introduced by a commit. It differs from the hash of the commit itself, which is a hash of the result of applying that change (i.e. the resulting trees and blobs) as well as author and committer information, the commit message, and the hashes of the parents of the commit. The patch-id hash on the other hand is created only from the added and removed lines, even line numbers and whitespace changes are ignored when calculating this hash. The patch-ids of two commits can be used to answer the question "Do these commits make the same change?".} are being compared. The commit message is not used for this purpose. Generally speaking commits that are related to the stopped-at commit can have any of the used colors, though not all color/word combinations are possible. Words used for stopped-at commits are: @itemize @item When a commit is prefixed with @code{void}, then that indicates that Magit knows for sure that all the changes in that commit have been applied using several new commits. This commit is no longer reachable from @code{HEAD}, and it also isn't one of the commits that will be applied when resuming the session. @item When a commit is prefixed with @code{join}, then that indicates that the rebase sequence stopped at that commit due to a conflict - you now have to join (merge) the changes with what has already been applied. In a sense this is the commit rebase stopped at, but while its effect is already in the index and in the worktree (with conflict markers), the commit itself has not actually been applied yet (it isn't the @code{HEAD}). So it is shown in yellow, like the other commits that still have to be applied. @item When a commit is prefixed with @code{stop} or a @emph{blue} or @emph{green} @code{same}, then that indicates that rebase stopped at this commit, that it is still applied or has been applied again, and that at least its patch-id is unchanged. @itemize @item When a commit is prefixed with @code{stop}, then that indicates that rebase stopped at that commit because you requested that earlier, and its patch-id is unchanged. It might even still be the exact same commit. @item When a commit is prefixed with a @emph{blue} or @emph{green} @code{same}, then that indicates that while its tree or hash changed, its patch-id did not. If it is blue, then it is the @code{HEAD} commit (as always for blue). When it is green, then it no longer is @code{HEAD} because other commit have been created since (but before continuing the rebase). @end itemize @item When a commit is prefixed with @code{goal}, a @emph{yellow} @code{same,} or @code{work}, then that indicates that rebase applied that commit but that you then reset @code{HEAD} to an earlier commit (likely to split it up into multiple commits), and that there are some uncommitted changes remaining which likely (but not necessarily) originate from that commit. @itemize @item When a commit is prefixed with @code{goal}, then that indicates that it is still possible to create a new commit with the exact same tree (the "goal") without manually editing any files, by committing the index, or by staging all changes and then committing that. This is the case when the original tree still exists in the index or worktree in untainted form. @item When a commit is prefixed with a yellow @code{same}, then that indicates that it is no longer possible to create a commit with the exact same tree, but that it is still possible to create a commit with the same patch-id. This would be the case if you created a new commit with other changes, but the changes from the original commit still exist in the index or working tree in untainted form. @item When a commit is prefixed with @code{work}, then that indicates that you reset @code{HEAD} to an earlier commit, and that there are some staged and/or unstaged changes (likely, but not necessarily) originating from that commit. However it is no longer possible to create a new commit with the same tree or at least the same patch-id because you have already made other changes. @end itemize @item When a commit is prefixed with @code{poof} or @code{gone}, then that indicates that rebase applied that commit but that you then reset @code{HEAD} to an earlier commit (likely to split it up into multiple commits), and that there are no uncommitted changes. @itemize @item When a commit is prefixed with @code{poof}, then that indicates that it is no longer reachable from @code{HEAD}, but that it has been replaced with one or more commits, which together have the exact same effect. @item When a commit is prefixed with @code{gone}, then that indicates that it is no longer reachable from @code{HEAD} and that we also cannot determine whether its changes are still in effect in one or more new commits. They might be, but if so, then there must also be other changes which makes it impossible to know for sure. @end itemize @end itemize @end itemize Do not worry if you do not fully understand the above. That's okay, you will acquire a good enough understanding through practice. For other sequence operations such as cherry-picking, a similar section is displayed, but they lack some of the features described above, due to limitations in the git commands used to implement them. Most importantly these sequences only support "picking" a commit but not other actions such as "rewording", and they do not keep track of the commits which have already been applied. @node Cherry Picking @section Cherry Picking Also see @ifinfo @ref{git-cherry-pick,,,gitman,}. @end ifinfo @ifhtml @html the git-cherry-pick(1) manpage. @end html @end ifhtml @iftex the git-cherry-pick(1) manpage. @end iftex @table @asis @kindex A @cindex magit-cherry-pick-popup @item @kbd{A} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-pick-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table When no cherry-pick or revert is in progress, then the popup buffer features the following commands. @table @asis @kindex A A @cindex magit-cherry-copy @item @kbd{A A} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-copy}) This command copies COMMITS from another branch onto the current branch. If the region selects multiple commits, then those are copied, without prompting. Otherwise the user is prompted for a commit or range, defaulting to the commit at point. @kindex A a @cindex magit-cherry-apply @item @kbd{A a} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-apply}) This command applies the changes in COMMITS from another branch onto the current branch. If the region selects multiple commits, then those are used, without prompting. Otherwise the user is prompted for a commit or range, defaulting to the commit at point. This command also has a top-level binding, which can be invoked without using the popup by typing @code{a} at the top-level. @end table The following commands not only apply some commits to some branch, but also remove them from some other branch. The removal is performed using either @code{git-update-ref} or if necessary @code{git-rebase}. Both applying commits as well as removing them using @code{git-rebase} can lead to conflicts. If that happens, then these commands abort and you not only have to resolve the conflicts but also finish the process the same way you would have to if these commands didn't exist at all. @table @asis @kindex A h @cindex magit-cherry-harvest @item @kbd{A h} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-harvest}) This command moves the selected COMMITS that must be located on another BRANCH onto the current branch instead, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the current branch or removing them from the other branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. @kindex A d @cindex magit-cherry-donate @item @kbd{A d} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-donate}) This command moves the selected COMMITS from the current branch onto another existing BRANCH, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. @kindex A n @cindex magit-cherry-spinout @item @kbd{A n} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-spinout}) This command moves the selected COMMITS from the current branch onto a new branch BRANCH, removing them from the former. When this command succeeds, then the same branch is current as before. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. @kindex A s @cindex magit-cherry-spinoff @item @kbd{A s} @tie{}@tie{}@tie{}@tie{}(@code{magit-cherry-spinoff}) This command moves the selected COMMITS from the current branch onto a new branch BRANCH, removing them from the former. When this command succeeds, then the new branch is checked out. Applying the commits on the other branch or removing them from the current branch can lead to conflicts. When that happens, then this command stops and you have to resolve the conflicts and then finish the process manually. @end table When a cherry-pick or revert is in progress, then the popup buffer features these commands instead. @table @asis @kindex A A @cindex magit-sequence-continue @item @kbd{A A} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-continue}) Resume the current cherry-pick or revert sequence. @kindex A s @cindex magit-sequence-skip @item @kbd{A s} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-skip}) Skip the stopped at commit during a cherry-pick or revert sequence. @kindex A a @cindex magit-sequence-abort @item @kbd{A a} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-abort}) Abort the current cherry-pick or revert sequence. This discards all changes made since the sequence started. @end table @menu * Reverting:: @end menu @node Reverting @subsection Reverting @table @asis @kindex V @cindex magit-revert-popup @item @kbd{V} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table When no cherry-pick or revert is in progress, then the popup buffer features the following commands. @table @asis @kindex V V @cindex magit-revert-and-commit @item @kbd{V V} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert-and-commit}) Revert a commit by creating a new commit. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting. @kindex V v @cindex magit-revert-no-commit @item @kbd{V v} @tie{}@tie{}@tie{}@tie{}(@code{magit-revert-no-commit}) Revert a commit by applying it in reverse to the working tree. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting. @end table When a cherry-pick or revert is in progress, then the popup buffer features these commands instead. @table @asis @kindex V A @cindex magit-sequence-continue @item @kbd{V A} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-continue}) Resume the current cherry-pick or revert sequence. @kindex V s @cindex magit-sequence-skip @item @kbd{V s} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-skip}) Skip the stopped at commit during a cherry-pick or revert sequence. @kindex V a @cindex magit-sequence-abort @item @kbd{V a} @tie{}@tie{}@tie{}@tie{}(@code{magit-sequence-abort}) Abort the current cherry-pick or revert sequence. This discards all changes made since the sequence started. @end table @node Resetting @section Resetting Also see @ifinfo @ref{git-reset,,,gitman,}. @end ifinfo @ifhtml @html the git-reset(1) manpage. @end html @end ifhtml @iftex the git-reset(1) manpage. @end iftex @table @asis @kindex x @cindex magit-reset-quickly @item @kbd{x} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-quickly}) Reset the @code{HEAD} and index to some commit read from the user and defaulting to the commit at point, and possibly also reset the working tree. With a prefix argument reset the working tree otherwise don't. @kindex X m @cindex magit-reset-mixed @item @kbd{X m} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-mixed}) Reset the @code{HEAD} and index to some commit read from the user and defaulting to the commit at point. The working tree is kept as-is. @kindex X s @cindex magit-reset-soft @item @kbd{X s} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-soft}) Reset the @code{HEAD} to some commit read from the user and defaulting to the commit at point. The index and the working tree are kept as-is. @kindex X h @cindex magit-reset-hard @item @kbd{X h} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-hard}) Reset the @code{HEAD}, index, and working tree to some commit read from the user and defaulting to the commit at point. @kindex X i @cindex magit-reset-index @item @kbd{X i} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-index}) Reset the index to some commit read from the user and defaulting to the commit at point. Keep the @code{HEAD} and working tree as-is, so if the commit refers to the @code{HEAD}, then this effectively unstages all changes. @kindex X w @cindex magit-reset-worktree @item @kbd{X w} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-worktree}) Reset the working tree to some commit read from the user and defaulting to the commit at point. Keep the @code{HEAD} and index as-is. @kindex X f @cindex magit-file-checkout @item @kbd{X f} @tie{}@tie{}@tie{}@tie{}(@code{magit-file-checkout}) Update file in the working tree and index to the contents from a revision. Both the revision and file are read from the user. @end table @node Stashing @section Stashing Also see @ifinfo @ref{git-stash,,,gitman,}. @end ifinfo @ifhtml @html the git-stash(1) manpage. @end html @end ifhtml @iftex the git-stash(1) manpage. @end iftex @table @asis @kindex z @cindex magit-stash-popup @item @kbd{z} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex z z @cindex magit-stash-both @item @kbd{z z} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-both}) Create a stash of the index and working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to @code{--include-untracked} while two prefix arguments are equivalent to @code{--all}. @kindex z i @cindex magit-stash-index @item @kbd{z i} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-index}) Create a stash of the index only. Unstaged and untracked changes are not stashed. @kindex z w @cindex magit-stash-worktree @item @kbd{z w} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-worktree}) Create a stash of unstaged changes in the working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to @code{--include-untracked} while two prefix arguments are equivalent to @code{--all}. @kindex z x @cindex magit-stash-keep-index @item @kbd{z x} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-keep-index}) Create a stash of the index and working tree, keeping index intact. Untracked files are included according to popup arguments. One prefix argument is equivalent to @code{--include-untracked} while two prefix arguments are equivalent to @code{--all}. @kindex z Z @cindex magit-snapshot-both @item @kbd{z Z} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-both}) Create a snapshot of the index and working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to @code{--include-untracked} while two prefix arguments are equivalent to @code{--all}. @kindex z I @cindex magit-snapshot-index @item @kbd{z I} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-index}) Create a snapshot of the index only. Unstaged and untracked changes are not stashed. @kindex z W @cindex magit-snapshot-worktree @item @kbd{z W} @tie{}@tie{}@tie{}@tie{}(@code{magit-snapshot-worktree}) Create a snapshot of unstaged changes in the working tree. Untracked files are included according to popup arguments. One prefix argument is equivalent to @code{--include-untracked} while two prefix arguments are equivalent to @code{--all}-. @kindex z a @cindex magit-stash-apply @item @kbd{z a} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-apply}) 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. @kindex z p @cindex magit-stash-pop @item @kbd{z p} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-pop}) 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. @kindex z k @cindex magit-stash-drop @item @kbd{z k} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-drop}) Remove a stash from the stash list. When the region is active, offer to drop all contained stashes. @kindex z v @cindex magit-stash-show @item @kbd{z v} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-show}) Show all diffs of a stash in a buffer. @kindex z b @cindex magit-stash-branch @item @kbd{z b} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-branch}) Create and checkout a new BRANCH from STASH@. The branch starts at the commit that was current when the stash was created. @kindex z B @cindex magit-stash-branch-here @item @kbd{z B} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-branch-here}) Create and checkout a new BRANCH using @code{magit-branch} with the current branch or @code{HEAD} as the starting-point. Then apply STASH, dropping it if it applies cleanly. @kindex z f @cindex magit-stash-format-patch @item @kbd{z f} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-format-patch}) Create a patch from STASH@. @kindex k @cindex magit-stash-clear @item @kbd{k} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-clear}) Remove all stashes saved in REF's reflog by deleting REF@. @kindex z l @cindex magit-stash-list @item @kbd{z l} @tie{}@tie{}@tie{}@tie{}(@code{magit-stash-list}) List all stashes in a buffer. @end table @defopt magit-stashes-margin This option specifies whether the margin is initially shown in stashes buffers and how it is formatted. The value has the form @code{(INIT STYLE WIDTH AUTHOR AUTHOR-WIDTH)}. @itemize @item If INIT is non-nil, then the margin is shown initially. @item STYLE controls how to format the committer date. It can be one of @code{age} (to show the age of the commit), @code{age-abbreviated} (to abbreviate the time unit to a character), or a string (suitable for @code{format-time-string}) to show the actual date. @item WIDTH controls the width of the margin. This exists for forward compatibility and currently the value should not be changed. @item AUTHOR controls whether the name of the author is also shown by default. @item 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. @end itemize @end defopt @node Transferring @chapter Transferring @menu * Remotes:: * Fetching:: * Pulling:: * Pushing:: * Creating and Sending Patches:: * Applying Patches:: @end menu @node Remotes @section Remotes @menu * The Remote Popup:: * The Remote Config Popup:: @end menu @node The Remote Popup @subsection The Remote Popup The popup @code{magit-remote-popup} is used to add remotes and to make changes to existing remotes. This popup only deals with remotes themselves, not with branches or the transfer of commits. Those features are available from separate popups. Also see @ifinfo @ref{git-remote,,,gitman,}. @end ifinfo @ifhtml @html the git-remote(1) manpage. @end html @end ifhtml @iftex the git-remote(1) manpage. @end iftex @table @asis @kindex M @cindex magit-remote-popup @item @kbd{M} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table @defopt magit-remote-popup-show-variables This option controls whether the @code{magit-remote-popup} shows remote related Git variables. When set to nil, no variables are displayed directly in this popup, and the sub-popup @code{magit-remote-config-popup} has to be used instead to view and change remote related variables. @end defopt @table @asis @kindex M C @cindex magit-remote-config-popup @item @kbd{M C} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-config-popup}) This command shows remote related variables in a separate popup. By default this asks the user for which remote the variables should be shown. When @code{magit-remote-popup-show-variables} is @code{nil}, then it shows the variables for the upstream of the current branch or "origin" it that branch has no remote upstream. To select another remote use a prefix argument. @kindex M a @cindex magit-remote-add @item @kbd{M a} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-add}) This command add a remote and fetches it. The remote name and url are read in the minibuffer. @kindex M r @cindex magit-remote-rename @item @kbd{M r} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-rename}) This command renames a remote. Both the old and the new names are read in the minibuffer. @kindex M u @cindex magit-remote-set-url @item @kbd{M u} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-set-url}) This command changes the url of a remote. Both the remote and the new url are read in the minibuffer. @kindex M k @cindex magit-remote-remove @item @kbd{M k} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-remove}) This command deletes a remote, read in the minibuffer. @kindex M p @cindex magit-remote-prune @item @kbd{M p} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-prune}) This command removes stale remote-tracking branches for a remote read in the minibuffer. @kindex M P @cindex magit-remote-prune-refspecs @item @kbd{M P} @tie{}@tie{}@tie{}@tie{}(@code{magit-remote-prune-refspecs}) This command removes stale refspecs for a remote read in the minibuffer. 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 this command offers to either delete the remote or to replace the stale refspecs with the default refspec ("+refs/heads/*:refs/remotes/REMOTE/*"). This command also removes the remote-tracking branches that were created due to the now stale refspecs. Other stale branches are not removed. @end table @defopt magit-remote-add-set-remote.pushDefault This option controls whether the user is asked whether they want to set @code{remote.pushDefault} after adding a remote. If @code{ask}, then users is always ask. If @code{ask-if-unset}, then the user is only if the variable isn't set already. If @code{nil}, then the user isn't asked and the variable isn't set. If the value is a string, then the variable is set without the user being asked, provided that the name of the added remote is equal to that string and the variable isn't already set. @end defopt @node The Remote Config Popup @subsection The Remote Config Popup @cindex magit-remote-config-popup @deffn Command magit-remote-config-popup This prefix command shows the following remote-related Git variables in a popup buffer. The values can be changed from that buffer. This popup is a sub-popup of the @code{magit-remote-popup} in which "C" is bound to this popup. @end deffn The following variables are used to configure a specific remote. The values are being displayed for the upstream remote of the current branch. To change the value for another remote invoke @code{magit-remote-config-popup} with a prefix argument. @defvar remote.NAME.url This variable specifies the url of the remote named NAME@. It can have multiple values. @end defvar @defvar remote.NAME.fetch The refspec used when fetching from the remote named NAME@. It can have multiple values. @end defvar @defvar remote.NAME.pushurl This variable specifies the url used for fetching from the remote named NAME@. If it is not specified, then @code{remote.NAME.url} is used instead. It can have multiple values. @end defvar @defvar remote.NAME.push The refspec used when pushing to the remote named NAME@. It can have multiple values. @end defvar @defvar remote.NAME.tagOpts This variable specifies what tags are fetched by default. If the value is @code{--no-tags} then no tags are fetched. If the value is @code{--tags}, then all tags are fetched. If this variable has not value, then only tags are fetched that are reachable from fetched branches. @end defvar @node Fetching @section Fetching For information about the differences between the @emph{upstream} and the @emph{push-remote}, see @ref{Branching}. Also see @ifinfo @ref{git-fetch,,,gitman,}. @end ifinfo @ifhtml @html the git-fetch(1) manpage. @end html @end ifhtml @iftex the git-fetch(1) manpage. @end iftex @table @asis @kindex f @cindex magit-fetch-popup @item @kbd{f} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex f p @cindex magit-fetch-from-pushremote @item @kbd{f p} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-from-pushremote}) Fetch from the push-remote of the current branch. @kindex f u @cindex magit-fetch-from-upstream @item @kbd{f u} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-from-upstream}) Fetch from the upstream of the current branch. @kindex f e @cindex magit-fetch-other @item @kbd{f e} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-other}) Fetch from another repository. @kindex f o @cindex magit-fetch-branch @item @kbd{f o} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-branch}) Fetch a branch from a remote, both of which are read from the minibuffer. @kindex f r @cindex magit-fetch-refspec @item @kbd{f r} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-refspec}) Fetch from a remote using an explicit refspec, both of which are read from the minibuffer. @kindex f a @cindex magit-fetch-all @item @kbd{f a} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-all}) Fetch from all remotes. @kindex f m @cindex magit-submodule-fetch @item @kbd{f m} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-fetch}) Fetch all submodules. With a prefix argument fetch all remotes of all submodules. @end table Instead of using one popup for fetching and another for pulling, you could also use @code{magit-pull-and-fetch-popup}. See its doc-string for more information. @node Pulling @section Pulling For information about the differences between the @emph{upstream} and the @emph{push-remote}, see @ref{Branching}. Also see @ifinfo @ref{git-pull,,,gitman,}. @end ifinfo @ifhtml @html the git-pull(1) manpage. @end html @end ifhtml @iftex the git-pull(1) manpage. @end iftex @table @asis @kindex F @cindex magit-pull-popup @item @kbd{F} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-popup}) This prefix command shows the following suffix commands in a popup buffer. @kindex F p @cindex magit-pull-from-pushremote @item @kbd{F p} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-from-pushremote}) Pull from the push-remote of the current branch. @kindex F u @cindex magit-pull-from-upstream @item @kbd{F u} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-from-upstream}) Pull from the upstream of the current branch. @kindex F e @cindex magit-pull-branch @item @kbd{F e} @tie{}@tie{}@tie{}@tie{}(@code{magit-pull-branch}) Pull from a branch read in the minibuffer. @end table Instead of using one popup for fetching and another for pulling, you could also use @code{magit-pull-and-fetch-popup}. See its doc-string for more information. @node Pushing @section Pushing For information about the differences between the @emph{upstream} and the @emph{push-remote}, see @ref{Branching}. Also see @ifinfo @ref{git-push,,,gitman,}. @end ifinfo @ifhtml @html the git-push(1) manpage. @end html @end ifhtml @iftex the git-push(1) manpage. @end iftex @table @asis @kindex P @cindex magit-push-popup @item @kbd{P} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex P p @cindex magit-push-current-to-pushremote @item @kbd{P p} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current-to-pushremote}) Push the current branch to @code{branch..pushRemote} or if that is unset to @code{remote.pushDefault}. When @code{magit-push-current-set-remote-if-missing} is non-nil and 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. @kindex P u @cindex magit-push-current-to-upstream @item @kbd{P u} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current-to-upstream}) Push the current branch to its upstream branch. When @code{magit-push-current-set-remote-if-missing} is non-nil and the push-remote is not configured, then read the upstream from the user, set it, and then push to it. With a prefix argument the push-remote can be changed before pushed to it. @kindex P e @cindex magit-push-current @item @kbd{P e} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-current}) Push the current branch to a branch read in the minibuffer. @kindex P o @cindex magit-push-other @item @kbd{P o} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-other}) Push an arbitrary branch or commit somewhere. Both the source and the target are read in the minibuffer. @kindex P r @cindex magit-push-refspecs @item @kbd{P r} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-refspecs}) Push one or multiple refspecs to a remote, both of which 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. @kindex P m @cindex magit-push-matching @item @kbd{P m} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-matching}) Push all matching branches to another repository. If multiple remotes exit, then read one from the user. If just one exists, use that without requiring confirmation. @kindex P t @cindex magit-push-tags @item @kbd{P t} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-tags}) 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. @kindex P T @cindex magit-push-tag @item @kbd{P T} @tie{}@tie{}@tie{}@tie{}(@code{magit-push-tag}) Push a tag to another repository. @end table Two more push commands exist, which by default are not available from the push popup. See their doc-strings for instructions on how to add them to the popup. @cindex magit-push-implicitly args @deffn Command magit-push-implicitly args Push somewhere without using an explicit refspec. This command simply runs @code{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: @code{push.default}, @code{remote.pushDefault}, @code{branch..pushRemote}, @code{branch..remote}, @code{branch..merge}, and @code{remote..push}. @end deffn @cindex magit-push-to-remote remote args @deffn Command magit-push-to-remote remote args Push to the remote REMOTE without using an explicit refspec. The remote is read in the minibuffer. This command simply runs @code{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: @code{push.default}, @code{remote.pushDefault}, @code{branch..pushRemote}, @code{branch..remote}, @code{branch..merge}, and @code{remote..push}. @end deffn @defopt magit-push-current-set-remote-if-missing This option controls whether missing remotes are configured before pushing. When @code{nil}, then the command @code{magit-push-current-to-pushremote} and @code{magit-push-current-to-upstream} do not appear in the push popup if the push-remote resp. upstream is not configured. If the user invokes one of these commands anyway, then it raises an error. When @code{non-nil}, then these commands always appear in the push popup. But if the required configuration is missing, then they do appear in a way that indicates that this is the case. If the user invokes one of them, then it asks for the necessary configuration, stores the configuration, and then uses it to push a first time. This option also affects whether the argument @code{--set-upstream} is available in the popup. If the value is @code{non-nil}, then that argument is redundant. But note that changing the value of this option does not take affect immediately, the argument will only be added or removed after restarting Emacs. @end defopt @node Creating and Sending Patches @section Creating and Sending Patches @table @asis @kindex W @cindex magit-patch-popup @item @kbd{W} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex W p @cindex magit-format-patch @item @kbd{W p} @tie{}@tie{}@tie{}@tie{}(@code{magit-format-patch}) Create patches for a set commits. If the region marks commits, then create patches for those. Otherwise prompt for a range or a single commit, defaulting to the commit at point. @kindex W r @cindex magit-request-pull @item @kbd{W r} @tie{}@tie{}@tie{}@tie{}(@code{magit-request-pull}) Request that upstream pulls from your public repository. @end table It is also possible to save a plain patch file by using @code{C-x C-w} inside a @code{magit-diff-mode} or @code{magit-revision-mode} buffer. @node Applying Patches @section Applying Patches Also see @ifinfo @ref{git-am,,,gitman,}. @end ifinfo @ifhtml @html the git-am(1) manpage. @end html @end ifhtml @iftex the git-am(1) manpage. @end iftex and @ifinfo @ref{git-apply,,,gitman,}. @end ifinfo @ifhtml @html the git-apply(1) manpage. @end html @end ifhtml @iftex the git-apply(1) manpage. @end iftex @table @asis @kindex w @cindex magit-am-popup @item @kbd{w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex w w @cindex magit-am-apply-patches @item @kbd{w w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-apply-patches}) Apply one or more patches. If the region marks files, then apply those patches. Otherwise read a file name in the minibuffer defaulting to the file at point. @kindex w m @cindex magit-am-apply-maildir @item @kbd{w m} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-apply-maildir}) Apply the patches from a maildir. @end table When an "am" operation is in progress, then the popup buffer features these commands instead. @table @asis @kindex w w @cindex magit-am-continue @item @kbd{w w} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-continue}) Resume the current patch applying sequence. @kindex w s @cindex magit-am-skip @item @kbd{w s} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-skip}) Skip the stopped at patch during a patch applying sequence. @kindex w a @cindex magit-am-abort @item @kbd{w a} @tie{}@tie{}@tie{}@tie{}(@code{magit-am-abort}) Abort the current patch applying sequence. This discards all changes made since the sequence started. @end table In addition to the commands listed at the top, the "am" popup also has a binding for the related "patch" popup. @table @asis @kindex w a @cindex magit-patch-apply-popup @item @kbd{w a} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-apply-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex w a a @cindex magit-patch-apply @item @kbd{w a a} @tie{}@tie{}@tie{}@tie{}(@code{magit-patch-apply}) This command applies a simple patch file, which may not contain any Git metadata in addition to the actual diff. @end table @node Miscellaneous @chapter Miscellaneous @menu * Tagging:: * Notes:: * Submodules:: * Subtree:: * Worktree:: * Common Commands:: * Wip Modes:: * Minor Mode for Buffers Visiting Files:: * Minor Mode for Buffers Visiting Blobs:: @end menu @node Tagging @section Tagging Also see @ifinfo @ref{git-tag,,,gitman,}. @end ifinfo @ifhtml @html the git-tag(1) manpage. @end html @end ifhtml @iftex the git-tag(1) manpage. @end iftex @table @asis @kindex t @cindex magit-tag-popup @item @kbd{t} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex t t @cindex magit-tag-create @item @kbd{t t} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-create}) Create a new tag with the given NAME at REV@. With a prefix argument annotate the tag. @kindex t k @cindex magit-tag-delete @item @kbd{t k} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-delete}) 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. @kindex t p @cindex magit-tag-prune @item @kbd{t p} @tie{}@tie{}@tie{}@tie{}(@code{magit-tag-prune}) Offer to delete tags missing locally from REMOTE, and vice versa. @end table @cindex magit-tag-release @deffn Command magit-tag-release Create an opinionated release tag. Assume version tags that match "\\`v?[0-9]\*\\'". Prompt for the name of the new tag using the highest existing tag as initial input and call "git tag --annotate --sign -m MSG" TAG, regardless of whether these arguments are enabled in the popup. Given a TAG "v1.2.3" and a repository "/path/to/foo-bar", the MESSAGE would be "Foo-Bar 1.2.3". Because it is so opinionated, this command is not available from the tag popup by default. @end deffn @node Notes @section Notes Also see @ifinfo @ref{git-notes,,,gitman,}. @end ifinfo @ifhtml @html the git-notes(1) manpage. @end html @end ifhtml @iftex the git-notes(1) manpage. @end iftex @table @asis @kindex T @cindex magit-notes-popup @item @kbd{T} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @kindex T T @cindex magit-notes-edit @item @kbd{T T} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-edit}) Edit the note attached to a commit, defaulting to the commit at point. By default use the value of Git variable @code{core.notesRef} or "refs/notes/commits" if that is undefined. @kindex T r @cindex magit-notes-remove @item @kbd{T r} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-remove}) Remove the note attached to a commit, defaulting to the commit at point. By default use the value of Git variable @code{core.notesRef} or "refs/notes/commits" if that is undefined. @kindex T p @cindex magit-notes-prune @item @kbd{T p} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-prune}) Remove notes about unreachable commits. @end table It is possible to merge one note ref into another. That may result in conflicts which have to resolved in the temporary worktree ".git/NOTES@math{_MERGE}@math{_WORKTREE}". @table @asis @kindex T m @cindex magit-notes-merge @item @kbd{T m} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge}) Merge the notes of a ref read from the user into the current notes ref. The current notes ref is the value of Git variable @code{core.notesRef} or "refs/notes/commits" if that is undefined. @end table When a notes merge is in progress then the popup features the following suffix commands, instead of those listed above. @table @asis @kindex T c @cindex magit-notes-merge-commit @item @kbd{T c} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge-commit}) Commit the current notes ref merge, after manually resolving conflicts. @kindex T a @cindex magit-notes-merge-abort @item @kbd{T a} @tie{}@tie{}@tie{}@tie{}(@code{magit-notes-merge-abort}) Abort the current notes ref merge. @end table The following variables control what notes reference @code{magit-notes-*}, @code{git notes} and @code{git show} act on and display. Both the local and global values are displayed and can be modified. @defvar core.notesRef This variable specifies the notes ref that is displayed by default and which commands act on by default. @end defvar @defvar notes.displayRef This variable specifies additional notes ref to be displayed in addition to the ref specified by @code{core.notesRef}. It can have multiple values and may end with @code{*} to display all refs in the @code{refs/notes/} namespace (or @code{**} if some names contain slashes). @end defvar @node Submodules @section Submodules Also see @ifinfo @ref{git-submodule,,,gitman,}. @end ifinfo @ifhtml @html the git-submodule(1) manpage. @end html @end ifhtml @iftex the git-submodule(1) manpage. @end iftex @menu * Listing Submodules:: * Submodule Popup:: @end menu @node Listing Submodules @subsection Listing Submodules The command @code{magit-list-submodules} displays a list of the current repository's submodules in a separate buffer. It's also possible to display information about submodules directly in the status buffer of the super-repository by adding @code{magit-insert-submodules} to the hook @code{magit-status-sections-hook} as described in @ref{Status Module Sections}. @cindex magit-list-submodules @deffn Command magit-list-submodules This command displays a list of the current repository's submodules in a separate buffer. It can be invoked by pressing @code{RET} on the section titled "Modules". @end deffn @defopt magit-submodule-list-columns This option controls what columns are displayed by the command @code{magit-list-submodules} and how they are displayed. Each element has the form @code{(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 @code{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 @code{:right-align} and @code{:pad-right}. @end defopt @defun magit-insert-submodules Insert sections for all submodules. For each section insert the path, the branch, and the output of @code{git describe --tags}, or, failing that, the abbreviated HEAD commit hash. Press @code{RET} on such a submodule section to show its own status buffer. Press @code{RET} on the "Modules" section to display a list of submodules in a separate buffer. This shows additional information not displayed in the super-repository's status buffer. @end defun @node Submodule Popup @subsection Submodule Popup @table @asis @kindex o @cindex magit-submodule-popup @item @kbd{o} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table Some of the below commands default to act on the modules that are selected using the region. For brevity their description talk about "the selected modules", but if no modules are selected, then they act on the current module instead, or if point isn't on a module, then the read a single module to act on. With a prefix argument these commands ignore the selection and the current module and instead act on all suitable modules. @table @asis @kindex o a @cindex magit-submodule-add @item @kbd{o a} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-add}) This commands adds the repository at URL as a module. Optional PATH is the path to the module relative to the root of the super-project. If it is nil then the path is determined based on URL@. @kindex o r @cindex magit-submodule-register @item @kbd{o r} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-register}) This command registers the selected modules by copying their urls from ".gitmodules" to "$GIT@math{_DIR}/config". These values can then be edited before running @code{magit-submodule-populate}. If you don't need to edit any urls, then use the latter directly. @kindex o p @cindex magit-submodule-populate @item @kbd{o p} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-populate}) This command creates the working directory or directories of the selected modules, checking out the recorded commits. @kindex o u @cindex magit-submodule-update @item @kbd{o u} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-update}) This command updates the selected modules checking out the recorded commits. @kindex o s @cindex magit-submodule-synchronize @item @kbd{o s} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-synchronize}) This command synchronizes the urls of the selected modules, copying the values from ".gitmodules" to the ".git/config" of the super-project as well those of the modules. @kindex o d @cindex magit-submodule-unpopulate @item @kbd{o d} @tie{}@tie{}@tie{}@tie{}(@code{magit-submodule-unpopulate}) This command removes the working directory of the selected modules. @kindex o l @cindex magit-list-submodules @item @kbd{o l} @tie{}@tie{}@tie{}@tie{}(@code{magit-list-submodules}) This command displays a list of the current repository's modules. @kindex o f @cindex magit-fetch-modules @item @kbd{o f} @tie{}@tie{}@tie{}@tie{}(@code{magit-fetch-modules}) This command fetches all modules. Option @code{magit-fetch-modules-jobs} controls how many submodules are being fetched in parallel. Also fetch the super-repository, because @code{git fetch} does not support not doing that. With a prefix argument fetch all remotes. @end table @node Subtree @section Subtree Also see @ifinfo @ref{git-subtree,,,gitman,}. @end ifinfo @ifhtml @html the git-subtree(1) manpage. @end html @end ifhtml @iftex the git-subtree(1) manpage. @end iftex @table @asis @kindex O @cindex magit-tree-popup @item @kbd{O} @tie{}@tie{}@tie{}@tie{}(@code{magit-tree-popup}) This prefix command shows the following suffix commands along with the appropriate infix arguments in a popup buffer. @end table Most infix arguments only apply to some of the @code{git subtree} subcommands. When an argument that does not apply to the invoked command is set, then it is silently ignored. When the @code{--prefix} argument is set in the popup buffer, then that is used. Otherwise the prefix is read in the minibuffer. @table @asis @kindex O a @cindex magit-subtree-add @item @kbd{O a} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-add}) Add COMMIT from REPOSITORY as a new subtree at PREFIX@. @kindex O c @cindex magit-subtree-add-commit @item @kbd{O c} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-add-commit}) Add COMMIT as a new subtree at PREFIX@. @kindex O m @cindex magit-subtree-merge @item @kbd{O m} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-merge}) Merge COMMIT into the PREFIX subtree. @kindex O f @cindex magit-subtree-pull @item @kbd{O f} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-pull}) Pull COMMIT from REPOSITORY into the PREFIX subtree. @kindex O p @cindex magit-subtree-push @item @kbd{O p} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-push}) Extract the history of the subtree PREFIX and push it to REF on REPOSITORY@. @kindex O s @cindex magit-subtree-split @item @kbd{O s} @tie{}@tie{}@tie{}@tie{}(@code{magit-subtree-split}) Extract the history of the subtree PREFIX@. @end table @node Worktree @section Worktree Also see @ifinfo @ref{git-worktree,,,gitman,}. @end ifinfo @ifhtml @html the git-worktree(1) manpage. @end html @end ifhtml @iftex the git-worktree(1) manpage. @end iftex @table @asis @kindex % @cindex magit-worktree-popup @item @kbd{%} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-popup}) This prefix command shows the following suffix commands in a popup buffer. @kindex % b @cindex magit-worktree-checkout @item @kbd{% b} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-checkout}) Checkout BRANCH in a new worktree at PATH@. @kindex % c @cindex magit-worktree-branch @item @kbd{% c} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-branch}) Create a new BRANCH and check it out in a new worktree at PATH@. @kindex % p @cindex magit-worktree-checkout-pull-request @item @kbd{% p} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-checkout-pull-request}) Create, configure and checkout a new worktree from a pull-request. This is like @code{magit-checkout-pull-request} (which see) except that it also creates a new worktree. @kindex % k @cindex magit-worktree-delete @item @kbd{% k} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-delete}) Delete a worktree, defaulting to the worktree at point. The primary worktree cannot be deleted. @kindex % g @cindex magit-worktree-status @item @kbd{% g} @tie{}@tie{}@tie{}@tie{}(@code{magit-worktree-status}) 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. @end table @node Common Commands @section Common Commands These are some of the commands that can be used in all buffers whose major-modes derive from @code{magit-mode}. There are other common commands beside the ones below, but these didn't fit well anywhere else. @table @asis @kindex M-w @cindex magit-copy-section-value @item @kbd{M-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-copy-section-value}) This command saves the value of the current section to the @code{kill-ring}, and, provided that the current section is a commit, branch, or tag section, it also pushes the (referenced) revision to the @code{magit-revision-stack}. When the current section is a branch or a tag, and a prefix argument is used, then it saves the revision at its tip to the @code{kill-ring} instead of the reference name. @kindex C-w @cindex magit-copy-buffer-revision @item @kbd{C-w} @tie{}@tie{}@tie{}@tie{}(@code{magit-copy-buffer-revision}) This command saves the revision being displayed in the current buffer to the @code{kill-ring} and also pushes it to the @code{magit-revision-stack}. It is mainly intended for use in @code{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. @end table Outside of Magit @code{M-w} and @code{C-w} are usually bound to @code{kill-ring-save} and @code{kill-region}, and these commands would also be useful in Magit buffers. Therefore when the region is active, then both of these commands behave like @code{kill-ring-save} instead of as described above. @node Wip Modes @section Wip Modes Git keeps @strong{committed} changes around long enough for users to recover changes they have accidentally deleted. It does so by not garbage collecting any committed but no longer referenced objects for a certain period of time, by default 30 days. But Git does @strong{not} keep track of @strong{uncommitted} changes in the working tree and not even the index (the staging area). Because Magit makes it so convenient to modify uncommitted changes, it also makes it easy to shoot yourself in the foot in the process. For that reason Magit provides a global mode that saves @strong{tracked} files to work-in-progress references after or before certain actions. (At present untracked files are never saved and for technical reasons nothing is saved before the first commit has been created). Two separate work-in-progress references are used to track the state of the index and of the working tree: @code{refs/wip/index/} and @code{refs/wip/wtree/}, where @code{} is the full ref of the current branch, e.g. @code{refs/heads/master}. When the @code{HEAD} is detached then @code{HEAD} is used in place of @code{}. Checking out another branch (or detaching @code{HEAD}) causes the use of different wip refs for subsequent changes. @defopt magit-wip-mode When this mode is enabled, then uncommitted changes are committed to dedicated work-in-progress refs whenever appropriate (i.e. when dataloss would be a possibility otherwise). Setting this variable directly does not take effect; either use the Custom interface to do so or call the respective mode function. For historic reasons this mode is implemented on top of four other @code{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. See @ref{Legacy Wip Modes}. @end defopt To view the log for a branch and its wip refs use the commands @code{magit-wip-log} and @code{magit-wip-log-current}. You should use @code{--graph} when using these commands. @cindex magit-wip-log @deffn Command magit-wip-log This command shows the log for a branch and its wip refs. With a negative prefix argument only the worktree wip ref is shown. The absolute numeric value of the prefix argument controls how many "branches" of each wip ref are shown. This is only relevant if the value of @code{magit-wip-merge-branch} is @code{nil}. @end deffn @cindex magit-wip-log-current @deffn Command magit-wip-log-current This command shows the log for the current branch and its wip refs. With a negative prefix argument only the worktree wip ref is shown. The absolute numeric value of the prefix argument controls how many "branches" of each wip ref are shown. This is only relevant if the value of @code{magit-wip-merge-branch} is @code{nil}. @end deffn @table @asis @kindex X w @cindex magit-reset-worktree @item @kbd{X w} @tie{}@tie{}@tie{}@tie{}(@code{magit-reset-worktree}) This command resets the working tree to some commit read from the user and defaulting to the commit at point, while keeping the @code{HEAD} and index as-is. This can be used to restore files to the state committed to a wip ref. Note that this will discard any unstaged changes that might have existed before invoking this command (but of course only after committing that to the working tree wip ref). @end table Note that even if you enable @code{magit-wip-mode} this won't give you perfect protection. The most likely scenario for losing changes despite the use of @code{magit-wip-mode} is making a change outside Emacs and then destroying it also outside Emacs. In some such a scenario, Magit, being an Emacs package, didn't get the opportunity to keep you from shooting yourself in the foot. When you are unsure whether Magit did commit a change to the wip refs, then you can explicitly request that all changes to all tracked files are being committed. @table @asis @kindex M-x magit-wip-commit @cindex magit-wip-commit @item @kbd{M-x magit-wip-commit} @tie{}@tie{}@tie{}@tie{}(@code{magit-wip-commit}) This command commits all changes to all tracked files to the index and working tree work-in-progress refs. Like the modes described above, it does not commit untracked files, but it does check all tracked files for changes. Use this command when you suspect that the modes might have overlooked a change made outside Emacs/Magit. @end table @defopt magit-wip-namespace The namespace used for work-in-progress refs. It has to end with a slash. The wip refs are named @code{index/} and @code{wtree/}. When snapshots are created while the @code{HEAD} is detached then @code{HEAD} is used in place of @code{}. @end defopt @defopt magit-wip-mode-lighter Mode-line lighter for @code{magit-wip--mode}. @end defopt @menu * Wip Graph:: * Legacy Wip Modes:: @end menu @node Wip Graph @subsection Wip Graph @defopt magit-wip-merge-branch This option controls whether the current branch is merged into the wip refs after a new commit was created on the branch. 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. @end defopt When @code{magit-wip-merge-branch} is @code{t}, then the history looks like this: @example *--*--*--*--*--* refs/wip/index/refs/heads/master / / / A-----B-----C refs/heads/master @end example When @code{magit-wip-merge-branch} is @code{nil}, then creating a commit on the real branch and then making a change causes the wip refs to be recreated to fork from the new commit. But the old commits on the wip refs are not lost. They are still available from the reflog. To make it easier to see when the fork point of a wip ref was changed, an additional commit with the message "restart autosaving" is created on it (@code{xxO} commits below are such boundary commits). Starting with @example BI0---BI1 refs/wip/index/refs/heads/master / A---B refs/heads/master \ BW0---BW1 refs/wip/wtree/refs/heads/master @end example and committing the staged changes and editing and saving a file would result in @example BI0---BI1 refs/wip/index/refs/heads/master / A---B---C refs/heads/master \ \ \ CW0---CW1 refs/wip/wtree/refs/heads/master \ BW0---BW1 refs/wip/wtree/refs/heads/master@@@{2@} @end example The fork-point of the index wip ref is not changed until some change is being staged. Likewise just checking out a branch or creating a commit does not change the fork-point of the working tree wip ref. The fork-points are not adjusted until there actually is a change that should be committed to the respective wip ref. @node Legacy Wip Modes @subsection Legacy Wip Modes It is recommended that you use the mode @code{magit-wip-mode} (which see) and ignore the existence of the following modes, which are preserved for historic reasons. Setting the following variables directly does not take effect; either use the Custom interface to do so or call the respective mode functions. @defopt magit-wip-after-save-mode When this mode is enabled, then saving a buffer that visits a file tracked in a Git repository causes its current state to be committed to the working tree wip ref for the current branch. @end defopt @defopt magit-wip-after-apply-mode When this mode is enabled, then applying (i.e. staging, unstaging, discarding, reversing, and regularly applying) a change to a file tracked in a Git repository causes its current state to be committed to the index and/or working tree wip refs for the current branch. @end defopt If you only ever edit files using Emacs and only ever interact with Git using Magit, then the above two modes should be enough to protect each and every change from accidental loss. In practice nobody does that. Two additional modes exists that do commit to the wip refs before making changes that could cause the loss of earlier changes. @defopt magit-wip-before-change-mode When this mode is enabled, then certain commands commit the existing changes to the files they are about to make changes to. @end defopt @defopt magit-wip-initial-backup-mode When this mode is enabled, then the current version of a file is committed to the worktree wip ref before the buffer visiting that file is saved for the first time since the buffer was created. This backs up the same version of the file that @code{backup-buffer} would save. While @code{backup-buffer} uses a backup file, this mode uses the same worktree wip ref as used by the other Magit Wip modes. Like @code{backup-buffer}, it only does this once; unless you kill the buffer and visit the file again only one backup will be created per Emacs session. This mode ignores the variables that affect @code{backup-buffer} and can be used along-side that function, which is recommended because it only backs up files that are tracked in a Git repository. @end defopt @defopt magit-wip-after-save-local-mode-lighter Mode-line lighter for @code{magit-wip-after-save-local-mode}. @end defopt @defopt magit-wip-after-apply-mode-lighter Mode-line lighter for @code{magit-wip-after-apply-mode}. @end defopt @defopt magit-wip-before-change-mode-lighter Mode-line lighter for @code{magit-wip-before-change-mode}. @end defopt @defopt magit-wip-initial-backup-mode-lighter Mode-line lighter for @code{magit-wip-initial-backup-mode}. @end defopt @node Minor Mode for Buffers Visiting Files @section Minor Mode for Buffers Visiting Files The @code{magit-file-mode} enables certain Magit features in file-visiting buffers belonging to a Git repository. It should be enabled globally using @code{global-magit-file-mode}. Currently this mode only establishes a few key bindings, but this might be extended in the future. @defopt magit-file-mode Whether to establish certain Magit key bindings in all file-visiting buffers belonging to a Git repository. This establishes the bindings suggested in @ref{Getting Started} (but only for file-visiting buffers), and additionally binds @code{C-c M-g} to @code{magit-file-popup}. @end defopt @table @asis @kindex C-c M-g @cindex magit-file-popup @item @kbd{C-c M-g} @tie{}@tie{}@tie{}@tie{}(@code{magit-file-popup}) This prefix command shows a popup buffer featuring suffix commands that operate on the file being visited in the current buffer. @kindex C-c M-g s @cindex magit-stage-file @item @kbd{C-c M-g s} @tie{}@tie{}@tie{}@tie{}(@code{magit-stage-file}) Stage all changes to the file being visited in the current buffer. @kindex C-c M-g u @cindex magit-unstage-file @item @kbd{C-c M-g u} @tie{}@tie{}@tie{}@tie{}(@code{magit-unstage-file}) Unstage all changes to the file being visited in the current buffer. @kindex C-c M-g c @cindex magit-commit-popup @item @kbd{C-c M-g c} @tie{}@tie{}@tie{}@tie{}(@code{magit-commit-popup}) This prefix command shows suffix commands along with the appropriate infix arguments in a popup buffer. See @ref{Initiating a Commit}. @kindex C-c M-g D @cindex magit-diff-buffer-file-popup @item @kbd{C-c M-g D} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-buffer-file-popup}) This prefix command shows the same suffix commands and infix arguments in a popup buffer as @code{magit-diff-popup}. But this variant has to be called from a file-visiting buffer and the visited file is automatically used in the popup to limit the diff to that file. @kindex C-c M-g d @cindex magit-diff-buffer-file @item @kbd{C-c M-g d} @tie{}@tie{}@tie{}@tie{}(@code{magit-diff-buffer-file}) This command shows the diff for the file of blob that the current buffer visits. @end table @defopt magit-diff-buffer-file-locked This option controls whether @code{magit-diff-buffer-file} uses a dedicated buffer. See @ref{Modes and Buffers}. @end defopt @table @asis @kindex C-c M-g L @cindex magit-log-buffer-file-popup @item @kbd{C-c M-g L} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-buffer-file-popup}) This prefix command shows the same suffix commands and infix arguments in a popup buffer as @code{magit-log-popup}. But this variant has to be called from a file-visiting buffer and the visited file is automatically used in the popup to limit the log to that file. @kindex C-c M-g l @cindex magit-log-buffer-file @item @kbd{C-c M-g l} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-buffer-file}) This command shows the log for the file of blob that the current buffer visits. Renames are followed when a prefix argument is used or when @code{--follow} is part of @code{magit-log-arguments}. When the region is active, the log is restricted to the selected line range. @kindex C-c M-g t @cindex magit-log-trace-definition @item @kbd{C-c M-g t} @tie{}@tie{}@tie{}@tie{}(@code{magit-log-trace-definition}) This command shows the log for the definition at point. @end table @defopt magit-log-buffer-file-locked This option controls whether @code{magit-log-buffer-file} uses a dedicated buffer. See @ref{Modes and Buffers}. @end defopt @table @asis @kindex C-c M-g B @cindex magit-blame-popup @item @kbd{C-c M-g B} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-popup}) This prefix command shows all blaming suffix command along with the appropriate infix arguments in a popup buffer. See @ref{Blaming}. @kindex C-c M-g b @cindex magit-blame-addition @item @kbd{C-c M-g b} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-addition}) This command shows for each line the revision in which it was added. @kindex C-c M-g r @cindex magit-blame-removal @item @kbd{C-c M-g r} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-removal}) This command shows for each line the revision in which it was removed. This command is only available in blob-visiting buffers. @kindex C-c M-g f @cindex magit-blame-reverse @item @kbd{C-c M-g f} @tie{}@tie{}@tie{}@tie{}(@code{magit-blame-reverse}) This command shows for each line the last revision in which it still exists. This command is only available in blob-visiting buffers. @kindex C-c M-g e @cindex magit-edit-line-commit @item @kbd{C-c M-g e} @tie{}@tie{}@tie{}@tie{}(@code{magit-edit-line-commit}) This command makes the commit editable that added the current line. With a prefix argument it makes the commit editable that removes the line, if any. The commit is determined using @code{git blame} and made editable using @code{git rebase --interactive} if it is reachable from @code{HEAD}, or by checking out the commit (or a branch that points at it) otherwise. @kindex C-c M-g p @cindex magit-blob-previous @item @kbd{C-c M-g p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-previous}) Visit the previous blob which modified the current file. @end table There are a few additional commands that operate on a single file but are not available from the file popup by default: @cindex magit-file-rename @deffn Command magit-file-rename This command renames a file read from the user. @end deffn @cindex magit-file-delete @deffn Command magit-file-delete This command deletes a file read from the user. @end deffn @cindex magit-file-untrack @deffn Command magit-file-untrack This command untracks a file read from the user. @end deffn @cindex magit-file-checkout @deffn Command magit-file-checkout This command updates a file in the working tree and index to the contents from a revision. Both the revision and file are read from the user. @end deffn You could add them to the popup like so: @lisp (magit-define-popup-action 'magit-file-popup ?R "Rename file" 'magit-file-rename) (magit-define-popup-action 'magit-file-popup ?K "Delete file" 'magit-file-delete) (magit-define-popup-action 'magit-file-popup ?U "Untrack file" 'magit-file-untrack) (magit-define-popup-action 'magit-file-popup ?C "Checkout file" 'magit-file-checkout) @end lisp @node Minor Mode for Buffers Visiting Blobs @section Minor Mode for Buffers Visiting Blobs The @code{magit-blob-mode} enables certain Magit features in blob-visiting buffers. Such buffers can be created using @code{magit-find-file} and some of the commands mentioned below, which also take care of turning on this minor mode. Currently this mode only establishes a few key bindings, but this might be extended. @table @asis @kindex p @cindex magit-blob-previous @item @kbd{p} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-previous}) Visit the previous blob which modified the current file. @kindex n @cindex magit-blob-next @item @kbd{n} @tie{}@tie{}@tie{}@tie{}(@code{magit-blob-next}) Visit the next blob which modified the current file. @kindex q @cindex magit-kill-this-buffer @item @kbd{q} @tie{}@tie{}@tie{}@tie{}(@code{magit-kill-this-buffer}) Kill the current buffer. @end table @node Customizing @chapter Customizing Both Git and Emacs are highly customizable. Magit is both a Git porcelain as well as an Emacs package, so it makes sense to customize it using both Git variables as well as Emacs options. However this flexibility doesn't come without problems, including but not limited to the following. @itemize @item Some Git variables automatically have an effect in Magit without requiring any explicit support. Sometimes that is desirable - in other cases, it breaks Magit. When a certain Git setting breaks Magit but you want to keep using that setting on the command line, then that can be accomplished by overriding the value for Magit only by appending something like @code{("-c" "some.variable=compatible-value")} to @code{magit-git-global-arguments}. @item Certain settings like @code{fetch.prune=true} are respected by Magit commands (because they simply call the respective Git command) but their value is not reflected in the respective popup buffers. In this case the @code{--prune} argument in @code{magit-fetch-popup} might be active or inactive depending on the value of @code{magit-fetch-arguments} only, but that doesn't keep the Git variable from being honored by the suffix commands anyway. So pruning might happen despite the @code{--prune} arguments being displayed in a way that seems to indicate that no pruning will happen. @end itemize I intend to address these and similar issues in a future release. @menu * Per-Repository Configuration:: * Essential Settings:: @end menu @node Per-Repository Configuration @section Per-Repository Configuration Magit can be configured on a per-repository level using both Git variables as well as Emacs options. To set a Git variable for one repository only, simply set it in @code{/path/to/repo/.git/config} instead of @code{$HOME/.gitconfig} or @code{/etc/gitconfig}. See @ifinfo @ref{git-config,,,gitman,}. @end ifinfo @ifhtml @html the git-config(1) manpage. @end html @end ifhtml @iftex the git-config(1) manpage. @end iftex Similarly, Emacs options can be set for one repository only by editing @code{/path/to/repo/.dir-locals.el}. See @ref{Directory Variables,,,emacs,}. For example to disable automatic refreshes of file-visiting buffers in just one huge repository use this: @itemize @item @code{/path/to/huge/repo/.dir-locals.el} @lisp ((nil . ((magit-refresh-buffers . nil)))) @end lisp @end itemize If you want to apply the same settings to several, but not all, repositories then keeping the repository-local config files in sync would quickly become annoying. To avoid that you can create config files for certain classes of repositories (e.g. "huge repositories") and then include those files in the per-repository config files. For example: @itemize @item @code{/path/to/huge/repo/.git/config} @example [include] path = /path/to/huge-gitconfig @end example @item @code{/path/to/huge-gitconfig} @example [status] showUntrackedFiles = no @end example @item @code{$HOME/.emacs.d/init.el} @lisp (dir-locals-set-class-variables 'huge-git-repository '((nil . ((magit-refresh-buffers . nil))))) (dir-locals-set-directory-class "/path/to/huge/repo/" 'huge-git-repository) @end lisp @end itemize @node Essential Settings @section Essential Settings The next two sections list and discuss several variables that many users might want to customize, for safety and/or performance reasons. @menu * Safety:: * Performance:: @end menu @node Safety @subsection Safety This section discusses various variables that you might want to change (or @strong{not} change) for safety reasons. Git keeps @strong{committed} changes around long enough for users to recover changes they have accidentally been deleted. It does not do the same for @strong{uncommitted} changes in the working tree and not even the index (the staging area). Because Magit makes it so easy to modify uncommitted changes, it also makes it easy to shoot yourself in the foot in the process. For that reason Magit provides three global modes that save @strong{tracked} files to work-in-progress references after or before certain actions. See @ref{Wip Modes}. These modes are not enabled by default because of performance concerns. Instead a lot of potentially destructive commands require confirmation every time they are used. In many cases this can be disabled by adding a symbol to @code{magit-no-confirm} (see @ref{Completion and Confirmation}). If you enable the various wip modes then you should add @code{safe-with-wip} to this list. Similarly it isn't necessary to require confirmation before moving a file to the system trash - if you trashed a file by mistake then you can recover it from the there. Option @code{magit-delete-by-moving-to-trash} controls whether the system trash is used, which is the case by default. Nevertheless, @code{trash} isn't a member of @code{magit-no-confirm} - you might want to change that. By default buffers visiting files are automatically reverted when the visited file changes on disk. This isn't as risky as it might seem, but to make an informed decision you should see @ref{Risk of Reverting Automatically}. @node Performance @subsection Performance After Magit has run @code{git} for side-effects, it also refreshes the current Magit buffer and the respective status buffer. This is necessary because otherwise outdated information might be displayed without the user noticing. Magit buffers are updated by recreating their content from scratch, which makes updating simpler and less error-prone, but also more costly. Keeping it simple and just re-creating everything from scratch is an old design decision and departing from that will require major refactoring. I plan to do that in time for the next major release. I also intend to create logs and diffs asynchronously, which should also help a lot but also requires major refactoring. Meanwhile you can tell Magit to only automatically refresh the current Magit buffer, but not the status buffer. If you do that, then the status buffer is only refreshed automatically if it is the current buffer. @lisp (setq magit-refresh-status-buffer nil) @end lisp You should also check whether any third-party packages have added anything to @code{magit-refresh-buffer-hook}, @code{magit-status-refresh-hook}, @code{magit-pre-refresh-hook}, and @code{magit-post-refresh-hook}. If so, then check whether those additions impact performance significantly. Setting @code{magit-refresh-verbose} and then inspecting the output in the @code{*Messages*} buffer, should help doing so. Magit also reverts buffers for visited files located inside the current repository when the visited file changes on disk. That is implemented on top of @code{auto-revert-mode} from the built-in library @code{autorevert}. To figure out whether that impacts performance, check whether performance is significantly worse, when many buffers exist and/or when some buffers visit files using TRAMP@. If so, then this should help. @lisp (setq auto-revert-buffer-list-filter 'magit-auto-revert-repository-buffers-p) @end lisp For alternative approaches see @ref{Automatic Reverting of File-Visiting Buffers}. If you have enabled any features that are disabled by default, then you should check whether they impact performance significantly. It's likely that they were not enabled by default because it is known that they reduce performance at least in large repositories. If performance is only slow inside certain unusually large repositories, then you might want to disable certain features on a per-repository or per-repository-class basis only. See @ref{Per-Repository Configuration}. @menu * Microsoft Windows Performance:: * MacOS Performance:: @end menu @unnumberedsubsubsec Log Performance When showing logs, Magit limits the number of commits initially shown in the hope that this avoids unnecessary work. When using @code{--graph} is used, then this unfortunately does not have the desired effect for large histories. Junio, Git's maintainer, said on the git mailing list (@uref{http://www.spinics.net/lists/git/msg232230.html}): "@code{--graph} wants to compute the whole history and the max-count only affects the output phase after @code{--graph} does its computation". In other words, it's not that Git is slow at outputting the differences, or that Magit is slow at parsing the output - the problem is that Git first goes outside and has a smoke. We actually work around this issue by limiting the number of commits not only by using @code{-} but by also using a range. But unfortunately that's not always possible. In repositories with more than a few thousand commits @code{--graph} should never be a member of @code{magit-log-section-arguments}. That variable is used in the status buffer which is refreshed every time you run any Magit command. Using @code{--color --graph} is even slower. Magit uses code that is part of Emacs to turn control characters into faces. That code is pretty slow and this is quite noticeable when showing a log with many branches and merges. For that reason @code{--color} is not enabled by default anymore. Consider leaving it at that. @unnumberedsubsubsec Diff Performance If diffs are slow, then consider turning off some optional diff features by setting all or some of the following variables to @code{nil}: @code{magit-diff-highlight-indentation}, @code{magit-diff-highlight-trailing}, @code{magit-diff-paint-whitespace}, @code{magit-diff-highlight-hunk-body}, and @code{magit-diff-refine-hunk}. When showing a commit instead of some arbitrary diff, then some additional information is displayed. Calculating this information can be quite expensive given certain circumstances. If looking at a commit using @code{magit-revision-mode} takes considerably more time than looking at the same commit in @code{magit-diff-mode}, then consider setting @code{magit-revision-insert-related-refs} to @code{nil}. @unnumberedsubsubsec Refs Buffer Performance When refreshing the "references buffer" is slow, then that's usually because several hundred refs are being displayed. The best way to address that is to display fewer refs, obviously. If you are not, or only mildly, interested in seeing the list of tags, then start by not displaying them: @lisp (remove-hook 'magit-refs-sections-hook 'magit-insert-tags) @end lisp Then you should also make sure that the listed remote branches actually all exist. You can do so by pruning branches which no longer exist using @code{f-pa}. @unnumberedsubsubsec Committing Performance When you initiate a commit, then Magit by default automatically shows a diff of the changes you are about to commit. For large commits this can take a long time, which is especially distracting when you are committing large amounts of generated data which you don't actually intend to inspect before committing. This behavior can be turned off using: @lisp (remove-hook 'server-switch-hook 'magit-commit-diff) @end lisp Then you can type @code{C-c C-d} to show the diff when you actually want to see it, but only then. Alternatively you can leave the hook alone and just type @code{C-g} in those cases when it takes too long to generate the diff. If you do that, then you will end up with a broken diff buffer, but doing it this way has the advantage that you usually get to see the diff, which is useful because it increases the odds that you spot potential issues. @unnumberedsubsubsec The Built-In VC Package Emacs comes with a version control interface called "VC", see @ref{Version Control,,,emacs,}. It is enabled be default, and if you don't use it in addition to Magit, then you should disable it to keep it from performing unnecessary work: @lisp (setq vc-handled-backends nil) @end lisp You can also disable its use for Git but keep using it when using another version control system: @lisp (setq vc-handled-backends (delq 'Git vc-handled-backends)) @end lisp @node Microsoft Windows Performance @unnumberedsubsubsec Microsoft Windows Performance In order to update the status buffer, @code{git} has to be run a few dozen times. That is problematic on Microsoft Windows, because that operating system is exceptionally slow at starting processes. Sadly this is an issue that can only be fixed by Microsoft itself, and they don't appear to be particularly interested in doing so. Beside the subprocess issue, there are also other Windows-specific performance issues. Some of these have workarounds. The maintainers of "Git for Windows" try to improve performance on Windows. Always use the latest release in order to benefit from the latest performance tweaks. Magit too tries to work around some Windows-specific issues. According to some sources, setting the following Git variables can also help. @example git config --global core.preloadindex true # default since v2.1 git config --global core.fscache true # default since v2.8 git config --global gc.auto 256 @end example You should also check whether an anti-virus program is affecting performance. @node MacOS Performance @unnumberedsubsubsec MacOS Performance On macOS Emacs currently creates child processes using @code{fork}. It appears that this also copies GUI resources. The result is that forking takes about 30 times as long on Darwin than on Linux. And because Magit starts many @code{git} processes even when doing simple things, that makes quite a difference. On the @code{master} branch Emacs now uses @code{vfork} when possible, like this was already done on Linux, and now child creation only takes about twice as long on Darwin. See @footnote{@uref{https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-04/msg00201.html}} for more information. Nobody knows when the changes on the @code{master} branch will be released as @code{26.1}, but it is still a long way off. You might want to get your hands on this change before then. The easiest way to get a patched Emacs is to install the @code{emacs-plus} formula @footnote{@uref{https://github.com/d12frosted/homebrew-emacs-plus}} using @code{homebrew}. The change has been backported, so you get it not only when using @code{--HEAD}, but also when using @code{--devel} or when installing the latest release (by not using a version argument). Alternatively you can apply the backport @footnote{@uref{https://gist.githubusercontent.com/aaronjensen/f45894ddf431ecbff78b1bcf533d3e6b/raw/6a5cd7f57341aba673234348d8b0d2e776f86719/Emacs-25-OS-X-use-vfork.patch}} manually. @node Plumbing @chapter Plumbing The following sections describe how to use several of Magit's core abstractions to extend Magit itself or implement a separate extension. A few of the low-level features used by Magit have been factored out into separate libraries/packages, so that they can be used by other packages, without having to depend on Magit. These libraries are described in separate manuals, see @ref{Top,,,with-editor,} and @ref{Top,,,magit-popup,}. If you are trying to find an unused key that you can bind to a command provided by your own Magit extension, then checkout @uref{https://github.com/magit/magit/wiki/Plugin-Dispatch-Key-Registry}. @menu * Calling Git:: * Section Plumbing:: * Refreshing Buffers:: * Conventions:: @end menu @node Calling Git @section Calling Git Magit provides many specialized functions for calling Git. All of these functions are defined in either @code{magit-git.el} or @code{magit-process.el} and have one of the prefixes @code{magit-run-}, @code{magit-call-}, @code{magit-start-}, or @code{magit-git-} (which is also used for other things). All of these functions accept an indefinite number of arguments, which are strings that specify command line arguments for Git (or in some cases an arbitrary executable). These arguments are flattened before being passed on to the executable; so instead of strings they can also be lists of strings and arguments that are @code{nil} are silently dropped. Some of these functions also require a single mandatory argument before these command line arguments. Roughly speaking, these functions run Git either to get some value or for side-effects. The functions that return a value are useful to collect the information necessary to populate a Magit buffer, while the others are used to implement Magit commands. The functions in the value-only group always run synchronously, and they never trigger a refresh. The function in the side-effect group can be further divided into subgroups depending on whether they run Git synchronously or asynchronously, and depending on whether they trigger a refresh when the executable has finished. @menu * Getting a Value from Git:: * Calling Git for Effect:: @end menu @node Getting a Value from Git @subsection Getting a Value from Git These functions run Git in order to get a value, an exit status, or output. Of course you could also use them to run Git commands that have side-effects, but that should be avoided. @defun magit-git-exit-code &rest args Executes git with ARGS and returns its exit code. @end defun @defun magit-git-success &rest args Executes git with ARGS and returns @code{t} if the exit code is @code{0}, @code{nil} otherwise. @end defun @defun magit-git-failure &rest args Executes git with ARGS and returns @code{t} if the exit code is @code{1}, @code{nil} otherwise. @end defun @defun magit-git-true &rest args Executes git with ARGS and returns @code{t} if the first line printed by git is the string "true", @code{nil} otherwise. @end defun @defun magit-git-false &rest args Executes git with ARGS and returns @code{t} if the first line printed by git is the string "false", @code{nil} otherwise. @end defun @defun magit-git-insert &rest args Executes git with ARGS and inserts its output at point. @end defun @defun magit-git-string &rest args Executes git with ARGS and returns the first line of its output. If there is no output or if it begins with a newline character, then this returns @code{nil}. @end defun @defun magit-git-lines &rest args Executes git with ARGS and returns its output as a list of lines. Empty lines anywhere in the output are omitted. @end defun @defun magit-git-items &rest args Executes git with ARGS and returns its null-separated output as a list. Empty items anywhere in the output are omitted. If the value of option @code{magit-git-debug} is non-nil and git exits with a non-zero exit status, then warn about that in the echo area and add a section containing git's standard error in the current repository's process buffer. @end defun If an error occurs when using one of the above functions, then that is usually due to a bug, i.e. using an argument which is not actually supported. Such errors are usually not reported, but when they occur we need to be able to debug them. @defopt magit-git-debug Whether to report errors that occur when using @code{magit-git-insert}, @code{magit-git-string}, @code{magit-git-lines}, or @code{magit-git-items}. This does not actually raise an error. Instead a message is shown in the echo area, and git's standard error is insert into a new section in the current repository's process buffer. @end defopt @defun magit-git-str &rest args This is a variant of @code{magit-git-string} that ignores the option @code{magit-git-debug}. It is mainly intended to be used while handling errors in functions that do respect that option. Using such a function while handing an error could cause yet another error and therefore lead to an infinite recursion. You probably won't ever need to use this function. @end defun @node Calling Git for Effect @subsection Calling Git for Effect These functions are used to run git to produce some effect. Most Magit commands that actually run git do so by using such a function. Because we do not need to consume git's output when using these functions, their output is instead logged into a per-repository buffer, which can be shown using @code{$} from a Magit buffer or @code{M-x magit-process} elsewhere. These functions can have an effect in two distinct ways. Firstly, running git may change something, i.e. create or push a new commit. Secondly, that change may require that Magit buffers are refreshed to reflect the changed state of the repository. But refreshing isn't always desirable, so only some of these functions do perform such a refresh after git has returned. Sometimes it is useful to run git asynchronously. For example, when the user has just initiated a push, then there is no reason to make her wait until that has completed. In other cases it makes sense to wait for git to complete before letting the user do something else. For example after staging a change it is useful to wait until after the refresh because that also automatically moves to the next change. @defun magit-call-git &rest args Calls git synchronously with ARGS@. @end defun @defun magit-call-process program &rest args Calls PROGRAM synchronously with ARGS@. @end defun @defun magit-run-git &rest args Calls git synchronously with ARGS and then refreshes. @end defun @defun magit-run-git-with-input input &rest args Calls git synchronously with ARGS and sends it INPUT on standard input. INPUT should be a buffer or the name of an existing buffer. The content of that buffer is used as the process' standard input. After the process returns a refresh is performed. As a special case, INPUT may also be nil. In that case the content of the current buffer is used as standard input and @strong{no} refresh is performed. This function actually runs git asynchronously. But then it waits for the process to return, so the function itself is synchronous. @end defun @defun magit-run-git-with-logfile file &rest args Calls git synchronously with ARGS@. The process' output is saved in FILE@. This is rarely useful and so this function might be removed in the future. This function actually runs git asynchronously. But then it waits for the process to return, so the function itself is synchronous. @end defun @defun magit-git &rest args Calls git synchronously with ARGS for side-effects only. This function does not refresh the buffer. @end defun @defun magit-git-wash washer &rest args Execute Git with ARGS, inserting washed output at point. Actually first insert the raw output at point. If there is no output call @code{magit-cancel-section}. Otherwise temporarily narrow the buffer to the inserted text, move to its beginning, and then call function WASHER with ARGS as its sole argument. @end defun And now for the asynchronous variants. @defun magit-run-git-async &rest args Start Git, prepare for refresh, and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if @code{magit-revert-buffers} is non-nil. @end defun @defun magit-run-git-with-editor &rest args Export GIT@math{_EDITOR} and start Git. Also prepare for refresh and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. @end defun @defun magit-start-git &rest args Start Git, prepare for refresh, and return the process object. If INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. Option @code{magit-git-executable} specifies the Git executable and option @code{magit-git-global-arguments} specifies constant arguments. The remaining arguments ARGS specify arguments to Git. They are flattened before use. After Git returns, some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if @code{magit-revert-buffers} is non-nil. @end defun @defun magit-start-process &rest args Start PROGRAM, prepare for refresh, and return the process object. If optional argument INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. The process is started using @code{start-file-process} and then setup to use the sentinel @code{magit-process-sentinel} and the filter @code{magit-process-filter}. Information required by these functions is stored in the process object. When this function returns the process has not started to run yet so it is possible to override the sentinel and filter. After the process returns, @code{magit-process-sentinel} refreshes the buffer that was current when @code{magit-start-process} was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. Unmodified buffers visiting files that are tracked in the current repository are reverted if @code{magit-revert-buffers} is non-nil. @end defun @defvar magit-this-process The child process which is about to start. This can be used to change the filter and sentinel. @end defvar @defvar magit-process-raise-error When this is non-nil, then @code{magit-process-sentinel} raises an error if git exits with a non-zero exit status. For debugging purposes. @end defvar @node Section Plumbing @section Section Plumbing @menu * Creating Sections:: * Section Selection:: * Matching Sections:: @end menu @node Creating Sections @subsection Creating Sections @defmac magit-insert-section &rest args Insert a section at point. TYPE is the section type, a symbol. Many commands that act on the current section behave differently depending on that type. Also if a variable @code{magit-TYPE-section-map} exists, then use that as the text-property @code{keymap} of all text belonging to the section (but this may be overwritten in subsections). TYPE can also have the form @code{(eval FORM)} in which case FORM is evaluated at runtime. Optional VALUE is the value of the section, usually a string that is required when acting on the section. When optional HIDE is non-nil collapse the section body by default, i.e. when first creating the section, but not when refreshing the buffer. Otherwise, expand it by default. This can be overwritten using @code{magit-section-set-visibility-hook}. When a section is recreated during a refresh, then the visibility of predecessor is inherited and HIDE is ignored (but the hook is still honored). BODY is any number of forms that actually insert the section's heading and body. Optional NAME, if specified, has to be a symbol, which is then bound to the struct of the section being inserted. Before BODY is evaluated the @code{start} of the section object is set to the value of @code{point} and after BODY was evaluated its @code{end} is set to the new value of @code{point}; BODY is responsible for moving @code{point} forward. If it turns out inside BODY that the section is empty, then @code{magit-cancel-section} can be used to abort and remove all traces of the partially inserted section. This can happen when creating a section by washing Git's output and Git didn't actually output anything this time around. @end defmac @defun magit-insert-heading &rest args Insert the heading for the section currently being inserted. This function should only be used inside @code{magit-insert-section}. When called without any arguments, then just set the @code{content} slot of the object representing the section being inserted to a marker at @code{point}. The section should only contain a single line when this function is used like this. When called with arguments ARGS, which have to be strings, then insert those strings at point. The section should not contain any text before this happens and afterwards it should again only contain a single line. If the @code{face} property is set anywhere inside any of these strings, then insert all of them unchanged. Otherwise use the @code{magit-section-heading} face for all inserted text. The @code{content} property of the section struct is the end of the heading (which lasts from @code{start} to @code{content}) and the beginning of the body (which lasts from @code{content} to @code{end}). If the value of @code{content} is nil, then the section has no heading and its body cannot be collapsed. If a section does have a heading then its height must be exactly one line, including a trailing newline character. This isn't enforced; you are responsible for getting it right. The only exception is that this function does insert a newline character if necessary. @end defun @defun magit-cancel-section Cancel the section currently being inserted. This exits the innermost call to @code{magit-insert-section} and removes all traces of what has already happened inside that call. @end defun @defun magit-define-section-jumper sym title &optional value Define an interactive function to go to section SYM@. TITLE is the displayed title of the section. @end defun @node Section Selection @subsection Section Selection @defun magit-current-section Return the section at point. @end defun @defun magit-region-sections &optional condition multiple Return a list of the selected sections. When the region is active and constitutes a valid section selection, then return a list of all selected sections. This is the case when the region begins in the heading of a section and ends in the heading of the same section or in that of a sibling section. If optional MULTIPLE is non-nil, then the region cannot begin and end in the same section. When the selection is not valid, then return nil. In this case, most commands that can act on the selected sections will instead act on the section at point. When the region looks like it would in any other buffer then the selection is invalid. When the selection is valid then the region uses the @code{magit-section-highlight} face. This does not apply to diffs where things get a bit more complicated, but even here if the region looks like it usually does, then that's not a valid selection as far as this function is concerned. If optional CONDITION is non-nil, then the selection not only has to be valid; all selected sections additionally have to match CONDITION, or nil is returned. See @code{magit-section-match} for the forms CONDITION can take. @end defun @defun magit-region-values &optional condition multiple Return a list of the values of the selected sections. Return the values that themselves would be returned by @code{magit-region-sections} (which see). @end defun @node Matching Sections @subsection Matching Sections @table @asis @kindex M-x magit-describe-section-briefly @cindex magit-describe-section-briefly @item @kbd{M-x magit-describe-section-briefly} @tie{}@tie{}@tie{}@tie{}(@code{magit-describe-section-briefly}) Show information about the section at point. This command is intended for debugging purposes. @end table @defun magit-section-ident section Return an unique identifier for SECTION@. The return value has the form @code{((TYPE . VALUE)...)}. @end defun @defun magit-get-section ident &optional root Return the section identified by IDENT@. IDENT has to be a list as returned by @code{magit-section-ident}. @end defun @defun magit-section-match condition &optional section Return @code{t} if SECTION matches CONDITION@. SECTION defaults to the section at point. If SECTION is not specified and there also is no section at point, then return @code{nil}. CONDITION can take the following forms: @itemize @item @code{(CONDITION...)} matches if any of the CONDITIONs matches. @item @code{[CLASS...]} matches if the section's class is the same as the first CLASS or a subclass of that; the section's parent class matches the second CLASS; and so on. @item @code{[* CLASS...]} matches sections that match @code{[CLASS...]} and also recursively all their child sections. @item @code{CLASS} matches if the section's class is the same as CLASS or a subclass of that; regardless of the classes of the parent sections. @end itemize Each CLASS should be a class symbol, identifying a class that derives from @code{magit-section}. For backward compatibility CLASS can also be a "type symbol". A section matches such a symbol if the value of its @code{type} slot is @code{eq}. If a type symbol has an entry in @code{magit--section-type-alist}, then a section also matches that type if its class is a subclass of the class that corresponds to the type as per that alist. Note that it is not necessary to specify the complete section lineage as printed by @code{magit-describe-section-briefly}, unless of course you want to be that precise. @end defun @defun magit-section-value-if condition &optional section If the section at point matches CONDITION, then return its value. If optional SECTION is non-nil then test whether that matches instead. If there is no section at point and SECTION is nil, then return nil. If the section does not match, then return nil. See @code{magit-section-match} for the forms CONDITION can take. @end defun @defun magit-section-case &rest clauses Choose among clauses on the type of the section at point. Each clause looks like (CONDITION BODY@dots{}). The type of the section is compared against each CONDITION; the BODY forms of the first match are evaluated sequentially and the value of the last form is returned. Inside BODY the symbol @code{it} is bound to the section at point. If no clause succeeds or if there is no section at point return nil. See @code{magit-section-match} for the forms CONDITION can take. Additionally a CONDITION of t is allowed in the final clause and matches if no other CONDITION match, even if there is no section at point. @end defun @defvar magit-root-section The root section in the current buffer. All other sections are descendants of this section. The value of this variable is set by @code{magit-insert-section} and you should never modify it. @end defvar For diff related sections a few additional tools exist. @defun magit-diff-type &optional section Return the diff type of SECTION@. The returned type is one of the symbols @code{staged}, @code{unstaged}, @code{committed}, or @code{undefined}. This type serves a similar purpose as the general type common to all sections (which is stored in the @code{type} slot of the corresponding @code{magit-section} struct) but takes additional information into account. When the SECTION isn't related to diffs and the buffer containing it also isn't a diff-only buffer, then return nil. Currently the type can also be one of @code{tracked} and @code{untracked}, but these values are not handled explicitly in every place they should be. A possible fix could be to just return nil here. The section has to be a @code{diff} or @code{hunk} section, or a section whose children are of type @code{diff}. If optional SECTION is nil, return the diff type for the current section. In buffers whose major mode is @code{magit-diff-mode} SECTION is ignored and the type is determined using other means. In @code{magit-revision-mode} buffers the type is always @code{committed}. @end defun @defun magit-diff-scope &optional section strict Return the diff scope of SECTION or the selected section(s). A diff's "scope" describes what part of a diff is selected, it is a symbol, one of @code{region}, @code{hunk}, @code{hunks}, @code{file}, @code{files}, or @code{list}. Do not confuse this with the diff "type", as returned by @code{magit-diff-type}. If optional SECTION is non-nil, then return the scope of that, ignoring the sections selected by the region. Otherwise return the scope of the current section, or if the region is active and selects a valid group of diff related sections, the type of these sections, i.e. @code{hunks} or @code{files}. If SECTION (or if the current section that is nil) is a @code{hunk} section and the region starts and ends inside the body of a that section, then the type is @code{region}. If optional STRICT is non-nil then return nil if the diff type of the section at point is @code{untracked} or the section at point is not actually a @code{diff} but a @code{diffstat} section. @end defun @node Refreshing Buffers @section Refreshing Buffers All commands that create a new Magit buffer or change what is being displayed in an existing buffer do so by calling @code{magit-mode-setup}. Among other things, that function sets the buffer local values of @code{default-directory} (to the top-level of the repository), @code{magit-refresh-function}, and @code{magit-refresh-args}. Buffers are refreshed by calling the function that is the local value of @code{magit-refresh-function} (a function named @code{magit-*-refresh-buffer}, where @code{*} may be something like @code{diff}) with the value of @code{magit-refresh-args} as arguments. @defmac magit-mode-setup buffer switch-func mode refresh-func &optional refresh-args This function displays and selects BUFFER, turns on MODE, and refreshes a first time. This function displays and optionally selects BUFFER by calling @code{magit-mode-display-buffer} with BUFFER, MODE and SWITCH-FUNC as arguments. Then it sets the local value of @code{magit-refresh-function} to REFRESH-FUNC and that of @code{magit-refresh-args} to REFRESH-ARGS@. Finally it creates the buffer content by calling REFRESH-FUNC with REFRESH-ARGS as arguments. All arguments are evaluated before switching to BUFFER@. @end defmac @defun magit-mode-display-buffer buffer mode &optional switch-function This function display BUFFER in some window and select it. BUFFER may be a buffer or a string, the name of a buffer. The buffer is returned. Unless BUFFER is already displayed in the selected frame, store the previous window configuration as a buffer local value, so that it can later be restored by @code{magit-mode-bury-buffer}. The buffer is displayed and selected using SWITCH-FUNCTION@. If that is @code{nil} then @code{pop-to-buffer} is used if the current buffer's major mode derives from @code{magit-mode}. Otherwise @code{switch-to-buffer} is used. @end defun @defvar magit-refresh-function The value of this buffer-local variable is the function used to refresh the current buffer. It is called with @code{magit-refresh-args} as arguments. @end defvar @defvar magit-refresh-args The list of arguments used by @code{magit-refresh-function} to refresh the current buffer. @code{magit-refresh-function} is called with these arguments. The value is usually set using @code{magit-mode-setup}, but in some cases it's also useful to provide commands which can change the value. For example, the @code{magit-diff-refresh-popup} can be used to change any of the arguments used to display the diff, without having to specify again which differences should be shown. @code{magit-diff-more-context}, @code{magit-diff-less-context}, and @code{magit-diff-default-context} change just the @code{-U} argument. In both case this is done by changing the value of this variable and then calling this @code{magit-refresh-function}. @end defvar @node Conventions @section Conventions Also see @ref{Completion and Confirmation}. @menu * Theming Faces:: @end menu @node Theming Faces @subsection Theming Faces The default theme uses blue for local branches, green for remote branches, and goldenrod (brownish yellow) for tags. When creating a new theme, you should probably follow that example. If your theme already uses other colors, then stick to that. In older releases these reference faces used to have a background color and a box around them. The basic default faces no longer do so, to make Magit buffers much less noisy, and you should follow that example at least with regards to boxes. (Boxes were used in the past to work around a conflict between the highlighting overlay and text property backgrounds. That's no longer necessary because highlighting no longer causes other background colors to disappear.) Alternatively you can keep the background color and/or box, but then have to take special care to adjust @code{magit-branch-current} accordingly. By default it looks mostly like @code{magit-branch-local}, but with a box (by default the former is the only face that uses a box, exactly so that it sticks out). If the former also uses a box, then you have to make sure that it differs in some other way from the latter. The most difficult faces to theme are those related to diffs, headings, highlighting, and the region. There are faces that fall into all four groups - expect to spend some time getting this right. The @code{region} face in the default theme, in both the light and dark variants, as well as in many other themes, distributed with Emacs or by third-parties, is very ugly. It is common to use a background color that really sticks out, which is ugly but if that were the only problem then it would be acceptable. Unfortunately many themes also set the foreground color, which ensures that all text within the region is readable. Without doing that there might be cases where some foreground color is too close to the region background color to still be readable. But it also means that text within the region loses all syntax highlighting. I consider the work that went into getting the @code{region} face right to be a good indicator for the general quality of a theme. My recommendation for the @code{region} face is this: use a background color slightly different from the background color of the @code{default} face, and do not set the foreground color at all. So for a light theme you might use a light (possibly tinted) gray as the background color of @code{default} and a somewhat darker gray for the background of @code{region}. That should usually be enough to not collide with the foreground color of any other face. But if some other faces also set a light gray as background color, then you should also make sure it doesn't collide with those (in some cases it might be acceptable though). Magit only uses the @code{region} face when the region is "invalid" by its own definition. In a Magit buffer the region is used to either select multiple sibling sections, so that commands which support it act on all of these sections instead of just the current section, or to select lines within a single hunk section. In all other cases, the section is considered invalid and Magit won't act on it. But such invalid sections happen, either because the user has not moved point enough yet to make it valid or because she wants to use a non-magit command to act on the region, e.g. @code{kill-region}. So using the regular @code{region} face for invalid sections is a feature. It tells the user that Magit won't be able to act on it. It's acceptable if that face looks a bit odd and even (but less so) if it collides with the background colors of section headings and other things that have a background color. Magit highlights the current section. If a section has subsections, then all of them are highlighted. This is done using faces that have "highlight" in their names. For most sections, @code{magit-section-highlight} is used for both the body and the heading. Like the @code{region} face, it should only set the background color to something similar to that of @code{default}. The highlight background color must be different from both the @code{region} background color and the @code{default} background color. For diff related sections Magit uses various faces to highlight different parts of the selected section(s). Note that hunk headings, unlike all other section headings, by default have a background color, because it is useful to have very visible separators between hunks. That face @code{magit-diff-hunk-heading}, should be different from both @code{magit-diff-hunk-heading-highlight} and @code{magit-section-highlight}, as well as from @code{magit-diff-context} and @code{magit-diff-context-highlight}. By default we do that by changing the foreground color. Changing the background color would lead to complications, and there are already enough we cannot get around. (Also note that it is generally a good idea for section headings to always be bold, but only for sections that have subsections). When there is a valid region selecting diff-related sibling sections, i.e. multiple files or hunks, then the bodies of all these sections use the respective highlight faces, but additionally the headings instead use one of the faces @code{magit-diff-file-heading-selection} or @code{magit-diff-hunk-heading-selection}. These faces have to be different from the regular highlight variants to provide explicit visual indication that the region is active. When theming diff related faces, start by setting the option @code{magit-diff-refine-hunk} to @code{all}. You might personally prefer to only refine the current hunk or not use hunk refinement at all, but some of the users of your theme want all hunks to be refined, so you have to cater to that. (Also turn on @code{magit-diff-highlight-indentation}, @code{magit-diff-highlight-trailing}, and @code{magit-diff-paint-whitespace}; and insert some whitespace errors into the code you use for testing.) For e.g. "added lines" you have to adjust three faces: @code{magit-diff-added}, @code{magit-diff-added-highlight}, and @code{smerge-refined-added}. Make sure that the latter works well with both of the former, as well as @code{smerge-other} and @code{diff-added}. Then do the same for the removed lines, context lines, lines added by us, and lines added by them. Also make sure the respective added, removed, and context faces use approximately the same saturation for both the highlighted and unhighlighted variants. Also make sure the file and diff headings work nicely with context lines (e.g. make them look different). Line faces should set both the foreground and the background color. For example, for added lines use two different greens. It's best if the foreground color of both the highlighted and the unhighlighted variants are the same, so you will need to have to find a color that works well on the highlight and unhighlighted background, the refine background, and the highlight context background. When there is an hunk internal region, then the added- and removed-lines background color is used only within that region. Outside the region the highlighted context background color is used. This makes it easier to see what is being staged. With an hunk internal region the hunk heading is shown using @code{magit-diff-hunk-heading-selection}, and so are the thin lines that are added around the lines that fall within the region. The background color of that has to be distinct enough from the various other involved background colors. Nobody said this would be easy. If your theme restricts itself to a certain set of colors, then you should make an exception here. Otherwise it would be impossible to make the diffs look good in each and every variation. Actually you might want to just stick to the default definitions for these faces. You have been warned. Also please note that if you do not get this right, this will in some cases look to users like bugs in Magit - so please do it right or not at all. @node FAQ @appendix FAQ The next two nodes lists frequently asked questions. For a list of frequently @strong{and recently} asked questions, i.e. questions that haven't made it into the manual yet, see @uref{https://github.com/magit/magit/wiki/FAQ}. Please also use the @ref{Debugging Tools}. @menu * FAQ - How to @dots{}?:: * FAQ - Issues and Errors:: @end menu @node FAQ - How to @dots{}? @appendixsec FAQ - How to @dots{}? @menu * How to show git's output?:: * How to install the gitman info manual?:: * How to show diffs for gpg-encrypted files?:: * How does branching and pushing work?:: * Can Magit be used as @code{ediff-version-control-package}?:: @end menu @node How to show git's output? @appendixsubsec How to show git's output? To show the output of recently run git commands, press @code{$} (or, if that isn't available, @code{M-x magit-process-buffer}). This will show a buffer containing a section per git invocation; as always press @code{TAB} to expand or collapse them. By default, git's output is only inserted into the process buffer if it is run for side-effects. When the output is consumed in some way, also inserting it into the process buffer would be too expensive. For debugging purposes, it's possible to do so anyway by setting @code{magit-git-debug} to @code{t}. @node How to install the gitman info manual? @appendixsubsec How to install the gitman info manual? Git's manpages can be exported as an info manual called @code{gitman}. Magit's own info manual links to nodes in that manual instead of the actual manpages because Info doesn't support linking to manpages. Unfortunately some distributions do not install the @code{gitman} manual by default and you will have to install a separate documentation package to get it. Magit patches Info adding the ability to visit links to the @code{gitman} Info manual by instead viewing the respective manpage. If you prefer that approach, then set the value of @code{magit-view-git-manual-method} to one of the supported packages @code{man} or @code{woman}, e.g.: @lisp (setq magit-view-git-manual-method 'man) @end lisp @node How to show diffs for gpg-encrypted files? @appendixsubsec How to show diffs for gpg-encrypted files? Git supports showing diffs for encrypted files, but has to be told to do so. Since Magit just uses Git to get the diffs, configuring Git also affects the diffs displayed inside Magit. @example git config --global diff.gpg.textconv "gpg --no-tty --decrypt" echo "*.gpg filter=gpg diff=gpg" > .gitattributes @end example @node How does branching and pushing work? @appendixsubsec How does branching and pushing work? Please see @ref{Branching} and @uref{http://emacsair.me/2016/01/17/magit-2.4} @node Can Magit be used as @code{ediff-version-control-package}? @appendixsubsec Can Magit be used as @code{ediff-version-control-package}? No, it cannot. For that to work the functions @code{ediff-magit-internal} and @code{ediff-magit-merge-internal} would have to be implemented, and they are not. These two functions are only used by the three commands @code{ediff-revision}, @code{ediff-merge-revisions-with-ancestor}, and @code{ediff-merge-revisions}. These commands only delegate the task of populating buffers with certain revisions to the "internal" functions. The equally important task of determining which revisions are to be compared/merged is not delegated. Instead this is done without any support whatsoever from the version control package/system - meaning that the user has to enter the revisions explicitly. Instead of implementing @code{ediff-magit-internal} we provide @code{magit-ediff-compare}, which handles both tasks like it is 2005. The other commands @code{ediff-merge-revisions} and @code{ediff-merge-revisions-with-ancestor} are normally not what you want when using a modern version control system like Git. Instead of letting the user resolve only those conflicts which Git could not resolve on its own, they throw away all work done by Git and then expect the user to manually merge all conflicts, including those that had already been resolved. That made sense back in the days when version control systems couldn't merge (or so I have been told), but not anymore. Once in a blue moon you might actually want to see all conflicts, in which case you @strong{can} use these commands, which then use @code{ediff-vc-merge-internal}. So we don't actually have to implement @code{ediff-magit-merge-internal}. Instead we provide the more useful command @code{magit-ediff-resolve} which only shows yet-to-be resolved conflicts. @node FAQ - Issues and Errors @appendixsec FAQ - Issues and Errors @menu * Magit is slow:: * I changed several thousand files at once and now Magit is unusable:: * I am having problems committing:: * I am using MS Windows and cannot push with Magit:: * I am using OS X and SOMETHING works in shell, but not in Magit: I am using OS X and SOMETHING works in shell but not in Magit. * Diffs contain control sequences:: * Expanding a file to show the diff causes it to disappear:: * Point is wrong in the @code{COMMIT_EDITMSG} buffer:: * The mode-line information isn't always up-to-date:: * A branch and tag sharing the same name breaks SOMETHING:: * My Git hooks work on the command-line but not inside Magit:: * @code{git-commit-mode} isn't used when committing from the command-line:: * Point ends up inside invisible text when jumping to a file-visiting buffer:: @end menu @node Magit is slow @appendixsubsec Magit is slow See @ref{Performance}. @node I changed several thousand files at once and now Magit is unusable @appendixsubsec I changed several thousand files at once and now Magit is unusable Magit is @strong{currently} not expected to work under such conditions. It sure would be nice if it did, and v2.5 will hopefully be a big step into that direction. But it might take until v3.1 to accomplish fully satisfactory performance, because that requires some heavy refactoring. But for now we recommend you use the command line to complete this one commit. Also see @ref{Performance}. @node I am having problems committing @appendixsubsec I am having problems committing That likely means that Magit is having problems finding an appropriate emacsclient executable. See @ref{Configuring With-Editor,,,with-editor,} and @ref{Debugging,,,with-editor,}. @node I am using MS Windows and cannot push with Magit @appendixsubsec I am using MS Windows and cannot push with Magit It's almost certain that Magit is only incidental to this issue. It is much more likely that this is a configuration issue, even if you can push on the command line. Detailed setup instructions can be found at @uref{https://github.com/magit/magit/wiki/Pushing-with-Magit-from-Windows}. @node I am using OS X and SOMETHING works in shell but not in Magit @appendixsubsec I am using OS X and SOMETHING works in shell, but not in Magit This usually occurs because Emacs doesn't have the same environment variables as your shell. Try installing and configuring @uref{https://github.com/purcell/exec-path-from-shell}. By default it synchronizes @code{$PATH}, which helps Magit find the same @code{git} as the one you are using on the shell. If SOMETHING is "passphrase caching with gpg-agent for commit and/or tag signing", then you'll also need to synchronize @code{$GPG_AGENT_INFO}. @node Diffs contain control sequences @appendixsubsec Diffs contain control sequences This happens when you configure Git to always color diffs and/or all of its output. The valid values for relevant Git variables @code{color.ui} and @code{color.diff} are @code{false}, @code{true} and @code{always}, and the default is @code{true}. You should leave it that way because then you get colorful output in terminals by default but when git's output is consumed by something else, then no color control sequences are used. If you actually use some other tool that requires setting @code{color.ui} and/or @code{color.diff} to @code{always} (which is highly unlikely), then you can override these settings just for Magit by using: @lisp (setq magit-git-global-arguments (nconc magit-git-global-arguments '("-c" "color.ui=false" "-c" "color.diff=false"))) @end lisp @node Expanding a file to show the diff causes it to disappear @appendixsubsec Expanding a file to show the diff causes it to disappear This is probably caused by a change of a @code{diff.*} Git variable. You probably set that variable for a reason, and should therefore only undo that setting in Magit by customizing @code{magit-git-global-arguments}. @node Point is wrong in the @code{COMMIT_EDITMSG} buffer @appendixsubsec Point is wrong in the @code{COMMIT_EDITMSG} buffer Neither Magit nor `git-commit` fiddle with point in the buffer used to write commit messages, so something else must be doing it. You have probably globally enabled a mode which does restore point in file-visiting buffers. It might be a bit surprising, but when you write a commit message, then you are actually editing a file. So you have to figure out which package is doing. @code{saveplace}, @code{pointback}, and @code{session} are likely candidates. These snippets might help: @lisp (setq session-name-disable-regexp "\\(?:\\`'\\.git/[A-Z_]+\\'\\)") (with-eval-after-load 'pointback (lambda () (when (or git-commit-mode git-rebase-mode) (pointback-mode -1)))) @end lisp @node The mode-line information isn't always up-to-date @appendixsubsec The mode-line information isn't always up-to-date Magit is not responsible for the version control information that is being displayed in the mode-line and looks something like @code{Git-master}. The built-in "Version Control" package, also known as "VC", updates that information, and can be told to do so more often: @lisp (setq auto-revert-check-vc-info t) @end lisp But doing so isn't good for performance. For more (overly optimistic) information see @ref{VC Mode Line,,,emacs,}. If you don't really care about seeing that information in the mode-line, but just don't want to see @emph{incorrect} information, then consider disabling VC when using Git: @lisp (setq vc-handled-backends (delq 'Git vc-handled-backends)) @end lisp Or to disable it completely: @lisp (setq vc-handled-backends nil) @end lisp @node A branch and tag sharing the same name breaks SOMETHING @appendixsubsec A branch and tag sharing the same name breaks SOMETHING Or more generally, ambiguous refnames break SOMETHING@. Magit assumes that refs are named non-ambiguously across the "refs/heads/", "refs/tags/", and "refs/remotes/" namespaces (i.e., all the names remain unique when those prefixes are stripped). We consider ambiguous refnames unsupported and recommend that you use a non-ambiguous naming scheme. However, if you do work with a repository that has ambiguous refnames, please report any issues you encounter so that we can investigate whether there is a simple fix. @node My Git hooks work on the command-line but not inside Magit @appendixsubsec My Git hooks work on the command-line but not inside Magit When Magit calls @code{git} it adds a few global arguments including @code{--literal-pathspecs} and the @code{git} process started by Magit then passes that setting on to other @code{git} process it starts itself. It does so by setting the environment variable @code{GIT_LITERAL_PATHSPECS}, not by calling subprocesses with the @code{--literal-pathspecs}. You can therefore override this setting in hook scripts using @code{unset GIT_LITERAL_PATHSPECS}. @node @code{git-commit-mode} isn't used when committing from the command-line @appendixsubsec @code{git-commit-mode} isn't used when committing from the command-line The reason for this is that @code{git-commit.el} has not been loaded yet and/or that the server has not been started yet. These things have always already been taken care of when you commit from Magit because in order to do so, Magit has to be loaded and doing that involves loading @code{git-commit} and starting the server. If you want to commit from the command-line, then you have to take care of these things yourself. Your @code{init.el} file should contain: @lisp (require 'git-commit) (server-mode) @end lisp Instead of `(require 'git-commit)` you may also use: @lisp (load "/path/to/magit-autoloads.el") @end lisp You might want to do that because loading @code{git-commit} causes large parts of Magit to be loaded. There are also some variations of @code{(server-mode)} that you might want to try. Personally I use: @lisp (use-package server :config (or (server-running-p) (server-mode))) @end lisp Now you can use: @example $ emacs& $ EDITOR=emacsclient git commit @end example However you cannot use: @example $ killall emacs $ EDITOR="emacsclient --alternate-editor emacs" git commit @end example This will actually end up using @code{emacs}, not @code{emacsclient}. If you do this, then can still edit the commit message but @code{git-commit-mode} won't be used and you have to exit @code{emacs} to finish the process. Tautology ahead. If you want to be able to use @code{emacsclient} to connect to a running @code{emacs} instance, even though no @code{emacs} instance is running, then you cannot use @code{emacsclient} directly. Instead you have to create a script that does something like this: Try to use @code{emacsclient} (without using @code{--alternate-editor}). If that succeeds, do nothing else. Otherwise start @code{emacs &} (and @code{init.el} must call @code{server-start}) and try to use @code{emacsclient} again. @node Point ends up inside invisible text when jumping to a file-visiting buffer @appendixsubsec Point ends up inside invisible text when jumping to a file-visiting buffer This can happen when you type @code{RET} on a hunk to visit the respective file at the respective position. One solution to this problem is to use @code{global-reveal-mode}. It makes sure that text around point is always visible. If that is too drastic for your taste, then you may instead use @code{magit-diff-visit-file-hook} to reveal the text, possibly using @code{reveal-post-command} or for Org buffers @code{org-reveal}. @node Debugging Tools @chapter Debugging Tools Magit and its dependencies provide a few debugging tools, and we appreciate it very much if you use those tools before reporting an issue. Please include all relevant output when reporting an issue. @table @asis @kindex M-x magit-version @cindex magit-version @item @kbd{M-x magit-version} @tie{}@tie{}@tie{}@tie{}(@code{magit-version}) This command shows the currently used versions of Magit, Git, and Emacs in the echo area. Non-interactively this just returns the Magit version. @kindex M-x magit-emacs-Q-command @cindex magit-emacs-Q-command @item @kbd{M-x magit-emacs-Q-command} @tie{}@tie{}@tie{}@tie{}(@code{magit-emacs-Q-command}) This command shows a debugging shell command in the echo area and adds it to the kill ring. Paste that command into a shell and run it. This shell command starts @code{emacs} with only @code{magit} and its dependencies loaded. Neither your configuration nor other installed packages are loaded. This makes it easier to determine whether some issue lays with Magit or something else. If you run Magit from its Git repository, then you should be able to use @code{make emacs-Q} instead of the output of this command. @kindex M-x magit-debug-git-executable @cindex magit-debug-git-executable @item @kbd{M-x magit-debug-git-executable} @tie{}@tie{}@tie{}@tie{}(@code{magit-debug-git-executable}) This command displays a buffer containing information about the available and used @code{git} executable(s), and can be useful when investigating @code{exec-path} issues. Also see @ref{Git Executable}. @kindex M-x with-editor-debug @cindex with-editor-debug @item @kbd{M-x with-editor-debug} @tie{}@tie{}@tie{}@tie{}(@code{with-editor-debug}) This command displays a buffer containing information about the available and used @code{~emacsclient} executable(s), and can be useful when investigating why Magit (or rather @code{with-editor}) cannot find an appropriate @code{emacsclient} executable. Also see @ref{Debugging,,,with-editor,}. @end table Please also see the @ref{FAQ}. @node Keystroke Index @appendix Keystroke Index @printindex ky @node Command Index @appendix Command Index @printindex cp @node Function Index @appendix Function Index @printindex fn @node Variable Index @appendix Variable Index @printindex vr @bye magit-2.90.1/LICENSE000066400000000000000000001043741337354740400137340ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. 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. Copyright (C) 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 . 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: Copyright (C) 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 . 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 . magit-2.90.1/Makefile000066400000000000000000000156411337354740400143650ustar00rootroot00000000000000-include config.mk include default.mk ## ################################################################### .PHONY: lisp \ install install-lisp install-docs install-info \ test test-interactive magit \ clean clean-lisp clean-docs clean-archives \ stats bump-version melpa-post-release \ dist versionlib magit-$(VERSION).tar.gz all: lisp docs help: $(info ) $(info See default.mk for variables you might want to set.) $(info ) $(info Build) $(info =====) $(info ) $(info make [all] - compile elisp and documentation) $(info make lisp - compile elisp) $(info make docs - generate info manuals) $(info make info - generate info manuals) $(info make html - generate html manual files) $(info make html-dir - generate html manual directories) $(info make pdf - generate pdf manuals) $(info make epub - generate epub manuals) $(info ) $(info Install) $(info =======) $(info ) $(info make install - install elisp and documentation) $(info make install-lisp - install elisp) $(info make install-docs - install all documentation) $(info make install-info - install info manuals only) $(info ) $(info Clean) $(info ====) $(info ) $(info make clean - clean elisp, documentation and tarball) $(info make clean-lisp - clean elisp) $(info make clean-docs - clean docs) $(info make clean-archives - clean release tarball) $(info make clean-all - clean everything except tracked texi) $(info make clean-stats - clean stats) $(info ) $(info Test) $(info ====) $(info ) $(info make test - run tests) $(info make test-interactive - run tests interactively) $(info make emacs-Q - run emacs -Q plus Magit) $(info ) $(info Release Management) $(info ==================) $(info ) $(info make texi - regenerate texi from org) $(info make stats - regenerate statistics) $(info make authors - regenerate AUTHORS.md) $(info make publish-stats - publish statistics) $(info make publish-manuals - publish snapshot manuals) $(info make release-manuals - publish release manuals) $(info make dist - create tarballs) $(info make bump-versions - bump versions for release) $(info make bump-snapshots - bump versions after release) @printf "\n" ## Build ############################################################# lisp: @$(MAKE) -C lisp lisp docs: @$(MAKE) -C Documentation all info: @$(MAKE) -C Documentation info html: @$(MAKE) -C Documentation html html-dir: @$(MAKE) -C Documentation html-dir pdf: @$(MAKE) -C Documentation pdf epub: @$(MAKE) -C Documentation epub ## Install ########################################################### install: install-lisp install-docs install-lisp: lisp @$(MAKE) -C lisp install install-docs: docs @$(MAKE) -C Documentation install-docs install-info: info @$(MAKE) -C Documentation install-info ## Test ############################################################## test: @$(BATCH) --eval "(progn\ $$suppress_warnings\ (load-file \"t/magit-tests.el\")\ (ert-run-tests-batch-and-exit))" test-interactive: @$(EMACSBIN) -Q $(LOAD_PATH) --eval "(progn\ (load-file \"t/magit-tests.el\")\ (ert t))" emacs-Q: clean-lisp @$(EMACSBIN) -Q $(LOAD_PATH) --debug-init --eval "(progn\ (setq debug-on-error t)\ (require 'magit)\ (global-set-key \"\\C-xg\" 'magit-status))" ## Clean ############################################################# clean: clean-lisp clean-docs clean-archives @printf "Cleaning...\n" @$(RM) *.elc $(ELGS) # temporary cleanup kludge @$(RM) Documentation/*.texi~ Documentation/*.info-1 Documentation/*.info-2 @$(RM) magit-pkg.el t/magit-tests.elc clean-lisp: @$(MAKE) -C lisp clean clean-docs: @$(MAKE) -C Documentation clean clean-archives: @$(RM) *.tar.gz *.tar lisp/magit-version.el @$(RMDIR) magit-$(VERSION) clean-all: clean clean-stats clean-stats: @$(RMDIR) $(statsdir) ## Release management ################################################ texi: @$(MAKE) -C Documentation texi stats: @$(MAKE) -C Documentation stats authors: @$(MAKE) -C Documentation authors publish-stats: @$(MAKE) -C Documentation publish-stats publish-manuals: @$(MAKE) -C Documentation publish-manuals release-manuals: @$(MAKE) -C Documentation release-manuals dist: magit-$(VERSION).tar.gz versionlib: @$(MAKE) -C lisp versionlib DIST_ROOT_FILES = LICENSE default.mk Makefile README.md DIST_LISP_FILES = $(addprefix lisp/,$(ELS) magit-version.el Makefile) DIST_DOCS_FILES = $(addprefix Documentation/,$(TEXIPAGES) AUTHORS.md Makefile) ifneq ("$(wildcard Documentation/RelNotes/$(VERSION).txt)","") DIST_DOCS_FILES += Documentation/RelNotes/$(VERSION).txt endif magit-$(VERSION).tar.gz: lisp versionlib info @printf "Packing $@\n" @$(MKDIR) magit-$(VERSION) @$(CP) $(DIST_ROOT_FILES) magit-$(VERSION) @$(MKDIR) magit-$(VERSION)/lisp @$(CP) $(DIST_LISP_FILES) magit-$(VERSION)/lisp @$(MKDIR) magit-$(VERSION)/Documentation @$(CP) $(DIST_DOCS_FILES) magit-$(VERSION)/Documentation @$(TAR) cz --mtime=./magit-$(VERSION) -f magit-$(VERSION).tar.gz magit-$(VERSION) @$(RMDIR) magit-$(VERSION) define set_package_requires (with-temp-file "lisp/git-commit.el" (insert-file-contents "lisp/git-commit.el") (re-search-forward "^;; Package-Requires: ") (delete-region (point) (line-end-position)) (insert (format "%S" `((emacs ,emacs-version) ;` (dash ,dash-version) (with-editor ,with-editor-version)))) (with-temp-file "lisp/magit-pkg.el" (insert (pp-to-string `(define-package "magit" "$(VERSION)" ;` "A Git porcelain inside Emacs." '((emacs ,emacs-version) ;' (async ,async-version) (dash ,dash-version) (ghub ,ghub-version) (git-commit ,git-commit-version) (magit-popup ,magit-popup-version) (with-editor ,with-editor-version))))) (goto-char (point-min)) (re-search-forward " \"A") (goto-char (match-beginning 0)) (insert "\n "))) endef export set_package_requires bump-versions: bump-versions-1 texi bump-versions-1: @$(BATCH) --eval "(let (\ (emacs-version \"$(EMACS_VERSION)\")\ (async-version \"$(ASYNC_VERSION)\")\ (dash-version \"$(DASH_VERSION)\")\ (ghub-version \"$(GHUB_VERSION)\")\ (git-commit-version \"$(GIT_COMMIT_VERSION)\")\ (magit-popup-version \"$(MAGIT_POPUP_VERSION)\")\ (with-editor-version \"$(WITH_EDITOR_VERSION)\"))\ $$set_package_requires)" bump-snapshots: @$(BATCH) --eval "(let (\ (emacs-version \"$(EMACS_VERSION)\")\ (async-version \"$(ASYNC_MELPA_SNAPSHOT)\")\ (dash-version \"$(DASH_MELPA_SNAPSHOT)\")\ (ghub-version \"$(GHUB_MELPA_SNAPSHOT)\")\ (git-commit-version \"$(GIT_COMMIT_MELPA_SNAPSHOT)\")\ (magit-popup-version \"$(MAGIT_POPUP_MELPA_SNAPSHOT)\")\ (with-editor-version \"$(WITH_EDITOR_MELPA_SNAPSHOT)\"))\ $$set_package_requires)" @git commit -a -m "Reset Package-Requires for Melpa" magit-2.90.1/README.md000066400000000000000000000125521337354740400142020ustar00rootroot00000000000000

A Git Porcelain inside Emacs

homepage | manual | faq | wiki | mailing list | forum | news


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. (more)



Please support Magit by buying some stickers!

1987 backers made sure the Kickstarter campaign was a huge success! Thanks for your generosity and enthusiastic support!
Thank you! — Jonas Bernoulli


My thanks also go to these three sponsors!

Mojotech Google Open Source Directangular


Support ======= When something doesn't work as expected then please first see the [FAQ][faq]. Then also try the list of [open issues][issues] and use the search box at the top of that page to find older related issues. You should also consult the [manual][manual] and ask a general-purpose search engine. If that doesn't answer your question, then ask for help on the **[Emacs Stackexchange site][forum]** or the [mailing list][list]. We only use the GitHub issue tracker for feature requests and bug reports, so please don't ask for help there. Contributing ============ To report bugs and suggest new feature use the [issue tracker][issues]. If you have some code which you would like to be merged, then open a [pull request][pulls]. Please also see [CONTRIBUTING.md][contrib]. Acknowledgments =============== Magit was started by [Marius Vollmer][marius], and is now maintained by [Jonas Bernoulli][jonas], [Kyle Meyer][kyle], and [Noam Postavsky][noam]. Other former maintainers are [Nicolas Dudebout][nicolas], [Peter J. Weisberg][peter], [Phil Jackson][phil], [Rémi Vanicat][remi], and [Yann Hodique][yann]. Many more people have [contributed code][authors] and suggested features. Thanks to all of you, may (the history of) the source be with you! *** [![GPL v3](https://img.shields.io/badge/license-GPL_v3-green.svg)](http://www.gnu.org/licenses/gpl-3.0.txt) [![Build Status](https://travis-ci.org/magit/magit.svg?branch=master)](https://travis-ci.org/magit/magit) [![Melpa](https://melpa.org/packages/magit-badge.svg)](https://melpa.org/#/magit) [![Melpa Stable](https://stable.melpa.org/packages/magit-badge.svg)](https://stable.melpa.org/#/magit) [![Git Xkcd](https://img.shields.io/badge/xkcd-git-orange.svg)](https://xkcd.com/1597) [![Eierlegende Wollmilchsau](https://img.shields.io/badge/eierlegende-Wollmilchsau-green.svg)](https://magit.vc/manual/magit) [![Swiss Made](https://img.shields.io/badge/swiss-made-red.svg?colorA=E11A27&colorB=555555)](https://magit.vc/stats/authors.html#commits_per_author) [![Netscape](https://magit.vc/assets/netscape-20px.png)](https://en.wikipedia.org/wiki/Browser_wars) [![Paren Xkcb](https://img.shields.io/badge/%28-%20%20%20-red.svg)](https://xkcd.com/859) [contrib]: https://github.com/magit/magit/blob/master/.github/CONTRIBUTING.md [issues]: https://github.com/magit/magit/issues [pulls]: https://github.com/magit/magit/pulls [authors]: https://magit.vc/stats/authors.html [faq]: https://magit.vc/manual/magit/FAQ.html [manual]: https://magit.vc/manual [forum]: https://emacs.stackexchange.com/questions/tagged/magit [list]: https://groups.google.com/forum/?fromgroups#!forum/magit [jonas]: https://emacsair.me [kyle]: https://github.com/kyleam [marius]: https://github.com/mvollmer [nicolas]: http://dudebout.com [noam]: https://github.com/npostavs [peter]: https://github.com/pjweisberg [phil]: https://github.com/philjackson [remi]: https://github.com/vanicat [yann]: http://www.hodique.info magit-2.90.1/RelNotes.org000077700000000000000000000000001337354740400227612Documentation/RelNotes/2.90.1.orgustar00rootroot00000000000000magit-2.90.1/default.mk000066400000000000000000000137621337354740400147040ustar00rootroot00000000000000TOP := $(dir $(lastword $(MAKEFILE_LIST))) ## User options ###################################################### # # You can override these settings in "config.mk" or on the command # line. # # You might also want to set LOAD_PATH. If you do, then it must # contain "-L .". # # If you don't do so, then the default is set in the "Load-Path" # section below. The default assumes that all dependencies are # installed either at "../", or when using package.el # at "ELPA_DIR/-". PREFIX ?= /usr/local sharedir ?= $(PREFIX)/share lispdir ?= $(sharedir)/emacs/site-lisp/magit infodir ?= $(sharedir)/info docdir ?= $(sharedir)/doc/magit statsdir ?= $(TOP)/Documentation/stats CP ?= install -p -m 644 MKDIR ?= install -p -m 755 -d RMDIR ?= rm -rf TAR ?= tar SED ?= sed EMACSBIN ?= emacs BATCH = $(EMACSBIN) -Q --batch $(LOAD_PATH) INSTALL_INFO ?= $(shell command -v ginstall-info || printf install-info) MAKEINFO ?= makeinfo MANUAL_HTML_ARGS ?= --css-ref /assets/page.css ## Files ############################################################# PKG = magit PACKAGES = magit git-commit TEXIPAGES = $(addsuffix .texi,$(filter-out git-commit,$(PACKAGES))) INFOPAGES = $(addsuffix .info,$(filter-out git-commit,$(PACKAGES))) HTMLFILES = $(addsuffix .html,$(filter-out git-commit,$(PACKAGES))) HTMLDIRS = $(filter-out git-commit,$(PACKAGES)) PDFFILES = $(addsuffix .pdf,$(filter-out git-commit,$(PACKAGES))) EPUBFILES = $(addsuffix .epub,$(filter-out git-commit,$(PACKAGES))) ELS = git-commit.el ELS += magit-utils.el ELS += magit-section.el ELS += magit-git.el ELS += magit-mode.el ELS += magit-margin.el ELS += magit-process.el ELS += magit-autorevert.el ELS += magit-core.el ELS += magit-diff.el ELS += magit-log.el ELS += magit-wip.el ELS += magit-apply.el ELS += magit-repos.el ELS += magit.el ELS += magit-status.el ELS += magit-refs.el ELS += magit-files.el ELS += magit-collab.el ELS += magit-reset.el ELS += magit-branch.el ELS += magit-merge.el ELS += magit-tag.el ELS += magit-worktree.el ELS += magit-notes.el ELS += magit-obsolete.el ELS += magit-sequence.el ELS += magit-commit.el ELS += magit-remote.el ELS += magit-clone.el ELS += magit-fetch.el ELS += magit-pull.el ELS += magit-push.el ELS += magit-patch.el ELS += magit-bisect.el ELS += magit-stash.el ELS += magit-blame.el ELS += magit-submodule.el ELS += magit-subtree.el ELS += magit-ediff.el ELS += magit-gitignore.el ELS += magit-extras.el ELS += git-rebase.el ELS += magit-imenu.el ELS += magit-bookmark.el ELCS = $(ELS:.el=.elc) ELMS = magit.el $(filter-out $(addsuffix .el,$(PACKAGES)),$(ELS)) ELGS = magit-autoloads.el magit-version.el ## Versions ########################################################## VERSION ?= $(shell test -e $(TOP).git && git describe --tags --abbrev=0 | cut -c2-) ASYNC_VERSION = 1.9.3 DASH_VERSION = 2.14.1 GHUB_VERSION = 3.0.0 GIT_COMMIT_VERSION = 2.90.0 MAGIT_POPUP_VERSION = 2.12.4 WITH_EDITOR_VERSION = 2.8.0 ASYNC_MELPA_SNAPSHOT = 20180527 DASH_MELPA_SNAPSHOT = 20180910 GHUB_MELPA_SNAPSHOT = 20181107 GIT_COMMIT_MELPA_SNAPSHOT = 20181104 MAGIT_POPUP_MELPA_SNAPSHOT = 20181003 WITH_EDITOR_MELPA_SNAPSHOT = 20181103 EMACS_VERSION = 25.1 EMACSOLD := $(shell $(BATCH) --eval \ "(and (version< emacs-version \"$(EMACS_VERSION)\") (princ \"true\"))") ifeq "$(EMACSOLD)" "true" $(error At least version $(EMACS_VERSION) of Emacs is required) endif ## Load-Path ######################################################### ifndef LOAD_PATH ELPA_DIR ?= $(HOME)/.emacs.d/elpa DASH_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/dash-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(DASH_DIR)" "" DASH_DIR = $(TOP)../dash endif GHUB_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/ghub-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(GHUB_DIR)" "" GHUB_DIR = $(TOP)../ghub endif GRAPHQL_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/graphql-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(GRAPHQL_DIR)" "" GRAPHQL_DIR = $(TOP)../graphql endif MAGIT_POPUP_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/magit-popup-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(MAGIT_POPUP_DIR)" "" MAGIT_POPUP_DIR = $(TOP)../magit-popup endif TREEPY_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/treepy-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(TREEPY_DIR)" "" TREEPY_DIR = $(TOP)../treepy endif WITH_EDITOR_DIR ?= $(shell \ find -L $(ELPA_DIR) -maxdepth 1 -regex '.*/with-editor-[.0-9]*' 2> /dev/null | \ sort | tail -n 1) ifeq "$(WITH_EDITOR_DIR)" "" WITH_EDITOR_DIR = $(TOP)../with-editor endif SYSTYPE := $(shell $(EMACSBIN) -Q --batch --eval "(princ system-type)") ifeq ($(SYSTYPE), windows-nt) CYGPATH := $(shell cygpath --version 2>/dev/null) endif LOAD_PATH = -L $(TOP)/lisp # When making changes here, then don't forget to adjust Makefile, # .travis.yml, magit-emacs-Q-command and the "Installing from the # Git Repository" info node accordingly. ifdef CYGPATH LOAD_PATH += -L $(shell cygpath --mixed $(DASH_DIR)) LOAD_PATH += -L $(shell cygpath --mixed $(GHUB_DIR)) LOAD_PATH += -L $(shell cygpath --mixed $(GRAPHQL_DIR)) LOAD_PATH += -L $(shell cygpath --mixed $(MAGIT_POPUP_DIR)) LOAD_PATH += -L $(shell cygpath --mixed $(TREEPY_DIR)) LOAD_PATH += -L $(shell cygpath --mixed $(WITH_EDITOR_DIR)) else LOAD_PATH += -L $(DASH_DIR) LOAD_PATH += -L $(GHUB_DIR) LOAD_PATH += -L $(GRAPHQL_DIR) LOAD_PATH += -L $(MAGIT_POPUP_DIR) LOAD_PATH += -L $(TREEPY_DIR) LOAD_PATH += -L $(WITH_EDITOR_DIR) endif endif # ifndef LOAD_PATH ifndef ORG_LOAD_PATH ORG_LOAD_PATH = $(LOAD_PATH) ORG_LOAD_PATH += -L ../../org/lisp ORG_LOAD_PATH += -L ../../org/contrib/lisp ORG_LOAD_PATH += -L ../../ox-texinfo+ endif ## Publish ########################################################### PUBLISH_TARGETS ?= html html-dir pdf epub DOCBOOK_XSL ?= /usr/share/xml/docbook/stylesheet/docbook-xsl/epub/docbook.xsl EPUBTRASH = epub.xml META-INF OEBPS magit-2.90.1/lisp/000077500000000000000000000000001337354740400136655ustar00rootroot00000000000000magit-2.90.1/lisp/Makefile000066400000000000000000000106731337354740400153340ustar00rootroot00000000000000-include ../config.mk include ../default.mk ## ################################################################### .PHONY: magit-version.el install all: lisp ## Build order ####################################################### git-commit.elc: magit-utils.elc: magit-section.elc: magit-utils.elc magit-git.elc: magit-utils.elc magit-section.elc magit-mode.elc: magit-section.elc magit-git.elc magit-margin.elc: magit-section.elc magit-mode.elc magit-process.elc: magit-utils.elc magit-section.elc \ magit-git.elc magit-mode.elc magit-autorevert.elc: magit-git.elc magit-process.elc magit-core.elc: magit-margin.elc magit-utils.elc \ magit-section.elc magit-git.elc magit-mode.elc \ magit-process.elc magit-autorevert.elc magit-diff.elc: git-commit.elc magit-core.elc magit-log.elc: magit-core.elc magit-diff.elc magit-wip.elc: magit-core.elc magit-log.elc magit-apply.elc: magit-core.elc magit-diff.elc magit-wip.elc magit-repos.elc: magit-core.elc magit.elc: git-commit.elc magit-core.elc magit-diff.elc \ magit-log.elc magit-apply.elc magit-repos.elc magit-status.elc: magit.elc magit-refs.elc: magit.elc magit-files.elc: magit.elc magit-collab.elc: magit.elc magit-reset.elc: magit.elc magit-branch.elc: magit.elc magit-collab.elc magit-reset.elc magit-merge.elc: magit.elc magit-tag.elc: magit.elc magit-worktree.elc: magit.elc magit-notes.elc: magit.elc magit-sequence.elc: magit.elc magit-commit.elc: magit.elc magit-sequence.elc magit-remote.elc: magit.elc magit-clone.elc: magit.elc magit-fetch.elc: magit.elc magit-pull.elc: magit.elc magit-push.elc: magit.elc magit-patch.elc: magit.elc magit-bisect.elc: magit.elc magit-stash.elc: magit.elc magit-blame.elc: magit.elc magit-obsolete.elc: magit.elc magit-submodule.elc: magit.elc magit-subtree.elc: magit.elc magit-ediff.elc: magit.elc magit-gitignore.elc: magit.elc magit-extras.elc: magit.elc magit-merge.elc git-rebase.elc: magit.elc magit-imenu.elc: magit.elc git-rebase.elc magit-bookmark.elc: magit.elc magit-obsolete.elc: magit.elc ## Build ############################################################# lisp: $(ELCS) loaddefs loaddefs: $(PKG)-autoloads.el versionlib: $(PKG)-version.el %.elc: %.el @printf "Compiling $<\n" @$(BATCH) --eval "(progn\ (when (file-exists-p \"$@\")\ (delete-file \"$@\"))\ (setq with-editor-emacsclient-executable nil)\ $$suppress_warnings)" \ -f batch-byte-compile $< $(PKG)-autoloads.el: $(ELS) @printf "Generating $@\n" @printf "%s" "$$LOADDEFS_TMPL" > $@ @$(BATCH) --eval "(progn\ (fset 'message (lambda (&rest _)))\ (setq make-backup-files nil)\ (setq vc-handled-backends nil)\ (setq default-directory (file-truename default-directory))\ (setq generated-autoload-file (expand-file-name \"$@\"))\ (setq find-file-visit-truename t)\ (update-directory-autoloads default-directory))" $(PKG)-version.el: @printf "Generating $@\n" @printf "%s" "$$VERSIONLIB_TMPL" > $@ ## Install ########################################################### install: lisp versionlib @$(MKDIR) $(DESTDIR)$(lispdir) $(CP) $(ELS) magit-autoloads.el magit-version.el $(ELCS) $(DESTDIR)$(lispdir) ## Clean ############################################################# clean: @printf "Cleaning lisp/*...\n" @$(RM) *.elc $(ELGS) ## Templates ######################################################### define LOADDEFS_TMPL ;;; $(PKG)-autoloads.el --- automatically extracted autoloads ;; ;;; Code: (add-to-list 'load-path (directory-file-name \ (or (file-name-directory #$$) (car load-path)))) ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t ;; End: ;;; $(PKG)-autoloads.el ends here endef export LOADDEFS_TMPL #' define VERSIONLIB_TMPL ;;; $(PKG)-version.el --- the Magit version you are using (setq $(PKG)-version "$(VERSION)") (provide '$(PKG)-version) ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t ;; coding: utf-8 ;; End: ;;; $(PKG)-version.el ends here endef export VERSIONLIB_TMPL #' define suppress_warnings (fset 'original-message (symbol-function 'message)) (fset 'message ;' (lambda (f &rest a) (unless (or (equal f "Wrote %s") (equal f "pcase-memoize: equal first branch, yet different") (and (equal f "Warning: Unknown defun property `%S' in %S") (memq (car a) '(pure side-effect-free interactive-only)))) (apply 'original-message f a)))) endef export suppress_warnings magit-2.90.1/lisp/git-commit.el000066400000000000000000001104761337354740400162710ustar00rootroot00000000000000;;; git-commit.el --- Edit Git commit messages -*- lexical-binding: t; -*- ;; Copyright (C) 2010-2018 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. ;; Authors: Jonas Bernoulli ;; Sebastian Wiesner ;; Florian Ragwitz ;; Marius Vollmer ;; Maintainer: Jonas Bernoulli ;; Package-Requires: ((emacs "25.1") (dash "2.14.1") (with-editor "2.8.0")) ;; Keywords: git tools vc ;; Homepage: https://github.com/magit/magit ;; 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 . ;;; Commentary: ;; This package assists the user in writing good Git commit messages. ;; While Git allows for the message to be provided on the command ;; line, it is preferable to tell Git to create the commit without ;; actually passing it a message. Git then invokes the `$GIT_EDITOR' ;; (or if that is undefined `$EDITOR') asking the user to provide the ;; message by editing the file ".git/COMMIT_EDITMSG" (or another file ;; in that directory, e.g. ".git/MERGE_MSG" for merge commits). ;; When `global-git-commit-mode' is enabled, which it is by default, ;; then opening such a file causes the features described below, to ;; be enabled in that buffer. Normally this would be done using a ;; major-mode but to allow the use of any major-mode, as the user sees ;; fit, it is done here by running a setup function, which among other ;; things turns on the preferred major-mode, by default `text-mode'. ;; Git waits for the `$EDITOR' to finish and then either creates the ;; commit using the contents of the file as commit message, or, if the ;; editor process exited with a non-zero exit status, aborts without ;; creating a commit. Unfortunately Emacsclient (which is what Emacs ;; users should be using as `$EDITOR' or at least as `$GIT_EDITOR') ;; does not differentiate between "successfully" editing a file and ;; aborting; not out of the box that is. ;; By making use of the `with-editor' package this package provides ;; both ways of finish an editing session. In either case the file ;; is saved, but Emacseditor's exit code differs. ;; ;; C-c C-c Finish the editing session successfully by returning ;; with exit code 0. Git then creates the commit using ;; the message it finds in the file. ;; ;; C-c C-k Aborts the edit editing session by returning with exit ;; code 1. Git then aborts the commit. ;; Aborting the commit does not cause the message to be lost, but ;; relying solely on the file not being tampered with is risky. This ;; package additionally stores all aborted messages for the duration ;; of the current session (i.e. until you close Emacs). To get back ;; an aborted message use M-p and M-n while editing a message. ;; ;; M-p Replace the buffer contents with the previous message ;; from the message ring. Of course only after storing ;; the current content there too. ;; ;; M-n Replace the buffer contents with the next message from ;; the message ring, after storing the current content. ;; Some support for pseudo headers as used in some projects is ;; provided by these commands: ;; ;; C-c C-s Insert a Signed-off-by header. ;; C-c C-a Insert a Acked-by header. ;; C-c C-m Insert a Modified-by header. ;; C-c C-t Insert a Tested-by header. ;; C-c C-r Insert a Reviewed-by header. ;; C-c C-o Insert a Cc header. ;; C-c C-p Insert a Reported-by header. ;; C-c M-s Insert a Suggested-by header. ;; When Git requests a commit message from the user, it does so by ;; having her edit a file which initially contains some comments, ;; instructing her what to do, and providing useful information, such ;; as which files were modified. These comments, even when left ;; intact by the user, do not become part of the commit message. This ;; package ensures these comments are propertizes as such and further ;; prettifies them by using different faces for various parts, such as ;; files. ;; Finally this package highlights style errors, like lines that are ;; too long, or when the second line is not empty. It may even nag ;; you when you attempt to finish the commit without having fixed ;; these issues. The style checks and many other settings can easily ;; be configured: ;; ;; M-x customize-group RET git-commit RET ;;; Code: ;;;; Dependencies (require 'dash) (require 'log-edit) (require 'magit-git nil t) (require 'magit-utils nil t) (require 'ring) (require 'server) (require 'with-editor) (eval-when-compile (require 'recentf)) ;;;; Declarations (defvar diff-default-read-only) (defvar flyspell-generic-check-word-predicate) (defvar font-lock-beg) (defvar font-lock-end) (declare-function magit-expand-git-file-name "magit-git" (filename)) (declare-function magit-list-local-branch-names "magit-git" ()) (declare-function magit-list-remote-branch-names "magit-git" (&optional remote relative)) ;;; Options ;;;; Variables (defgroup git-commit nil "Edit Git commit messages." :prefix "git-commit-" :link '(info-link "(magit)Editing Commit Messages") :group 'tools) ;;;###autoload (define-minor-mode global-git-commit-mode "Edit Git commit messages. This global mode arranges for `git-commit-setup' to be called when a Git commit message file is opened. That usually happens when Git uses the Emacsclient as $GIT_EDITOR to have the user provide such a commit message." :group 'git-commit :type 'boolean :global t :init-value t :initialize (lambda (symbol exp) (custom-initialize-default symbol exp) (when global-git-commit-mode (add-hook 'find-file-hook 'git-commit-setup-check-buffer))) (if global-git-commit-mode (add-hook 'find-file-hook 'git-commit-setup-check-buffer) (remove-hook 'find-file-hook 'git-commit-setup-check-buffer))) (defcustom git-commit-major-mode 'text-mode "Major mode used to edit Git commit messages. The major mode configured here is turned on by the minor mode `git-commit-mode'." :group 'git-commit :type '(choice (function-item text-mode) (const :tag "No major mode"))) (defcustom git-commit-setup-hook '(git-commit-save-message git-commit-setup-changelog-support git-commit-turn-on-auto-fill git-commit-propertize-diff bug-reference-mode with-editor-usage-message) "Hook run at the end of `git-commit-setup'." :group 'git-commit :type 'hook :get (and (featurep 'magit-utils) 'magit-hook-custom-get) :options '(git-commit-save-message git-commit-setup-changelog-support git-commit-turn-on-auto-fill git-commit-turn-on-flyspell git-commit-propertize-diff bug-reference-mode with-editor-usage-message)) (defcustom git-commit-post-finish-hook nil "Hook run after the user finished writing a commit message. \\\ This hook is only run after pressing \\[with-editor-finish] in a buffer used to edit a commit message. If a commit is created without the user typing a message into a buffer, then this hook is not run. This hook is not run until the new commit has been created. If doing so takes Git longer than one second, then this hook isn't run at all. For certain commands such as `magit-rebase-continue' this hook is never run because doing so would lead to a race condition. Also see `magit-post-commit-hook'." :group 'git-commit :type 'hook :get (and (featurep 'magit-utils) 'magit-hook-custom-get)) (defcustom git-commit-finish-query-functions '(git-commit-check-style-conventions) "List of functions called to query before performing commit. The commit message buffer is current while the functions are called. If any of them returns nil, then the commit is not performed and the buffer is not killed. The user should then fix the issue and try again. The functions are called with one argument. If it is non-nil, then that indicates that the user used a prefix argument to force finishing the session despite issues. Functions should usually honor this wish and return non-nil." :options '(git-commit-check-style-conventions) :type 'hook :group 'git-commit) (defcustom git-commit-style-convention-checks '(non-empty-second-line) "List of checks performed by `git-commit-check-style-conventions'. Valid members are `non-empty-second-line' and `overlong-summary-line'. That function is a member of `git-commit-finish-query-functions'." :options '(non-empty-second-line overlong-summary-line) :type '(list :convert-widget custom-hook-convert-widget) :group 'git-commit) (defcustom git-commit-summary-max-length 68 "Column beyond which characters in the summary lines are highlighted. The highlighting indicates that the summary is getting too long by some standards. It does in no way imply that going over the limit a few characters or in some cases even many characters is anything that deserves shaming. It's just a friendly reminder that if you can make the summary shorter, then you might want to consider doing so." :group 'git-commit :safe 'numberp :type 'number) (defcustom git-commit-fill-column nil "Override `fill-column' in commit message buffers. If this is non-nil, then it should be an integer. If that is the case and the buffer-local value of `fill-column' is not already set by the time `git-commit-turn-on-auto-fill' is called as a member of `git-commit-setup-hook', then that function sets the buffer-local value of `fill-column' to the value of this option. This option exists mostly for historic reasons. If you are not already using it, then you probably shouldn't start doing so." :group 'git-commit :safe 'numberp :type '(choice (const :tag "use regular fill-column") number)) (make-obsolete-variable 'git-commit-fill-column 'fill-column "Magit 2.11.0" 'set) (defcustom git-commit-known-pseudo-headers '("Signed-off-by" "Acked-by" "Modified-by" "Cc" "Suggested-by" "Reported-by" "Tested-by" "Reviewed-by") "A list of Git pseudo headers to be highlighted." :group 'git-commit :safe (lambda (val) (and (listp val) (-all-p 'stringp val))) :type '(repeat string)) ;;;; Faces (defgroup git-commit-faces nil "Faces used for highlighting Git commit messages." :prefix "git-commit-" :group 'git-commit :group 'faces) (defface git-commit-summary '((t :inherit font-lock-type-face)) "Face used for the summary in commit messages." :group 'git-commit-faces) (defface git-commit-overlong-summary '((t :inherit font-lock-warning-face)) "Face used for the tail of overlong commit message summaries." :group 'git-commit-faces) (defface git-commit-nonempty-second-line '((t :inherit font-lock-warning-face)) "Face used for non-whitespace on the second line of commit messages." :group 'git-commit-faces) (defface git-commit-note '((t :inherit font-lock-string-face)) "Face used for notes in commit messages." :group 'git-commit-faces) (defface git-commit-pseudo-header '((t :inherit font-lock-string-face)) "Face used for pseudo headers in commit messages." :group 'git-commit-faces) (defface git-commit-known-pseudo-header '((t :inherit font-lock-keyword-face)) "Face used for the keywords of known pseudo headers in commit messages." :group 'git-commit-faces) (defface git-commit-comment-branch-local (if (featurep 'magit) '((t :inherit magit-branch-local)) '((t :inherit font-lock-variable-name-face))) "Face used for names of local branches in commit message comments." :group 'git-commit-faces) (define-obsolete-face-alias 'git-commit-comment-branch 'git-commit-comment-branch-local "Git-Commit 2.12.0") (defface git-commit-comment-branch-remote (if (featurep 'magit) '((t :inherit magit-branch-remote)) '((t :inherit font-lock-variable-name-face))) "Face used for names of remote branches in commit message comments. This is only used if Magit is available." :group 'git-commit-faces) (defface git-commit-comment-detached '((t :inherit git-commit-comment-branch-local)) "Face used for detached `HEAD' in commit message comments." :group 'git-commit-faces) (defface git-commit-comment-heading '((t :inherit git-commit-known-pseudo-header)) "Face used for headings in commit message comments." :group 'git-commit-faces) (defface git-commit-comment-file '((t :inherit git-commit-pseudo-header)) "Face used for file names in commit message comments." :group 'git-commit-faces) (defface git-commit-comment-action '((t :inherit bold)) "Face used for actions in commit message comments." :group 'git-commit-faces) ;;; Keymap (defvar git-commit-mode-map (let ((map (make-sparse-keymap))) (cond ((featurep 'jkl) (define-key map (kbd "C-M-i") 'git-commit-prev-message) (define-key map (kbd "C-M-k") 'git-commit-next-message)) (t (define-key map (kbd "M-p") 'git-commit-prev-message) (define-key map (kbd "M-n") 'git-commit-next-message) ;; Old bindings to avoid confusion (define-key map (kbd "C-c C-x a") 'git-commit-ack) (define-key map (kbd "C-c C-x i") 'git-commit-suggested) (define-key map (kbd "C-c C-x m") 'git-commit-modified) (define-key map (kbd "C-c C-x o") 'git-commit-cc) (define-key map (kbd "C-c C-x p") 'git-commit-reported) (define-key map (kbd "C-c C-x r") 'git-commit-review) (define-key map (kbd "C-c C-x s") 'git-commit-signoff) (define-key map (kbd "C-c C-x t") 'git-commit-test))) (define-key map (kbd "C-c C-a") 'git-commit-ack) (define-key map (kbd "C-c C-i") 'git-commit-suggested) (define-key map (kbd "C-c C-m") 'git-commit-modified) (define-key map (kbd "C-c C-o") 'git-commit-cc) (define-key map (kbd "C-c C-p") 'git-commit-reported) (define-key map (kbd "C-c C-r") 'git-commit-review) (define-key map (kbd "C-c C-s") 'git-commit-signoff) (define-key map (kbd "C-c C-t") 'git-commit-test) (define-key map (kbd "C-c M-s") 'git-commit-save-message) map) "Key map used by `git-commit-mode'.") ;;; Menu (require 'easymenu) (easy-menu-define git-commit-mode-menu git-commit-mode-map "Git Commit Mode Menu" '("Commit" ["Previous" git-commit-prev-message t] ["Next" git-commit-next-message t] "-" ["Ack" git-commit-ack :active t :help "Insert an 'Acked-by' header"] ["Sign-Off" git-commit-signoff :active t :help "Insert a 'Signed-off-by' header"] ["Modified-by" git-commit-modified :active t :help "Insert a 'Modified-by' header"] ["Tested-by" git-commit-test :active t :help "Insert a 'Tested-by' header"] ["Reviewed-by" git-commit-review :active t :help "Insert a 'Reviewed-by' header"] ["CC" git-commit-cc t :help "Insert a 'Cc' header"] ["Reported" git-commit-reported :active t :help "Insert a 'Reported-by' header"] ["Suggested" git-commit-suggested t :help "Insert a 'Suggested-by' header"] "-" ["Save" git-commit-save-message t] ["Cancel" with-editor-cancel t] ["Commit" with-editor-finish t])) ;;; Hooks ;;;###autoload (defconst git-commit-filename-regexp "/\\(\ \\(\\(COMMIT\\|NOTES\\|PULLREQ\\|TAG\\)_EDIT\\|MERGE_\\|\\)MSG\ \\|\\(BRANCH\\|EDIT\\)_DESCRIPTION\\)\\'") (eval-after-load 'recentf '(add-to-list 'recentf-exclude git-commit-filename-regexp)) (add-to-list 'with-editor-file-name-history-exclude git-commit-filename-regexp) (defun git-commit-setup-font-lock-in-buffer () (and buffer-file-name (string-match-p git-commit-filename-regexp buffer-file-name) (git-commit-setup-font-lock))) (add-hook 'after-change-major-mode-hook 'git-commit-setup-font-lock-in-buffer) ;;;###autoload (defun git-commit-setup-check-buffer () (and buffer-file-name (string-match-p git-commit-filename-regexp buffer-file-name) (git-commit-setup))) (defvar git-commit-mode) (defun git-commit-file-not-found () ;; cygwin git will pass a cygwin path (/cygdrive/c/foo/.git/...), ;; try to handle this in window-nt Emacs. (--when-let (and (or (string-match-p git-commit-filename-regexp buffer-file-name) (and (boundp 'git-rebase-filename-regexp) (string-match-p git-rebase-filename-regexp buffer-file-name))) (not (file-accessible-directory-p (file-name-directory buffer-file-name))) (if (require 'magit-git nil t) ;; Emacs prepends a "c:". (magit-expand-git-file-name (substring buffer-file-name 2)) ;; Fallback if we can't load `magit-git'. (and (string-match "\\`[a-z]:/\\(cygdrive/\\)?\\([a-z]\\)/\\(.*\\)" buffer-file-name) (concat (match-string 2 buffer-file-name) ":/" (match-string 3 buffer-file-name))))) (when (file-accessible-directory-p (file-name-directory it)) (let ((inhibit-read-only t)) (insert-file-contents it t) t)))) (when (eq system-type 'windows-nt) (add-hook 'find-file-not-found-functions #'git-commit-file-not-found)) ;;;###autoload (defun git-commit-setup () ;; Pretend that git-commit-mode is a major-mode, ;; so that directory-local settings can be used. (let ((default-directory (if (or (file-exists-p ".dir-locals.el") (not (fboundp 'magit-toplevel))) default-directory ;; When $GIT_DIR/.dir-locals.el doesn't exist, ;; fallback to $GIT_WORK_TREE/.dir-locals.el, ;; because the maintainer can use the latter ;; to enforce conventions, while s/he has no ;; control over the former. (and (fboundp 'magit-toplevel) ; silence byte-compiler (magit-toplevel))))) (let ((buffer-file-name nil) ; trick hack-dir-local-variables (major-mode 'git-commit-mode)) ; trick dir-locals-collect-variables (hack-dir-local-variables) (hack-local-variables-apply))) (when git-commit-major-mode (let ((auto-mode-alist (list (cons (concat "\\`" (regexp-quote buffer-file-name) "\\'") git-commit-major-mode))) ;; The major-mode hook might want to consult these minor ;; modes, while the minor-mode hooks might want to consider ;; the major mode. (git-commit-mode t) (with-editor-mode t)) (normal-mode t))) (setq with-editor-show-usage nil) (unless with-editor-mode ;; Maybe already enabled when using `shell-command' or an Emacs shell. (with-editor-mode 1)) (add-hook 'with-editor-finish-query-functions 'git-commit-finish-query-functions nil t) (add-hook 'with-editor-pre-finish-hook 'git-commit-save-message nil t) (add-hook 'with-editor-pre-cancel-hook 'git-commit-save-message nil t) (when (and (fboundp 'magit-rev-parse) (not (memq last-command '(magit-sequencer-continue magit-sequencer-skip magit-am-continue magit-am-skip magit-rebase-continue magit-rebase-skip)))) (add-hook 'with-editor-post-finish-hook (apply-partially 'git-commit-run-post-finish-hook (magit-rev-parse "HEAD")) nil t) (when (fboundp 'magit-wip-maybe-add-commit-hook) (magit-wip-maybe-add-commit-hook))) (setq with-editor-cancel-message 'git-commit-cancel-message) (make-local-variable 'log-edit-comment-ring-index) (git-commit-mode 1) (git-commit-setup-font-lock) (when (boundp 'save-place) (setq save-place nil)) (save-excursion (goto-char (point-min)) (when (looking-at "\\`\\(\\'\\|\n[^\n]\\)") (open-line 1))) (run-hooks 'git-commit-setup-hook) (set-buffer-modified-p nil)) (defun git-commit-run-post-finish-hook (previous) (when git-commit-post-finish-hook (cl-block nil (let ((break (time-add (current-time) (seconds-to-time 1)))) (while (equal (magit-rev-parse "HEAD") previous) (if (time-less-p (current-time) break) (sit-for 0.01) (message "No commit created after 1 second. Not running %s." 'git-commit-post-finish-hook) (cl-return)))) (run-hooks 'git-commit-post-finish-hook)))) (define-minor-mode git-commit-mode "Auxiliary minor mode used when editing Git commit messages. This mode is only responsible for setting up some key bindings. Don't use it directly, instead enable `global-git-commit-mode'." :lighter "") (put 'git-commit-mode 'permanent-local t) (defun git-commit-setup-changelog-support () "Treat ChangeLog entries as paragraphs." (setq-local paragraph-start (concat paragraph-start "\\|\\*\\|("))) (defun git-commit-turn-on-auto-fill () "Unconditionally turn on Auto Fill mode. If `git-commit-fill-column' is non-nil, and `fill-column' doesn't already have a buffer-local value, then set that to `git-commit-fill-column'." (when (and (numberp git-commit-fill-column) (not (local-variable-p 'fill-column))) (setq fill-column git-commit-fill-column)) (setq-local comment-auto-fill-only-comments nil) (turn-on-auto-fill)) (defun git-commit-turn-on-flyspell () "Unconditionally turn on Flyspell mode. Also prevent comments from being checked and finally check current non-comment text." (require 'flyspell) (turn-on-flyspell) (setq flyspell-generic-check-word-predicate 'git-commit-flyspell-verify) (let ((end) (comment-start-regex (format "^\\(%s\\|$\\)" comment-start))) (save-excursion (goto-char (point-max)) (while (and (not (bobp)) (looking-at comment-start-regex)) (forward-line -1)) (unless (looking-at comment-start-regex) (forward-line)) (setq end (point))) (flyspell-region (point-min) end))) (defun git-commit-flyspell-verify () (not (= (char-after (line-beginning-position)) (aref comment-start 0)))) (defun git-commit-finish-query-functions (force) (run-hook-with-args-until-failure 'git-commit-finish-query-functions force)) (defun git-commit-check-style-conventions (force) "Check for violations of certain basic style conventions. For each violation ask the user if she wants to proceed anyway. Option `git-commit-check-style-conventions' controls which conventions are checked." (or force (save-excursion (goto-char (point-min)) (re-search-forward (git-commit-summary-regexp) nil t) (if (equal (match-string 1) "") t ; Just try; we don't know whether --allow-empty-message was used. (and (or (not (memq 'overlong-summary-line git-commit-style-convention-checks)) (equal (match-string 2) "") (y-or-n-p "Summary line is too long. Commit anyway? ")) (or (not (memq 'non-empty-second-line git-commit-style-convention-checks)) (not (match-string 3)) (y-or-n-p "Second line is not empty. Commit anyway? "))))))) (defun git-commit-cancel-message () (message (concat "Commit canceled" (and (memq 'git-commit-save-message with-editor-pre-cancel-hook) ". Message saved to `log-edit-comment-ring'")))) ;;; History (defun git-commit-prev-message (arg) "Cycle backward through message history, after saving current message. With a numeric prefix ARG, go back ARG comments." (interactive "*p") (when (and (git-commit-save-message) (> arg 0)) (setq log-edit-comment-ring-index (log-edit-new-comment-index arg (ring-length log-edit-comment-ring)))) (save-restriction (goto-char (point-min)) (narrow-to-region (point) (if (re-search-forward (concat "^" comment-start) nil t) (max 1 (- (point) 2)) (point-max))) (log-edit-previous-comment arg))) (defun git-commit-next-message (arg) "Cycle forward through message history, after saving current message. With a numeric prefix ARG, go forward ARG comments." (interactive "*p") (git-commit-prev-message (- arg))) (defun git-commit-save-message () "Save current message to `log-edit-comment-ring'." (interactive) (--when-let (git-commit-buffer-message) (unless (ring-member log-edit-comment-ring it) (ring-insert log-edit-comment-ring it)))) (defun git-commit-buffer-message () (let ((flush (concat "^" comment-start)) (str (buffer-substring-no-properties (point-min) (point-max)))) (with-temp-buffer (insert str) (goto-char (point-min)) (when (re-search-forward (concat flush " -+ >8 -+$") nil t) (delete-region (point-at-bol) (point-max))) (goto-char (point-min)) (flush-lines flush) (goto-char (point-max)) (unless (eq (char-before) ?\n) (insert ?\n)) (setq str (buffer-string))) (unless (string-match "\\`[ \t\n\r]*\\'" str) (when (string-match "\\`\n\\{2,\\}" str) (setq str (replace-match "\n" t t str))) (when (string-match "\n\\{2,\\}\\'" str) (setq str (replace-match "\n" t t str))) str))) ;;; Headers (defun git-commit-ack (name mail) "Insert a header acknowledging that you have looked at the commit." (interactive (git-commit-self-ident)) (git-commit-insert-header "Acked-by" name mail)) (defun git-commit-modified (name mail) "Insert a header to signal that you have modified the commit." (interactive (git-commit-self-ident)) (git-commit-insert-header "Modified-by" name mail)) (defun git-commit-review (name mail) "Insert a header acknowledging that you have reviewed the commit." (interactive (git-commit-self-ident)) (git-commit-insert-header "Reviewed-by" name mail)) (defun git-commit-signoff (name mail) "Insert a header to sign off the commit." (interactive (git-commit-self-ident)) (git-commit-insert-header "Signed-off-by" name mail)) (defun git-commit-test (name mail) "Insert a header acknowledging that you have tested the commit." (interactive (git-commit-self-ident)) (git-commit-insert-header "Tested-by" name mail)) (defun git-commit-cc (name mail) "Insert a header mentioning someone who might be interested." (interactive (git-commit-read-ident)) (git-commit-insert-header "Cc" name mail)) (defun git-commit-reported (name mail) "Insert a header mentioning the person who reported the issue." (interactive (git-commit-read-ident)) (git-commit-insert-header "Reported-by" name mail)) (defun git-commit-suggested (name mail) "Insert a header mentioning the person who suggested the change." (interactive (git-commit-read-ident)) (git-commit-insert-header "Suggested-by" name mail)) (defun git-commit-self-ident () (list (or (getenv "GIT_AUTHOR_NAME") (getenv "GIT_COMMITTER_NAME") (ignore-errors (car (process-lines "git" "config" "user.name"))) user-full-name (read-string "Name: ")) (or (getenv "GIT_AUTHOR_EMAIL") (getenv "GIT_COMMITTER_EMAIL") (getenv "EMAIL") (ignore-errors (car (process-lines "git" "config" "user.email"))) (read-string "Email: ")))) (defun git-commit-read-ident () (list (read-string "Name: ") (read-string "Email: "))) (defun git-commit-insert-header (header name email) (setq header (format "%s: %s <%s>" header name email)) (save-excursion (goto-char (point-max)) (cond ((re-search-backward "^[-a-zA-Z]+: [^<]+? <[^>]+>" nil t) (end-of-line) (insert ?\n header) (unless (= (char-after) ?\n) (insert ?\n))) (t (while (re-search-backward (concat "^" comment-start) nil t)) (unless (looking-back "\n\n" nil) (insert ?\n)) (insert header ?\n))) (unless (or (eobp) (= (char-after) ?\n)) (insert ?\n)))) ;;; Font-Lock (defun git-commit-summary-regexp () (concat ;; Leading empty lines and comments (format "\\`\\(?:^\\(?:\\s-*\\|%s.*\\)\n\\)*" comment-start) ;; Summary line (format "\\(.\\{0,%d\\}\\)\\(.*\\)" git-commit-summary-max-length) ;; Non-empty non-comment second line (format "\\(?:\n%s\\|\n\\(.+\\)\\)?" comment-start))) (defun git-commit-extend-region-summary-line () "Identify the multiline summary-regexp construct. Added to `font-lock-extend-region-functions'." (save-excursion (save-match-data (goto-char (point-min)) (when (looking-at (git-commit-summary-regexp)) (let ((summary-beg (match-beginning 0)) (summary-end (match-end 0))) (when (or (< summary-beg font-lock-beg summary-end) (< summary-beg font-lock-end summary-end)) (setq font-lock-beg (min font-lock-beg summary-beg)) (setq font-lock-end (max font-lock-end summary-end)))))))) (defvar-local git-commit--branch-name-regexp nil) (defconst git-commit-comment-headings '("Changes to be committed:" "Untracked files:" "Changed but not updated:" "Changes not staged for commit:" "Unmerged paths:" "Author:" "Date:")) (defconst git-commit-font-lock-keywords-1 '(;; Pseudo headers (eval . `(,(format "^\\(%s:\\)\\( .*\\)" (regexp-opt git-commit-known-pseudo-headers)) (1 'git-commit-known-pseudo-header) (2 'git-commit-pseudo-header))) ("^[-a-zA-Z]+: [^<]+? <[^>]+>" (0 'git-commit-pseudo-header)) ;; Summary (eval . `(,(git-commit-summary-regexp) (1 'git-commit-summary))) ;; - Note (overrides summary) ("\\[.+?\\]" (0 'git-commit-note t)) ;; - Non-empty second line (overrides summary and note) (eval . `(,(git-commit-summary-regexp) (2 'git-commit-overlong-summary t t) (3 'git-commit-nonempty-second-line t t))))) (defconst git-commit-font-lock-keywords-2 `(,@git-commit-font-lock-keywords-1 ;; Comments (eval . `(,(format "^%s.*" comment-start) (0 'font-lock-comment-face))) (eval . `(,(format "^%s On branch \\(.*\\)" comment-start) (1 'git-commit-comment-branch-local t))) (eval . `(,(format "^%s \\(HEAD\\) detached at" comment-start) (1 'git-commit-comment-detached t))) (eval . `(,(format "^%s %s" comment-start (regexp-opt git-commit-comment-headings t)) (1 'git-commit-comment-heading t))) (eval . `(,(format "^%s\t\\(?:\\([^:\n]+\\):\\s-+\\)?\\(.*\\)" comment-start) (1 'git-commit-comment-action t t) (2 'git-commit-comment-file t))))) (defconst git-commit-font-lock-keywords-3 `(,@git-commit-font-lock-keywords-2 ;; More comments (eval ;; Your branch is ahead of 'master' by 3 commits. ;; Your branch is behind 'master' by 2 commits, and can be fast-forwarded. . `(,(format "^%s Your branch is \\(?:ahead\\|behind\\) of '%s' by \\([0-9]*\\)" comment-start git-commit--branch-name-regexp) (1 'git-commit-comment-branch-local t) (2 'git-commit-comment-branch-remote t) (3 'bold t))) (eval ;; Your branch is up to date with 'master'. ;; Your branch and 'master' have diverged, . `(,(format "^%s Your branch \\(?:is up-to-date with\\|and\\) '%s'" comment-start git-commit--branch-name-regexp) (1 'git-commit-comment-branch-local t) (2 'git-commit-comment-branch-remote t))) (eval ;; and have 1 and 2 different commits each, respectively. . `(,(format "^%s and have \\([0-9]*\\) and \\([0-9]*\\) commits each" comment-start) (1 'bold t) (2 'bold t))))) (defvar git-commit-font-lock-keywords git-commit-font-lock-keywords-2 "Font-Lock keywords for Git-Commit mode.") (defun git-commit-setup-font-lock () (let ((table (make-syntax-table (syntax-table)))) (when comment-start (modify-syntax-entry (string-to-char comment-start) "." table)) (modify-syntax-entry ?# "." table) (modify-syntax-entry ?\" "." table) (modify-syntax-entry ?\' "." table) (modify-syntax-entry ?` "." table) (set-syntax-table table)) (setq-local comment-start (or (ignore-errors (car (process-lines "git" "config" "core.commentchar"))) "#")) (setq-local comment-start-skip (format "^%s+[\s\t]*" comment-start)) (setq-local comment-end-skip "\n") (setq-local comment-use-syntax nil) (setq-local git-commit--branch-name-regexp (if (and (featurep 'magit-git) ;; When using cygwin git, we may end up in a ;; non-existing directory, which would cause ;; any git calls to signal an error. (file-accessible-directory-p default-directory)) (progn ;; Make sure the below functions are available. (require 'magit) ;; Font-Lock wants every submatch to succeed, ;; so also match the empty string. Do not use ;; `regexp-quote' because that is slow if there ;; are thousands of branches outweighing the ;; benefit of an efficient regep. (format "\\(\\(?:%s\\)\\|\\)\\(\\(?:%s\\)\\|\\)" (mapconcat #'identity (magit-list-local-branch-names) "\\|") (mapconcat #'identity (magit-list-remote-branch-names) "\\|"))) "\\([^']*\\)")) (setq-local font-lock-multiline t) (add-hook 'font-lock-extend-region-functions #'git-commit-extend-region-summary-line t t) (font-lock-add-keywords nil git-commit-font-lock-keywords t)) (defun git-commit-propertize-diff () (require 'diff-mode) (save-excursion (goto-char (point-min)) (when (re-search-forward "^diff --git" nil t) (beginning-of-line) (let ((buffer (current-buffer))) (insert (with-temp-buffer (insert (with-current-buffer buffer (prog1 (buffer-substring-no-properties (point) (point-max)) (delete-region (point) (point-max))))) (let ((diff-default-read-only nil)) (diff-mode)) (let (font-lock-verbose font-lock-support-mode) (if (fboundp 'font-lock-ensure) (font-lock-ensure) (with-no-warnings (font-lock-fontify-buffer)))) (let (next (pos (point-min))) (while (setq next (next-single-property-change pos 'face)) (put-text-property pos next 'font-lock-face (get-text-property pos 'face)) (setq pos next)) (put-text-property pos (point-max) 'font-lock-face (get-text-property pos 'face))) (buffer-string))))))) ;;; Elisp Text Mode (define-derived-mode git-commit-elisp-text-mode text-mode "ElText" "Major mode for editing commit messages of elisp projects. This is intended for use as `git-commit-major-mode' for projects that expect `symbols' to look like this. I.e. like they look in Elisp doc-strings, including this one. Unlike in doc-strings, \"strings\" also look different than the other text." (setq font-lock-defaults '(git-commit-elisp-text-mode-keywords))) (defvar git-commit-elisp-text-mode-keywords `((,(concat "[`‘]\\(\\(?:\\sw\\|\\s_\\|\\\\.\\)" lisp-mode-symbol-regexp "\\)['’]") (1 font-lock-constant-face prepend)) ("\"[^\"]*\"" (0 font-lock-string-face prepend)))) ;;; _ (provide 'git-commit) ;;; git-commit.el ends here magit-2.90.1/lisp/git-rebase.el000066400000000000000000000541421337354740400162370ustar00rootroot00000000000000;;; git-rebase.el --- Edit Git rebase files -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 . ;;; 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. ;; 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. ;; 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) (memq 'magit (bound-and-true-p async-bytecomp-allowed-packages)) (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-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 action and exec 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 "e") 'git-rebase-edit) (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 "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-line nil) (defvar-local git-rebase-comment-re nil) (defun git-rebase-set-action (action) (goto-char (line-beginning-position)) (if (and (looking-at git-rebase-line) (not (string-match-p "\\(e\\|exec\\|noop\\)$" (match-string 1)))) (let ((inhibit-read-only t)) (replace-match action t t nil 1) (when git-rebase-auto-advance (forward-line))) (ding))) (defun git-rebase-line-p (&optional pos) (save-excursion (when pos (goto-char pos)) (goto-char (line-beginning-position)) (looking-at-p git-rebase-line))) (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+ (save-excursion (goto-char (point-min)) (while (re-search-forward git-rebase-line nil t)) (point)))) (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)) (when (and (looking-at git-rebase-line) (not (eq (char-after) (string-to-char comment-start)))) (let ((inhibit-read-only t)) (insert comment-start) (insert " ")) (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-exec (arg) "Insert a shell command to be run after the proceeding 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") (let ((inhibit-read-only t) initial command) (unless arg (goto-char (line-beginning-position)) (when (looking-at (concat git-rebase-comment-re "?" "\\(e\\|exec\\) \\(.*\\)")) (setq initial (match-string-no-properties 2)))) (setq command (read-shell-command "Execute: " initial)) (pcase (list command initial) (`("" nil) (ding)) (`("" ,_) (delete-region (match-beginning 0) (1+ (match-end 0)))) (`(,_ nil) (forward-line) (insert (concat "exec " command "\n")) (unless git-rebase-auto-advance (forward-line -1))) (_ (replace-match (concat "exec " command) t t) (if git-rebase-auto-advance (forward-line) (goto-char (line-beginning-position))))))) (defun git-rebase-noop (&optional arg) "Add noop action at point. If the current line already contains a 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 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") (goto-char (line-beginning-position)) ;; The extra space at the end is only there to make the action ;; consistent with the others (action argument). This keeps ;; the regexp `git-rebase-line' from getting complicated. (let ((noop-string "noop \n")) (when (or arg (not (looking-at noop-string))) (let ((inhibit-read-only t)) (if (and (not arg) (looking-at (concat comment-start noop-string))) (delete-char 1) (insert noop-string)))))) (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 (and (looking-at git-rebase-line) (match-string 2)) (pcase scroll (`up (magit-diff-show-or-scroll-up)) (`down (magit-diff-show-or-scroll-down)) (_ (apply #'magit-show-commit it (magit-diff-arguments)))) (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 git-rebase-line (concat "^\\(" (regexp-quote comment-start) "? *" "\\(?:[fprse]\\|pick\\|reword\\|edit\\|squash\\|fixup\\|exec\\|noop\\)\\) " "\\(?:\\([^ \n]+\\) \\(.*\\)\\)?")) (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." (let ((action-re "\ \\([efprs]\\|pick\\|reword\\|edit\\|squash\\|fixup\\) \\([^ \n]+\\) \\(.*\\)")) `((,(concat "^" action-re) (1 'font-lock-keyword-face) (2 'git-rebase-hash) (3 'git-rebase-description)) ("^\\(exec\\) \\(.*\\)" (1 'font-lock-keyword-face) (2 'git-rebase-description)) ("^\\(noop\\)" (1 'font-lock-keyword-face)) (git-rebase-match-comment-line 0 'font-lock-comment-face) (,(concat git-rebase-comment-re " *" action-re) 0 'git-rebase-killed-action t) ("\\[[^[]*\\]" 0 'magit-keyword 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))))) (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))) ", ")) 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 magit-2.90.1/lisp/magit-apply.el000066400000000000000000000723101337354740400164360ustar00rootroot00000000000000;;; magit-apply.el --- apply Git diffs -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;; For `magit-apply' (declare-function magit-am-popup "magit-sequence" (&optional arg)) (declare-function magit-patch-apply-popup "magit-files" (&optional arg)) ;; 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 "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)) (magit-am-popup)) (`(,_ region) (magit-apply-region it args)) (`(,_ hunk) (magit-apply-hunk it args)) (`(,_ hunks) (magit-apply-hunks it args)) (`(rebase-sequence file) (magit-patch-apply-popup)) (`(,_ 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-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 '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--section-content section)))) (defun magit-apply-region (section &rest args) (unless (magit-diff-context-p) (user-error "Not enough context to apply region. Increase the context")) (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-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")) (no-context (not (magit-diff-context-p))) (ignore-context (magit-diff-ignore-any-space-p))) (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 no-context "--unidiff-zero") (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 (if (derived-mode-p 'magit-diff-mode) (nth 2 magit-refresh-args) magit-diff-section-arguments) '("--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")))) (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 (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 ,_ ,_) (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")) ;;;###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-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) (if (memq (magit-diff-type) '(unstaged untracked)) (progn (dired-delete-file file dired-recursive-deletes magit-delete-by-moving-to-trash) (dired-clean-up-after-deletion file)) (pcase (nth 3 (assoc file status)) (? (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) (let ((rev (car magit-refresh-args))) (format "%s^..%s" rev rev))) ((derived-mode-p 'magit-diff-mode) (car magit-refresh-args)) (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 magit-2.90.1/lisp/magit-autorevert.el000066400000000000000000000252331337354740400175130ustar00rootroot00000000000000;;; magit-autorevert.el --- revert buffers when files in repository change -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 redefines `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-buffers-p'. However the default is nil, to not 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. ;; - When `magit-revert-buffers' is nil, then the user has opted out ;; of the automatic reverts while a very old implementation was ;; still in use. We continued to respect that setting for another ;; two and a half years, but no longer do so now. :init-value (and (not global-auto-revert-mode) (not 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 has set the obsolete variable `magit-revert-buffers' ;; to nil before or after loading magit, 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 (current-time) 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. With a prefix argument ARG, enable Magit Auto Revert mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. 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) (when (< emacs-major-version 25) (defvar auto-revert-buffers-counter 1 "Incremented each time `auto-revert-buffers' is called")) (defun magit-auto-revert-buffer-p (buffer) "Return t if BUFFER visits a file inside the current repository. The current repository is the one in which `default-directory' is located. 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 t if BUFFER visits a file inside the current repository. The current repository is the one in which `default-directory' is located. 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) auto-revert-buffers-counter)) (setq magit-auto-revert-toplevel (cons (or (magit-toplevel) 'no-repo) auto-revert-buffers-counter))) (let ((top (car magit-auto-revert-toplevel))) (if (eq top 'no-repo) fallback (let ((dir (with-current-buffer buffer default-directory))) (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 () (when (< emacs-major-version 25) (cl-incf auto-revert-buffers-counter)) (when auto-revert-buffer-list-filter (setq auto-revert-buffer-list (--filter auto-revert-buffer-list-filter auto-revert-buffer-list)))) (advice-add 'auto-revert-buffers :before 'auto-revert-buffers--buffer-list-filter) ;;; _ (provide 'magit-autorevert) ;;; magit-autorevert.el ends here magit-2.90.1/lisp/magit-bisect.el000066400000000000000000000200071337354740400165560ustar00rootroot00000000000000;;; magit-bisect.el --- bisect support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2011-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup "magit-bisect" nil t) (magit-define-popup magit-bisect-popup "Popup console for bisect commands." :man-page "git-bisect" :actions '((?B "Start" magit-bisect-start) (?s "Start script" magit-bisect-run)) :sequence-actions '((?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)) :sequence-predicate 'magit-bisect-in-progress-p) ;;;###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 popup (\ \\\\[magit-bisect-popup])." (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")) (magit-with-toplevel (magit-run-git-with-logfile (magit-git-dir "BISECT_CMD_OUTPUT") "bisect" subcommand args))) ;;; 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)) '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%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 '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 magit-2.90.1/lisp/magit-blame.el000066400000000000000000001074661337354740400164040ustar00rootroot00000000000000;;; magit-blame.el --- blame support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2012-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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))) "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. `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 specifing the information to be shown above each chunk of lines. It must end with a newline character. `margin-format' String specifing 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)) :background "grey80" :foreground "black") (((class color) (background dark)) :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 :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 :initarg :orig-rev) (orig-line :initarg :orig-line) (final-line :initarg :final-line) (num-lines :initarg :num-lines) ;; previous (prev-rev :initform nil) (prev-file :initform nil) ;; filename (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-popup)) (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-popup))) (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' or `magit-blame-popup'"))) (add-hook 'after-save-hook 'magit-blame--run 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--run 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 sentinal (remove-hook 'after-save-hook 'magit-blame--run 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--run 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-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 () (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" (magit-blame-arguments)) (magit-blame-arguments)) (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 '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" "")) 'face face) (magit--format-spec (propertize format 'face face) (cl-flet* ((p0 (s f) (propertize s '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) 'face face)) str))) (defun magit-blame--format-separator () (propertize (concat (propertize "\s" 'display '(space :height (2))) (propertize "\n" 'line-height t)) '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 (not (version< emacs-version "25")) (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 (assq 'heading (gethash (oref (magit-current-blame-chunk) orig-rev) magit-blame-cache))))) (progn (setq msg (substring msg 0 -1)) (set-text-properties 0 (length msg) nil msg) (message msg)) (message "Commit data not available yet. Still blaming."))))) ;;; Commands ;;;###autoload (defun magit-blame-echo () "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'." (interactive) (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-addition)) (read-only-mode -1) (magit-blame--update-overlays))) ;;;###autoload (defun magit-blame-addition () "For each line show the revision in which it was added." (interactive) (magit-blame--pre-blame-assert 'addition) (magit-blame--pre-blame-setup 'addition) (magit-blame--run)) ;;;###autoload (defun magit-blame-removal () "For each line show the revision in which it was removed." (interactive) (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)) ;;;###autoload (defun magit-blame-reverse () "For each line show the last revision in which it still exists." (interactive) (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)) (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)))) (defun magit-blame-quit () "Turn off Magit-Blame mode. If the buffer was created during a recursive blame, then also kill the buffer." (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) (copy-region-as-kill nil nil 'region) (kill-new (message "%s" (oref (magit-current-blame-chunk) orig-rev))))) ;;; Popup ;;;###autoload (autoload 'magit-blame-popup "magit-blame" nil t) (magit-define-popup magit-blame-popup "Popup console for blame commands." :man-page "git-blame" :switches '((?w "Ignore whitespace" "-w") (?r "Do not treat root commits as boundaries" "--root")) :options '((?M "Detect lines moved or copied within a file" "-M") (?C "Detect lines moved or copied between files" "-C")) :actions '("Actions" (?b "Show commits adding lines" magit-blame-addition) (?r (lambda () (with-current-buffer magit-pre-popup-buffer (and (not buffer-file-name) (propertize "Show commits removing lines" 'face 'default)))) magit-blame-removal) (?f (lambda () (with-current-buffer magit-pre-popup-buffer (and (not buffer-file-name) (propertize "Show last commits that still have lines" 'face 'default)))) magit-blame-reverse) (lambda () (and (with-current-buffer magit-pre-popup-buffer magit-blame-mode) (propertize "Refresh" 'face 'magit-popup-heading))) (?c "Cycle style" magit-blame-cycle-style)) :default-arguments '("-w") :max-action-columns 1 :default-action 'magit-blame-addition) ;;; Utilities (defun magit-blame-maybe-update-revision-buffer () (unless magit--update-revision-buffer (setq magit--update-revision-buffer nil) (when-let ((chunk (magit-current-blame-chunk)) (commit (oref chunk orig-rev)) (buffer (magit-mode-get-buffer 'magit-revision-mode nil t))) (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)))))))))) ;;; _ (provide 'magit-blame) ;;; magit-blame.el ends here magit-2.90.1/lisp/magit-bookmark.el000066400000000000000000000314071337354740400171200ustar00rootroot00000000000000;;; magit-bookmark.el --- bookmark support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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: Yuri Khan ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Supporting primitives (defun magit-bookmark--jump (bookmark fn &rest args) "Handle a Magit BOOKMARK. This function will: 1. Bind `default-directory' to the repository root directory stored in the `filename' bookmark property. 2. Invoke the function FN with ARGS as arguments. This needs to restore the buffer. 3. Restore the expanded/collapsed status of top level sections and the point position." (declare (indent 2)) (let* ((default-directory (bookmark-get-filename bookmark))) (if default-directory (apply fn args) (signal 'bookmark-error-no-filename (list 'stringp default-directory))) (when (derived-mode-p 'magit-mode) (when-let ((hidden-sections (bookmark-prop-get bookmark 'magit-hidden-sections))) (dolist (child (oref magit-root-section children)) (if (member (cons (oref child type) (oref child value)) hidden-sections) (magit-section-hide child) (magit-section-show child))))) (--when-let (bookmark-get-position bookmark) (goto-char it)) (--when-let (bookmark-get-front-context-string bookmark) (when (search-forward it (point-max) t) (goto-char (match-beginning 0)))) (--when-let (bookmark-get-rear-context-string bookmark) (when (search-backward it (point-min) t) (goto-char (match-end 0)))) nil)) (defun magit-bookmark--make-record (mode handler &optional make-props) "Create a Magit bookmark. MODE specifies the expected major mode of current buffer. HANDLER should be a function that will be used to restore this buffer. MAKE-PROPS should be either nil or a function that will be called with `magit-refresh-args' as the argument list, and may return an alist whose every element has the form (PROP . VALUE) and specifies additional properties to store in the bookmark." (declare (indent 1)) (unless (eq major-mode mode) (user-error "Not in a %s buffer" mode)) (let ((bookmark (bookmark-make-record-default 'no-file))) (bookmark-prop-set bookmark 'handler handler) (bookmark-set-filename bookmark (magit-toplevel)) (when (derived-mode-p 'magit-mode) (bookmark-prop-set bookmark 'magit-hidden-sections (--map (cons (oref it type) (oref it value)) (--filter (oref it hidden) (oref magit-root-section children))))) (when make-props (pcase-dolist (`(,prop . ,value) (apply make-props magit-refresh-args)) (bookmark-prop-set bookmark prop value))) bookmark)) ;;; Status ;;;###autoload (defun magit-bookmark--status-jump (bookmark) "Handle a Magit status BOOKMARK." (magit-bookmark--jump bookmark (lambda () (magit-status-internal default-directory)))) ;;;###autoload (defun magit-bookmark--status-make-record () "Create a Magit status bookmark." (magit-bookmark--make-record 'magit-status-mode #'magit-bookmark--status-jump)) ;;; Refs ;;;###autoload (defun magit-bookmark--refs-jump (bookmark) "Handle a Magit refs BOOKMARK." (magit-bookmark--jump bookmark #'magit-show-refs (bookmark-prop-get bookmark 'magit-refs) (bookmark-prop-get bookmark 'magit-args))) ;;;###autoload (defun magit-bookmark--refs-make-record () "Create a Magit refs bookmark." (magit-bookmark--make-record 'magit-refs-mode #'magit-bookmark--refs-jump (lambda (refs args) `((magit-refs . ,refs) (magit-args . ,args))))) ;;; Log ;;;###autoload (defun magit-bookmark--log-jump (bookmark) "Handle a Magit log BOOKMARK." (magit-bookmark--jump bookmark #'magit-log-other (bookmark-prop-get bookmark 'magit-revs) (bookmark-prop-get bookmark 'magit-args) (bookmark-prop-get bookmark 'magit-files))) (defun magit-bookmark--log-make-name (buffer-name revs _args files) "Generate the default name for a log bookmark." (concat buffer-name " " (mapconcat #'identity revs " ") (and files (concat " touching " (mapconcat #'identity files " "))))) ;;;###autoload (defun magit-bookmark--log-make-record () "Create a Magit log bookmark." (magit-bookmark--make-record 'magit-log-mode #'magit-bookmark--log-jump (lambda (revs args files) `((defaults . (,(magit-bookmark--log-make-name (buffer-name) revs args files))) (magit-revs . ,revs) (magit-args . ,args) (magit-files . ,files))))) ;;; Reflog ;;;###autoload (defun magit-bookmark--reflog-jump (bookmark) "Handle a Magit reflog BOOKMARK." (magit-bookmark--jump bookmark (lambda () (let ((magit-reflog-arguments (bookmark-prop-get bookmark 'magit-args))) (magit-git-reflog (bookmark-prop-get bookmark 'magit-ref) magit-reflog-arguments))))) (defun magit-bookmark--reflog-make-name (buffer-name ref) "Generate the default name for a reflog bookmark." (concat buffer-name " " ref)) ;;;###autoload (defun magit-bookmark--reflog-make-record () "Create a Magit reflog bookmark." (magit-bookmark--make-record 'magit-reflog-mode #'magit-bookmark--reflog-jump (lambda (ref args) `((defaults . (,(magit-bookmark--reflog-make-name (buffer-name) ref))) (magit-ref . ,ref) (magit-args . ,args))))) ;;; Stashes ;;;###autoload (defun magit-bookmark--stashes-jump (bookmark) "Handle a Magit stash list BOOKMARK." (magit-bookmark--jump bookmark #'magit-stash-list)) ;;;###autoload (defun magit-bookmark--stashes-make-record () "Create a Magit stash list bookmark." (magit-bookmark--make-record 'magit-stashes-mode #'magit-bookmark--stashes-jump)) ;;; Cherry ;;;###autoload (defun magit-bookmark--cherry-jump (bookmark) "Handle a Magit cherry BOOKMARK." (magit-bookmark--jump bookmark #'magit-cherry (bookmark-prop-get bookmark 'magit-head) (bookmark-prop-get bookmark 'magit-upstream))) (defun magit-bookmark--cherry-make-name (buffer-name head upstream) "Generate the default name for a cherry bookmark." (concat buffer-name " " head " upstream " upstream)) ;;;###autoload (defun magit-bookmark--cherry-make-record () "Create a Magit cherry bookmark." (magit-bookmark--make-record 'magit-cherry-mode #'magit-bookmark--cherry-jump (lambda (upstream head) `((defaults . (,(magit-bookmark--cherry-make-name (buffer-name) head upstream))) (magit-head . ,head) (magit-upstream . ,upstream))))) ;;; Diff ;;;###autoload (defun magit-bookmark--diff-jump (bookmark) "Handle a Magit diff BOOKMARK." (magit-bookmark--jump bookmark #'magit-diff-setup (bookmark-prop-get bookmark 'magit-rev-or-range) (bookmark-prop-get bookmark 'magit-const) (bookmark-prop-get bookmark 'magit-args) (bookmark-prop-get bookmark 'magit-files))) (defun magit-bookmark--resolve (rev-or-range) "Return REV-OR-RANGE with ref names resolved to commit hashes." (pcase (magit-git-lines "rev-parse" rev-or-range) (`(,rev) (magit-rev-abbrev rev)) ((and `(,rev1 ,rev2) (guard (/= ?^ (aref rev1 0))) (guard (= ?^ (aref rev2 0)))) (concat (magit-rev-abbrev (substring rev2 1)) ".." (magit-rev-abbrev rev1))) ((and `(,rev1 ,rev2 ,rev3) (guard (/= ?^ (aref rev1 0))) (guard (/= ?^ (aref rev2 0))) (guard (= ?^ (aref rev3 0)))) (ignore rev3) (concat (magit-rev-abbrev rev1) "..." (magit-rev-abbrev rev2))) (_ rev-or-range))) (defun magit-bookmark--diff-make-name (buffer-name rev-or-range const _args files) "Generate a default name for a diff bookmark." (if (member "--no-index" const) (apply #'format "*magit-diff %s %s" files) (concat buffer-name " " (cond (rev-or-range) ((member "--cached" const) "staged") (t "unstaged")) (when files (concat " in " (mapconcat #'identity files ", ")))))) ;;;###autoload (defun magit-bookmark--diff-make-record () "Create a Magit diff bookmark." (magit-bookmark--make-record 'magit-diff-mode #'magit-bookmark--diff-jump (lambda (rev-or-range const args files) (let ((resolved (magit-bookmark--resolve rev-or-range))) `((defaults . (,(magit-bookmark--diff-make-name (buffer-name) resolved const args files))) (magit-rev-or-range . ,resolved) (magit-const . ,const) (magit-args . ,args) (magit-files . ,files)))))) ;;; Revision ;;;###autoload (defun magit-bookmark--revision-jump (bookmark) "Handle a Magit revision BOOKMARK." (magit-bookmark--jump bookmark #'magit-show-commit (bookmark-prop-get bookmark 'magit-rev) (bookmark-prop-get bookmark 'args) (bookmark-prop-get bookmark 'files))) (defun magit-bookmark--revision-make-name (buffer-name rev _args files) "Generate a default name for a revision bookmark." (let ((subject (magit-rev-format "%s" rev))) (concat buffer-name " " (magit-rev-abbrev rev) (cond (files (concat " " (mapconcat #'identity files " "))) (subject (concat " " subject)))))) ;;;###autoload (defun magit-bookmark--revision-make-record () "Create a Magit revision bookmark." ;; magit-refresh-args stores the revision in relative form. ;; For bookmarks, the exact hash is more appropriate. (magit-bookmark--make-record 'magit-revision-mode #'magit-bookmark--revision-jump (lambda (_rev _ args files) `((defaults . (,(magit-bookmark--revision-make-name (buffer-name) magit-buffer-revision-hash args files))) (magit-rev . ,magit-buffer-revision-hash) (magit-args . ,args) (magit-files . ,files))))) ;;; Stash ;;;###autoload (defun magit-bookmark--stash-jump (bookmark) "Handle a Magit stash BOOKMARK." (magit-bookmark--jump bookmark #'magit-stash-show (bookmark-prop-get bookmark 'magit-stash) (bookmark-prop-get bookmark 'magit-args) (bookmark-prop-get bookmark 'magit-files))) (defun magit-bookmark--stash-make-name (buffer-name stash _args files) "Generate the default name for a stash bookmark." (concat buffer-name " " stash " " (if files (mapconcat #'identity files " ") (magit-rev-format "%s" stash)))) ;;;###autoload (defun magit-bookmark--stash-make-record () "Create a Magit stash bookmark." (magit-bookmark--make-record 'magit-stash-mode #'magit-bookmark--stash-jump (lambda (stash _ args files) `((defaults . (,(magit-bookmark--stash-make-name (buffer-name) (magit-rev-abbrev magit-buffer-revision-hash) args files))) (magit-stash . ,magit-buffer-revision-hash) (magit-args . ,args) (magit-files . ,files) (magit-hidden-sections . ,(--map `(,(oref it type) . ,(replace-regexp-in-string (regexp-quote stash) magit-buffer-revision-hash (oref it value))) (--filter (oref it hidden) (oref magit-root-section children)))))))) ;;; Submodules ;;;###autoload (defun magit-bookmark--submodules-jump (bookmark) "Handle a Magit submodule list BOOKMARK." (magit-bookmark--jump bookmark #'magit-list-submodules)) ;;;###autoload (defun magit-bookmark--submodules-make-record () "Create a Magit submodule list bookmark." (magit-bookmark--make-record 'magit-submodule-list-mode #'magit-bookmark--submodules-jump)) ;;; _ (provide 'magit-bookmark) ;;; magit-bookmark.el ends here magit-2.90.1/lisp/magit-branch.el000066400000000000000000001355751337354740400165630ustar00rootroot00000000000000;;; magit-branch.el --- branch support -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 popups ;; and 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-collab) (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 specifing 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-popup-show-variables t "Whether the `magit-branch-popup' shows Git variables. This defaults to t to avoid changing key bindings. When set to nil, no variables are displayed directly in this popup, instead the sub-popup `magit-branch-config-popup' 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)) ;;; Branch Popup (defvar magit-branch-config-variables) ;;;###autoload (autoload 'magit-branch-popup "magit" nil t) (magit-define-popup magit-branch-popup "Popup console for branch commands." :man-page "git-branch" :variables (lambda () (and magit-branch-popup-show-variables magit-branch-config-variables)) :actions `((?b "Checkout" magit-checkout) nil (?C "Configure..." magit-branch-config-popup) (?l "Checkout local branch" magit-branch-checkout) (?s "Create new spin-off" magit-branch-spinoff) (?m "Rename" magit-branch-rename) (?c "Checkout new branch" magit-branch-and-checkout) (?n "Create new branch" magit-branch-create) (?x "Reset" magit-branch-reset) (?w "Checkout new worktree" magit-worktree-checkout) (?W "Create new worktree" magit-worktree-branch) (?k "Delete" magit-branch-delete) ,@(and (not (require (quote forge) nil t)) '((?y "Checkout pull-request" magit-checkout-pull-request) (?Y "Create from pull-request" magit-branch-pull-request)))) :default-action 'magit-checkout :max-action-columns 3 :setup-function 'magit-branch-popup-setup) (defun magit-branch-popup-setup (val def) (magit-popup-default-setup val def) (use-local-map (copy-keymap magit-popup-mode-map)) (dolist (ev (-filter #'magit-popup-event-p (magit-popup-get :variables))) (local-set-key (vector (magit-popup-event-key ev)) 'magit-invoke-popup-action))) ;;; Branch Commands ;;;###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 &optional args) "Create BRANCH at branch or revision START-POINT. \n(git branch [ARGS] BRANCH START-POINT)." (interactive (magit-branch-read-args "Create branch")) (magit-call-git "branch" args branch start-point) (magit-branch-maybe-adjust-upstream branch start-point) (magit-refresh)) ;;;###autoload (defun magit-branch-and-checkout (branch start-point &optional args) "Create and checkout BRANCH at branch or revision START-POINT. \n(git checkout [ARGS] -b BRANCH 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" args "-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-rev-verify-commit 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-branch-arguments)) (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 (magit-branch-arguments)) (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 &optional args) "Create and checkout an orphan BRANCH with contents from revision START-POINT. \n(git checkout --orphan [ARGS] BRANCH START-POINT)." (interactive (magit-branch-read-args "Create and checkout orphan branch")) (magit-run-git "checkout" "--orphan" args branch start-point)) ;;;###autoload (defun magit-branch-pull-request (pr) "Create and configure a new branch from a pull-request. Please see the manual for more information." (interactive (list (magit-read-pull-request "Branch pull request"))) (let-alist pr (let* ((upstream (or (--first (magit--github-url-equal (magit-get "remote" it "url") .base.repo.ssh_url) (magit-list-remotes)) (user-error "Upstream repository %s not available as a remote" .base.repo.ssh_url))) (upstream-url (magit-get "remote" upstream "url")) (remote .head.repo.owner.login) (branch (magit--pullreq-branch pr t)) (pr-branch .head.ref)) (if (magit--pullreq-from-upstream-p pr) (let ((tracking (concat upstream "/" pr-branch))) (unless (magit-branch-p tracking) (magit-call-git "fetch" upstream)) (let ((inhibit-magit-refresh t)) (magit-branch-create branch tracking)) (magit-set upstream "branch" branch "pushRemote") (magit-set upstream "branch" branch "pullRequestRemote")) (if (magit-remote-p remote) (let ((url (magit-get "remote" remote "url")) (fetch (magit-get-all "remote" remote "fetch"))) (unless (magit--github-url-equal url .head.repo.ssh_url) (user-error "Remote `%s' already exists but does not point to %s" remote url)) (unless (member (format "+refs/heads/*:refs/remotes/%s/*" remote) fetch) (magit-call-git "remote" "set-branches" "--add" remote pr-branch) (magit-call-git "fetch" remote))) (magit-call-git "remote" "add" "-f" "--no-tags" "-t" pr-branch remote (cond ((or (string-prefix-p "git@" upstream-url) (string-prefix-p "ssh://git@" upstream-url)) .head.repo.ssh_url) ((string-prefix-p "https://" upstream-url) .head.repo.clone_url) ((string-prefix-p "git://" upstream-url) .head.repo.git_url) (t (error "%s has an unexpected format" upstream-url))))) (magit-call-git "branch" branch (concat remote "/" pr-branch)) (if (or .locked (not (equal branch pr-branch))) (magit-set upstream "branch" branch "pushRemote") (magit-set remote "branch" branch "pushRemote")) (magit-set remote "branch" branch "pullRequestRemote")) (magit-set "true" "branch" branch "rebase") (magit-call-git "branch" branch (concat "--set-upstream-to=" (if magit-branch-prefer-remote-upstream (concat upstream "/" .base.ref) .base.ref))) (magit-set (number-to-string .number) "branch" branch "pullRequest") (magit-set .title "branch" branch "description") (magit-refresh) branch))) (defun magit-checkout-pull-request (pr) "Create, configure and checkout a new branch from a pull-request. Please see the manual for more information." (interactive (list (magit-read-pull-request "Checkout pull request"))) (magit-checkout (let ((inhibit-magit-refresh t)) (magit-branch-pull-request pr)))) (defun magit-branch-read-args (prompt) (let ((args (magit-branch-arguments))) (if magit-branch-read-upstream-first (let ((choice (magit-read-starting-point prompt))) (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 args) (if (eq magit-branch-read-upstream-first 'fallback) (list choice (magit-read-starting-point prompt choice) args) (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) args))))) ;;;###autoload (defun magit-branch-spinoff (branch &optional from &rest args) "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-arguments))) (when (magit-branch-p branch) (user-error "Cannot spin off %s. It already exists" branch)) (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)) (magit-call-git "checkout" args "-b" 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))) (magit-call-git "update-ref" "-m" (format "reset: moving to %s" base) (concat "refs/heads/" current) base)) (magit-refresh)) (magit-run-git "checkout" "-b" branch))) ;;;###autoload (defun magit-branch-reset (branch to &optional args 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))) (magit-branch-arguments) current-prefix-arg))) (unless (member "--force" args) (setq args (cons "--force" args))) (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) (when (and set-upstream (magit-branch-p to)) (magit-set-upstream-branch branch to))) (magit-branch-create branch to args))) ;;;###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 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"))) (magit-call-git "remote" "rm" remote) (magit-call-git "config" "--unset" variable (regexp-quote refspec))))))))) (defun magit-branch-unset-pushRemote (branch) (magit-set nil "branch" branch "pushRemote")) (defun magit-delete-remote-branch-sentinel (refs process event) (when (memq (process-status process) '(exit signal)) (if (= (process-exit-status process) 0) (magit-process-sentinel process event) (if-let ((rest (-filter #'magit-ref-exists-p 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))))) ;;;###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)))) ;;; Config Popup (defvar magit-branch-config-branch nil) ;;;###autoload (defun magit-branch-config-popup (branch) "Popup console for setting branch variables." (interactive (list (if (or current-prefix-arg (and (eq magit-current-popup 'magit-branch-popup) magit-branch-popup-show-variables)) (magit-read-local-branch "Configure branch") (magit-get-current-branch)))) (let ((magit-branch-config-branch branch)) (magit-invoke-popup 'magit-branch-config-popup nil nil))) (defvar magit-branch-config-variables '((lambda () (concat (propertize "Configure " 'face 'magit-popup-heading) (propertize (magit-branch-config-branch) 'face 'magit-branch-local))) (?d "branch.%s.description" magit-edit-branch*description magit-format-branch*description) (?u "branch.%s.merge" magit-set-branch*merge/remote magit-format-branch*merge/remote) (?r "branch.%s.rebase" magit-cycle-branch*rebase magit-format-branch*rebase) (?p "branch.%s.pushRemote" magit-cycle-branch*pushRemote magit-format-branch*pushRemote) "Configure repository defaults" (?\M-r "pull.rebase" magit-cycle-pull.rebase magit-format-pull.rebase) (?\M-p "remote.pushDefault" magit-cycle-remote.pushDefault magit-format-remote.pushDefault) "Configure branch creation" (?U "branch.autoSetupMerge" magit-cycle-branch*autoSetupMerge magit-format-branch*autoSetupMerge) (?R "branch.autoSetupRebase" magit-cycle-branch*autoSetupRebase magit-format-branch*autoSetupRebase))) (defvar magit-branch-config-popup `(:man-page "git-branch" :variables ,magit-branch-config-variables :setup-function magit-branch-config-popup-setup)) (defun magit-branch-config-popup-setup (val def) (magit-popup-default-setup val def) (setq-local magit-branch-config-branch magit-branch-config-branch) (use-local-map (copy-keymap magit-popup-mode-map)) (dolist (ev (-filter #'magit-popup-event-p (magit-popup-get :variables))) (local-set-key (vector (magit-popup-event-key ev)) 'magit-invoke-popup-action))) (defun magit-branch-config-branch (&optional prompt) (if prompt (or (and (not current-prefix-arg) (or magit-branch-config-branch (magit-get-current-branch))) (magit-read-local-branch prompt)) (or magit-branch-config-branch (magit-get-current-branch) ""))) ;;; Config Commands and Inserters ;;;###autoload (defun magit-edit-branch*description (branch) "Edit the description of the current branch. With a prefix argument edit the description of another branch. The description for the branch named NAME is stored in the Git variable `branch..description'." (interactive (list (magit-branch-config-branch "Edit branch description"))) (magit-run-git-with-editor "branch" "--edit-description" branch)) (defun magit-edit-branch*description-check-buffers () (and buffer-file-name (string-match-p "/\\(BRANCH\\|EDIT\\)_DESCRIPTION\\'" buffer-file-name) (add-hook 'with-editor-post-finish-hook (lambda () (when (derived-mode-p 'magit-popup-mode) (magit-refresh-popup-buffer))) nil t))) (add-hook 'find-file-hook 'magit-edit-branch*description-check-buffers) (defun magit-format-branch*description () (let* ((branch (magit-branch-config-branch)) (width (+ (length branch) 19)) (var (format "branch.%s.description" branch))) (concat var " " (make-string (- width (length var)) ?\s) (if-let ((value (magit-get var))) (propertize (car (split-string value "\n")) 'face 'magit-popup-option-value) (propertize "unset" 'face 'magit-popup-disabled-argument))))) ;;;###autoload (defun magit-set-branch*merge/remote (branch upstream) "Set or unset the upstream of the current branch. With a prefix argument do so for another branch. When the branch in question already has an upstream then simply unsets it. Invoke this command again to set another upstream. Together the Git variables `branch..remote' and `branch..merge' define the upstream branch of the local branch named NAME. The value of `branch..remote' is the name of the upstream remote. The value of `branch..merge' is the full reference of the upstream branch, on the remote. Non-interactively, when UPSTREAM is non-nil, then always set it as the new upstream, regardless of whether another upstream was already set. When nil, then always unset." (interactive (let ((branch (magit-branch-config-branch "Change upstream of branch"))) (list branch (and (not (magit-get-upstream-branch branch)) (magit-read-upstream-branch branch))))) (magit-set-upstream-branch branch upstream) (magit-refresh)) (defun magit-format-branch*merge/remote () (let* ((branch (magit-branch-config-branch)) (width (+ (length branch) 20)) (varM (format "branch.%s.merge" branch)) (varR (format "branch.%s.remote" branch)) (face (if (equal (magit-get varR) ".") 'magit-branch-local 'magit-branch-remote))) (concat varM (make-string (- width (length varM)) ?\s) (if-let ((value (magit-get varM))) (propertize value 'face face) (propertize "unset" 'face 'magit-popup-disabled-argument)) "\n " varR (make-string (- width (length varR)) ?\s) (if-let ((value (magit-get varR))) (propertize value 'face face) (propertize "unset" 'face 'magit-popup-disabled-argument))))) ;;;###autoload (defun magit-cycle-branch*rebase (branch) "Cycle the value of `branch..rebase' for the current branch. With a prefix argument cycle the value for another branch. The Git variables `branch..rebase' controls whether pulling into the branch named NAME is done by rebasing that branch onto the fetched branch or by merging that branch. When `true' then pulling is done by rebasing. When `false' then pulling is done by merging. When that variable is undefined then the value of `pull.rebase' is used instead. It defaults to `false'." (interactive (list (magit-branch-config-branch "Cycle branch..rebase for"))) (magit--set-popup-variable (format "branch.%s.rebase" branch) '("true" "false") "false" "pull.rebase")) (defun magit-format-branch*rebase () (let ((branch (magit-branch-config-branch))) (magit--format-popup-variable:choices (format "branch.%s.rebase" branch) '("true" "false") "false" "pull.rebase" (+ (length branch) 20)))) ;;;###autoload (defun magit-cycle-branch*pushRemote (branch) "Cycle the value of `branch..pushRemote' for the current branch. With a prefix argument cycle the value for another branch. The Git variable `branch..pushRemote' specifies the remote that the branch named NAME is usually pushed to. The value has to be the name of an existing remote. If that variable is undefined, then the value of the Git variable `remote.pushDefault' is used instead, provided that it is defined, which by default it is not." (interactive (list (magit-branch-config-branch "Cycle branch..pushRemote for"))) (magit--set-popup-variable (format "branch.%s.pushRemote" branch) (magit-list-remotes) "remote.pushDefault")) (defun magit-format-branch*pushRemote () (let ((branch (magit-branch-config-branch))) (magit--format-popup-variable:choices (format "branch.%s.pushRemote" branch) (magit-list-remotes) nil "remote.pushDefault" (+ (length branch) 20)))) ;;;###autoload (defun magit-cycle-pull.rebase () "Cycle the repository-local value of `pull.rebase'. The Git variable `pull.rebase' specifies whether pulling is done by rebasing or by merging. It can be overwritten using the Git variable `branch..rebase'. When `true' then pulling is done by rebasing. When `false' (the default) then pulling is done by merging." (interactive) (magit--set-popup-variable "pull.rebase" '("true" "false") "false")) (defun magit-format-pull.rebase () (magit--format-popup-variable:choices "pull.rebase" '("true" "false") "false" nil 19)) ;;;###autoload (defun magit-cycle-remote.pushDefault () "Cycle the repository-local value of `remote.pushDefault'. The Git variable `remote.pushDefault' specifies the remote that local branches are usually pushed to. It can be overwritten using the Git variable `branch..pushRemote'." (interactive) (magit--set-popup-variable "remote.pushDefault" (magit-list-remotes))) (defun magit-format-remote.pushDefault () (magit--format-popup-variable:choices "remote.pushDefault" (magit-list-remotes) nil nil 19)) ;;;###autoload (defun magit-cycle-branch*autoSetupMerge () "Cycle the repository-local value of `branch.autoSetupMerge'. The Git variable `branch.autoSetupMerge' under what circumstances creating a branch (named NAME) should result in the variables `branch..merge' and `branch..remote' being set according to the starting point used to create the branch. If the starting point isn't a branch, then these variables are never set. When `always' then the variables are set regardless of whether the starting point is a local or a remote branch. When `true' (the default) then the variable are set when the starting point is a remote branch, but not when it is a local branch. When `false' then the variables are never set." (interactive) (magit--set-popup-variable "branch.autoSetupMerge" '("always" "true" "false") "true")) (defun magit-format-branch*autoSetupMerge () (magit--format-popup-variable:choices "branch.autoSetupMerge" '("always" "true" "false") "true" nil 23)) ;;;###autoload (defun magit-cycle-branch*autoSetupRebase () "Cycle the repository-local value of `branch.autoSetupRebase'. The Git variable `branch.autoSetupRebase' specifies whether creating a branch (named NAME) should result in the variable `branch..rebase' being set to `true'. When `always' then the variable is set regardless of whether the starting point is a local or a remote branch. When `local' then the variable are set when the starting point is a local branch, but not when it is a remote branch. When `remote' then the variable are set when the starting point is a remote branch, but not when it is a local branch. When `never' (the default) then the variable is never set." (interactive) (magit--set-popup-variable "branch.autoSetupRebase" '("always" "local" "remote" "never") "never")) (defun magit-format-branch*autoSetupRebase () (magit--format-popup-variable:choices "branch.autoSetupRebase" '("always" "local" "remote" "never") "never" nil 23)) ;;; _ (provide 'magit-branch) ;;; magit-branch.el ends here magit-2.90.1/lisp/magit-clone.el000066400000000000000000000076271337354740400164220ustar00rootroot00000000000000;;; magit-clone.el --- clone a repository -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 `/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"))) ;;; Commands ;;;###autoload (defun magit-clone (repository directory) "Clone the REPOSITORY to DIRECTORY. Then show the status buffer for the new repository." (interactive (let ((url (magit-read-string-ns "Clone repository"))) (list url (read-directory-name "Clone to: " (if (functionp magit-clone-default-directory) (funcall magit-clone-default-directory url) magit-clone-default-directory) nil nil (and (string-match "\\([^/:]+?\\)\\(/?\\.git\\)?$" url) (match-string 1 url)))))) (setq directory (file-name-as-directory (expand-file-name directory))) (magit-run-git-async "clone" 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)) (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-internal directory)))))) ;;; _ (provide 'magit-clone) ;;; magit-clone.el ends here magit-2.90.1/lisp/magit-collab.el000066400000000000000000000151051337354740400165440ustar00rootroot00000000000000;;; magit-collab.el --- collaboration tools -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 various collaboration tools. These tools ;; are only early incarnation -- implementing collaboration tools is ;; a top priority for future development. ;; Currently these tools (including `magit-branch-pull-request', which ;; is defined elsewhere) only support Github, but support for other ;; Git forges as well as mailing list based collaboration is in ;; planning. ;;; Code: (require 'magit) (require 'ghub) ;;; Variables (defvar magit-github-token-scopes '(repo) "The Github API scopes needed by Magit. `repo' is the only required scope. Without this scope none of Magit's features that use the API work. Instead of this scope you could use `public_repo' if you are only interested in public repositories. `repo' Grants read/write access to code, commit statuses, invitations, collaborators, adding team memberships, and deployment statuses for public and private repositories and organizations. `public_repo' Grants read/write access to code, commit statuses, collaborators, and deployment statuses for public repositories and organizations. Also required for starring public repositories.") ;;; Commands ;;;###autoload (defun magit-browse-pull-request (pr) "Visit pull-request PR using `browse-url'. Currently this only supports Github, but that restriction will be lifted eventually to support other Git forges." (interactive (list (magit-read-pull-request "Visit pull request"))) (browse-url (format "https://github.com/%s/pull/%s" (--> pr (cdr (assq 'base it)) (cdr (assq 'repo it)) (cdr (assq 'full_name it))) (cdr (assq 'number pr))))) ;;; Utilities (defun magit-read-pull-request (prompt) "Read a pull request from the user, prompting with PROMPT. Return the Git forge's API response. Currently this function only supports Github, but that will change eventually." (let* ((origin (magit-upstream-repository)) (id (magit--forge-id origin)) (fmtfun (lambda (pull-request) (format "%s %s" (cdr (assq 'number pull-request)) (cdr (assq 'title pull-request))))) (prs (ghub-get (format "/repos/%s/pulls" id) nil :auth 'magit)) (choice (magit-completing-read prompt (mapcar fmtfun prs) nil nil nil nil (let ((default (thing-at-point 'github-pull-request))) (and default (funcall fmtfun default))))) (number (and (string-match "\\([0-9]+\\)" choice) (string-to-number (match-string 1 choice))))) (and number ;; Don't reuse the pr from the list, it lacks some information ;; that is only returned when requesting a single pr. #3371 (ghub-get (format "/repos/%s/pulls/%s" id number) nil :auth 'magit)))) (defun magit-upstream-repository () "Return the remote name of the upstream repository. If the Git variable `magit.upstream' is set, then return its value. Otherwise return \"origin\". If the remote does not exist, then raise an error." (let ((remote (or (magit-get "magit.upstream") "origin"))) (unless (magit-remote-p remote) (error "No remote named `%s' exists (consider setting `magit.upstream')" remote)) (unless (magit--github-remote-p remote) (error "Currently only Github is supported")) remote)) (defun magit--forge-id (remote) (let ((url (magit-get "remote" remote "url"))) (and (string-match "\\([^:/]+/[^/]+?\\)\\(?:\\.git\\)?\\'" url) (match-string 1 url)))) (defconst magit--github-url-regexp "\ \\`\\(?:git://\\|git@\\|ssh://git@\\|https://\\)\ \\(.*?\\)[/:]\ \\(\\([^:/]+\\)/\\([^/]+?\\)\\)\ \\(?:\\.git\\)?\\'") (defun magit--github-url-p (url) (save-match-data (and url (string-match magit--github-url-regexp url) (let ((host (match-string 1 url))) ;; Match values like "github.com-as-someone", which are ;; translated to just "github.com" according to settings ;; in "~/.ssh/config". Theoretically this could result ;; in false-positives, but that's rather unlikely. #3392 (and (or (string-match-p (regexp-quote "github.com") host) (string-match-p (regexp-quote (car (split-string (ghub--host) "/"))) host)) host))))) (defun magit--github-remote-p (remote) (or (--when-let (magit-git-string "remote" "get-url" "--push" remote) (magit--github-url-p it)) (--when-let (magit-git-string "remote" "get-url" "--all" remote) (magit--github-url-p it)))) (defun magit--github-url-equal (r1 r2) (or (equal r1 r2) (save-match-data (let ((n1 (and (string-match magit--github-url-regexp r1) (match-string 2 r1))) (n2 (and (string-match magit--github-url-regexp r2) (match-string 2 r2)))) (and n1 n2 (equal n1 n2)))))) (defun magit--pullreq-from-upstream-p (pr) (let-alist pr (equal .head.repo.full_name .base.repo.full_name))) (defun magit--pullreq-branch (pr &optional assert-new) (let-alist pr (let ((branch .head.ref)) (when (and (not (magit--pullreq-from-upstream-p pr)) (or (not .maintainer_can_modify) (magit-branch-p branch))) (setq branch (format "pr-%s" .number))) (when (and assert-new (magit-branch-p branch)) (user-error "Branch `%s' already exists" branch)) branch))) ;;; _ (provide 'magit-collab) ;;; magit-collab.el ends here magit-2.90.1/lisp/magit-commit.el000066400000000000000000000535711337354740400166110ustar00rootroot00000000000000;;; magit-commit.el --- create Git commits -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-arguments nil "The arguments used when committing." :group 'magit-git-arguments :type '(repeat (string :tag "Argument"))) (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 showing diff" verbose) (const :tag "Ask" t) (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-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 (defun magit-commit-popup (&optional arg) "Popup console for commit commands." (interactive "P") (--if-let (magit-commit-message-buffer) (switch-to-buffer it) (magit-invoke-popup 'magit-commit-popup nil arg))) (defvar magit-commit-popup '(:variable magit-commit-arguments :man-page "git-commit" :switches ((?a "Stage all modified and deleted files" "--all") (?e "Allow empty commit" "--allow-empty") (?v "Show diff of changes to be committed" "--verbose") (?h "Disable hooks" "--no-verify") (?s "Add Signed-off-by line" "--signoff") (?R "Claim authorship and reset author date" "--reset-author")) :options ((?A "Override the author" "--author=") (?S "Sign using gpg" "--gpg-sign=" magit-read-gpg-secret-key) (?C "Reuse commit message" "--reuse-message=" magit-read-reuse-message)) :actions ((?c "Commit" magit-commit-create) (?e "Extend" magit-commit-extend) (?f "Fixup" magit-commit-fixup) (?F "Instant Fixup" magit-commit-instant-fixup) nil (?w "Reword" magit-commit-reword) (?s "Squash" magit-commit-squash) (?S "Instant Squash" magit-commit-instant-squash) nil (?a "Amend" magit-commit-amend) (?A "Augment" magit-commit-augment)) :max-action-columns 4 :default-action magit-commit-create)) (magit-define-popup-keys-deferred 'magit-commit-popup) (defun magit-commit-arguments nil (if (eq magit-current-popup 'magit-commit-popup) magit-current-popup-args magit-commit-arguments)) (defvar magit-gpg-secret-key-hist nil) (defun magit-read-gpg-secret-key (prompt &optional _initial-input) (require 'epa) (let ((keys (--map (concat (epg-sub-key-id (car (epg-key-sub-key-list it))) " " (when-let ((id-obj (car (epg-key-user-id-list it)))) (let ((id-str (epg-user-id-string id-obj))) (if (stringp id-str) id-str (epg-decode-dn id-obj))))) (epg-list-keys (epg-make-context epa-protocol) nil t)))) (car (split-string (magit-completing-read prompt keys nil nil nil 'magit-gpg-secret-key-hist (car (or magit-gpg-secret-key-hist keys))) " ")))) (defun magit-read-reuse-message (prompt &optional default) (magit-completing-read prompt (magit-list-refnames) nil nil nil 'magit-revision-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)) (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") "" "true" nil t))) (format "Type %%p on a commit to %s into it," (substring option 2))) (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 (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-popup "magit-commit" nil t) (magit-define-popup magit-commit-absorb-popup "Spread unstaged changes across recent commits. Without a prefix argument just call `magit-commit-absorb'. With a prefix argument use a popup buffer to select arguments." :man-page "git-bisect" :options '((?c "Diff context lines" "--context=") (?s "Strictness" "--strict=")) :actions '((?x "Absorb" magit-commit-absorb)) :default-action 'magit-commit-absorb :use-prefix 'popup) (defun magit-commit-absorb (&optional commit args confirmed) "Spread unstaged changes across recent commits. This command requires the git-autofixup script, which is available from https://github.com/torbiak/git-autofixup." (interactive (list (magit-get-upstream-branch) (magit-commit-absorb-arguments))) (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 confirmed) (progn (magit-run-git-async "autofixup" "-vv" args commit) t) (magit-log-select (lambda (commit) (magit-commit-absorb commit args t)) nil nil nil nil commit))) ;;; Pending Diff (defun magit-commit-diff () (when (and git-commit-mode magit-commit-show-diff) (when-let ((diff-buffer (magit-mode-get-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)") (if-let ((fn (cl-case last-command (magit-commit (apply-partially 'magit-diff-staged nil)) (magit-commit-all (apply-partially 'magit-diff-working-tree nil)) ((magit-commit-amend magit-commit-reword magit-rebase-reword-commit) 'magit-diff-while-amending)))) (funcall fn args) (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) (let ((hunk (and (magit-section-match 'hunk) (magit-current-section))) (log (magit-commit-message-buffer)) buf pos) (save-window-excursion (call-interactively #'magit-diff-visit-file) (setq buf (current-buffer)) (setq pos (point))) (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))) (save-excursion (with-current-buffer buf (goto-char 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 magit-2.90.1/lisp/magit-core.el000066400000000000000000000107141337354740400162410ustar00rootroot00000000000000;;; magit-core.el --- core functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-autorevert) (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 "Miscellanous 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 'magit-popup 'custom-group) (custom-add-to-group 'magit-faces 'magit-popup-faces 'custom-group) (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 magit-2.90.1/lisp/magit-diff.el000066400000000000000000003440401337354740400162230ustar00rootroot00000000000000;;; magit-diff.el --- inspect Git diffs -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 diffs and ;; commits. ;;; Code: (eval-when-compile (require 'subr-x)) (require 'git-commit) (require 'magit-core) ;; For `magit-diff-popup' (declare-function magit-stash-show "magit-stash" (stash &optional args files)) ;; For `magit-diff-visit-file' (declare-function dired-jump "dired-x" (&optional other-window file-name)) (declare-function magit-find-file-noselect "magit-files" (rev file)) (declare-function magit-status-internal "magit-status" (directory)) ;; For `magit-diff-while-committing' (declare-function magit-commit-message-buffer "magit-commit" ()) ;; For `magit-insert-revision-gravatar' (defvar gravatar-size) ;; For `magit-show-commit' and `magit-diff-show-or-scroll' (declare-function magit-current-blame-chunk "magit-blame" ()) (eval-when-compile (cl-pushnew 'orig-rev eieio--known-slot-names)) (declare-function magit-blame-mode "magit-blame" (&optional arg)) (defvar magit-blame-mode) (defvar git-rebase-line) ;; For `magit-diff-unmerged' (declare-function magit-merge-in-progress-p "magit-merge" ()) (declare-function magit--merge-range "magit-merge" (&optional head)) (require 'diff-mode) (require 'smerge-mode) (defvar bookmark-make-record-function) ;;; Options ;;;; Diff Mode (defgroup magit-diff nil "Inspect and manipulate Git diffs." :link '(info-link "(magit)Diffing") :group 'magit-modes) (defcustom magit-diff-mode-hook nil "Hook run after entering Magit-Diff mode." :group 'magit-diff :type 'hook) (defcustom magit-diff-arguments '("--stat" "--no-ext-diff") "The diff arguments used in buffers whose mode derives from `magit-diff-mode'." :group 'magit-git-arguments :group 'magit-diff :type '(repeat (string :tag "Argument"))) (defcustom magit-diff-sections-hook '(magit-insert-diff magit-insert-xref-buttons) "Hook run to insert sections into a `magit-diff-mode' buffer." :package-version '(magit . "2.3.0") :group 'magit-diff :type 'hook) (defcustom magit-diff-expansion-threshold 60 "After how many seconds not to expand anymore diffs. Except in status buffers, diffs are usually start out fully expanded. Because that can take a long time, all diffs that haven't been fontified during a refresh before the threshold defined here are instead displayed with their bodies collapsed. Note that this can cause sections that were previously expanded to be collapsed. So you should not pick a very low value here. The hook function `magit-diff-expansion-threshold' has to be a member of `magit-section-set-visibility-hook' for this option to have any effect." :package-version '(magit . "2.9.0") :group 'magit-diff :type 'float) (defcustom magit-diff-highlight-hunk-body t "Whether to highlight bodies of selected hunk sections. This only has an effect if `magit-diff-highlight' is a member of `magit-section-highlight-hook', which see." :package-version '(magit . "2.1.0") :group 'magit-diff :type 'boolean) (defcustom magit-diff-highlight-hunk-region-functions '(magit-diff-highlight-hunk-region-dim-outside magit-diff-highlight-hunk-region-using-overlays) "The functions used to highlight the hunk-internal region. `magit-diff-highlight-hunk-region-dim-outside' overlays the outside of the hunk internal selection with a face that causes the added and removed lines to have the same background color as context lines. This function should not be removed from the value of this option. `magit-diff-highlight-hunk-region-using-overlays' and `magit-diff-highlight-hunk-region-using-underline' emphasize the region by placing delimiting horizonal lines before and after it. The underline variant was implemented because Eli said that is how we should do it. However the overlay variant actually works better. Also see https://github.com/magit/magit/issues/2758. Instead of, or in addition to, using delimiting horizontal lines, to emphasize the boundaries, you may which to emphasize the text itself, using `magit-diff-highlight-hunk-region-using-face'. In terminal frames it's not possible to draw lines as the overlay and underline variants normally do, so there they fall back to calling the face function instead." :package-version '(magit . "2.9.0") :set-after '(magit-diff-show-lines-boundaries) :group 'magit-diff :type 'hook :options '(magit-diff-highlight-hunk-region-dim-outside magit-diff-highlight-hunk-region-using-underline magit-diff-highlight-hunk-region-using-overlays magit-diff-highlight-hunk-region-using-face)) (defcustom magit-diff-unmarked-lines-keep-foreground t "Whether `magit-diff-highlight-hunk-region-dim-outside' preserves foreground. When this is set to nil, then that function only adjusts the foreground color but added and removed lines outside the region keep their distinct foreground colors." :package-version '(magit . "2.9.0") :group 'magit-diff :type 'boolean) (defcustom magit-diff-refine-hunk nil "Whether to show word-granularity differences within diff hunks. nil never show fine differences. t show fine differences for the current diff hunk only. `all' show fine differences for all displayed diff hunks." :group 'magit-diff :safe (lambda (val) (memq val '(nil t all))) :type '(choice (const :tag "Never" nil) (const :tag "Current" t) (const :tag "All" all))) (put 'magit-diff-refine-hunk 'permanent-local t) (defcustom magit-diff-adjust-tab-width nil "Whether to adjust the width of tabs in diffs. Determining the correct width can be expensive if it requires opening large and/or many files, so the widths are cached in the variable `magit-diff--tab-width-cache'. Set that to nil to invalidate the cache. nil Never ajust tab width. Use `tab-width's value from the Magit buffer itself instead. t If the corresponding file-visiting buffer exits, then use `tab-width's value from that buffer. Doing this is cheap, so this value is used even if a corresponding cache entry exists. `always' If there is no such buffer, then temporarily visit the file to determine the value. NUMBER Like `always', but don't visit files larger than NUMBER bytes." :package-version '(magit . "2.12.0") :group 'magit-diff :type '(choice (const :tag "Never" nil) (const :tag "If file-visiting buffer exists" t) (const :tag "... or file isn't larger than bytes" all) (const :tag "Always" always))) (defcustom magit-diff-paint-whitespace t "Specify where to highlight whitespace errors. See `magit-diff-highlight-trailing', `magit-diff-highlight-indentation'. The symbol t means in all diffs, `status' means only in the status buffer, and nil means nowhere." :group 'magit-diff :safe (lambda (val) (memq val '(t nil status))) :type '(choice (const :tag "Always" t) (const :tag "Never" nil) (const :tag "In status buffer" status))) (defcustom magit-diff-highlight-trailing t "Whether to highlight whitespace at the end of a line in diffs. Used only when `magit-diff-paint-whitespace' is non-nil." :group 'magit-diff :safe 'booleanp :type 'boolean) (defcustom magit-diff-highlight-indentation nil "Highlight the \"wrong\" indentation style. Used only when `magit-diff-paint-whitespace' is non-nil. The value is a list of cons cells. The car is a regular expression, and the cdr is the value that applies to repositories whose directory matches the regular expression. If more than one element matches, then the *last* element in the list applies. The default value should therefore come first in the list. If the value is `tabs', highlight indentation with tabs. If the value is an integer, highlight indentation with at least that many spaces. Otherwise, highlight neither." :group 'magit-diff :type `(repeat (cons (string :tag "Directory regexp") (choice (const :tag "Tabs" tabs) (integer :tag "Spaces" :value ,tab-width) (const :tag "Neither" nil))))) (defcustom magit-diff-hide-trailing-cr-characters (and (memq system-type '(ms-dos windows-nt)) t) "Whether to hide ^M characters at the end of a line in diffs." :package-version '(magit . "2.6.0") :group 'magit-diff :type 'boolean) (defcustom magit-diff-visit-previous-blob t "Whether `magit-diff-visit-file' may visit the previous blob. When this is t and point is on a removed line in a diff for a committed change, then `magit-diff-visit-file' visits the blob from the last revision which still had that line. Currently this is only supported for committed changes, for staged and unstaged changes `magit-diff-visit-file' always visits the file in the working tree." :package-version '(magit . "2.9.0") :group 'magit-diff :type 'boolean) (defcustom magit-diff-highlight-keywords t "Whether to highlight bracketed keywords in commit messages." :package-version '(magit . "2.12.0") :group 'magit-diff :type 'boolean) ;;;; File Diff (defcustom magit-diff-buffer-file-locked t "Whether `magit-diff-buffer-file' uses a dedicated buffer." :package-version '(magit . "2.7.0") :group 'magit-commands :group 'magit-diff :type 'boolean) ;;;; Revision Mode (defgroup magit-revision nil "Inspect and manipulate Git commits." :link '(info-link "(magit)Revision Buffer") :group 'magit-modes) (defcustom magit-revision-mode-hook '(bug-reference-mode) "Hook run after entering Magit-Revision mode." :group 'magit-revision :type 'hook :options '(bug-reference-mode)) (defcustom magit-revision-sections-hook '(magit-insert-revision-tag magit-insert-revision-headers magit-insert-revision-message magit-insert-revision-notes magit-insert-revision-diff magit-insert-xref-buttons) "Hook run to insert sections into a `magit-revision-mode' buffer." :package-version '(magit . "2.3.0") :group 'magit-revision :type 'hook) (defcustom magit-revision-headers-format "\ Author: %aN <%aE> AuthorDate: %ad Commit: %cN <%cE> CommitDate: %cd " "Format string used to insert headers in revision buffers. All headers in revision buffers are inserted by the section inserter `magit-insert-revision-headers'. Some of the headers are created by calling `git show --format=FORMAT' where FORMAT is the format specified here. Other headers are hard coded or subject to option `magit-revision-insert-related-refs'." :package-version '(magit . "2.3.0") :group 'magit-revision :type 'string) (defcustom magit-revision-insert-related-refs t "Whether to show related branches in revision buffers `nil' Don't show any related branches. `t' Show related local branches. `all' Show related local and remote branches. `mixed' Show all containing branches and local merged branches." :package-version '(magit . "2.1.0") :group 'magit-revision :type '(choice (const :tag "don't" nil) (const :tag "local only" t) (const :tag "all related" all) (const :tag "all containing, local merged" mixed))) (defcustom magit-revision-use-hash-sections 'quicker "Whether to turn hashes inside the commit message into sections. If non-nil, then hashes inside the commit message are turned into `commit' sections. There is a trade off to be made between performance and reliability: - `slow' calls git for every word to be absolutely sure. - `quick' skips words less than seven characters long. - `quicker' additionally skips words that don't contain a number. - `quickest' uses all words that are at least seven characters long and which contain at least one number as well as at least one letter. If nil, then no hashes are turned into sections, but you can still visit the commit at point using \"RET\"." :package-version '(magit . "2.12.0") :group 'magit-revision :type '(choice (const :tag "Use sections, quickest" quickest) (const :tag "Use sections, quicker" quicker) (const :tag "Use sections, quick" quick) (const :tag "Use sections, slow" slow) (const :tag "Don't use sections" nil))) (defcustom magit-revision-show-gravatars nil "Whether to show gravatar images in revision buffers. If nil, then don't insert any gravatar images. If t, then insert both images. If `author' or `committer', then insert only the respective image. If you have customized the option `magit-revision-header-format' and want to insert the images then you might also have to specify where to do so. In that case the value has to be a cons-cell of two regular expressions. The car specifies where to insert the author's image. The top half of the image is inserted right after the matched text, the bottom half on the next line in the same column. The cdr specifies where to insert the committer's image, accordingly. Either the car or the cdr may be nil." :package-version '(magit . "2.3.0") :group 'magit-revision :type '(choice (const :tag "Don't show gravatars" nil) (const :tag "Show gravatars" t) (const :tag "Show author gravatar" author) (const :tag "Show committer gravatar" committer) (cons :tag "Show gravatars using custom pattern." (regexp :tag "Author regexp" "^Author: ") (regexp :tag "Committer regexp" "^Commit: ")))) (defcustom magit-revision-use-gravatar-kludge nil "Whether to work around a bug which affects display of gravatars. Gravatar images are spliced into two halves which are then displayed on separate lines. On OS X the splicing has a bug in some Emacs builds, which causes the top and bottom halves to be interchanged. Enabling this option works around this issue by interchanging the halves once more, which cancels out the effect of the bug. See https://github.com/magit/magit/issues/2265 and https://debbugs.gnu.org/cgi/bugreport.cgi?bug=7847. Starting with Emacs 26.1 this kludge should not be required for any build." :package-version '(magit . "2.3.0") :group 'magit-revision :type 'boolean) (defcustom magit-revision-fill-summary-line nil "Whether to fill excessively long summary lines. If this is an integer, then the summary line is filled if it is longer than either the limit specified here or `window-width'. You may want to only set this locally in \".dir-locals-2.el\" for repositories known to contain bad commit messages. The body of the message is left alone because (a) most people who write excessively long summary lines usually don't add a body and (b) even people who have the decency to wrap their lines may have a good reason to include a long line in the body sometimes." :package-version '(magit . "2.90.0") :group 'magit-revision :type '(choice (const :tag "Don't fill" nil) (integer :tag "Fill if longer than"))) ;;;; Diff Sections (defcustom magit-diff-section-arguments '("--no-ext-diff") "The diff arguments used in buffers that show other things besides diffs." :group 'magit-git-arguments :group 'magit-diff :group 'magit-status :type '(repeat (string :tag "Argument"))) (put 'magit-diff-section-arguments 'permanent-local t) ;;; Faces (defface magit-diff-file-heading '((t :weight bold)) "Face for diff file headings." :group 'magit-faces) (defface magit-diff-file-heading-highlight '((t :inherit (magit-section-highlight))) "Face for current diff file headings." :group 'magit-faces) (defface magit-diff-file-heading-selection '((((class color) (background light)) :inherit magit-diff-file-heading-highlight :foreground "salmon4") (((class color) (background dark)) :inherit magit-diff-file-heading-highlight :foreground "LightSalmon3")) "Face for selected diff file headings." :group 'magit-faces) (defface magit-diff-hunk-heading '((((class color) (background light)) :background "grey80" :foreground "grey30") (((class color) (background dark)) :background "grey25" :foreground "grey70")) "Face for diff hunk headings." :group 'magit-faces) (defface magit-diff-hunk-heading-highlight '((((class color) (background light)) :background "grey75" :foreground "grey30") (((class color) (background dark)) :background "grey35" :foreground "grey70")) "Face for current diff hunk headings." :group 'magit-faces) (defface magit-diff-hunk-heading-selection '((((class color) (background light)) :inherit magit-diff-hunk-heading-highlight :foreground "salmon4") (((class color) (background dark)) :inherit magit-diff-hunk-heading-highlight :foreground "LightSalmon3")) "Face for selected diff hunk headings." :group 'magit-faces) (defface magit-diff-hunk-region '((t :inherit bold)) "Face used by `magit-diff-highlight-hunk-region-using-face'. This face is overlayed over text that uses other hunk faces, and those normally set the foreground and background colors. The `:foreground' and especially the `:background' properties should be avoided here. Setting the latter would cause the lose of information. Good properties to set here are `:weight' and `:slant'." :group 'magit-faces) (defface magit-diff-lines-heading '((((class color) (background light)) :inherit magit-diff-hunk-heading-highlight :background "LightSalmon3") (((class color) (background dark)) :inherit magit-diff-hunk-heading-highlight :foreground "grey80" :background "salmon4")) "Face for diff hunk heading when lines are marked." :group 'magit-faces) (defface magit-diff-lines-boundary '((t :inherit magit-diff-lines-heading)) "Face for boundary of marked lines in diff hunk." :group 'magit-faces) (defface magit-diff-conflict-heading '((t :inherit magit-diff-hunk-heading)) "Face for conflict markers." :group 'magit-faces) (defface magit-diff-added '((((class color) (background light)) :background "#ddffdd" :foreground "#22aa22") (((class color) (background dark)) :background "#335533" :foreground "#ddffdd")) "Face for lines in a diff that have been added." :group 'magit-faces) (defface magit-diff-removed '((((class color) (background light)) :background "#ffdddd" :foreground "#aa2222") (((class color) (background dark)) :background "#553333" :foreground "#ffdddd")) "Face for lines in a diff that have been removed." :group 'magit-faces) (defface magit-diff-our '((t :inherit magit-diff-removed)) "Face for lines in a diff for our side in a conflict." :group 'magit-faces) (defface magit-diff-base '((((class color) (background light)) :background "#ffffcc" :foreground "#aaaa11") (((class color) (background dark)) :background "#555522" :foreground "#ffffcc")) "Face for lines in a diff for the base side in a conflict." :group 'magit-faces) (defface magit-diff-their '((t :inherit magit-diff-added)) "Face for lines in a diff for their side in a conflict." :group 'magit-faces) (defface magit-diff-context '((((class color) (background light)) :foreground "grey50") (((class color) (background dark)) :foreground "grey70")) "Face for lines in a diff that are unchanged." :group 'magit-faces) (defface magit-diff-added-highlight '((((class color) (background light)) :background "#cceecc" :foreground "#22aa22") (((class color) (background dark)) :background "#336633" :foreground "#cceecc")) "Face for lines in a diff that have been added." :group 'magit-faces) (defface magit-diff-removed-highlight '((((class color) (background light)) :background "#eecccc" :foreground "#aa2222") (((class color) (background dark)) :background "#663333" :foreground "#eecccc")) "Face for lines in a diff that have been removed." :group 'magit-faces) (defface magit-diff-our-highlight '((t :inherit magit-diff-removed-highlight)) "Face for lines in a diff for our side in a conflict." :group 'magit-faces) (defface magit-diff-base-highlight '((((class color) (background light)) :background "#eeeebb" :foreground "#aaaa11") (((class color) (background dark)) :background "#666622" :foreground "#eeeebb")) "Face for lines in a diff for the base side in a conflict." :group 'magit-faces) (defface magit-diff-their-highlight '((t :inherit magit-diff-added-highlight)) "Face for lines in a diff for their side in a conflict." :group 'magit-faces) (defface magit-diff-context-highlight '((((class color) (background light)) :background "grey95" :foreground "grey50") (((class color) (background dark)) :background "grey20" :foreground "grey70")) "Face for lines in the current context in a diff." :group 'magit-faces) (defface magit-diff-whitespace-warning '((t :inherit trailing-whitespace)) "Face for highlighting whitespace errors added lines." :group 'magit-faces) (defface magit-diffstat-added '((((class color) (background light)) :foreground "#22aa22") (((class color) (background dark)) :foreground "#448844")) "Face for plus sign in diffstat." :group 'magit-faces) (defface magit-diffstat-removed '((((class color) (background light)) :foreground "#aa2222") (((class color) (background dark)) :foreground "#aa4444")) "Face for minus sign in diffstat." :group 'magit-faces) ;;; Commands ;;;; Diff popups (defconst magit-diff-popup-common-keywords '(:variable magit-diff-arguments :man-page "git-diff")) (defconst magit-diff-popup-common-options '((?f "Limit to files" "-- " magit-read-files) (?u "Context lines" "-U") (?m "Detect renames" "-M") (?c "Detect copies" "-C") (?a "Diff algorithm" "--diff-algorithm=" magit-diff-select-algorithm) (?i "Ignore submodules" "--ignore-submodules=" magit-diff-select-ignore-submodules))) (defconst magit-diff-popup-common-switches '((?f "Show surrounding functions" "--function-context") (?b "Ignore whitespace changes" "--ignore-space-change") (?w "Ignore all whitespace" "--ignore-all-space") (?x "Disallow external diff drivers" "--no-ext-diff"))) (defvar magit-diff-popup `(,@magit-diff-popup-common-keywords :options ,magit-diff-popup-common-options :switches (,@magit-diff-popup-common-switches (?s "Show stats" "--stat")) :actions ((?d "Dwim" magit-diff-dwim) (?u "Diff unstaged" magit-diff-unstaged) (?c "Show commit" magit-show-commit) (?r "Diff range" magit-diff-range) (?s "Diff staged" magit-diff-staged) (?t "Show stash" magit-stash-show) (?p "Diff paths" magit-diff-paths) (?w "Diff worktree" magit-diff-working-tree)) :default-action magit-diff-dwim :max-action-columns 3)) (defvar magit-diff-refresh-popup `(,@magit-diff-popup-common-keywords :options ,magit-diff-popup-common-options :switches ,magit-diff-popup-common-switches :actions ((?g "Refresh" magit-diff-refresh) (?t "Toggle hunk refinement" magit-diff-toggle-refine-hunk) (?s "Set defaults" magit-diff-set-default-arguments) (?F "Toggle file filter" magit-diff-toggle-file-filter) (?w "Save defaults" magit-diff-save-default-arguments)) :max-action-columns 2)) (defvar magit-diff-mode-refresh-popup `(,@magit-diff-popup-common-keywords :options ,magit-diff-popup-common-options :switches (,@magit-diff-popup-common-switches (?s "Show stats" "--stat")) :actions ((?g "Refresh" magit-diff-refresh) (?t "Toggle hunk refinement" magit-diff-toggle-refine-hunk) (?s "Set defaults" magit-diff-set-default-arguments) (?r "Switch range type" magit-diff-switch-range-type) (?w "Save defaults" magit-diff-save-default-arguments) (?f "Flip revisions" magit-diff-flip-revs) nil (?F "Toggle file filter" magit-diff-toggle-file-filter)) :max-action-columns 2)) (defvar magit-revision-mode-refresh-popup `(,@magit-diff-popup-common-keywords :options ,magit-diff-popup-common-options :switches (,@magit-diff-popup-common-switches (?s "Show stats" "--stat")) :actions ((?g "Refresh" magit-diff-refresh) (?t "Toggle hunk refinement" magit-diff-toggle-refine-hunk) (?s "Set defaults" magit-diff-set-default-arguments) (?F "Toggle file filter" magit-diff-toggle-file-filter) (?w "Save defaults" magit-diff-save-default-arguments)) :max-action-columns 2)) (magit-define-popup-keys-deferred 'magit-diff-popup) (magit-define-popup-keys-deferred 'magit-diff-refresh-popup) (magit-define-popup-keys-deferred 'magit-diff-mode-refresh-popup) (magit-define-popup-keys-deferred 'magit-revision-mode-refresh-popup) (defvar magit-diff-section-file-args nil) (put 'magit-diff-section-file-args 'permanent-local t) (put 'magit-diff-section-file-args 'safe-local-variable (lambda (val) (and (listp val) (-all-p #'stringp val)))) (defun magit-diff-get-buffer-args () (cond ((and magit-use-sticky-arguments (derived-mode-p 'magit-diff-mode)) (list (nth 2 magit-refresh-args) (nth 3 magit-refresh-args))) ((and (eq magit-use-sticky-arguments t) (--when-let (magit-mode-get-buffer 'magit-diff-mode) (with-current-buffer it (list (nth 2 magit-refresh-args) (nth 3 magit-refresh-args)))))) (t (list (default-value 'magit-diff-arguments) nil)))) (defun magit-diff-arguments (&optional refresh) (cond ((memq magit-current-popup '(magit-diff-popup magit-diff-refresh-popup)) (magit-popup-export-file-args magit-current-popup-args)) ((and refresh (not (derived-mode-p 'magit-diff-mode))) (list magit-diff-section-arguments magit-diff-section-file-args)) (t (magit-diff-get-buffer-args)))) ;;;###autoload (defun magit-diff-popup (arg) "Popup console for diff commands." (interactive "P") (let ((magit-diff-arguments ;; We cannot possibly know what suffix command the user is ;; about to invoke, so we also don't know from which buffer ;; we should get the current values. However it is much ;; more likely that we will end up updating the diff buffer, ;; and we therefore use the value from that buffer. (apply #'magit-popup-import-file-args (magit-diff-get-buffer-args)))) (magit-invoke-popup 'magit-diff-popup nil arg))) ;;;###autoload (defun magit-diff-buffer-file-popup () "Popup console for diff commands. This is a variant of `magit-diff-popup' which shows the same popup but which limits the diff to the file being visited in the current buffer." (interactive) (if-let ((file (magit-file-relative-name))) (let ((magit-diff-arguments (magit-popup-import-file-args (if-let ((buffer (magit-mode-get-buffer 'magit-diff-mode))) (with-current-buffer buffer (nth 3 magit-refresh-args)) (default-value 'magit-diff-arguments)) (list file)))) (magit-invoke-popup 'magit-diff-popup nil nil)) (user-error "Buffer isn't visiting a file"))) (defun magit-diff-refresh-popup (arg) "Popup console for changing diff arguments in the current buffer." (interactive "P") (let ((magit-diff-refresh-popup (pcase major-mode (`magit-revision-mode magit-revision-mode-refresh-popup) (`magit-diff-mode magit-diff-mode-refresh-popup) (_ magit-diff-refresh-popup))) (magit-diff-arguments (if (derived-mode-p 'magit-diff-mode) (magit-popup-import-file-args (nth 2 magit-refresh-args) (nth 3 magit-refresh-args)) (magit-popup-import-file-args magit-diff-section-arguments magit-diff-section-file-args)))) (magit-invoke-popup 'magit-diff-refresh-popup nil arg))) (defun magit-diff-select-algorithm (&rest _ignore) (magit-read-char-case nil t (?d "[d]efault" "default") (?m "[m]inimal" "minimal") (?p "[p]atience" "patience") (?h "[h]istogram" "histogram"))) (defun magit-diff-select-ignore-submodules (&rest _ignored) (magit-read-char-case "Ignore submodules " t (?u "[u]ntracked" "untracked") (?d "[d]irty" "dirty") (?a "[a]ll" "all"))) ;;;; Diff commands ;;;###autoload (defun magit-diff-dwim (&optional args files) "Show changes for the thing at point." (interactive (magit-diff-arguments)) (pcase (magit-diff--dwim) (`unmerged (magit-diff-unmerged args files)) (`unstaged (magit-diff-unstaged args files)) (`staged (let ((file (magit-file-at-point))) (if (and file (equal (cddr (car (magit-file-status file))) '(?D ?U))) ;; File was deleted by us and modified by them. Show the latter. (magit-diff-unmerged args (list file)) (magit-diff-staged nil args files)))) (`(commit . ,value) (magit-diff-range (format "%s^..%s" value value) args files)) (`(stash . ,value) (magit-stash-show value args)) ((and range (pred stringp)) (magit-diff-range range args files)) (_ (call-interactively #'magit-diff-range)))) (defun magit-diff--dwim () "Return information for performing DWIM diff. The information can be in three forms: 1. TYPE A symbol describing a type of diff where no additional information is needed to generate the diff. Currently, this includes `staged', `unstaged' and `unmerged'. 2. (TYPE . VALUE) Like #1 but the diff requires additional information, which is given by VALUE. Currently, this includes `commit' and `stash', where VALUE is the given commit or stash, respectively. 3. RANGE A string indicating a diff range. If no DWIM context is found, nil is returned." (cond ((--when-let (magit-region-values '(commit branch) t) (deactivate-mark) (concat (car (last it)) ".." (car it)))) (magit-buffer-refname (cons 'commit magit-buffer-refname)) ((derived-mode-p 'magit-stash-mode) (cons 'commit (magit-section-case (commit (oref it value)) (file (-> it (oref parent) (oref value))) (hunk (-> it (oref parent) (oref parent) (oref value)))))) ((derived-mode-p 'magit-revision-mode) (cons 'commit (car magit-refresh-args))) ((derived-mode-p 'magit-diff-mode) (nth 0 magit-refresh-args)) (t (magit-section-case ([* unstaged] 'unstaged) ([* staged] 'staged) (unmerged 'unmerged) (unpushed (oref it value)) (unpulled (oref it value)) (branch (let ((current (magit-get-current-branch)) (atpoint (oref it value))) (if (equal atpoint current) (--if-let (magit-get-upstream-branch) (format "%s...%s" it current) (if (magit-anything-modified-p) current (cons 'commit current))) (format "%s...%s" (or current "HEAD") atpoint)))) (commit (cons 'commit (oref it value))) (stash (cons 'stash (oref it value))))))) (defun magit-diff-read-range-or-commit (prompt &optional secondary-default mbase) "Read range or revision with special diff range treatment. If MBASE is non-nil, prompt for which rev to place at the end of a \"revA...revB\" range. Otherwise, always construct \"revA..revB\" range." (--if-let (magit-region-values '(commit branch) t) (let ((revA (car (last it))) (revB (car it))) (deactivate-mark) (if mbase (let ((base (magit-git-string "merge-base" revA revB))) (cond ((string= (magit-rev-parse revA) base) (format "%s..%s" revA revB)) ((string= (magit-rev-parse revB) base) (format "%s..%s" revB revA)) (t (let ((main (magit-completing-read "View changes along" (list revA revB) nil t nil nil revB))) (format "%s...%s" (if (string= main revB) revA revB) main))))) (format "%s..%s" revA revB))) (magit-read-range prompt (or (pcase (magit-diff--dwim) (`(commit . ,value) (format "%s^..%s" value value)) ((and range (pred stringp)) range)) secondary-default (magit-get-current-branch))))) (defun magit-diff-setup (rev-or-range const args files) (require 'magit) (magit-mode-setup #'magit-diff-mode rev-or-range const args files)) ;;;###autoload (defun magit-diff-range (rev-or-range &optional args files) "Show differences between two commits. REV-OR-RANGE should be a range or a single revision. If it is a revision, then show changes in the working tree relative to that revision. If it is a range, but one side is omitted, then show changes relative to `HEAD'. If the region is active, use the revisions on the first and last line of the region as the two sides of the range. 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 (cons (magit-diff-read-range-or-commit "Diff for range" nil current-prefix-arg) (magit-diff-arguments))) (magit-diff-setup rev-or-range nil args files)) ;;;###autoload (defun magit-diff-working-tree (&optional rev args files) "Show changes between the current working tree and the `HEAD' commit. With a prefix argument show changes between the working tree and a commit read from the minibuffer." (interactive (cons (and current-prefix-arg (magit-read-branch-or-commit "Diff working tree and commit")) (magit-diff-arguments))) (magit-diff-setup (or rev "HEAD") nil args files)) ;;;###autoload (defun magit-diff-staged (&optional rev args files) "Show changes between the index and the `HEAD' commit. With a prefix argument show changes between the index and a commit read from the minibuffer." (interactive (cons (and current-prefix-arg (magit-read-branch-or-commit "Diff index and commit")) (magit-diff-arguments))) (magit-diff-setup rev (list "--cached") args files)) ;;;###autoload (defun magit-diff-unstaged (&optional args files) "Show changes between the working tree and the index." (interactive (magit-diff-arguments)) (magit-diff-setup nil nil args files)) ;;;###autoload (defun magit-diff-unmerged (&optional args files) "Show changes that are being merged." (interactive (magit-diff-arguments)) (unless (magit-merge-in-progress-p) (user-error "No merge is in progress")) (magit-diff-setup (magit--merge-range) nil args files)) ;;;###autoload (defun magit-diff-while-committing (&optional args) "While committing, show the changes that are about to be committed. While amending, invoking the command again toggles between showing just the new changes or all the changes that will be committed." (interactive (list (car (magit-diff-arguments)))) (unless (magit-commit-message-buffer) (user-error "No commit in progress")) (let ((magit-display-buffer-noselect t) (diff-buf (magit-mode-get-buffer 'magit-diff-mode))) (if (and diff-buf (get-buffer-window diff-buf)) (with-current-buffer diff-buf (pcase-let ((`(,rev ,arg . ,_) magit-refresh-args)) (cond ((and (equal rev "HEAD^") (equal arg '("--cached"))) (magit-diff-staged nil args)) ((and (equal rev nil) (equal arg '("--cached"))) (magit-diff-while-amending args)) ((magit-anything-staged-p) (magit-diff-staged nil args)) (t (magit-diff-while-amending args))))) (if (magit-anything-staged-p) (magit-diff-staged nil args) (magit-diff-while-amending args))))) (define-key git-commit-mode-map (kbd "C-c C-d") 'magit-diff-while-committing) (defun magit-diff-while-amending (&optional args) (magit-diff-setup "HEAD^" (list "--cached") args nil)) ;;;###autoload (defun magit-diff-buffer-file () "Show diff for the blob or file visited in the current buffer." (interactive) (require 'magit) (if-let ((file (magit-file-relative-name))) (magit-mode-setup-internal #'magit-diff-mode (list (or magit-buffer-refname (magit-get-current-branch) "HEAD") nil (cadr (magit-diff-arguments)) (list file)) magit-diff-buffer-file-locked) (user-error "Buffer isn't visiting a file"))) ;;;###autoload (defun magit-diff-paths (a b) "Show changes between any two files on disk." (interactive (list (read-file-name "First file: " nil nil t) (read-file-name "Second file: " nil nil t))) (magit-diff-setup nil (list "--no-index") nil (list (magit-convert-filename-for-git (expand-file-name a)) (magit-convert-filename-for-git (expand-file-name b))))) (defvar-local magit-buffer-revision-hash nil) (defun magit-show-commit--arguments () (pcase-let ((`(,args ,diff-files) (magit-diff-arguments))) (list args (if (derived-mode-p 'magit-log-mode) (and (not (member "--follow" (nth 1 magit-refresh-args))) (nth 2 magit-refresh-args)) diff-files)))) ;;;###autoload (defun magit-show-commit (rev &optional args files module) "Visit the revision at point in another buffer. If there is no revision at point or with a prefix argument prompt for a revision." (interactive (pcase-let* ((mcommit (magit-section-value-if 'module-commit)) (atpoint (or (and (bound-and-true-p magit-blame-mode) (oref (magit-current-blame-chunk) orig-rev)) mcommit (magit-branch-or-commit-at-point))) (`(,args ,files) (magit-show-commit--arguments))) (list (or (and (not current-prefix-arg) atpoint) (magit-read-branch-or-commit "Show commit" atpoint)) args files (and mcommit (magit-section-parent-value (magit-current-section)))))) (require 'magit) (magit-with-toplevel (when module (setq default-directory (expand-file-name (file-name-as-directory module)))) (unless (magit-rev-verify-commit rev) (user-error "%s is not a commit" rev)) (magit-mode-setup #'magit-revision-mode rev nil args files))) ;;;; Setting commands (defun magit-diff-refresh (args files) "Set the local diff arguments for the current buffer." (interactive (magit-diff-arguments t)) (cond ((derived-mode-p 'magit-diff-mode) (setcdr (cdr magit-refresh-args) (list args files))) (t (setq-local magit-diff-section-arguments args) (setq-local magit-diff-section-file-args files))) (magit-refresh)) (defun magit-diff-set-default-arguments (args files) "Set the global diff arguments for the current buffer." (interactive (magit-diff-arguments t)) (cond ((derived-mode-p 'magit-diff-mode) (customize-set-variable 'magit-diff-arguments args) (setcdr (cdr magit-refresh-args) (list args files))) (t (customize-set-variable 'magit-diff-section-arguments args) (kill-local-variable 'magit-diff-section-arguments) (kill-local-variable 'magit-diff-section-file-args))) (magit-refresh)) (defun magit-diff-save-default-arguments (args files) "Set and save the global diff arguments for the current buffer." (interactive (magit-diff-arguments t)) (cond ((derived-mode-p 'magit-diff-mode) (customize-save-variable 'magit-diff-arguments args) (setcdr (cdr magit-refresh-args) (list args files))) (t (customize-save-variable 'magit-diff-section-arguments args) (kill-local-variable 'magit-diff-section-arguments) (kill-local-variable 'magit-diff-section-file-args))) (magit-refresh)) (defun magit-diff-switch-range-type () "Convert diff range type. Change \"revA..revB\" to \"revB...revA\", or vice versa." (interactive) (let ((range (car magit-refresh-args))) (if (and range (derived-mode-p 'magit-diff-mode) (string-match magit-range-re range)) (progn (setcar magit-refresh-args (concat (match-string 1 range) (if (string= (match-string 2 range) "..") "..." "..") (match-string 3 range))) (magit-refresh)) (user-error "No range to change")))) (defun magit-diff-flip-revs () "Swap revisions in diff range. Change \"revA..revB\" to \"revB..revA\"." (interactive) (let ((range (car magit-refresh-args))) (if (and range (derived-mode-p 'magit-diff-mode) (string-match magit-range-re range)) (progn (setcar magit-refresh-args (concat (match-string 3 range) (match-string 2 range) (match-string 1 range))) (magit-refresh)) (user-error "No range to swap")))) (defvar-local magit-diff--last-file-args nil) (defun magit-diff--toggle-file-args (files) (cond (files (setq magit-diff--last-file-args files) nil) (magit-diff--last-file-args) (t (user-error "No diff file filter to toggle")))) (defun magit-diff-toggle-file-filter () "Toggle the file restriction of the current buffer's diffs. If the current buffer's mode is derived from `magit-log-mode', toggle the file restriction in the repository's revision buffer instead." (interactive) (--if-let (and (derived-mode-p 'magit-log-mode) (magit-mode-get-buffer 'magit-revision-mode)) (with-current-buffer it (setf (nth 3 magit-refresh-args) (magit-diff--toggle-file-args (nth 3 magit-refresh-args))) (magit-refresh)) (if (derived-mode-p 'magit-diff-mode) (setf (nth 3 magit-refresh-args) (magit-diff--toggle-file-args (nth 3 magit-refresh-args))) (setq-local magit-diff-section-file-args (magit-diff--toggle-file-args magit-diff-section-file-args))) (magit-refresh))) (defun magit-diff-less-context (&optional count) "Decrease the context for diff hunks by COUNT lines." (interactive "p") (magit-diff-set-context `(lambda (cur) (max 0 (- (or cur 0) ,count))))) (defun magit-diff-more-context (&optional count) "Increase the context for diff hunks by COUNT lines." (interactive "p") (magit-diff-set-context `(lambda (cur) (+ (or cur 0) ,count)))) (defun magit-diff-default-context () "Reset context for diff hunks to the default height." (interactive) (magit-diff-set-context #'ignore)) (defun magit-diff-set-context (fn) (let* ((def (--if-let (magit-get "diff.context") (string-to-number it) 3)) (val (car (magit-diff-arguments t))) (arg (--first (string-match "^-U\\([0-9]+\\)?$" it) val)) (num (--if-let (and arg (match-string 1 arg)) (string-to-number it) def)) (val (delete arg val)) (num (funcall fn num)) (arg (and num (not (= num def)) (format "-U%i" num))) (val (if arg (cons arg val) val))) (if (derived-mode-p 'magit-diff-mode) (setcar (cddr magit-refresh-args) val) (setq magit-diff-section-arguments val))) (magit-refresh)) (defun magit-diff-context-p () (--if-let (--first (string-match "^-U\\([0-9]+\\)$" it) (car (magit-diff-arguments t))) (not (equal "-U0" it)) t)) (defun magit-diff-ignore-any-space-p () (let ((args (car (magit-diff-arguments t)))) (--any-p (member it args) '("--ignore-cr-at-eol" "--ignore-space-at-eol" "--ignore-space-change" "-b" "--ignore-all-space" "-w" "--ignore-blank-space")))) (defun magit-diff-toggle-refine-hunk (&optional style) "Turn diff-hunk refining on or off. If hunk refining is currently on, then hunk refining is turned off. If hunk refining is off, then hunk refining is turned on, in `selected' mode (only the currently selected hunk is refined). With a prefix argument, the \"third choice\" is used instead: If hunk refining is currently on, then refining is kept on, but the refining mode (`selected' or `all') is switched. If hunk refining is off, then hunk refining is turned on, in `all' mode (all hunks refined). Customize variable `magit-diff-refine-hunk' to change the default mode." (interactive "P") (setq-local magit-diff-refine-hunk (if style (if (eq magit-diff-refine-hunk 'all) t 'all) (not magit-diff-refine-hunk))) (magit-diff-update-hunk-refinement)) ;;;; Visit commands (defun magit-diff-visit-file (file &optional other-window force-worktree display-fn) "From a diff, visit the corresponding file at the appropriate position. If the diff shows changes in the worktree, the index, or `HEAD', then visit the actual file. Otherwise, when the diff is about an older commit or a range, then visit the appropriate blob. If point is on a removed line, then visit the blob for the first parent of the commit which removed that line, i.e. the last commit where that line still existed. Otherwise visit the blob for the commit whose changes are being shown. Interactively, when the file or blob to be displayed is already being displayed in another window of the same frame, then just select that window and adjust point. Otherwise, or with a prefix argument, display the buffer in another window. The meaning of the prefix argument can be inverted or further modified using the option `magit-display-file-buffer-function'. Non-interactively the optional OTHER-WINDOW argument is taken literally. DISPLAY-FN can be used to specify the display function explicitly, in which case OTHER-WINDOW is ignored. The optional FORCE-WORKTREE means to force visiting the worktree version of the file. To do this interactively use the command `magit-diff-visit-file-worktree' instead." (interactive (list (--if-let (magit-file-at-point) (expand-file-name it) (user-error "No file at point")) current-prefix-arg)) (if (magit-file-accessible-directory-p file) (magit-diff-visit-directory file other-window) (let* ((hunk (magit-diff-visit--hunk)) (last (and magit-diff-visit-previous-blob (not force-worktree) (magit-section-match 'hunk) (save-excursion (goto-char (line-beginning-position)) (looking-at "-")))) (line (and hunk (magit-diff-hunk-line hunk))) (col (and hunk (magit-diff-hunk-column hunk last))) (rev (if last (magit-diff-visit--range-beginning) (magit-diff-visit--range-end))) (buf (if (and (not force-worktree) (stringp rev)) (magit-find-file-noselect rev file) (or (get-file-buffer file) (find-file-noselect file))))) (cond ((called-interactively-p 'any) (magit-display-file-buffer buf)) (display-fn (funcall display-fn buf)) ((or other-window (get-buffer-window buf)) (switch-to-buffer-other-window buf)) (t (pop-to-buffer buf))) (with-selected-window (or (get-buffer-window buf 'visible) (error "File buffer is not visible")) (when line (setq line (cond ((eq rev 'staged) (apply 'magit-diff-visit--offset file nil line)) ((and force-worktree (stringp rev)) (apply 'magit-diff-visit--offset file rev line)) (t (apply '+ line)))) (let ((pos (save-restriction (widen) (goto-char (point-min)) (forward-line (1- line)) (move-to-column col) (point)))) (unless (<= (point-min) pos (point-max)) (widen) (goto-char pos)))) (when (magit-anything-unmerged-p file) (smerge-start-session)) (run-hooks 'magit-diff-visit-file-hook))))) (defun magit-diff-visit-file-other-window (file) "From a diff, visit the corresponding file at the appropriate position. The file is shown in another window. If the diff shows changes in the worktree, the index, or `HEAD', then visit the actual file. Otherwise, when the diff is about an older commit or a range, then visit the appropriate blob. If point is on a removed line, then visit the blob for the first parent of the commit which removed that line, i.e. the last commit where that line still existed. Otherwise visit the blob for the commit whose changes are being shown." (interactive (list (--if-let (magit-file-at-point) (expand-file-name it) (user-error "No file at point")))) (magit-diff-visit-file file t)) (defvar magit-display-file-buffer-function 'magit-display-file-buffer-traditional "The function used by `magit-diff-visit-file' to display blob buffers. Other commands such as `magit-find-file' do not use this function. Instead they use high-level functions to select the window to be used to display the buffer. This variable and the related functions are an experimental feature and should be treated as such.") (defun magit-display-file-buffer (buffer) (funcall magit-display-file-buffer-function buffer)) (defun magit-display-file-buffer-traditional (buffer) "Display BUFFER in the current window. With a prefix argument display it in another window. Option `magit-display-file-buffer-function' controls whether `magit-diff-visit-file' uses this function." (if (or current-prefix-arg (get-buffer-window buffer)) (pop-to-buffer buffer) (switch-to-buffer buffer))) (defun magit-display-file-buffer-other-window (buffer) "Display BUFFER in another window. With a prefix argument display it in the current window. Option `magit-display-file-buffer-function' controls whether `magit-diff-visit-file' uses this function." (if (or current-prefix-arg (get-buffer-window buffer)) (switch-to-buffer buffer) (pop-to-buffer buffer))) (defun magit-diff-visit-file-worktree (file &optional other-window) "From a diff, visit the corresponding file at the appropriate position. When the file is already being displayed in another window of the same frame, then just select that window and adjust point. With a prefix argument also display in another window. The actual file in the worktree is visited. The positions in the hunk headers get less useful the \"older\" the changes are, and as a result, jumping to the appropriate position gets less reliable. Also see `magit-diff-visit-file' which visits the respective blob, unless the diff shows changes in the worktree, the index, or `HEAD'." (interactive (list (or (magit-file-at-point) (user-error "No file at point")) current-prefix-arg)) (magit-diff-visit-file file other-window t)) (defun magit-diff-visit--range-end () (let ((rev (magit-diff--dwim))) (if (symbolp rev) rev (setq rev (if (consp rev) (cdr rev) (cdr (magit-split-range rev)))) (if (magit-rev-head-p rev) 'unstaged rev)))) (defun magit-diff-visit--range-beginning () (let ((rev (magit-diff--dwim))) (cond ((consp rev) (concat (cdr rev) "^")) ((stringp rev) (car (magit-split-range rev))) (t rev)))) (defun magit-diff-visit--hunk () (when-let ((scope (magit-diff-scope))) (let ((section (magit-current-section))) (cl-case scope ((file files) (setq section (car (oref section children)))) (list (setq section (car (oref section children))) (when section (setq section (car (oref section children)))))) (and ;; Unmerged files appear in the list of staged changes ;; but unlike in the list of unstaged changes no diffs ;; are shown here. In that case `section' is nil. section ;; Currently the `hunk' type is also abused for file ;; mode changes, which we are not interested in here. ;; Such sections have no value. (oref section value) section)))) (defun magit-diff-visit--offset (file rev hunk-start line-offset) (let ((offset 0)) (with-temp-buffer (save-excursion (magit-with-toplevel (magit-git-insert "diff" rev "--" file))) (catch 'found (while (re-search-forward "^@@ -\\([0-9]+\\),\\([0-9]+\\) \\+\\([0-9]+\\),\\([0-9]+\\) @@" nil t) (let* ((abeg (string-to-number (match-string 1))) (alen (string-to-number (match-string 2))) (bbeg (string-to-number (match-string 3))) (blen (string-to-number (match-string 4))) (aend (+ abeg alen)) (bend (+ bbeg blen)) (hend (+ hunk-start line-offset))) (if (<= abeg hunk-start) (if (or (>= aend hend) (>= bend hend)) (let ((line 0)) (while (<= line alen) (forward-line 1) (cl-incf line) (cond ((looking-at "^\\+") (cl-incf offset)) ((looking-at "^-") (cl-decf offset))))) (cl-incf offset (- blen alen))) (throw 'found nil)))))) (+ hunk-start line-offset offset))) (defun magit-diff-hunk-line (section) (let* ((value (oref section value)) (prefix (- (length value) 2)) (cpos (marker-position (oref section content))) (stop (line-number-at-pos)) (cstart (save-excursion (goto-char cpos) (line-number-at-pos))) (prior (and (= (length value) 3) (save-excursion (goto-char (line-beginning-position)) (looking-at "-")))) (offset 0) (line (if prior (cadr value) (car (last value))))) (string-match (format "^%s\\([0-9]+\\)" (if prior "-" "\\+")) line) (setq line (string-to-number (match-string 1 line))) (when (> cstart stop) (save-excursion (goto-char cpos) (re-search-forward "^[-+]") (setq stop (line-number-at-pos)))) (save-excursion (goto-char cpos) (while (< (line-number-at-pos) stop) (unless (string-match-p (if prior "\\+" "-") (buffer-substring (point) (+ (point) prefix))) (cl-incf offset)) (forward-line))) (list line offset))) (defun magit-diff-hunk-column (section visit-beginning) (if (or (< (point) (oref section content)) (and (not visit-beginning) (save-excursion (beginning-of-line) (looking-at-p "-")))) 0 (max 0 (- (+ (current-column) 2) (length (oref section value)))))) (defun magit-diff-visit-directory (directory &optional other-window) (if (equal (magit-toplevel directory) (magit-toplevel)) (dired-jump other-window (concat directory "/.")) (let ((display-buffer-overriding-action (if other-window '(nil (inhibit-same-window t)) '(display-buffer-same-window)))) (magit-status-internal directory)))) ;;;; Scroll commands (defun magit-diff-show-or-scroll-up () "Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer up. If there is no commit or stash at point, then prompt for a commit." (interactive) (magit-diff-show-or-scroll 'scroll-up)) (defun magit-diff-show-or-scroll-down () "Update the commit or diff buffer for the thing at point. Either show the commit or stash at point in the appropriate buffer, or if that buffer is already being displayed in the current frame and contains information about that commit or stash, then instead scroll the buffer down. If there is no commit or stash at point, then prompt for a commit." (interactive) (magit-diff-show-or-scroll 'scroll-down)) (defun magit-diff-show-or-scroll (fn) (let (rev cmd buf win) (cond (magit-blame-mode (setq rev (oref (magit-current-blame-chunk) orig-rev)) (setq cmd 'magit-show-commit) (setq buf (magit-mode-get-buffer 'magit-revision-mode))) ((derived-mode-p 'git-rebase-mode) (save-excursion (goto-char (line-beginning-position)) (--if-let (and git-rebase-line (looking-at git-rebase-line) (match-string 2)) (progn (setq rev it) (setq cmd 'magit-show-commit) (setq buf (magit-mode-get-buffer 'magit-revision-mode))) (user-error "No commit on this line")))) (t (magit-section-case (branch (setq rev (magit-ref-maybe-qualify (oref it value))) (setq cmd 'magit-show-commit) (setq buf (magit-mode-get-buffer 'magit-revision-mode))) (commit (setq rev (oref it value)) (setq cmd 'magit-show-commit) (setq buf (magit-mode-get-buffer 'magit-revision-mode))) (stash (setq rev (oref it value)) (setq cmd 'magit-stash-show) (setq buf (magit-mode-get-buffer 'magit-stash-mode)))))) (if rev (if (and buf (setq win (get-buffer-window buf)) (with-current-buffer buf (and (equal rev (car magit-refresh-args)) (equal (magit-rev-parse rev) magit-buffer-revision-hash)))) (with-selected-window win (condition-case nil (funcall fn) (error (goto-char (pcase fn (`scroll-up (point-min)) (`scroll-down (point-max))))))) (let ((magit-display-buffer-noselect t)) (if (eq cmd 'magit-show-commit) (apply #'magit-show-commit rev (magit-show-commit--arguments)) (funcall cmd rev)))) (call-interactively #'magit-show-commit)))) ;;; Diff Mode (defvar magit-diff-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-mode-map) (define-key map "\C-c\C-d" 'magit-diff-while-committing) (define-key map "\C-c\C-b" 'magit-go-backward) (define-key map "\C-c\C-f" 'magit-go-forward) (define-key map "\s" 'scroll-up) (define-key map "\d" 'scroll-down) (define-key map "j" 'magit-jump-to-diffstat-or-diff) (define-key map [remap write-file] 'magit-patch-save) map) "Keymap for `magit-diff-mode'.") (define-derived-mode magit-diff-mode magit-mode "Magit Diff" "Mode for looking at a Git diff. This mode is documented in info node `(magit)Diff Buffer'. \\\ 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 hunk or file at point. Staging and applying changes is documented in info node `(magit)Staging and Unstaging' and info node `(magit)Applying'. \\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-diff-mode-map}" :group 'magit-diff (hack-dir-local-variables-non-file-buffer) (setq imenu-prev-index-position-function 'magit-imenu--diff-prev-index-position-function) (setq imenu-extract-index-name-function 'magit-imenu--diff-extract-index-name-function) (setq-local bookmark-make-record-function 'magit-bookmark--diff-make-record)) (defun magit-diff-refresh-buffer (rev-or-range const _args files) "Refresh the current `magit-diff-mode' buffer. In such buffers the buffer-local value of `magit-refresh-args' has the same form as the arguments of this function. The value is set in `magit-mode-setup'." (magit-set-header-line-format (if (member "--no-index" const) (apply #'format "Differences between %s and %s" files) (concat (if rev-or-range (if (string-match-p "\\(\\.\\.\\|\\^-\\)" rev-or-range) (format "Changes in %s" rev-or-range) (format "Changes from %s to working tree" rev-or-range)) (if (member "--cached" const) "Staged changes" "Unstaged changes")) (pcase (length files) (0) (1 (concat " in file " (car files))) (_ (concat " in files " (mapconcat #'identity files ", "))))))) (magit-insert-section (diffbuf) (magit-run-section-hook 'magit-diff-sections-hook rev-or-range))) (defun magit-insert-diff (rev-or-range) "Insert the diff into this `magit-diff-mode' buffer." (let ((magit-git-global-arguments (remove "--literal-pathspecs" magit-git-global-arguments))) (magit-git-wash #'magit-diff-wash-diffs "diff" rev-or-range "-p" "--no-prefix" (and (member "--stat" (nth 2 magit-refresh-args)) "--numstat") (nth 1 magit-refresh-args) (nth 2 magit-refresh-args) "--" (nth 3 magit-refresh-args)))) (defvar magit-file-section-map (let ((map (make-sparse-keymap))) (unless (featurep 'jkl) (define-key map (kbd "C-j") 'magit-diff-visit-file-worktree)) (define-key map [C-return] 'magit-diff-visit-file-worktree) (define-key map [remap magit-visit-thing] 'magit-diff-visit-file) (define-key map [remap magit-delete-thing] 'magit-discard) (define-key map [remap magit-revert-no-commit] 'magit-reverse) (define-key map "a" 'magit-apply) (define-key map "C" 'magit-commit-add-log) (define-key map "s" 'magit-stage) (define-key map "u" 'magit-unstage) (define-key map "&" 'magit-do-async-shell-command) (define-key map "\C-c\C-t" 'magit-diff-trace-definition) (define-key map "\C-c\C-e" 'magit-diff-edit-hunk-commit) map) "Keymap for `file' sections.") (defvar magit-hunk-section-map (let ((map (make-sparse-keymap))) (unless (featurep 'jkl) (define-key map (kbd "C-j") 'magit-diff-visit-file-worktree)) (define-key map [C-return] 'magit-diff-visit-file-worktree) (define-key map [remap magit-visit-thing] 'magit-diff-visit-file) (define-key map [remap magit-delete-thing] 'magit-discard) (define-key map [remap magit-revert-no-commit] 'magit-reverse) (define-key map "a" 'magit-apply) (define-key map "C" 'magit-commit-add-log) (define-key map "s" 'magit-stage) (define-key map "u" 'magit-unstage) (define-key map "&" 'magit-do-async-shell-command) (define-key map "\C-c\C-t" 'magit-diff-trace-definition) (define-key map "\C-c\C-e" 'magit-diff-edit-hunk-commit) map) "Keymap for `hunk' sections.") (defconst magit-diff-headline-re (concat "^\\(@@@?\\|diff\\|Submodule\\|" "\\* Unmerged path\\|merged\\|changed in both\\|" "added in remote\\|removed in remote\\)")) (defconst magit-diff-statline-re (concat "^ ?" "\\(.*\\)" ; file "\\( +| +\\)" ; separator "\\([0-9]+\\|Bin\\(?: +[0-9]+ -> [0-9]+ bytes\\)?$\\) ?" "\\(\\+*\\)" ; add "\\(-*\\)$")) ; del (defun magit-diff-wash-diffs (args &optional limit) (when (member "--stat" args) (magit-diff-wash-diffstat)) (when (re-search-forward magit-diff-headline-re limit t) (goto-char (line-beginning-position)) (magit-wash-sequence (apply-partially 'magit-diff-wash-diff args)) (insert ?\n))) (defun magit-jump-to-diffstat-or-diff () "Jump to the diffstat or diff. When point is on a file inside the diffstat section, then jump to the respective diff section, otherwise jump to the diffstat section or a child thereof." (interactive) (--if-let (magit-get-section (append (magit-section-case ([file diffstat] `((file . ,(oref it value)))) (file `((file . ,(oref it value)) (diffstat))) (t '((diffstat)))) (magit-section-ident magit-root-section))) (magit-section-goto it) (user-error "No diffstat in this buffer"))) (defun magit-diff-wash-diffstat () (let (heading (beg (point))) (when (re-search-forward "^ ?\\([0-9]+ +files? change[^\n]*\n\\)" nil t) (setq heading (match-string 1)) (magit-delete-match) (goto-char beg) (magit-insert-section (diffstat) (insert (propertize heading 'face 'magit-diff-file-heading)) (magit-insert-heading) (let (files) (while (looking-at "^[-0-9]+\t[-0-9]+\t\\(.+\\)$") (push (magit-decode-git-path (let ((f (match-string 1))) (if (string-match " => " f) (substring f (match-end 0)) f))) files) (magit-delete-line)) (setq files (nreverse files)) (while (looking-at magit-diff-statline-re) (magit-bind-match-strings (file sep cnt add del) nil (magit-delete-line) (when (string-match " +$" file) (setq sep (concat (match-string 0 file) sep)) (setq file (substring file 0 (match-beginning 0)))) (let ((le (length file)) ld) (setq file (magit-decode-git-path file)) (setq ld (length file)) (when (> le ld) (setq sep (concat (make-string (- le ld) ?\s) sep)))) (magit-insert-section (file (pop files)) (insert (propertize file 'face 'magit-filename) sep cnt " ") (when add (insert (propertize add 'face 'magit-diffstat-added))) (when del (insert (propertize del 'face 'magit-diffstat-removed))) (insert "\n"))))) (if (looking-at "^$") (forward-line) (insert "\n")))))) (defun magit-diff-wash-diff (args) (cond ((looking-at "^Submodule") (magit-diff-wash-submodule)) ((looking-at "^\\* Unmerged path \\(.*\\)") (let ((file (magit-decode-git-path (match-string 1)))) (magit-delete-line) (unless (and (derived-mode-p 'magit-status-mode) (not (member "--cached" args))) (magit-insert-section (file file) (insert (propertize (format "unmerged %s%s" file (pcase (cddr (car (magit-file-status file))) (`(?D ?D) " (both deleted)") (`(?D ?U) " (deleted by us)") (`(?U ?D) " (deleted by them)") (`(?A ?A) " (both added)") (`(?A ?U) " (added by us)") (`(?U ?A) " (added by them)") (`(?U ?U) ""))) 'face 'magit-diff-file-heading)) (insert ?\n)))) t) ((looking-at (concat "^\\(merged\\|changed in both\\|" "added in remote\\|removed in remote\\)")) (let ((status (pcase (match-string 1) ("merged" "merged") ("changed in both" "conflict") ("added in remote" "new file") ("removed in remote" "deleted"))) file orig base modes) (magit-delete-line) (while (looking-at "^ \\([^ ]+\\) +[0-9]\\{6\\} \\([a-z0-9]\\{40\\}\\) \\(.+\\)$") (magit-bind-match-strings (side _blob name) nil (pcase side ("result" (setq file name)) ("our" (setq orig name)) ("their" (setq file name)) ("base" (setq base name)))) (magit-delete-line)) (when orig (setq orig (magit-decode-git-path orig))) (when file (setq file (magit-decode-git-path file))) (magit-diff-insert-file-section (or file base) orig status modes nil))) ((looking-at "^diff --\\(?:\\(git\\) \\(?:\\(.+?\\) \\2\\)?\\|\\(cc\\|combined\\) \\(.+\\)\\)") (let ((status (cond ((equal (match-string 1) "git") "modified") ((derived-mode-p 'magit-revision-mode) "resolved") (t "unmerged"))) (file (or (match-string 2) (match-string 4))) (beg (point)) orig header modes) (save-excursion (forward-line 1) (setq header (buffer-substring beg (if (re-search-forward magit-diff-headline-re nil t) (match-beginning 0) (point-max))))) (magit-delete-line) (while (not (or (eobp) (looking-at magit-diff-headline-re))) (if (looking-at "^old mode \\([^\n]+\\)\nnew mode \\([^\n]+\\)\n") (progn (setq modes (match-string 0)) (magit-delete-match)) (cond ((looking-at "^--- \\([^/].*?\\)\t?$") ; i.e. not /dev/null (setq orig (match-string 1))) ((looking-at "^\\+\\+\\+ \\([^/].*?\\)\t?$") (setq file (match-string 1))) ((looking-at "^\\(copy\\|rename\\) from \\(.+\\)$") (setq orig (match-string 2))) ((looking-at "^\\(copy\\|rename\\) to \\(.+\\)$") (setq file (match-string 2)) (setq status (if (equal (match-string 1) "copy") "new file" "renamed"))) ((looking-at "^\\(new file\\|deleted\\)") (setq status (match-string 1)))) (magit-delete-line))) (when orig (setq orig (magit-decode-git-path orig))) (setq file (magit-decode-git-path file)) ;; KLUDGE `git-log' ignores `--no-prefix' when `-L' is used. (when (and (derived-mode-p 'magit-log-mode) (--first (string-match-p "\\`-L" it) (nth 1 magit-refresh-args))) (setq file (substring file 2)) (when orig (setq orig (substring orig 2)))) (magit-diff-insert-file-section file orig status modes header))))) (defun magit-diff-insert-file-section (file orig status modes header) (magit-insert-section section (file file (or (equal status "deleted") (derived-mode-p 'magit-status-mode))) (insert (propertize (format "%-10s %s\n" status (if (or (not orig) (equal orig file)) file (format "%s -> %s" orig file))) 'face 'magit-diff-file-heading)) (magit-insert-heading) (unless (equal orig file) (oset section source orig)) (oset section header header) (when modes (magit-insert-section (hunk) (insert modes))) (magit-wash-sequence #'magit-diff-wash-hunk))) (defun magit-diff-wash-submodule () ;; See `show_submodule_summary' in submodule.c and "this" commit. (when (looking-at "^Submodule \\([^ ]+\\)") (let ((module (match-string 1)) untracked modified) (when (looking-at "^Submodule [^ ]+ contains untracked content$") (magit-delete-line) (setq untracked t)) (when (looking-at "^Submodule [^ ]+ contains modified content$") (magit-delete-line) (setq modified t)) (cond ((and (looking-at "^Submodule \\([^ ]+\\) \\([^ :]+\\)\\( (rewind)\\)?:$") (equal (match-string 1) module)) (magit-bind-match-strings (_module range rewind) nil (magit-delete-line) (while (looking-at "^ \\([<>]\\) \\(.+\\)$") (magit-delete-line)) (when rewind (setq range (replace-regexp-in-string "[^.]\\(\\.\\.\\)[^.]" "..." range t t 1))) (magit-insert-section (magit-module-section module t) (magit-insert-heading (propertize (concat "modified " module) 'face 'magit-diff-file-heading) " (" (cond (rewind "rewind") ((string-match-p "\\.\\.\\." range) "non-ff") (t "new commits")) (and (or modified untracked) (concat ", " (and modified "modified") (and modified untracked " and ") (and untracked "untracked") " content")) ")") (let ((default-directory (file-name-as-directory (expand-file-name module (magit-toplevel))))) (magit-git-wash (apply-partially 'magit-log-wash-log 'module) "log" "--oneline" "--left-right" range) (delete-char -1))))) ((and (looking-at "^Submodule \\([^ ]+\\) \\([^ ]+\\) (\\([^)]+\\))$") (equal (match-string 1) module)) (magit-bind-match-strings (_module _range msg) nil (magit-delete-line) (magit-insert-section (magit-module-section module) (magit-insert-heading (propertize (concat "submodule " module) 'face 'magit-diff-file-heading) " (" msg ")")))) (t (magit-insert-section (magit-module-section module) (magit-insert-heading (propertize (concat "modified " module) 'face 'magit-diff-file-heading) " (" (and modified "modified") (and modified untracked " and ") (and untracked "untracked") " content)"))))))) (defun magit-diff-wash-hunk () (when (looking-at "^@\\{2,\\} \\(.+?\\) @\\{2,\\}\\(?: \\(.*\\)\\)?") (let ((heading (match-string 0)) (value (cons (match-string 2) (split-string (match-string 1))))) (magit-delete-line) (magit-insert-section it (hunk value) (insert (propertize (concat heading "\n") 'face 'magit-diff-hunk-heading)) (magit-insert-heading) (while (not (or (eobp) (looking-at "^[^-+\s\\]"))) (forward-line)) (oset it end (point)) (oset it washer 'magit-diff-paint-hunk))) t)) (defun magit-diff-expansion-threshold (section) "Keep new diff sections collapsed if washing takes too long." (and (magit-file-section-p section) (> (float-time (time-subtract (current-time) magit-refresh-start-time)) magit-diff-expansion-threshold) 'hide)) ;;; Revision Mode (define-derived-mode magit-revision-mode magit-diff-mode "Magit Rev" "Mode for looking at a Git commit. This mode is documented in info node `(magit)Revision Buffer'. \\\ 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 hunk or file at point. Staging and applying changes is documented in info node `(magit)Staging and Unstaging' and info node `(magit)Applying'. \\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-revision-mode-map}" :group 'magit-revision (hack-dir-local-variables-non-file-buffer) (setq-local bookmark-make-record-function 'magit-bookmark--revision-make-record)) (defun magit-revision-refresh-buffer (rev __const _args files) (magit-set-header-line-format (concat (capitalize (magit-object-type rev)) " " rev (pcase (length files) (0) (1 (concat " limited to file " (car files))) (_ (concat " limited to files " (mapconcat #'identity files ", ")))))) (setq magit-buffer-revision-hash (magit-rev-parse rev)) (magit-insert-section (commitbuf) (magit-run-section-hook 'magit-revision-sections-hook rev))) (defun magit-insert-revision-diff (rev) "Insert the diff into this `magit-revision-mode' buffer." (let ((magit-git-global-arguments (remove "--literal-pathspecs" magit-git-global-arguments))) ;; Before v2.2.0, "--format=" did not mean "no output". ;; Instead the default format was used. So use "--format=%n" ;; and then delete the empty lines. (magit-git-wash (lambda (args) (delete-region (point) (progn (forward-line 3) (point))) (magit-diff-wash-diffs args)) "show" "-p" "--cc" "--format=%n" "--no-prefix" (and (member "--stat" (nth 2 magit-refresh-args)) "--numstat") (nth 2 magit-refresh-args) (concat rev "^{commit}") "--" (nth 3 magit-refresh-args)))) (defun magit-insert-revision-tag (rev) "Insert tag message and headers into a revision buffer. This function only inserts anything when `magit-show-commit' is called with a tag as argument, when that is called with a commit or a ref which is not a branch, then it inserts nothing." (when (equal (magit-object-type rev) "tag") (magit-insert-section (taginfo) (let ((beg (point))) ;; "git verify-tag -v" would output what we need, but the gpg ;; output is send to stderr and we have no control over the ;; order in which stdout and stderr are inserted, which would ;; make parsing hard. We are forced to use "git cat-file tag" ;; instead, which inserts the signature instead of verifying ;; it. We remove that later and then insert the verification ;; output using "git verify-tag" (without the "-v"). (magit-git-insert "cat-file" "tag" rev) (goto-char beg) (forward-line 3) (delete-region beg (point))) (looking-at "^tagger \\([^<]+\\) <\\([^>]+\\)") (let ((heading (format "Tagger: %s <%s>" (match-string 1) (match-string 2)))) (magit-delete-line) (insert (propertize heading 'face 'magit-section-secondary-heading))) (magit-insert-heading) (if (re-search-forward "-----BEGIN PGP SIGNATURE-----" nil t) (progn (let ((beg (match-beginning 0))) (re-search-forward "-----END PGP SIGNATURE-----") (delete-region beg (point))) (insert ?\n) (process-file magit-git-executable nil t nil "verify-tag" rev)) (goto-char (point-max))) (insert ?\n)))) (defvar magit-commit-message-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-show-commit) map) "Keymap for `commit-message' sections.") (defun magit-insert-revision-message (rev) "Insert the commit message into a revision buffer." (magit-insert-section section (commit-message) (oset section heading-highlight-face 'magit-diff-hunk-heading-highlight) (let ((beg (point))) (insert (save-excursion ; The risky var query can move point. (with-temp-buffer (magit-rev-insert-format "%B" rev) (magit-revision--wash-message)))) (if (= (point) (+ beg 2)) (progn (backward-delete-char 2) (insert "(no message)\n")) (goto-char beg) (save-excursion (while (search-forward "\r\n" nil t) ; Remove trailing CRs. (delete-region (match-beginning 0) (1+ (match-beginning 0))))) (when magit-revision-fill-summary-line (let ((fill-column (min magit-revision-fill-summary-line (window-width)))) (fill-region (point) (line-end-position)))) (when magit-revision-use-hash-sections (save-excursion (while (not (eobp)) (re-search-forward "\\_<" nil 'move) (let ((beg (point))) (re-search-forward "\\_>" nil t) (when (> (point) beg) (let ((text (buffer-substring-no-properties beg (point)))) (when (pcase magit-revision-use-hash-sections (`quickest ; false negatives and positives (and (>= (length text) 7) (string-match-p "[0-9]" text) (string-match-p "[a-z]" text))) (`quicker ; false negatives (number-less hashes) (and (>= (length text) 7) (string-match-p "[0-9]" text) (magit-rev-verify-commit text))) (`quick ; false negatives (short hashes) (and (>= (length text) 7) (magit-rev-verify-commit text))) (`slow (magit-rev-verify-commit text))) (put-text-property beg (point) 'face 'magit-hash) (let ((end (point))) (goto-char beg) (magit-insert-section (commit text) (goto-char end)))))))))) (save-excursion (forward-line) (add-face-text-property beg (point) 'magit-diff-hunk-heading) (magit-insert-heading)) (when magit-diff-highlight-keywords (save-excursion (while (re-search-forward "\\[[^[]*\\]" nil t) (let ((beg (match-beginning 0)) (end (match-end 0))) (put-text-property beg end 'face (if-let ((face (get-text-property beg 'face))) (list face 'magit-keyword) 'magit-keyword)))))) (goto-char (point-max)))))) (defun magit-insert-revision-notes (rev) "Insert commit notes into a revision buffer." (let* ((var "core.notesRef") (def (or (magit-get var) "refs/notes/commits"))) (dolist (ref (or (magit-list-active-notes-refs))) (magit-insert-section section (notes ref (not (equal ref def))) (oset section heading-highlight-face 'magit-diff-hunk-heading-highlight) (let ((beg (point))) (insert (with-temp-buffer (magit-git-insert "-c" (concat "core.notesRef=" ref) "notes" "show" rev) (magit-revision--wash-message))) (if (= (point) beg) (magit-cancel-section) (goto-char beg) (end-of-line) (insert (format " (%s)" (propertize (if (string-prefix-p "refs/notes/" ref) (substring ref 11) ref) 'face 'magit-refname))) (forward-char) (add-face-text-property beg (point) 'magit-diff-hunk-heading) (magit-insert-heading) (goto-char (point-max)) (insert ?\n))))))) (defun magit-revision--wash-message () (let ((major-mode 'git-commit-mode)) (hack-dir-local-variables) (hack-local-variables-apply)) (unless (memq git-commit-major-mode '(nil text-mode)) (funcall git-commit-major-mode) (font-lock-ensure)) (buffer-string)) (defun magit-insert-revision-headers (rev) "Insert headers about the commit into a revision buffer." (magit-insert-section (headers) ;; Before v2.2.0, "%D" was not supported. (--when-let (magit-rev-format "%d" rev "--decorate=full") (insert (magit-format-ref-labels it) ?\s)) (insert (propertize (magit-rev-parse (concat rev "^{commit}")) 'face 'magit-hash)) (magit-insert-heading) (let ((beg (point))) (magit-rev-insert-format magit-revision-headers-format rev) (magit-insert-revision-gravatars rev beg)) (when magit-revision-insert-related-refs (dolist (parent (magit-commit-parents rev)) (magit-insert-section (commit parent) (let ((line (magit-rev-format "%h %s" parent))) (string-match "^\\([^ ]+\\) \\(.*\\)" line) (magit-bind-match-strings (hash msg) line (insert "Parent: ") (insert (propertize hash 'face 'magit-hash)) (insert " " msg "\n"))))) (magit--insert-related-refs rev "--merged" "Merged" (eq magit-revision-insert-related-refs 'all)) (magit--insert-related-refs rev "--contains" "Contained" (eq magit-revision-insert-related-refs '(all mixed))) (when-let ((follows (magit-get-current-tag rev t))) (let ((tag (car follows)) (cnt (cadr follows))) (magit-insert-section (tag tag) (insert (format "Follows: %s (%s)\n" (propertize tag 'face 'magit-tag) (propertize (number-to-string cnt) 'face 'magit-branch-local)))))) (when-let ((precedes (magit-get-next-tag rev t))) (let ((tag (car precedes)) (cnt (cadr precedes))) (magit-insert-section (tag tag) (insert (format "Precedes: %s (%s)\n" (propertize tag 'face 'magit-tag) (propertize (number-to-string cnt) 'face 'magit-tag)))))) (insert ?\n)))) (defun magit--insert-related-refs (rev arg title remote) (when-let ((refs (magit-list-related-branches arg rev (and remote "-a")))) (insert title ":" (make-string (- 10 (length title)) ?\s)) (dolist (branch refs) (if (<= (+ (current-column) 1 (length branch)) (window-width)) (insert ?\s) (insert ?\n (make-string 12 ?\s))) (magit-insert-section (branch branch) (insert (propertize branch 'face (if (string-prefix-p "remotes/" branch) 'magit-branch-remote 'magit-branch-local))))) (insert ?\n))) (defun magit-insert-revision-gravatars (rev beg) (when (and magit-revision-show-gravatars (window-system)) (require 'gravatar) (pcase-let ((`(,author . ,committer) (pcase magit-revision-show-gravatars (`t '("^Author: " . "^Commit: ")) (`author '("^Author: " . nil)) (`committer '(nil . "^Commit: ")) (_ magit-revision-show-gravatars)))) (--when-let (and author (magit-rev-format "%aE" rev)) (magit-insert-revision-gravatar beg rev it author)) (--when-let (and committer (magit-rev-format "%cE" rev)) (magit-insert-revision-gravatar beg rev it committer))))) (defun magit-insert-revision-gravatar (beg rev email regexp) (save-excursion (goto-char beg) (when (re-search-forward regexp nil t) (let* ((column (length (match-string 0))) (font-obj (query-font (font-at (point) (get-buffer-window)))) (size (* 2 (+ (aref font-obj 4) (aref font-obj 5)))) (align-to (+ column (ceiling (/ size (aref font-obj 7) 1.0)) 1)) (gravatar-size (- size 2))) (ignore-errors ; service may be unreachable (gravatar-retrieve email 'magit-insert-revision-gravatar-cb (list rev (point-marker) align-to column))))))) (defun magit-insert-revision-gravatar-cb (image rev marker align-to column) (unless (eq image 'error) (when-let ((buffer (marker-buffer marker))) (with-current-buffer buffer (save-excursion (goto-char marker) ;; The buffer might display another revision by now or ;; it might have been refreshed, in which case another ;; process might already have inserted the image. (when (and (equal rev (car magit-refresh-args)) (not (eq (car-safe (car-safe (get-text-property (point) 'display))) 'image))) (let ((top `((,@image :ascent center :relief 1) (slice 0.0 0.0 1.0 0.5))) (bot `((,@image :ascent center :relief 1) (slice 0.0 0.5 1.0 1.0))) (align `((space :align-to ,align-to)))) (when magit-revision-use-gravatar-kludge (cl-rotatef top bot)) (let ((inhibit-read-only t)) (insert (propertize " " 'display top)) (insert (propertize " " 'display align)) (forward-line) (forward-char column) (insert (propertize " " 'display bot)) (insert (propertize " " 'display align)))))))))) ;;; Diff Sections (defvar magit-unstaged-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-diff-unstaged) (define-key map [remap magit-delete-thing] 'magit-discard) (define-key map "s" 'magit-stage) (define-key map "u" 'magit-unstage) map) "Keymap for the `unstaged' section.") (magit-define-section-jumper magit-jump-to-unstaged "Unstaged changes" unstaged) (defun magit-insert-unstaged-changes () "Insert section showing unstaged changes." (magit-insert-section (unstaged) (magit-insert-heading "Unstaged changes:") (magit-git-wash #'magit-diff-wash-diffs "diff" magit-diff-section-arguments "--no-prefix" "--" magit-diff-section-file-args))) (defvar magit-staged-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-diff-staged) (define-key map [remap magit-delete-thing] 'magit-discard) (define-key map [remap magit-revert-no-commit] 'magit-reverse) (define-key map "s" 'magit-stage) (define-key map "u" 'magit-unstage) map) "Keymap for the `staged' section.") (magit-define-section-jumper magit-jump-to-staged "Staged changes" staged) (defun magit-insert-staged-changes () "Insert section showing staged changes." ;; Avoid listing all files as deleted when visiting a bare repo. (unless (magit-bare-repo-p) (magit-insert-section (staged) (magit-insert-heading "Staged changes:") (magit-git-wash #'magit-diff-wash-diffs "diff" "--cached" magit-diff-section-arguments "--no-prefix" "--" magit-diff-section-file-args)))) ;;; Diff Type (defun magit-diff-type (&optional section) "Return the diff type of SECTION. The returned type is one of the symbols `staged', `unstaged', `committed', or `undefined'. This type serves a similar purpose as the general type common to all sections (which is stored in the `type' slot of the corresponding `magit-section' struct) but takes additional information into account. When the SECTION isn't related to diffs and the buffer containing it also isn't a diff-only buffer, then return nil. Currently the type can also be one of `tracked' and `untracked' but these values are not handled explicitly everywhere they should be and a possible fix could be to just return nil here. The section has to be a `diff' or `hunk' section, or a section whose children are of type `diff'. If optional SECTION is nil, return the diff type for the current section. In buffers whose major mode is `magit-diff-mode' SECTION is ignored and the type is determined using other means. In `magit-revision-mode' buffers the type is always `committed'. Do not confuse this with `magit-diff-scope' (which see)." (--when-let (or section (magit-current-section)) (cond ((derived-mode-p 'magit-revision-mode 'magit-stash-mode) 'committed) ((derived-mode-p 'magit-diff-mode) (let ((range (nth 0 magit-refresh-args)) (const (nth 1 magit-refresh-args))) (cond ((member "--no-index" const) 'undefined) ((or (not range) (magit-rev-eq range "HEAD")) (if (member "--cached" const) 'staged 'unstaged)) ((member "--cached" const) (if (magit-rev-head-p range) 'staged 'undefined)) ; i.e. committed and staged (t 'committed)))) ((derived-mode-p 'magit-status-mode) (let ((stype (oref it type))) (if (memq stype '(staged unstaged tracked untracked)) stype (pcase stype ((or `file `module) (let* ((parent (oref it parent)) (type (oref parent type))) (if (memq type '(file module)) (magit-diff-type parent) type))) (`hunk (-> it (oref parent) (oref parent) (oref type))))))) ((derived-mode-p 'magit-log-mode) (if (or (and (magit-section-match 'commit section) (oref section children)) (magit-section-match [* file commit] section)) 'committed 'undefined)) (t 'undefined)))) (cl-defun magit-diff-scope (&optional (section nil ssection) strict) "Return the diff scope of SECTION or the selected section(s). A diff's \"scope\" describes what part of a diff is selected, it is a symbol, one of `region', `hunk', `hunks', `file', `files', or `list'. Do not confuse this with the diff \"type\", as returned by `magit-diff-type'. If optional SECTION is non-nil, then return the scope of that, ignoring the sections selected by the region. Otherwise return the scope of the current section, or if the region is active and selects a valid group of diff related sections, the type of these sections, i.e. `hunks' or `files'. If SECTION, or if that is nil the current section, is a `hunk' section; and the region region starts and ends inside the body of a that section, then the type is `region'. If the region is empty after a mouse click, then `hunk' is returned instead of `region'. If optional STRICT is non-nil, then return nil if the diff type of the section at point is `untracked' or the section at point is not actually a `diff' but a `diffstat' section." (let ((siblings (and (not ssection) (magit-region-sections nil t)))) (setq section (or section (car siblings) (magit-current-section))) (when (and section (or (not strict) (and (not (eq (magit-diff-type section) 'untracked)) (not (eq (--when-let (oref section parent) (oref it type)) 'diffstat))))) (pcase (list (oref section type) (and siblings t) (magit-diff-use-hunk-region-p) ssection) (`(hunk nil t ,_) (if (magit-section-internal-region-p section) 'region 'hunk)) (`(hunk t t nil) 'hunks) (`(hunk ,_ ,_ ,_) 'hunk) (`(file t t nil) 'files) (`(file ,_ ,_ ,_) 'file) (`(module t t nil) 'files) (`(module ,_ ,_ ,_) 'file) (`(,(or `staged `unstaged `untracked) nil ,_ ,_) 'list))))) (defun magit-diff-use-hunk-region-p () (and (region-active-p) (not (and (if (version< emacs-version "25.1") (eq this-command 'mouse-drag-region) ;; TODO implement this from first principals ;; currently it's trial-and-error (or (eq this-command 'mouse-drag-region) (eq last-command 'mouse-drag-region) ;; When another window was previously ;; selected then the last-command is ;; some byte-code function. (byte-code-function-p last-command))) (eq (region-end) (region-beginning)))))) ;;; Diff Highlight (defun magit-diff-unhighlight (section selection) "Remove the highlighting of the diff-related SECTION." (when (magit-hunk-section-p section) (magit-diff-paint-hunk section selection nil) t)) (defun magit-diff-highlight (section selection) "Highlight the diff-related SECTION. If SECTION is not a diff-related section, then do nothing and return nil. If SELECTION is non-nil, then it is a list of sections selected by the region, including SECTION. All of these sections are highlighted." (if (and (magit-section-match 'commit section) (oref section children)) (progn (if selection (dolist (section selection) (magit-diff-highlight-list section selection)) (magit-diff-highlight-list section)) t) (when-let ((scope (magit-diff-scope section t))) (cond ((eq scope 'region) (magit-diff-paint-hunk section selection t)) (selection (dolist (section selection) (magit-diff-highlight-recursive section selection))) (t (magit-diff-highlight-recursive section))) t))) (defun magit-diff-highlight-recursive (section &optional selection) (pcase (magit-diff-scope section) (`list (magit-diff-highlight-list section selection)) (`file (magit-diff-highlight-file section selection)) (`hunk (magit-diff-highlight-heading section selection) (magit-diff-paint-hunk section selection t)) (_ (magit-section-highlight section nil)))) (defun magit-diff-highlight-list (section &optional selection) (let ((beg (oref section start)) (cnt (oref section content)) (end (oref section end))) (when (or (eq this-command 'mouse-drag-region) (not selection)) (unless (and (region-active-p) (<= (region-beginning) beg)) (magit-section-make-overlay beg cnt 'magit-section-highlight)) (unless (oref section hidden) (dolist (child (oref section children)) (when (or (eq this-command 'mouse-drag-region) (not (and (region-active-p) (<= (region-beginning) (oref child start))))) (magit-diff-highlight-recursive child selection))))) (when magit-diff-highlight-hunk-body (magit-section-make-overlay (1- end) end 'magit-section-highlight)))) (defun magit-diff-highlight-file (section &optional selection) (magit-diff-highlight-heading section selection) (unless (oref section hidden) (dolist (child (oref section children)) (magit-diff-highlight-recursive child selection)))) (defun magit-diff-highlight-heading (section &optional selection) (magit-section-make-overlay (oref section start) (or (oref section content) (oref section end)) (pcase (list (oref section type) (and (member section selection) (not (eq this-command 'mouse-drag-region)))) (`(file t) 'magit-diff-file-heading-selection) (`(file nil) 'magit-diff-file-heading-highlight) (`(module t) 'magit-diff-file-heading-selection) (`(module nil) 'magit-diff-file-heading-highlight) (`(hunk t) 'magit-diff-hunk-heading-selection) (`(hunk nil) 'magit-diff-hunk-heading-highlight)))) ;;; Hunk Paint (cl-defun magit-diff-paint-hunk (section &optional selection (highlight (magit-section-selected-p section selection))) (let (paint) (unless magit-diff-highlight-hunk-body (setq highlight nil)) (cond (highlight (unless (oref section hidden) (add-to-list 'magit-section-highlighted-sections section) (cond ((memq section magit-section-unhighlight-sections) (setq magit-section-unhighlight-sections (delq section magit-section-unhighlight-sections))) (magit-diff-highlight-hunk-body (setq paint t))))) (t (cond ((and (oref section hidden) (memq section magit-section-unhighlight-sections)) (add-to-list 'magit-section-highlighted-sections section) (setq magit-section-unhighlight-sections (delq section magit-section-unhighlight-sections))) (t (setq paint t))))) (when paint (save-excursion (goto-char (oref section start)) (let ((end (oref section end)) (merging (looking-at "@@@")) (stage nil) (tab-width (magit-diff-tab-width (magit-section-parent-value section)))) (forward-line) (while (< (point) end) (when (and magit-diff-hide-trailing-cr-characters (char-equal ?\r (char-before (line-end-position)))) (put-text-property (1- (line-end-position)) (line-end-position) 'invisible t)) (put-text-property (point) (1+ (line-end-position)) 'face (cond ((looking-at "^\\+\\+?\\([<=|>]\\)\\{7\\}") (setq stage (pcase (list (match-string 1) highlight) (`("<" nil) 'magit-diff-our) (`("<" t) 'magit-diff-our-highlight) (`("|" nil) 'magit-diff-base) (`("|" t) 'magit-diff-base-highlight) (`("=" nil) 'magit-diff-their) (`("=" t) 'magit-diff-their-highlight) (`(">" nil) nil))) 'magit-diff-conflict-heading) ((looking-at (if merging "^\\(\\+\\| \\+\\)" "^\\+")) (magit-diff-paint-tab merging tab-width) (magit-diff-paint-whitespace merging) (or stage (if highlight 'magit-diff-added-highlight 'magit-diff-added))) ((looking-at (if merging "^\\(-\\| -\\)" "^-")) (magit-diff-paint-tab merging tab-width) (if highlight 'magit-diff-removed-highlight 'magit-diff-removed)) (t (magit-diff-paint-tab merging tab-width) (if highlight 'magit-diff-context-highlight 'magit-diff-context)))) (forward-line)))))) (magit-diff-update-hunk-refinement section)) (defvar magit-diff--tab-width-cache nil) (defun magit-diff-tab-width (file) (setq file (expand-file-name file)) (cl-flet ((cache (value) (let ((elt (assoc file magit-diff--tab-width-cache))) (if elt (setcdr elt value) (setq magit-diff--tab-width-cache (cons (cons file value) magit-diff--tab-width-cache)))) value)) (cond ((not magit-diff-adjust-tab-width) tab-width) ((--when-let (find-buffer-visiting file) (cache (buffer-local-value 'tab-width it)))) ((--when-let (assoc file magit-diff--tab-width-cache) (or (cdr it) tab-width))) ((or (eq magit-diff-adjust-tab-width 'always) (and (numberp magit-diff-adjust-tab-width) (>= magit-diff-adjust-tab-width (nth 7 (file-attributes file))))) (cache (buffer-local-value 'tab-width (find-file-noselect file)))) (t (cache nil) tab-width)))) (defun magit-diff-paint-tab (merging width) (save-excursion (forward-char (if merging 2 1)) (while (= (char-after) ?\t) (put-text-property (point) (1+ (point)) 'display (list (list 'space :width width))) (forward-char)))) (defun magit-diff-paint-whitespace (merging) (when (and magit-diff-paint-whitespace (or (derived-mode-p 'magit-status-mode) (not (eq magit-diff-paint-whitespace 'status)))) (let ((prefix (if merging "^[-\\+\s]\\{2\\}" "^[-\\+]")) (indent (if (local-variable-p 'magit-diff-highlight-indentation) magit-diff-highlight-indentation (setq-local magit-diff-highlight-indentation (cdr (--first (string-match-p (car it) default-directory) (nreverse (default-value 'magit-diff-highlight-indentation)))))))) (when (and magit-diff-highlight-trailing (looking-at (concat prefix ".*?\\([ \t]+\\)$"))) (let ((ov (make-overlay (match-beginning 1) (match-end 1) nil t))) (overlay-put ov 'face 'magit-diff-whitespace-warning) (overlay-put ov 'evaporate t))) (when (or (and (eq indent 'tabs) (looking-at (concat prefix "\\( *\t[ \t]*\\)"))) (and (integerp indent) (looking-at (format "%s\\([ \t]* \\{%s,\\}[ \t]*\\)" prefix indent)))) (let ((ov (make-overlay (match-beginning 1) (match-end 1) nil t))) (overlay-put ov 'face 'magit-diff-whitespace-warning) (overlay-put ov 'evaporate t)))))) (defun magit-diff-update-hunk-refinement (&optional section) (if section (unless (oref section hidden) (pcase (list magit-diff-refine-hunk (oref section refined) (eq section (magit-current-section))) ((or `(all nil ,_) `(t nil t)) (oset section refined t) (save-excursion (goto-char (oref section start)) ;; `diff-refine-hunk' does not handle combined diffs. (unless (looking-at "@@@") ;; Avoid fsyncing many small temp files (let ((write-region-inhibit-fsync t)) (diff-refine-hunk))))) ((or `(nil t ,_) `(t t nil)) (oset section refined nil) (remove-overlays (oref section start) (oref section end) 'diff-mode 'fine)))) (cl-labels ((recurse (section) (if (magit-section-match 'hunk section) (magit-diff-update-hunk-refinement section) (dolist (child (oref section children)) (recurse child))))) (recurse magit-root-section)))) ;;; Hunk Region (defun magit-diff-hunk-region-beginning () (save-excursion (goto-char (region-beginning)) (line-beginning-position))) (defun magit-diff-hunk-region-end () (save-excursion (goto-char (region-end)) (line-end-position))) (defun magit-diff-update-hunk-region (section) "Highlight the hunk-internal region if any." (when (eq (magit-diff-scope section t) 'region) (magit-diff--make-hunk-overlay (oref section start) (1- (oref section content)) 'face 'magit-diff-lines-heading 'display (magit-diff-hunk-region-header section) 'after-string (magit-diff--hunk-after-string 'magit-diff-lines-heading)) (run-hook-with-args 'magit-diff-highlight-hunk-region-functions section) t)) (defun magit-diff-highlight-hunk-region-dim-outside (section) "Dim the parts of the hunk that are outside the hunk-internal region. This is done by using the same foreground and background color for added and removed lines as for context lines." (let ((face (if magit-diff-highlight-hunk-body 'magit-diff-context-highlight 'magit-diff-context))) (when magit-diff-unmarked-lines-keep-foreground (setq face (list :background (face-attribute face :background)))) (magit-diff--make-hunk-overlay (oref section content) (magit-diff-hunk-region-beginning) 'face face 'priority 2) (magit-diff--make-hunk-overlay (1+ (magit-diff-hunk-region-end)) (oref section end) 'face face 'priority 2))) (defun magit-diff-highlight-hunk-region-using-face (_section) "Highlight the hunk-internal region by making it bold. Or rather highlight using the face `magit-diff-hunk-region', though changing only the `:weight' and/or `:slant' is recommended for that face." (magit-diff--make-hunk-overlay (magit-diff-hunk-region-beginning) (1+ (magit-diff-hunk-region-end)) 'face 'magit-diff-hunk-region)) (defun magit-diff-highlight-hunk-region-using-overlays (section) "Emphasize the hunk-internal region using delimiting horizontal lines. This is implemented as single-pixel newlines places inside overlays." (if (window-system) (let ((beg (magit-diff-hunk-region-beginning)) (end (magit-diff-hunk-region-end)) (str (propertize (concat (propertize "\s" 'display '(space :height (1))) (propertize "\n" 'line-height t)) 'face 'magit-diff-lines-boundary))) (magit-diff--make-hunk-overlay beg (1+ beg) 'before-string str) (magit-diff--make-hunk-overlay end (1+ end) 'after-string str)) (magit-diff-highlight-hunk-region-using-face section))) (defun magit-diff-highlight-hunk-region-using-underline (section) "Emphasize the hunk-internal region using delimiting horizontal lines. This is implemented by overlining and underlining the first and last (visual) lines of the region." (if (window-system) (let* ((beg (magit-diff-hunk-region-beginning)) (end (magit-diff-hunk-region-end)) (beg-eol (save-excursion (goto-char beg) (end-of-visual-line) (point))) (end-bol (save-excursion (goto-char end) (beginning-of-visual-line) (point))) (color (face-background 'magit-diff-lines-boundary nil t))) (cl-flet ((ln (b e &rest face) (magit-diff--make-hunk-overlay b e 'face face 'after-string (magit-diff--hunk-after-string face)))) (if (= beg end-bol) (ln beg beg-eol :overline color :underline color) (ln beg beg-eol :overline color) (ln end-bol end :underline color)))) (magit-diff-highlight-hunk-region-using-face section))) (defun magit-diff--make-hunk-overlay (start end &rest args) (let ((ov (make-overlay start end nil t))) (overlay-put ov 'evaporate t) (while args (overlay-put ov (pop args) (pop args))) (push ov magit-region-overlays) ov)) (defun magit-diff--hunk-after-string (face) (propertize "\s" 'face face 'display (list 'space :align-to `(+ (0 . right) ,(min (window-hscroll) (- (line-end-position) (line-beginning-position))))) ;; This prevents the cursor from being rendered at the ;; edge of the window. 'cursor t)) ;;; Hunk Utilities (defun magit-diff-inside-hunk-body-p () "Return non-nil if point is inside the body of a hunk." (and (magit-section-match 'hunk) (> (point) (oref (magit-current-section) content)))) ;;; Diff Extract (defun magit-diff-file-header (section) (when (magit-hunk-section-p section) (setq section (oref section parent))) (when (magit-file-section-p section) (oref section header))) (defun magit-diff-hunk-region-header (section) (let ((patch (magit-diff-hunk-region-patch section))) (string-match "\n" patch) (substring patch 0 (1- (match-end 0))))) (defun magit-diff-hunk-region-patch (section &optional args) (let ((op (if (member "--reverse" args) "+" "-")) (sbeg (oref section start)) (rbeg (magit-diff-hunk-region-beginning)) (rend (region-end)) (send (oref section end)) (patch nil)) (save-excursion (goto-char sbeg) (while (< (point) send) (looking-at "\\(.\\)\\([^\n]*\n\\)") (cond ((or (string-match-p "[@ ]" (match-string-no-properties 1)) (and (>= (point) rbeg) (<= (point) rend))) (push (match-string-no-properties 0) patch)) ((equal op (match-string-no-properties 1)) (push (concat " " (match-string-no-properties 2)) patch))) (forward-line))) (with-temp-buffer (insert (mapconcat 'identity (reverse patch) "")) (diff-fixup-modifs (point-min) (point-max)) (setq patch (buffer-string))) patch)) ;;; _ (provide 'magit-diff) ;;; magit-diff.el ends here magit-2.90.1/lisp/magit-ediff.el000066400000000000000000000510641337354740400163710ustar00rootroot00000000000000;;; magit-ediff.el --- Ediff extension for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup "magit-ediff" nil t) (magit-define-popup magit-ediff-popup "Popup console for ediff commands." :actions '((?E "Dwim" magit-ediff-dwim) (?u "Show unstaged" magit-ediff-show-unstaged) (?s "Stage" magit-ediff-stage) (?i "Show staged" magit-ediff-show-staged) (?m "Resolve" magit-ediff-resolve) (?w "Show worktree" magit-ediff-show-working-tree) (?r "Diff range" magit-ediff-compare) (?c "Show commit" magit-ediff-show-commit) nil (?z "Show stash" magit-ediff-show-stash)) :max-action-columns 2) ;;;###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 (list (magit-completing-read "Selectively stage file" (magit-tracked-files) nil nil nil nil (magit-current-file)))) (magit-with-toplevel (let* ((conf (current-window-configuration)) (bufA (magit-get-revision-buffer "HEAD" file)) (bufB (get-buffer (concat file ".~{index}~"))) (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 (car magit-refresh-args)))) (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 magit-2.90.1/lisp/magit-extras.el000066400000000000000000000643021337354740400166210ustar00rootroot00000000000000;;; magit-extras.el --- additional functionality for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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)) (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. It does work in Emacs 25 and Emacs 27. 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) (with-no-warnings ; FIXME these are internal variables (setq ido-exit 'fallback) (setq fallback 'magit-status) ; for Emacs 25 (setq ido-fallback 'magit-status)) ; for Emacs 27 (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-mode-setup-internal #'magit-log-mode (list (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))) (let (buf pos) (save-window-excursion (call-interactively #'magit-diff-visit-file) (setq buf (current-buffer)) (setq pos (point))) (save-excursion (with-current-buffer buf (goto-char 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))))) (find-file file) (when blame-type (magit-blame--pre-blame-setup blame-type) (magit-blame--run))))))))) (put 'magit-edit-line-commit 'disabled t) (defun magit-diff-edit-hunk-commit () "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) (let ((magit-diff-visit-previous-blob nil)) (magit-diff-visit-file (--if-let (magit-file-at-point) (expand-file-name it) (user-error "No file at point")) nil 'switch-to-buffer)) (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. The 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." (interactive) (if (use-region-p) (copy-region-as-kill nil nil 'region) (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) (copy-region-as-kill nil nil 'region) (when-let ((rev (cond ((memq major-mode '(magit-cherry-mode magit-log-select-mode magit-reflog-mode magit-refs-mode magit-revision-mode magit-stash-mode magit-stashes-mode)) (car magit-refresh-args)) ((memq major-mode '(magit-diff-mode magit-log-mode)) (let ((r (caar magit-refresh-args))) (if (string-match "\\.\\.\\.?\\(.+\\)" r) (match-string 1 r) r))) ((eq major-mode 'magit-status-mode) "HEAD")))) (when (magit-rev-verify-commit 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 magit-2.90.1/lisp/magit-fetch.el000066400000000000000000000125601337354740400164030ustar00rootroot00000000000000;;; magit-fetch.el --- download objects and refs -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup "magit-fetch" nil t) (magit-define-popup magit-fetch-popup "Popup console for fetch commands." :man-page "git-fetch" :switches '((?p "Prune deleted branches" "--prune")) :actions '("Configure" (?C "variables..." magit-branch-config-popup) "Fetch from" (?p magit-get-push-remote magit-fetch-from-pushremote) (?u magit-get-remote 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)) :default-action 'magit-fetch :max-action-columns 1) (defun magit-git-fetch (remote args) (run-hooks 'magit-credential-hook) (magit-run-git-async "fetch" remote args)) ;;;###autoload (defun magit-fetch-from-pushremote (args) "Fetch from the push-remote of the current branch." (interactive (list (magit-fetch-arguments))) (--if-let (magit-get-push-remote) (magit-git-fetch it args) (--if-let (magit-get-current-branch) (user-error "No push-remote is configured for %s" it) (user-error "No branch is checked out")))) ;;;###autoload (defun magit-fetch-from-upstream (args) "Fetch from the upstream repository of the current branch." (interactive (list (magit-fetch-arguments))) (--if-let (magit-get-remote) (magit-git-fetch it args) (--if-let (magit-get-current-branch) (user-error "No upstream is configured for %s" it) (user-error "No branch is checked out")))) ;;;###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 (cl-intersection (magit-fetch-arguments) (list "--verbose" "--prune") :test #'equal))) (run-hooks 'magit-credential-hook) (magit-run-git-async "remote" "update" 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 magit-2.90.1/lisp/magit-files.el000066400000000000000000000466751337354740400164320ustar00rootroot00000000000000;;; magit-files.el --- finding files -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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." (interactive (magit-find-file-read-args "Find file")) (switch-to-buffer (magit-find-file-noselect rev file))) ;;;###autoload (defun magit-find-file-other-window (rev file) "View FILE from REV, in another window. Like `magit-find-file', but create a new window or reuse an existing one." (interactive (magit-find-file-read-args "Find file in other window")) (switch-to-buffer-other-window (magit-find-file-noselect rev file))) (defun magit-find-file-read-args (prompt) (let ((rev (magit-read-branch-or-commit "Find file from revision"))) (list rev (magit-read-file-from-rev rev prompt)))) (defun magit-find-file-noselect (rev file) "Read FILE from REV into a buffer and return the buffer. FILE must be relative to the top directory of the repository." (magit-find-file-noselect-1 rev file 'magit-find-file-hook)) (defun magit-find-file-noselect-1 (rev file hookvar &optional revert) "Read FILE from REV into a buffer and return the buffer. FILE must be relative to the top directory of the repository. An empty REV stands for index." (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 (string= rev "") "{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 hookvar)) (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 (if (equal rev "") "index" (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}" (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" (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 "" file 'magit-find-index-hook (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 "") (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-mode-get-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-popup) (define-key map "\C-c\M-g" 'magit-file-popup) map) "Keymap for `magit-file-mode'.") ;;;###autoload (autoload 'magit-file-popup "magit" nil t) (magit-define-popup magit-file-popup "Popup console for Magit commands in file-visiting buffers." :actions '((?s "Stage" magit-stage-file) (?D "Diff..." magit-diff-buffer-file-popup) (?L "Log..." magit-log-buffer-file-popup) (?B "Blame..." magit-blame-popup) nil (?u "Unstage" magit-unstage-file) (?d "Diff" magit-diff-buffer-file) (?l "Log" magit-log-buffer-file) (?b "Blame" magit-blame-addition) (?p "Prev blob" magit-blob-previous) (?c "Commit" magit-commit-popup) nil (?t "Trace" magit-log-trace-definition) (?r (lambda () (with-current-buffer magit-pre-popup-buffer (and (not buffer-file-name) (propertize "...removal" 'face 'default)))) magit-blame-removal) (?n "Next blob" magit-blob-next) (?e "Edit line" magit-edit-line-commit) nil nil (?f (lambda () (with-current-buffer magit-pre-popup-buffer (and (not buffer-file-name) (propertize "...reverse" 'face 'default)))) magit-blame-reverse) nil) :max-action-columns 5) (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) (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) (line-number-at-pos)) (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 (line-number-at-pos)) (user-error "You have reached the beginning of time")) (user-error "Buffer isn't visiting a file or blob"))) (defun magit-blob-visit (blob-or-file line) (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))))) (goto-char (point-min)) (forward-line (1- line))) (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)))) (if (magit-file-tracked-p (magit-convert-filename-for-git file)) (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)) (magit-run-git "mv" (magit-convert-filename-for-git file) (magit-convert-filename-for-git newname)) (when oldbuf (with-current-buffer oldbuf (let ((buffer-read-only buffer-read-only)) (set-visited-file-name newname)) (if (fboundp 'vc-refresh-state) (vc-refresh-state) (with-no-warnings (vc-find-file-hook)))))) (rename-file file newname current-prefix-arg) (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-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))) (defun magit-read-files (prompt initial-contents) (mapconcat 'identity (completing-read-multiple (or prompt "File,s: ") (magit-list-files) nil nil initial-contents) ",")) ;;; _ (provide 'magit-files) ;;; magit-files.el ends here magit-2.90.1/lisp/magit-git.el000066400000000000000000002645351337354740400161100ustar00rootroot00000000000000;;; magit-git.el --- Git functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 wrappers for various Git plumbing commands. ;;; Code: (require 'cl-lib) (require 'dash) (eval-when-compile (require 'subr-x)) (require 'magit-utils) (require 'magit-section) (declare-function magit-call-git "magit-process" (&rest args)) (declare-function magit-maybe-make-margin-overlay "magit-margin" ()) (declare-function magit-process-buffer "magit-process" (&optional nodisplay)) (declare-function magit-process-file "magit-process" (&rest args)) (declare-function magit-process-insert-section "magit-process" (pwe program args &optional errcode errlog)) (declare-function magit-refresh "magit-mode" ()) (defvar magit-process-error-message-regexps) (defvar magit-refresh-args) ; from `magit-mode' for `magit-current-file' (defvar magit-branch-prefer-remote-upstream) (defvar magit-published-branches) (defvar magit-diff-section-arguments) (defvar magit-tramp-process-environment nil) ;;; Options ;; For now this is shared between `magit-process' and `magit-git'. (defgroup magit-process nil "Git and other external processes used by Magit." :group 'magit) (defvar magit-git-environment (list (format "INSIDE_EMACS=%s,magit" emacs-version)) "Prepended to `process-environment' while running git.") (defcustom magit-git-output-coding-system (and (eq system-type 'windows-nt) 'utf-8) "Coding system for receiving output from Git. If non-nil, the Git config value `i18n.logOutputEncoding' should be set via `magit-git-global-arguments' to value consistent with this." :package-version '(magit . "2.9.0") :group 'magit-process :type '(choice (coding-system :tag "Coding system to decode Git output") (const :tag "Use system default" nil))) (defvar magit-git-w32-path-hack nil "Alist of (EXE . (PATHENTRY)). This specifies what additional PATH setting needs to be added to the environment in order to run the non-wrapper git executables successfully.") (defcustom magit-git-executable ;; Git might be installed in a different location on a remote, so ;; it is better not to use the full path to the executable, except ;; on Window were we would otherwise end up using one one of the ;; wrappers "cmd/git.exe" or "cmd/git.cmd", which are much slower ;; than using "bin/git.exe" directly. (or (and (eq system-type 'windows-nt) (--when-let (executable-find "git") (ignore-errors ;; Git for Windows 2.x provides cygpath so we can ;; ask it for native paths. (let* ((core-exe (car (process-lines it "-c" "alias.X=!x() { which \"$1\" | cygpath -mf -; }; x" "X" "git"))) (hack-entry (assoc core-exe magit-git-w32-path-hack)) ;; Running the libexec/git-core executable ;; requires some extra PATH entries. (path-hack (list (concat "PATH=" (car (process-lines it "-c" "alias.P=!cygpath -wp \"$PATH\"" "P")))))) ;; The defcustom STANDARD expression can be ;; evaluated many times, so make sure it is ;; idempotent. (if hack-entry (setcdr hack-entry path-hack) (push (cons core-exe path-hack) magit-git-w32-path-hack)) core-exe)))) "git") "The Git executable used by Magit." :group 'magit-process :type 'string) (defcustom magit-git-global-arguments `("--no-pager" "--literal-pathspecs" "-c" "core.preloadindex=true" "-c" "log.showSignature=false" ,@(and (eq system-type 'windows-nt) (list "-c" "i18n.logOutputEncoding=UTF-8"))) "Global Git arguments. The arguments set here are used every time the git executable is run as a subprocess. They are placed right after the executable itself and before the git command - as in `git HERE... COMMAND REST'. See the manpage `git(1)' for valid arguments. Be careful what you add here, especially if you are using Tramp to connect to servers with ancient Git versions. Never remove anything that is part of the default value, unless you really know what you are doing. And think very hard before adding something; it will be used every time Magit runs Git for any purpose." :package-version '(magit . "2.9.0") :group 'magit-git-arguments :group 'magit-process :type '(repeat string)) (defvar magit-git-debug nil "Whether to enable additional reporting of git errors. Magit basically calls git for one of these two reasons: for side-effects or to do something with its standard output. When git is run for side-effects then its output, including error messages, go into the process buffer which is shown when using \ \\\\[magit-process]. When git's output is consumed in some way, then it would be too expensive to also insert it into this buffer, but when this option is non-nil and git returns with a non-zero exit status, then at least its standard error is inserted into this buffer. This is only intended for debugging purposes. Do not enable this permanently, that would negatively affect performance.") (defcustom magit-prefer-remote-upstream nil "Whether to favor remote branches when reading the upstream branch. This controls whether commands that read a branch from the user and then set it as the upstream branch, offer a local or a remote branch as default completion candidate, when they have the choice. This affects all commands that use `magit-read-upstream-branch' or `magit-read-starting-point', which includes all commands that change the upstream and many which create new branches." :package-version '(magit . "2.4.2") :group 'magit-commands :type 'boolean) (defcustom magit-list-refs-sortby nil "How to sort the ref collection in the prompt. This affects commands that read a ref. More specifically, it controls the order of refs returned by `magit-list-refs', which is called by functions like `magit-list-branch-names' to generate the collection of refs. By default, refs are sorted according to their full refname (i.e., 'refs/...'). Any value accepted by the `--sort' flag of `git for-each-ref' can be used. For example, \"-creatordate\" places refs with more recent committer or tagger dates earlier in the list. A list of strings can also be given in order to pass multiple sort keys to `git for-each-ref'. Note that, depending on the completion framework you use, this may not be sufficient to change the order in which the refs are displayed. It only controls the order of the collection passed to `magit-completing-read' or, for commands that support reading multiple strings, `read-from-minibuffer'. The completion framework ultimately determines how the collection is displayed." :package-version '(magit . "2.11.0") :group 'magit-miscellanous :type '(choice string (repeat string))) ;;; Git (defvar magit--refresh-cache nil) (defmacro magit--with-refresh-cache (key &rest body) (declare (indent 1) (debug (form body))) (let ((k (cl-gensym))) `(if magit--refresh-cache (let ((,k ,key)) (--if-let (assoc ,k (cdr magit--refresh-cache)) (progn (cl-incf (caar magit--refresh-cache)) (cdr it)) (cl-incf (cdar magit--refresh-cache)) (let ((value ,(macroexp-progn body))) (push (cons ,k value) (cdr magit--refresh-cache)) value))) ,@body))) (defvar magit-with-editor-envvar "GIT_EDITOR" "The environment variable exported by `magit-with-editor'. Set this to \"GIT_SEQUENCE_EDITOR\" if you do not want to use Emacs to edit commit messages but would like to do so to edit rebase sequences.") (defmacro magit-with-editor (&rest body) "Like `with-editor' but let-bind some more variables. Also respect the value of `magit-with-editor-envvar'." (declare (indent 0) (debug (body))) `(let ((magit-process-popup-time -1) ;; The user may have customized `shell-file-name' to ;; something which results in `w32-shell-dos-semantics' nil ;; (which changes the quoting style used by ;; `shell-quote-argument'), but Git for Windows expects shell ;; quoting in the dos style. (shell-file-name (if (and (eq system-type 'windows-nt) ;; If we have Cygwin mount points, ;; the git flavor is cygwin, so dos ;; shell quoting is probably wrong. (not magit-cygwin-mount-points)) "cmdproxy" shell-file-name))) (with-editor* magit-with-editor-envvar ,@body))) (defun magit-process-git-arguments (args) "Prepare ARGS for a function that invokes Git. Magit has many specialized functions for running Git; they all pass arguments through this function before handing them to Git, to do the following. * Flatten ARGS, removing nil arguments. * Prepend `magit-git-global-arguments' to ARGS. * On w32 systems, encode to `w32-ansi-code-page'." (setq args (append magit-git-global-arguments (-flatten args))) (if (and (eq system-type 'windows-nt) (boundp 'w32-ansi-code-page)) ;; On w32, the process arguments *must* be encoded in the ;; current code-page (see #3250). (mapcar (lambda (arg) (encode-coding-string arg (intern (format "cp%d" w32-ansi-code-page)))) args) args)) (defun magit-git-exit-code (&rest args) "Execute Git with ARGS, returning its exit code." (apply #'magit-process-file magit-git-executable nil nil nil (magit-process-git-arguments args))) (defun magit-git-success (&rest args) "Execute Git with ARGS, returning t if its exit code is 0." (= (magit-git-exit-code args) 0)) (defun magit-git-failure (&rest args) "Execute Git with ARGS, returning t if its exit code is 1." (= (magit-git-exit-code args) 1)) (defun magit-git-str (&rest args) "Execute Git with ARGS, returning the first line of its output. If there is no output, return nil. If the output begins with a newline, return an empty string. Like `magit-git-string' but ignore `magit-git-debug'." (setq args (-flatten args)) (magit--with-refresh-cache (cons default-directory args) (with-temp-buffer (apply #'magit-process-file magit-git-executable nil (list t nil) nil (magit-process-git-arguments args)) (unless (bobp) (goto-char (point-min)) (buffer-substring-no-properties (point) (line-end-position)))))) (defun magit-git-output (&rest args) "Execute Git with ARGS, returning its output." (setq args (-flatten args)) (magit--with-refresh-cache (cons default-directory args) (with-temp-buffer (apply #'magit-process-file magit-git-executable nil (list t nil) nil (magit-process-git-arguments args)) (buffer-substring-no-properties (point-min) (point-max))))) (define-error 'magit-invalid-git-boolean "Not a Git boolean") (defun magit-git-true (&rest args) "Execute Git with ARGS, returning t if it prints \"true\". If it prints \"false\", then return nil. For any other output signal `magit-invalid-git-boolean'." (pcase (magit-git-output args) ((or "true" "true\n") t) ((or "false" "false\n") nil) (output (signal 'magit-invalid-git-boolean output)))) (defun magit-git-false (&rest args) "Execute Git with ARGS, returning t if it prints \"false\". If it prints \"true\", then return nil. For any other output signal `magit-invalid-git-boolean'." (pcase (magit-git-output args) ((or "true" "true\n") nil) ((or "false" "false\n") t) (output (signal 'magit-invalid-git-boolean output)))) (defun magit-git-insert (&rest args) "Execute Git with ARGS, inserting its output at point. If Git exits with a non-zero exit status, then show a message and add a section in the respective process buffer." (setq args (magit-process-git-arguments args)) (if magit-git-debug (let (log) (unwind-protect (progn (setq log (make-temp-file "magit-stderr")) (delete-file log) (let ((exit (apply #'magit-process-file magit-git-executable nil (list t log) nil args))) (when (> exit 0) (let ((msg "Git failed")) (when (file-exists-p log) (setq msg (with-temp-buffer (insert-file-contents log) (goto-char (point-max)) (cond ((functionp magit-git-debug) (funcall magit-git-debug (buffer-string))) ((run-hook-wrapped 'magit-process-error-message-regexps (lambda (re) (re-search-backward re nil t))) (match-string-no-properties 1))))) (let ((magit-git-debug nil)) (with-current-buffer (magit-process-buffer t) (magit-process-insert-section default-directory magit-git-executable args exit log)))) (message "%s" msg))) exit)) (ignore-errors (delete-file log)))) (apply #'magit-process-file magit-git-executable nil (list t nil) nil args))) (defun magit-git-string (&rest args) "Execute Git with ARGS, returning the first line of its output. If there is no output, return nil. If the output begins with a newline, return an empty string." (setq args (-flatten args)) (magit--with-refresh-cache (cons default-directory args) (with-temp-buffer (apply #'magit-git-insert args) (unless (bobp) (goto-char (point-min)) (buffer-substring-no-properties (point) (line-end-position)))))) (defun magit-git-lines (&rest args) "Execute Git with ARGS, returning its output as a list of lines. Empty lines anywhere in the output are omitted. If Git exits with a non-zero exit status, then report show a message and add a section in the respective process buffer." (with-temp-buffer (apply #'magit-git-insert args) (split-string (buffer-string) "\n" t))) (defun magit-git-items (&rest args) "Execute Git with ARGS, returning its null-separated output as a list. Empty items anywhere in the output are omitted. If Git exits with a non-zero exit status, then report show a message and add a section in the respective process buffer." (with-temp-buffer (apply #'magit-git-insert args) (split-string (buffer-string) "\0" t))) (defun magit-git-wash (washer &rest args) "Execute Git with ARGS, inserting washed output at point. Actually first insert the raw output at point. If there is no output, call `magit-cancel-section'. Otherwise temporarily narrow the buffer to the inserted text, move to its beginning, and then call function WASHER with ARGS as its sole argument." (declare (indent 1)) (let ((beg (point))) (setq args (-flatten args)) (magit-git-insert args) (if (= (point) beg) (magit-cancel-section) (unless (bolp) (insert "\n")) (save-restriction (narrow-to-region beg (point)) (goto-char beg) (funcall washer args)) (when (or (= (point) beg) (= (point) (1+ beg))) (magit-cancel-section)) (magit-maybe-make-margin-overlay)))) (defun magit-git-version (&optional raw) (--when-let (let (magit-git-global-arguments) (ignore-errors (substring (magit-git-string "version") 12))) (if raw it (and (string-match "^\\([0-9]+\\.[0-9]+\\.[0-9]+\\)" it) (match-string 1 it))))) ;;; Variables (defun magit-config-get-from-cached-list (key) (gethash ;; `git config --list' downcases first and last components of the key. (--> key (replace-regexp-in-string "\\`[^.]+" #'downcase it t t) (replace-regexp-in-string "[^.]+\\'" #'downcase it t t)) (magit--with-refresh-cache (cons (magit-toplevel) 'config) (let ((configs (make-hash-table :test 'equal))) (dolist (conf (magit-git-items "config" "--list" "-z")) (let* ((nl-pos (cl-position ?\n conf)) (key (substring conf 0 nl-pos)) (val (if nl-pos (substring conf (1+ nl-pos)) ""))) (puthash key (nconc (gethash key configs) (list val)) configs))) configs)))) (defun magit-get (&rest keys) "Return the value of the Git variable specified by KEYS." (car (last (apply 'magit-get-all keys)))) (defun magit-get-all (&rest keys) "Return all values of the Git variable specified by KEYS." (let ((magit-git-debug nil) (arg (and (or (null (car keys)) (string-prefix-p "--" (car keys))) (pop keys))) (key (mapconcat 'identity keys "."))) (if (and magit--refresh-cache (not arg)) (magit-config-get-from-cached-list key) (magit-git-items "config" arg "-z" "--get-all" key)))) (defun magit-get-boolean (&rest keys) "Return the boolean value of the Git variable specified by KEYS." (let ((key (mapconcat 'identity keys "."))) (if magit--refresh-cache (equal "true" (car (last (magit-config-get-from-cached-list key)))) (equal (magit-git-str "config" "--bool" key) "true")))) (defun magit-set (value &rest keys) "Set the value of the Git variable specified by KEYS to VALUE." (let ((arg (and (or (null (car keys)) (string-prefix-p "--" (car keys))) (pop keys))) (key (mapconcat 'identity keys "."))) (if value (magit-git-success "config" arg key value) (magit-git-success "config" arg "--unset" key)) value)) (gv-define-setter magit-get (val &rest keys) `(magit-set ,val ,@keys)) (defun magit-set-all (values &rest keys) "Set all values of the Git variable specified by KEYS to VALUES." (let ((arg (and (or (null (car keys)) (string-prefix-p "--" (car keys))) (pop keys))) (var (mapconcat 'identity keys "."))) (when (magit-get var) (magit-call-git "config" arg "--unset-all" var)) (dolist (v values) (magit-call-git "config" arg "--add" var v)))) ;;; Files (defun magit--safe-default-directory (&optional file) (catch 'unsafe-default-dir (let ((dir (file-name-as-directory (expand-file-name (or file default-directory)))) (previous nil)) (while (not (magit-file-accessible-directory-p dir)) (setq dir (file-name-directory (directory-file-name dir))) (when (equal dir previous) (throw 'unsafe-default-dir nil)) (setq previous dir)) dir))) (defmacro magit--with-safe-default-directory (file &rest body) (declare (indent 1) (debug (form body))) `(when-let ((default-directory (magit--safe-default-directory ,file))) ,@body)) (defun magit-gitdir (&optional directory) "Return the absolute and resolved path of the .git directory. If the `GIT_DIR' environment variable is define then return that. Otherwise return the .git directory for DIRECTORY, or if that is nil, then for `default-directory' instead. If the directory is not located inside a Git repository, then return nil." (let ((default-directory (or directory default-directory))) (magit-git-dir))) (defun magit-git-dir (&optional path) "Return the absolute and resolved path of the .git directory. If the `GIT_DIR' environment variable is define then return that. Otherwise return the .git directory for `default-directory'. If the directory is not located inside a Git repository, then return nil." (magit--with-refresh-cache (list default-directory 'magit-git-dir path) (magit--with-safe-default-directory nil (when-let ((dir (magit-rev-parse-safe "--git-dir"))) (setq dir (file-name-as-directory (magit-expand-git-file-name dir))) (unless (file-remote-p dir) (setq dir (concat (file-remote-p default-directory) dir))) (if path (expand-file-name (convert-standard-filename path) dir) dir))))) (defvar magit--separated-gitdirs nil) (defun magit--record-separated-gitdir () (let ((topdir (magit-toplevel)) (gitdir (magit-git-dir))) ;; Kludge: git-annex converts submodule gitdirs to symlinks. See #3599. (when (file-symlink-p (directory-file-name gitdir)) (setq gitdir (file-truename gitdir))) ;; We want to delete the entry for `topdir' here, rather than within ;; (unless ...), in case a `--separate-git-dir' repository was switched to ;; the standard structure (i.e., "topdir/.git/"). (setq magit--separated-gitdirs (cl-delete topdir magit--separated-gitdirs :key #'car :test #'equal)) (unless (equal (file-name-as-directory (expand-file-name ".git" topdir)) gitdir) (push (cons topdir gitdir) magit--separated-gitdirs)))) (defun magit-toplevel (&optional directory) "Return the absolute path to the toplevel of the current repository. From within the working tree or control directory of a repository return the absolute path to the toplevel directory of the working tree. As a special case, from within a bare repository return the control directory instead. When called outside a repository then return nil. When optional DIRECTORY is non-nil then return the toplevel for that directory instead of the one for `default-directory'. Try to respect the option `find-file-visit-truename', i.e. when the value of that option is nil, then avoid needlessly returning the truename. When a symlink to a sub-directory of the working tree is involved, or when called from within a sub-directory of the gitdir or from the toplevel of a gitdir, which itself is not located within the working tree, then it is not possible to avoid returning the truename." (magit--with-refresh-cache (cons (or directory default-directory) 'magit-toplevel) (magit--with-safe-default-directory directory (if-let ((topdir (magit-rev-parse-safe "--show-toplevel"))) (let (updir) (setq topdir (magit-expand-git-file-name topdir)) (if (and ;; Always honor these settings. (not find-file-visit-truename) (not (getenv "GIT_WORK_TREE")) ;; `--show-cdup' is the relative path to the toplevel ;; from `(file-truename default-directory)'. Here we ;; pretend it is relative to `default-directory', and ;; go to that directory. Then we check whether ;; `--show-toplevel' still returns the same value and ;; whether `--show-cdup' now is the empty string. If ;; both is the case, then we are at the toplevel of ;; the same working tree, but also avoided needlessly ;; following any symlinks. (progn (setq updir (file-name-as-directory (magit-rev-parse-safe "--show-cdup"))) (setq updir (if (file-name-absolute-p updir) (concat (file-remote-p default-directory) updir) (expand-file-name updir))) (let ((default-directory updir)) (and (string-equal (magit-rev-parse-safe "--show-cdup") "") (--when-let (magit-rev-parse-safe "--show-toplevel") (string-equal (magit-expand-git-file-name it) topdir)))))) updir (concat (file-remote-p default-directory) (file-name-as-directory topdir)))) (when-let ((gitdir (magit-rev-parse-safe "--git-dir"))) (setq gitdir (file-name-as-directory (if (file-name-absolute-p gitdir) ;; We might have followed a symlink. (concat (file-remote-p default-directory) (magit-expand-git-file-name gitdir)) (expand-file-name gitdir)))) (if (magit-bare-repo-p) gitdir (let* ((link (expand-file-name "gitdir" gitdir)) (wtree (and (file-exists-p link) (magit-file-line link)))) (cond ((and wtree ;; Ignore .git/gitdir files that result from a ;; Git bug. See #2364. (not (equal wtree ".git"))) ;; Return the linked working tree. (file-name-directory wtree)) ;; The working directory may not be the parent directory of ;; .git if it was set up with `git init --separate-git-dir'. ;; See #2955. ((car (rassoc gitdir magit--separated-gitdirs))) (t ;; Step outside the control directory to enter the working tree. (file-name-directory (directory-file-name gitdir))))))))))) (defmacro magit-with-toplevel (&rest body) (declare (indent defun) (debug (body))) (let ((toplevel (cl-gensym "toplevel"))) `(let ((,toplevel (magit-toplevel))) (if ,toplevel (let ((default-directory ,toplevel)) ,@body) (magit--not-inside-repository-error))))) (define-error 'magit-outside-git-repo "Not inside Git repository") (define-error 'magit-git-executable-not-found "Git executable cannot be found (see https://magit.vc/goto/e6a78ed2)") (defun magit--not-inside-repository-error () (if (executable-find magit-git-executable) (signal 'magit-outside-git-repo default-directory) (signal 'magit-git-executable-not-found magit-git-executable))) (defun magit-inside-gitdir-p (&optioal noerror) "Return t if `default-directory' is below the repository directory. If it is below the working directory, then return nil. If it isn't below either, then signal an error unless NOERROR is non-nil, in which case return nil." (and (magit--assert-default-directory noerror) ;; Below a repository directory that is not located below the ;; working directory "git rev-parse --is-inside-git-dir" prints ;; "false", which is wrong. (let ((gitdir (magit-git-dir))) (cond (gitdir (file-in-directory-p default-directory gitdir)) (noerror nil) (t (signal 'magit-outside-git-repo default-directory)))))) (defun magit-inside-worktree-p (&optional noerror) "Return t if `default-directory' is below the working directory. If it is below the repository directory, then return nil. If it isn't below either, then signal an error unless NOERROR is non-nil, in which case return nil." (and (magit--assert-default-directory noerror) (condition-case nil (magit-rev-parse-true "--is-inside-work-tree") (magit-invalid-git-boolean (and (not noerror) (signal 'magit-outside-git-repo default-directory)))))) (defun magit-bare-repo-p (&optional noerror) "Return t if the current repository is bare. If it is non-bare, then return nil. If `default-directory' isn't below a Git repository, then signal an error unless NOERROR is non-nil, in which case return nil." (and (magit--assert-default-directory noerror) (condition-case nil (magit-rev-parse-true "--is-bare-repository") (magit-invalid-git-boolean (and (not noerror) (signal 'magit-outside-git-repo default-directory)))))) (defun magit--assert-default-directory (&optional noerror) (or (file-directory-p default-directory) (and (not noerror) (let ((exists (file-exists-p default-directory))) (signal (if exists 'file-error 'file-missing) (list "Running git in directory" (if exists "Not a directory" "No such file or directory") default-directory)))))) (defun magit-git-repo-p (directory &optional non-bare) "Return t if DIRECTORY is a Git repository. When optional NON-BARE is non-nil also return nil if DIRECTORY is a bare repository." (and (file-directory-p directory) ; Avoid archives, see #3397. (or (file-regular-p (expand-file-name ".git" directory)) (file-directory-p (expand-file-name ".git" directory)) (and (not non-bare) (file-regular-p (expand-file-name "HEAD" directory)) (file-directory-p (expand-file-name "refs" directory)) (file-directory-p (expand-file-name "objects" directory)))))) (defvar-local magit-buffer-revision nil) (defvar-local magit-buffer-refname nil) (defvar-local magit-buffer-file-name nil) (put 'magit-buffer-revision 'permanent-local t) (put 'magit-buffer-refname 'permanent-local t) (put 'magit-buffer-file-name 'permanent-local t) (defun magit-file-relative-name (&optional file tracked) "Return the path of FILE relative to the repository root. If optional FILE is nil or omitted, return the relative path of the file being visited in the current buffer, if any, else nil. If the file is not inside a Git repository, then return nil. If TRACKED is non-nil, return the path only if it matches a tracked file." (unless file (with-current-buffer (or (buffer-base-buffer) (current-buffer)) (setq file (or magit-buffer-file-name buffer-file-name (and (derived-mode-p 'dired-mode) default-directory))))) (when (and file (or (not tracked) (magit-file-tracked-p (file-relative-name file)))) (--when-let (magit-toplevel (magit--safe-default-directory (directory-file-name (file-name-directory file)))) (file-relative-name file it)))) (defun magit-file-tracked-p (file) (magit-git-success "ls-files" "--error-unmatch" file)) (defun magit-list-files (&rest args) (apply #'magit-git-items "ls-files" "-z" "--full-name" args)) (defun magit-tracked-files () (magit-list-files "--cached")) (defun magit-untracked-files (&optional all files) (magit-list-files "--other" (unless all "--exclude-standard") "--" files)) (defun magit-unstaged-files (&optional nomodules files) (magit-git-items "diff-files" "-z" "--name-only" (and nomodules "--ignore-submodules") "--" files)) (defun magit-staged-files (&optional nomodules files) (magit-git-items "diff-index" "-z" "--name-only" "--cached" (and nomodules "--ignore-submodules") (magit-headish) "--" files)) (defun magit-binary-files (&rest args) (--mapcat (and (string-match "^-\t-\t\\(.+\\)" it) (list (match-string 1 it))) (apply #'magit-git-items "diff" "-z" "--numstat" "--ignore-submodules" args))) (defun magit-unmerged-files () (magit-git-items "diff-files" "-z" "--name-only" "--diff-filter=U")) (defun magit-ignored-files () (magit-git-items "ls-files" "-z" "--others" "--ignored" "--exclude-standard" "--directory")) (defun magit-revision-files (rev) (magit-with-toplevel (magit-git-items "ls-tree" "-z" "-r" "--name-only" rev))) (defun magit-changed-files (rev-or-range &optional other-rev) "Return list of files the have changed between two revisions. If OTHER-REV is non-nil, REV-OR-RANGE should be a revision, not a range. Otherwise, it can be any revision or range accepted by \"git diff\" (i.e., , .., or ...)." (magit-with-toplevel (magit-git-items "diff" "-z" "--name-only" rev-or-range other-rev))) (defun magit-renamed-files (revA revB) (--map (cons (nth 1 it) (nth 2 it)) (-partition 3 (magit-git-items "diff-tree" "-r" "--diff-filter=R" "-z" "-M" revA revB)))) (defun magit-file-status (&rest args) (with-temp-buffer (save-excursion (magit-git-insert "status" "-z" args)) (let ((pos (point)) status) (while (> (skip-chars-forward "[:print:]") 0) (let ((x (char-after pos)) (y (char-after (1+ pos))) (file (buffer-substring (+ pos 3) (point)))) (forward-char) (if (memq x '(?R ?C)) (progn (setq pos (point)) (skip-chars-forward "[:print:]") (push (list file (buffer-substring pos (point)) x y) status) (forward-char)) (push (list file nil x y) status))) (setq pos (point))) status))) (defcustom magit-cygwin-mount-points (when (eq system-type 'windows-nt) (cl-sort (--map (if (string-match "^\\(.*\\) on \\(.*\\) type" it) (cons (file-name-as-directory (match-string 2 it)) (file-name-as-directory (match-string 1 it))) (lwarn '(magit) :error "Failed to parse Cygwin mount: %S" it)) ;; If --exec-path is not a native Windows path, ;; then we probably have a cygwin git. (let ((process-environment (append magit-git-environment process-environment))) (and (not (string-match-p "\\`[a-zA-Z]:" (car (process-lines magit-git-executable "--exec-path")))) (ignore-errors (process-lines "mount"))))) #'> :key (pcase-lambda (`(,cyg . ,_win)) (length cyg)))) "Alist of (CYGWIN . WIN32) directory names. Sorted from longest to shortest CYGWIN name." :package-version '(magit . "2.3.0") :group 'magit-process :type '(alist :key-type string :value-type directory)) (defun magit-expand-git-file-name (filename) (unless (file-name-absolute-p filename) (setq filename (expand-file-name filename))) (-if-let ((cyg . win) (cl-assoc filename magit-cygwin-mount-points :test (lambda (f cyg) (string-prefix-p cyg f)))) (concat win (substring filename (length cyg))) filename)) (defun magit-convert-filename-for-git (filename) "Convert FILENAME so that it can be passed to git. 1. If it's a remote filename, then remove the remote part. 2. Deal with an `windows-nt' Emacs vs. Cygwin Git incompatibility." (if (file-name-absolute-p filename) (-if-let ((cyg . win) (cl-rassoc filename magit-cygwin-mount-points :test (lambda (f win) (string-prefix-p win f)))) (concat cyg (substring filename (length win))) (or (file-remote-p filename 'localname) filename)) filename)) (defun magit-decode-git-path (path) (if (eq (aref path 0) ?\") (decode-coding-string (read path) (or magit-git-output-coding-system (car default-process-coding-system)) t) path)) (defun magit-file-at-point () (magit-section-case (file (oref it value)) (hunk (magit-section-parent-value it)))) (defun magit-current-file () (or (magit-file-relative-name) (magit-file-at-point) (and (derived-mode-p 'magit-log-mode) (car (nth 2 magit-refresh-args))))) ;;; Predicates (defun magit-no-commit-p () "Return t if there is no commit in the current Git repository." (not (magit-rev-verify "HEAD"))) (defun magit-merge-commit-p (commit) "Return t if COMMIT is a merge commit." (> (length (magit-commit-parents commit)) 1)) (defun magit-anything-staged-p (&optional ignore-submodules &rest files) "Return t if there are any staged changes. If optional FILES is non-nil, then only changes to those files are considered." (magit-git-failure "diff" "--quiet" "--cached" (and ignore-submodules "--ignore-submodules") "--" files)) (defun magit-anything-unstaged-p (&optional ignore-submodules &rest files) "Return t if there are any unstaged changes. If optional FILES is non-nil, then only changes to those files are considered." (magit-git-failure "diff" "--quiet" (and ignore-submodules "--ignore-submodules") "--" files)) (defun magit-anything-modified-p (&optional ignore-submodules &rest files) "Return t if there are any staged or unstaged changes. If optional FILES is non-nil, then only changes to those files are considered." (or (apply 'magit-anything-staged-p ignore-submodules files) (apply 'magit-anything-unstaged-p ignore-submodules files))) (defun magit-anything-unmerged-p (&rest files) "Return t if there are any merge conflicts. If optional FILES is non-nil, then only conflicts in those files are considered." (and (magit-git-string "ls-files" "--unmerged" files) t)) (defun magit-module-worktree-p (module) (magit-with-toplevel (file-exists-p (expand-file-name (expand-file-name ".git" module))))) (defun magit-module-no-worktree-p (module) (not (magit-module-worktree-p module))) (defun magit-ignore-submodules-p () (cl-find-if (lambda (arg) (string-prefix-p "--ignore-submodules" arg)) magit-diff-section-arguments)) ;;; Revisions and References (defun magit-rev-parse (&rest args) "Execute `git rev-parse ARGS', returning first line of output. If there is no output, return nil." (apply #'magit-git-string "rev-parse" args)) (defun magit-rev-parse-safe (&rest args) "Execute `git rev-parse ARGS', returning first line of output. If there is no output, return nil. Like `magit-rev-parse' but ignore `magit-git-debug'." (apply #'magit-git-str "rev-parse" args)) (defun magit-rev-parse-true (&rest args) "Execute `git rev-parse ARGS', returning t if it prints \"true\". If it prints \"false\", then return nil. For any other output signal an error." (magit-git-true "rev-parse" args)) (defun magit-rev-parse-false (&rest args) "Execute `git rev-parse ARGS', returning t if it prints \"false\". If it prints \"true\", then return nil. For any other output signal an error." (magit-git-false "rev-parse" args)) (defun magit-rev-parse-p (&rest args) "Execute `git rev-parse ARGS', returning t if it prints \"true\". Return t if the first (and usually only) output line is the string \"true\", otherwise return nil." (equal (magit-git-str "rev-parse" args) "true")) (defun magit-rev-verify (rev) (magit-rev-parse-safe "--verify" rev)) (defun magit-rev-verify-commit (rev) "Return full hash for REV if it names an existing commit." (magit-rev-verify (concat rev "^{commit}"))) (defun magit-rev-equal (a b) (magit-git-success "diff" "--quiet" a b)) (defun magit-rev-eq (a b) (let ((a (magit-rev-verify a)) (b (magit-rev-verify b))) (and a b (equal a b)))) (defun magit-rev-ancestor-p (a b) "Return non-nil if commit A is an ancestor of commit B." (magit-git-success "merge-base" "--is-ancestor" a b)) (defun magit-rev-head-p (rev) (or (equal rev "HEAD") (and rev (not (string-match-p "\\.\\." rev)) (equal (magit-rev-parse rev) (magit-rev-parse "HEAD"))))) (defun magit-rev-author-p (rev) "Return t if the user is the author of REV. More precisely return t if `user.name' is equal to the author name of REV and/or `user.email' is equal to the author email of REV." (or (equal (magit-get "user.name") (magit-rev-format "%an" rev)) (equal (magit-get "user.email") (magit-rev-format "%ae" rev)))) (defun magit-rev-name (rev &optional pattern) "Return a symbolic name for REV. PATTERN is passed to the `--refs' flag of `git-name-rev' and can be used to limit the result to a matching ref. When structured as \"refs//*\", PATTERN is taken as a namespace. In this case, the name returned by `git-name-rev' is discarded if it corresponds to a ref outside of the namespace." (--when-let (magit-git-string "name-rev" "--name-only" "--no-undefined" (and pattern (concat "--refs=" pattern)) rev) ;; We can't use name-rev's --exclude to filter out "*/PATTERN" ;; because --exclude wasn't added until Git v2.13.0. (if (and pattern (string-match-p "\\`refs/[^/]+/\\*\\'" pattern)) (let ((namespace (substring pattern 0 -1))) (unless (and (string-match-p namespace it) (not (magit-rev-verify (concat namespace it)))) it)) it))) (defun magit-rev-branch (rev) (--when-let (magit-rev-name rev "refs/heads/*") (unless (string-match-p "[~^]" it) it))) (defun magit-get-shortname (rev) (let* ((fn (apply-partially 'magit-rev-name rev)) (name (or (funcall fn "refs/tags/*") (funcall fn "refs/heads/*") (funcall fn "refs/remotes/*")))) (cond ((not name) (magit-rev-parse "--short" rev)) ((string-match "^\\(?:tags\\|remotes\\)/\\(.+\\)" name) (if (magit-ref-ambiguous-p (match-string 1 name)) name (match-string 1 name))) (t (magit-ref-maybe-qualify name))))) (defun magit-name-branch (rev &optional lax) (or (magit-name-local-branch rev) (magit-name-remote-branch rev) (and lax (or (magit-name-local-branch rev t) (magit-name-remote-branch rev t))))) (defun magit-name-local-branch (rev &optional lax) (--when-let (magit-rev-name rev "refs/heads/*") (and (or lax (not (string-match-p "[~^]" it))) it))) (defun magit-name-remote-branch (rev &optional lax) (--when-let (magit-rev-name rev "refs/remotes/*") (and (or lax (not (string-match-p "[~^]" it))) (substring it 8)))) (defun magit-name-tag (rev &optional lax) (--when-let (magit-rev-name rev "refs/tags/*") (and (or lax (not (string-match-p "[~^]" it))) (substring it 5)))) (defun magit-ref-fullname (name) "Return fully qualified refname for NAME. If NAME is ambiguous, return nil. NAME may include suffixes such as \"^1\" and \"~3\". " (save-match-data (if (string-match "\\`\\([^^~]+\\)\\(.*\\)" name) (--when-let (magit-rev-parse "--symbolic-full-name" (match-string 1 name)) (concat it (match-string 2 name))) (error "`name' has an unrecognized format")))) (defun magit-ref-ambiguous-p (name) (not (magit-ref-fullname name))) (cl-defun magit-ref-maybe-qualify (name &optional (prefix "heads/")) "If NAME is ambiguous, prepend PREFIX to it." (concat (and (magit-ref-ambiguous-p name) prefix) name)) (defun magit-ref-exists-p (ref) (magit-git-success "show-ref" "--verify" ref)) (defun magit-ref-equal (a b) "Return t if the refs A and B are `equal'. A symbolic-ref pointing to some ref, is `equal' to that ref, as are two symbolic-refs pointing to the same ref." (equal (magit-ref-fullname a) (magit-ref-fullname b))) (defun magit-ref-eq (a b) "Return t if the refs A and B are `eq'. A symbolic-ref is `eq' to itself, but not to the ref it points to, or to some other symbolic-ref that points to the same ref." (let ((symbolic-a (magit-symbolic-ref-p a)) (symbolic-b (magit-symbolic-ref-p b))) (or (and symbolic-a symbolic-b (equal a b)) (and (not symbolic-a) (not symbolic-b) (magit-ref-equal a b))))) (defun magit-headish () "Return \"HEAD\" or if that doesn't exist the hash of the empty tree." (if (magit-no-commit-p) (magit-git-string "mktree") "HEAD")) (defun magit-branch-at-point () (magit-section-case (branch (oref it value)) (commit (or (magit--painted-branch-at-point) (magit-name-branch (oref it value)))))) (defun magit--painted-branch-at-point (&optional type) (or (and (not (eq type 'remote)) (memq (get-text-property (point) 'face) (list 'magit-branch-local 'magit-branch-current)) (cdr (magit-split-branch-name (thing-at-point 'git-revision t)))) (and (not (eq type 'local)) (memq (get-text-property (point) 'face) (list 'magit-branch-remote 'magit-branch-remote-head)) (thing-at-point 'git-revision t)))) (defun magit-local-branch-at-point () (magit-section-case (branch (let ((branch (magit-ref-maybe-qualify (oref it value)))) (when (member branch (magit-list-local-branch-names)) branch))) (commit (or (magit--painted-branch-at-point 'local) (magit-name-local-branch (oref it value)))))) (defun magit-remote-branch-at-point () (magit-section-case (branch (let ((branch (oref it value))) (when (member branch (magit-list-remote-branch-names)) branch))) (commit (or (magit--painted-branch-at-point 'remote) (magit-name-remote-branch (oref it value)))))) (defun magit-commit-at-point () (or (magit-section-value-if 'commit) (and (derived-mode-p 'magit-revision-mode) (car magit-refresh-args)))) (defun magit-branch-or-commit-at-point () (or magit-buffer-refname (magit-section-case (branch (magit-ref-maybe-qualify (oref it value))) (commit (or (magit--painted-branch-at-point) (let ((rev (oref it value))) (or (magit-name-branch rev) (magit-get-shortname rev) rev)))) (tag (magit-ref-maybe-qualify (oref it value) "tags/"))) (thing-at-point 'git-revision t) (and (derived-mode-p 'magit-revision-mode 'magit-merge-preview-mode) (car magit-refresh-args)))) (defun magit-tag-at-point () (magit-section-case (tag (oref it value)) (commit (magit-name-tag (oref it value))))) (defun magit-stash-at-point () (magit-section-value-if 'stash)) (defun magit-remote-at-point () (magit-section-case (remote (oref it value)) (branch (magit-section-parent-value it)))) (defun magit-module-at-point (&optional predicate) (when (magit-section-match 'magit-module-section) (let ((module (oref (magit-current-section) value))) (and (or (not predicate) (funcall predicate module)) module)))) (defun magit-get-current-branch () "Return the refname of the currently checked out branch. Return nil if no branch is currently checked out." (magit-git-string "symbolic-ref" "--short" "HEAD")) (defvar magit-get-previous-branch-timeout 0.5 "Maximum time to spend in `magit-get-previous-branch'. Given as a number of seconds.") (defun magit-get-previous-branch () "Return the refname of the previously checked out branch. Return nil if no branch can be found in the `HEAD' reflog which is different from the current branch and still exists. The amount of time spent searching is limited by `magit-get-previous-branch-timeout'." (let ((t0 (float-time)) (current (magit-get-current-branch)) (i 1) prev) (while (if (> (- (float-time) t0) magit-get-previous-branch-timeout) (setq prev nil) ;; Timed out. (and (setq prev (magit-rev-verify (format "@{-%i}" i))) (or (not (setq prev (magit-rev-branch prev))) (equal prev current)))) (cl-incf i)) prev)) (defun magit-get-upstream-ref (&optional branch) (and (or branch (setq branch (magit-get-current-branch))) (let ((remote (magit-get "branch" branch "remote")) (merge (magit-get "branch" branch "merge"))) (when (and remote merge) (cond ((string-equal remote ".") merge) ((string-prefix-p "refs/heads/" merge) (concat "refs/remotes/" remote "/" (substring merge 11)))))))) (defun magit-set-upstream-branch (branch upstream) (if upstream (pcase-let ((`(,remote . ,merge) (magit-split-branch-name upstream))) (setf (magit-get (format "branch.%s.remote" branch)) remote) (setf (magit-get (format "branch.%s.merge" branch)) (concat "refs/heads/" merge))) (magit-call-git "branch" "--unset-upstream" branch))) (defun magit-get-upstream-branch (&optional branch verify) (and (or branch (setq branch (magit-get-current-branch))) (when-let ((remote (magit-get "branch" branch "remote")) (merge (magit-get "branch" branch "merge"))) (and (string-prefix-p "refs/heads/" merge) (let* ((upstream (substring merge 11)) (upstream (cond ((string-equal remote ".") (propertize upstream 'face 'magit-branch-local)) ((string-match-p "[@:]" remote) (propertize (concat remote " " upstream) 'face 'magit-branch-remote)) (t (propertize (concat remote "/" upstream) 'face 'magit-branch-remote))))) (and (or (not verify) (magit-rev-verify upstream)) upstream)))))) (defun magit-get-indirect-upstream-branch (branch &optional force) (let ((remote (magit-get "branch" branch "remote"))) (and remote (not (equal remote ".")) ;; The user has opted in... (or force (--some (if (magit-git-success "check-ref-format" "--branch" it) (equal it branch) (string-match-p it branch)) magit-branch-prefer-remote-upstream)) ;; and local BRANCH tracks a remote branch... (let ((upstream (magit-get-upstream-branch branch))) ;; whose upstream... (and upstream ;; has the same name as BRANCH and... (equal (substring upstream (1+ (length remote))) branch) ;; and can be fast-forwarded to BRANCH. (magit-rev-ancestor-p upstream branch) upstream))))) (defun magit-get-upstream-remote (&optional branch non-local) (unless branch (setq branch (magit-get-current-branch))) (and branch (let ((remote (magit-get "branch" branch "remote"))) (and (not (and non-local (equal remote "."))) remote)))) (defun magit-get-push-remote (&optional branch) (or (and (or branch (setq branch (magit-get-current-branch))) (magit-get "branch" branch "pushRemote")) (magit-get "remote.pushDefault"))) (defun magit-get-push-branch (&optional branch verify) (and (or branch (setq branch (magit-get-current-branch))) (when-let ((remote (magit-get-push-remote branch)) (push-branch (concat remote "/" branch))) (and (or (not verify) (magit-rev-verify push-branch)) (propertize push-branch 'face 'magit-branch-remote))))) (defun magit-get-@{push}-branch (&optional branch) (let ((ref (magit-rev-parse "--symbolic-full-name" (concat branch "@{push}")))) (when (and ref (string-prefix-p "refs/remotes/" ref)) (substring ref 13)))) (defun magit-get-remote (&optional branch) (when (or branch (setq branch (magit-get-current-branch))) (let ((remote (magit-get "branch" branch "remote"))) (unless (equal remote ".") remote)))) (defun magit-get-some-remote (&optional branch) (or (magit-get-remote branch) (and (magit-branch-p "master") (magit-get-remote "master")) (let ((remotes (magit-list-remotes))) (or (car (member "origin" remotes)) (car remotes))))) (defun magit-branch-merged-p (branch &optional target) "Return non-nil if BRANCH is merged into its upstream and TARGET. TARGET defaults to the current branch. If `HEAD' is detached and TARGET is nil, then always return nil. As a special case, if TARGET is t, then return non-nil if BRANCH is merged into any one of the other local branches. If, and only if, BRANCH has an upstream, then only return non-nil if BRANCH is merged into both TARGET (as described above) as well as into its upstream." (and (--if-let (and (magit-branch-p branch) (magit-get-upstream-branch branch)) (magit-git-success "merge-base" "--is-ancestor" branch it) t) (if (eq target t) (delete (magit-name-local-branch branch) (magit-list-containing-branches branch)) (--when-let (or target (magit-get-current-branch)) (magit-git-success "merge-base" "--is-ancestor" branch it))))) (defun magit-split-branch-name (branch) (cond ((member branch (magit-list-local-branch-names)) (cons "." branch)) ((string-match " " branch) (pcase-let ((`(,url ,branch) (split-string branch " "))) (cons url branch))) ((string-match "/" branch) (let ((remote (substring branch 0 (match-beginning 0)))) (if (save-match-data (member remote (magit-list-remotes))) (cons remote (substring branch (match-end 0))) (error "Invalid branch name %s" branch)))))) (defun magit-get-current-tag (&optional rev with-distance) "Return the closest tag reachable from REV. If optional REV is nil, then default to `HEAD'. If optional WITH-DISTANCE is non-nil then return (TAG COMMITS), if it is `dirty' return (TAG COMMIT DIRTY). COMMITS is the number of commits in `HEAD' but not in TAG and DIRTY is t if there are uncommitted changes, nil otherwise." (--when-let (magit-git-str "describe" "--long" "--tags" (and (eq with-distance 'dirty) "--dirty") rev) (save-match-data (string-match "\\(.+\\)-\\(?:0[0-9]*\\|\\([0-9]+\\)\\)-g[0-9a-z]+\\(-dirty\\)?$" it) (if with-distance `(,(match-string 1 it) ,(string-to-number (or (match-string 2 it) "0")) ,@(and (match-string 3 it) (list t))) (match-string 1 it))))) (defun magit-get-next-tag (&optional rev with-distance) "Return the closest tag from which REV is reachable. If optional REV is nil, then default to `HEAD'. If no such tag can be found or if the distance is 0 (in which case it is the current tag, not the next), return nil instead. If optional WITH-DISTANCE is non-nil, then return (TAG COMMITS) where COMMITS is the number of commits in TAG but not in REV." (--when-let (magit-git-str "describe" "--contains" (or rev "HEAD")) (save-match-data (when (string-match "^[^^~]+" it) (setq it (match-string 0 it)) (unless (equal it (magit-get-current-tag rev)) (if with-distance (list it (car (magit-rev-diff-count it rev))) it)))))) (defvar magit-list-refs-namespaces '("refs/heads" "refs/remotes" "refs/tags" "refs/pull")) (defun magit-list-refs (&optional namespaces format sortby) "Return list of references. When NAMESPACES is non-nil, list refs from these namespaces rather than those from `magit-list-refs-namespaces'. FORMAT is passed to the `--format' flag of `git for-each-ref' and defaults to \"%(refname)\". If the format is \"%(refname)\" or \"%(refname:short)\", then drop the symbolic-ref \"HEAD\". SORTBY is a key or list of keys to pass to the `--sort' flag of `git for-each-ref'. When nil, use `magit-list-refs-sortby'" (unless format (setq format "%(refname)")) (let ((refs (magit-git-lines "for-each-ref" (concat "--format=" format) (--map (concat "--sort=" it) (pcase (or sortby magit-list-refs-sortby) ((and val (pred stringp)) (list val)) ((and val (pred listp)) val))) (or namespaces magit-list-refs-namespaces)))) (if (member format '("%(refname)" "%(refname:short)")) (--remove (string-match-p "\\(\\`\\|/\\)HEAD\\'" it) refs) refs))) (defun magit-list-branches () (magit-list-refs (list "refs/heads" "refs/remotes"))) (defun magit-list-local-branches () (magit-list-refs "refs/heads")) (defun magit-list-remote-branches (&optional remote) (magit-list-refs (concat "refs/remotes/" remote))) (defun magit-list-related-branches (relation &optional commit arg) (--remove (string-match-p "\\(\\`(HEAD\\|HEAD -> \\)" it) (--map (substring it 2) (magit-git-lines "branch" arg relation commit)))) (defun magit-list-containing-branches (&optional commit arg) (magit-list-related-branches "--contains" commit arg)) (defun magit-list-publishing-branches (&optional commit) (--filter (magit-rev-ancestor-p commit it) magit-published-branches)) (defun magit-list-merged-branches (&optional commit arg) (magit-list-related-branches "--merged" commit arg)) (defun magit-list-unmerged-branches (&optional commit arg) (magit-list-related-branches "--no-merged" commit arg)) (defun magit-list-unmerged-to-upstream-branches () (--filter (when-let ((upstream (magit-get-upstream-branch it))) (member it (magit-list-unmerged-branches upstream))) (magit-list-local-branch-names))) (defun magit-list-branches-pointing-at (commit) (let ((re (format "\\`%s refs/\\(heads\\|remotes\\)/\\(.*\\)\\'" (magit-rev-verify commit)))) (--keep (and (string-match re it) (let ((name (match-string 2 it))) (and (not (string-suffix-p "HEAD" name)) name))) (magit-git-lines "show-ref")))) (defun magit-list-refnames (&optional namespaces) (magit-list-refs namespaces "%(refname:short)")) (defun magit-list-branch-names () (magit-list-refnames (list "refs/heads" "refs/remotes"))) (defun magit-list-local-branch-names () (magit-list-refnames "refs/heads")) (defun magit-list-remote-branch-names (&optional remote relative) (if (and remote relative) (let ((regexp (format "^refs/remotes/%s/\\(.+\\)" remote))) (--mapcat (when (string-match regexp it) (list (match-string 1 it))) (magit-list-remote-branches remote))) (magit-list-refnames (concat "refs/remotes/" remote)))) (defun magit-format-refs (format &rest args) (let ((lines (magit-git-lines "for-each-ref" (concat "--format=" format) (or args (list "refs/heads" "refs/remotes" "refs/tags"))))) (if (string-match-p "\f" format) (--map (split-string it "\f") lines) lines))) (defun magit-list-remotes () (magit-git-lines "remote")) (defun magit-list-tags () (magit-git-lines "tag")) (defun magit-list-stashes (&optional format) (magit-git-lines "stash" "list" (concat "--format=" (or format "%gd")))) (defun magit-list-active-notes-refs () "Return notes refs according to `core.notesRef' and `notes.displayRef'." (magit-git-lines "for-each-ref" "--format=%(refname)" (or (magit-get "core.notesRef") "refs/notes/commits") (magit-get-all "notes.displayRef"))) (defun magit-list-notes-refnames () (--map (substring it 6) (magit-list-refnames "refs/notes"))) (defun magit-remote-list-tags (remote) (--keep (and (not (string-match-p "\\^{}$" it)) (substring it 51)) (magit-git-lines "ls-remote" "--tags" remote))) (defun magit-remote-list-branches (remote) (--keep (and (not (string-match-p "\\^{}$" it)) (substring it 52)) (magit-git-lines "ls-remote" "--heads" remote))) (defun magit-remote-list-refs (remote) (--keep (and (not (string-match-p "\\^{}$" it)) (substring it 41)) (magit-git-lines "ls-remote" remote))) (defun magit-list-module-paths () (--mapcat (and (string-match "^160000 [0-9a-z]\\{40\\} 0\t\\(.+\\)$" it) (list (match-string 1 it))) (magit-git-items "ls-files" "-z" "--stage"))) (defun magit-get-submodule-name (path) "Return the name of the submodule at PATH. PATH has to be relative to the super-repository." (cadr (split-string (car (or (magit-git-items "config" "-z" "-f" (expand-file-name ".gitmodules" (magit-toplevel)) "--get-regexp" "^submodule\\..*\\.path$" (concat "^" (regexp-quote (directory-file-name path)) "$")) (error "No such submodule `%s'" path))) "\n"))) (defun magit-list-worktrees () (let (worktrees worktree) (dolist (line (let ((magit-git-global-arguments ;; KLUDGE At least in v2.8.3 this triggers a segfault. (remove "--no-pager" magit-git-global-arguments))) (magit-git-lines "worktree" "list" "--porcelain"))) (cond ((string-prefix-p "worktree" line) (push (setq worktree (list (substring line 9) nil nil nil)) worktrees)) ((string-equal line "bare") (let* ((default-directory (car worktree)) (wt (and (not (magit-get-boolean "core.bare")) (magit-get "core.worktree")))) (if (and wt (file-exists-p (expand-file-name wt))) (progn (setf (nth 0 worktree) (expand-file-name wt)) (setf (nth 2 worktree) (magit-rev-parse "HEAD")) (setf (nth 3 worktree) (magit-get-current-branch))) (setf (nth 1 worktree) t)))) ((string-prefix-p "HEAD" line) (setf (nth 2 worktree) (substring line 5))) ((string-prefix-p "branch" line) (setf (nth 3 worktree) (substring line 18))) ((string-equal line "detached")))) (nreverse worktrees))) (defun magit-symbolic-ref-p (name) (magit-git-success "symbolic-ref" "--quiet" name)) (defun magit-ref-p (rev) (or (car (member rev (magit-list-refs))) (car (member rev (magit-list-refnames))))) (defun magit-branch-p (rev) (or (car (member rev (magit-list-branches))) (car (member rev (magit-list-branch-names))))) (defun magit-local-branch-p (rev) (or (car (member rev (magit-list-local-branches))) (car (member rev (magit-list-local-branch-names))))) (defun magit-remote-branch-p (rev) (or (car (member rev (magit-list-remote-branches))) (car (member rev (magit-list-remote-branch-names))))) (defun magit-branch-set-face (branch) (propertize branch 'face (if (magit-local-branch-p branch) 'magit-branch-local 'magit-branch-remote))) (defun magit-tag-p (rev) (car (member rev (magit-list-tags)))) (defun magit-remote-p (string) (car (member string (magit-list-remotes)))) (defun magit-rev-diff-count (a b) "Return the commits in A but not B and vice versa. Return a list of two integers: (A>B B>A)." (mapcar 'string-to-number (split-string (magit-git-string "rev-list" "--count" "--left-right" (concat a "..." b)) "\t"))) (defun magit-abbrev-length () (--if-let (magit-get "core.abbrev") (string-to-number it) ;; Guess the length git will be using based on an example ;; abbreviation. Actually HEAD's abbreviation might be an ;; outlier, so use the shorter of the abbreviations for two ;; commits. When a commit does not exist, then fall back ;; to the default of 7. See #3034. (min (--if-let (magit-rev-parse "--short" "HEAD") (length it) 7) (--if-let (magit-rev-parse "--short" "HEAD~") (length it) 7)))) (defun magit-abbrev-arg (&optional arg) (format "--%s=%d" (or arg "abbrev") (magit-abbrev-length))) (defun magit-rev-abbrev (rev) (magit-rev-parse (magit-abbrev-arg "short") rev)) (defun magit-commit-children (commit &optional args) (mapcar #'car (--filter (member commit (cdr it)) (--map (split-string it " ") (magit-git-lines "log" "--format=%H %P" (or args (list "--branches" "--tags" "--remotes")) "--not" commit))))) (defun magit-commit-parents (commit) (--when-let (magit-git-string "rev-list" "-1" "--parents" commit) (cdr (split-string it)))) (defun magit-patch-id (rev) (with-temp-buffer (magit-process-file shell-file-name nil '(t nil) nil shell-command-switch (let ((exec (shell-quote-argument magit-git-executable))) (format "%s diff-tree -u %s | %s patch-id" exec rev exec))) (car (split-string (buffer-string))))) (defun magit-rev-format (format &optional rev args) (let ((str (magit-git-string "show" "--no-patch" (concat "--format=" format) args (if rev (concat rev "^{commit}") "HEAD") "--"))) (unless (string-equal str "") str))) (defun magit-rev-insert-format (format &optional rev args) (magit-git-insert "show" "--no-patch" (concat "--format=" format) args (if rev (concat rev "^{commit}") "HEAD") "--")) (defun magit-format-rev-summary (rev) (--when-let (magit-rev-format "%h %s" rev) (string-match " " it) (put-text-property 0 (match-beginning 0) 'face 'magit-hash it) it)) (defvar magit-ref-namespaces '(("\\`HEAD\\'" . magit-head) ("\\`refs/tags/\\(.+\\)" . magit-tag) ("\\`refs/heads/\\(.+\\)" . magit-branch-local) ("\\`refs/remotes/\\(.+\\)" . magit-branch-remote) ("\\`refs/bisect/\\(bad\\)" . magit-bisect-bad) ("\\`refs/bisect/\\(skip.*\\)" . magit-bisect-skip) ("\\`refs/bisect/\\(good.*\\)" . magit-bisect-good) ("\\`refs/stash$" . magit-refname-stash) ("\\`refs/wip/\\(.+\\)" . magit-refname-wip) ("\\`refs/pullreqs/\\(.+\\)" . magit-refname-pullreq) ("\\`\\(bad\\):" . magit-bisect-bad) ("\\`\\(skip\\):" . magit-bisect-skip) ("\\`\\(good\\):" . magit-bisect-good) ("\\`\\(.+\\)" . magit-refname)) "How refs are formatted for display. Each entry controls how a certain type of ref is displayed, and has the form (REGEXP . FACE). REGEXP is a regular expression used to match full refs. The first entry whose REGEXP matches the reference is used. In log and revision buffers the first regexp submatch becomes the \"label\" that represents the ref and is propertized with FONT. In refs buffers the displayed text is controlled by other means and this option only controls what face is used.") (defun magit-format-ref-labels (string) ;; To support Git <2.2.0, we remove the surrounding parentheses here ;; rather than specifying that STRING should be generated with Git's ;; "%D" placeholder. (setq string (->> string (replace-regexp-in-string "\\`\\s-*(" "") (replace-regexp-in-string ")\\s-*\\'" ""))) (save-match-data (let ((regexp "\\(, \\|tag: \\|HEAD -> \\)") names) (if (and (derived-mode-p 'magit-log-mode) (member "--simplify-by-decoration" (cadr magit-refresh-args))) (let ((branches (magit-list-local-branch-names)) (re (format "^%s/.+" (regexp-opt (magit-list-remotes))))) (setq names (--map (cond ((string-equal it "HEAD") it) ((string-prefix-p "refs/" it) it) ((member it branches) (concat "refs/heads/" it)) ((string-match re it) (concat "refs/remotes/" it)) (t (concat "refs/" it))) (split-string (replace-regexp-in-string "tag: " "refs/tags/" string) regexp t)))) (setq names (split-string string regexp t))) (let (state head upstream tags branches remotes other combined) (dolist (ref names) (let* ((face (cdr (--first (string-match (car it) ref) magit-ref-namespaces))) (name (propertize (or (match-string 1 ref) ref) 'face face))) (cl-case face ((magit-bisect-bad magit-bisect-skip magit-bisect-good) (setq state name)) (magit-head (setq head (propertize "@" 'face 'magit-head))) (magit-tag (push name tags)) (magit-branch-local (push name branches)) (magit-branch-remote (push name remotes)) (t (push name other))))) (setq remotes (-keep (lambda (name) (if (string-match "\\`\\([^/]*\\)/\\(.*\\)\\'" name) (let ((r (match-string 1 name)) (b (match-string 2 name))) (and (not (equal b "HEAD")) (if (equal (concat "refs/remotes/" name) (magit-git-string "symbolic-ref" (format "refs/remotes/%s/HEAD" r))) (propertize name 'face 'magit-branch-remote-head) name))) name)) remotes)) (let* ((current (magit-get-current-branch)) (target (magit-get-upstream-branch current t))) (dolist (name branches) (let ((push (car (member (magit-get-push-branch name) remotes)))) (when push (setq remotes (delete push remotes)) (string-match "^[^/]*/" push) (setq push (substring push 0 (match-end 0)))) (cond ((equal name current) (setq head (concat push (propertize name 'face 'magit-branch-current)))) ((equal name target) (setq upstream (concat push (propertize name 'face '(magit-branch-upstream magit-branch-local))))) (t (push (concat push name) combined))))) (when (and target (not upstream)) (if (member target remotes) (progn (add-face-text-property 0 (length target) 'magit-branch-upstream nil target) (setq upstream target) (setq remotes (delete target remotes))) (when-let ((target (car (member target combined)))) (add-face-text-property 0 (length target) 'magit-branch-upstream nil target) (setq upstream target) (setq combined (delete target combined)))))) (mapconcat #'identity (-flatten `(,state ,head ,upstream ,@(nreverse tags) ,@(nreverse combined) ,@(nreverse remotes) ,@other)) " "))))) (defun magit-object-type (object) (magit-git-string "cat-file" "-t" object)) (defmacro magit-with-blob (commit file &rest body) (declare (indent 2) (debug (form form body))) `(with-temp-buffer (let ((buffer-file-name ,file)) (save-excursion (magit-git-insert "cat-file" "-p" (concat ,commit ":" buffer-file-name))) (decode-coding-inserted-region (point-min) (point-max) buffer-file-name t nil nil t) ,@body))) (defmacro magit-with-temp-index (tree arg &rest body) (declare (indent 2) (debug (form form body))) (let ((file (cl-gensym "file"))) `(let ((magit--refresh-cache nil) (,file (magit-convert-filename-for-git (make-temp-name (magit-git-dir "index.magit."))))) (unwind-protect (magit-with-toplevel (--when-let ,tree (or (magit-git-success "read-tree" ,arg it (concat "--index-output=" ,file)) (error "Cannot read tree %s" it))) (if (file-remote-p default-directory) (let ((magit-tramp-process-environment (cons (concat "GIT_INDEX_FILE=" ,file) magit-tramp-process-environment))) ,@body) (let ((process-environment (cons (concat "GIT_INDEX_FILE=" ,file) process-environment))) ,@body))) (ignore-errors (delete-file (concat (file-remote-p default-directory) ,file))))))) (defun magit-commit-tree (message &optional tree &rest parents) (magit-git-string "commit-tree" "--no-gpg-sign" "-m" message (--mapcat (list "-p" it) (delq nil parents)) (or tree (magit-git-string "write-tree") (error "Cannot write tree")))) (defun magit-commit-worktree (message &optional arg &rest other-parents) (magit-with-temp-index "HEAD" arg (and (magit-update-files (magit-unstaged-files)) (apply #'magit-commit-tree message nil "HEAD" other-parents)))) (defun magit-update-files (files) (magit-git-success "update-index" "--add" "--remove" "--" files)) (defun magit-update-ref (ref message rev &optional stashish) (let ((magit--refresh-cache nil)) (or (if (not (version< (magit-git-version) "2.6.0")) (zerop (magit-call-git "update-ref" "--create-reflog" "-m" message ref rev (or (magit-rev-verify ref) ""))) ;; `--create-reflog' didn't exist before v2.6.0 (let ((oldrev (magit-rev-verify ref)) (logfile (magit-git-dir (concat "logs/" ref)))) (unless (file-exists-p logfile) (when oldrev (magit-git-success "update-ref" "-d" ref oldrev)) (make-directory (file-name-directory logfile) t) (with-temp-file logfile) (when (and oldrev (not stashish)) (magit-git-success "update-ref" "-m" "enable reflog" ref oldrev "")))) (magit-git-success "update-ref" "-m" message ref rev (or (magit-rev-verify ref) ""))) (error "Cannot update %s with %s" ref rev)))) (defconst magit-range-re (concat "\\`\\([^ \t]*[^.]\\)?" ; revA "\\(\\.\\.\\.?\\)" ; range marker "\\([^.][^ \t]*\\)?\\'")) ; revB (defun magit-split-range (range) (and (string-match magit-range-re range) (let ((beg (or (match-string 1 range) "HEAD")) (end (or (match-string 3 range) "HEAD"))) (cons (if (string-equal (match-string 2 range) "...") (magit-git-string "merge-base" beg end) beg) end)))) (defvar magit-thingatpt--git-revision-chars "-_./[:alnum:]@{}^~!" "Characters allowable in filenames, excluding space and colon.") (put 'git-revision 'end-op (lambda () (re-search-forward (concat "\\=[" magit-thingatpt--git-revision-chars "]*") nil t))) (put 'git-revision 'beginning-op (lambda () (if (re-search-backward (concat "[^" magit-thingatpt--git-revision-chars "]") nil t) (forward-char) (goto-char (point-min))))) (put 'git-revision 'thing-at-point 'magit-thingatpt--git-revision) (defun magit-thingatpt--git-revision () (--when-let (bounds-of-thing-at-point 'git-revision) (let ((text (buffer-substring-no-properties (car it) (cdr it)))) (and (magit-rev-verify-commit text) text)))) ;;; Completion (defvar magit-revision-history nil) (defun magit-read-branch (prompt &optional secondary-default) (magit-completing-read prompt (magit-list-branch-names) nil t nil 'magit-revision-history (or (magit-branch-at-point) secondary-default (magit-get-current-branch)))) (defun magit-read-branch-or-commit (prompt &optional secondary-default) (or (magit-completing-read prompt (cons "HEAD" (magit-list-refnames)) nil nil nil 'magit-revision-history (or (magit-branch-or-commit-at-point) secondary-default (magit-get-current-branch))) (user-error "Nothing selected"))) (defun magit-read-range-or-commit (prompt &optional secondary-default) (magit-read-range prompt (or (--when-let (magit-region-values '(commit branch) t) (deactivate-mark) (concat (car (last it)) ".." (car it))) (magit-branch-or-commit-at-point) secondary-default (magit-get-current-branch)))) (defun magit-read-range (prompt &optional default) (magit-completing-read-multiple prompt (magit-list-refnames) "\\.\\.\\.?" default 'magit-revision-history)) (defun magit-read-remote-branch (prompt &optional remote default local-branch require-match) (let ((choice (magit-completing-read prompt (-union (and local-branch (if remote (concat remote "/" local-branch) (--map (concat it "/" local-branch) (magit-list-remotes)))) (magit-list-remote-branch-names remote t)) nil require-match nil 'magit-revision-history default))) (if (or remote (string-match "\\`\\([^/]+\\)/\\(.+\\)" choice)) choice (user-error "`%s' doesn't have the form REMOTE/BRANCH" choice)))) (defun magit-read-refspec (prompt remote) (magit-completing-read prompt (prog2 (message "Determining available refs...") (magit-remote-list-refs remote) (message "Determining available refs...done")))) (defun magit-read-local-branch (prompt &optional secondary-default) (magit-completing-read prompt (magit-list-local-branch-names) nil t nil 'magit-revision-history (or (magit-local-branch-at-point) secondary-default (magit-get-current-branch)))) (defun magit-read-local-branch-or-commit (prompt) (let ((branches (magit-list-local-branch-names)) (commit (magit-commit-at-point))) (or (magit-completing-read prompt (if commit (cons commit branches) branches) nil nil nil 'magit-revision-history (or (magit-local-branch-at-point) commit)) (user-error "Nothing selected")))) (defun magit-read-local-branch-or-ref (prompt &optional secondary-default) (magit-completing-read prompt (nconc (magit-list-local-branch-names) (magit-list-refs "refs/")) nil t nil 'magit-revision-history (or (magit-local-branch-at-point) secondary-default (magit-get-current-branch)))) (defun magit-read-other-branch (prompt &optional exclude secondary-default no-require-match) (let* ((current (magit-get-current-branch)) (atpoint (magit-branch-at-point)) (exclude (or exclude current)) (default (or (and (not (equal atpoint exclude)) atpoint) (and (not (equal current exclude)) current) secondary-default (magit-get-previous-branch)))) (magit-completing-read prompt (delete exclude (magit-list-branch-names)) nil (not no-require-match) nil 'magit-revision-history default))) (defun magit-read-other-branch-or-commit (prompt &optional exclude secondary-default) (let* ((current (magit-get-current-branch)) (atpoint (magit-branch-or-commit-at-point)) (exclude (or exclude current)) (default (or (and (not (equal atpoint exclude)) atpoint) (and (not (equal current exclude)) current) secondary-default (magit-get-previous-branch)))) (or (magit-completing-read prompt (delete exclude (magit-list-refnames)) nil nil nil 'magit-revision-history default) (user-error "Nothing selected")))) (defun magit-read-other-local-branch (prompt &optional exclude secondary-default no-require-match) (let* ((current (magit-get-current-branch)) (atpoint (magit-local-branch-at-point)) (exclude (or exclude current)) (default (or (and (not (equal atpoint exclude)) atpoint) (and (not (equal current exclude)) current) secondary-default (magit-get-previous-branch)))) (magit-completing-read prompt (delete exclude (magit-list-local-branch-names)) nil (not no-require-match) nil 'magit-revision-history default))) (defun magit-read-branch-prefer-other (prompt) (let* ((current (magit-get-current-branch)) (commit (magit-commit-at-point)) (atrev (and commit (magit-list-branches-pointing-at commit))) (atpoint (magit--painted-branch-at-point))) (magit-completing-read prompt (magit-list-branch-names) nil t nil 'magit-revision-history (or (magit-section-value-if 'branch) atpoint (and (not (cdr atrev)) (car atrev)) (--first (not (equal it current)) atrev) (magit-get-previous-branch) (car atrev))))) (cl-defun magit-read-upstream-branch (&optional (branch (magit-get-current-branch)) prompt) (magit-completing-read (or prompt (format "Change upstream of %s to" branch)) (-union (--map (concat it "/" branch) (magit-list-remotes)) (delete branch (magit-list-branch-names))) nil nil nil 'magit-revision-history (or (let ((r (magit-remote-branch-at-point)) (l (magit-branch-at-point))) (when (and l (equal l branch)) (setq l nil)) (if magit-prefer-remote-upstream (or r l) (or l r))) (let ((r (magit-branch-p "origin/master")) (l (and (not (equal branch "master")) (magit-branch-p "master")))) (if magit-prefer-remote-upstream (or r l) (or l r))) (let ((previous (magit-get-previous-branch))) (and (not (equal previous branch)) previous))))) (defun magit-read-starting-point (prompt &optional branch) (or (magit-completing-read (concat prompt (and branch (if (bound-and-true-p ivy-mode) ;; Ivy-mode strips faces from prompt. (format " `%s'" branch) (concat " " (propertize branch 'face 'magit-branch-local)))) " starting at") (nconc (list "HEAD") (magit-list-refnames) (directory-files (magit-git-dir) nil "_HEAD\\'")) nil nil nil 'magit-revision-history (magit--default-starting-point)) (user-error "Nothing selected"))) (defun magit--default-starting-point () (or (let ((r (magit-remote-branch-at-point)) (l (magit-local-branch-at-point))) (if magit-prefer-remote-upstream (or r l) (or l r))) (magit-commit-at-point) (magit-stash-at-point) (magit-get-current-branch))) (defun magit-read-tag (prompt &optional require-match) (magit-completing-read prompt (magit-list-tags) nil require-match nil 'magit-revision-history (magit-tag-at-point))) (defun magit-read-stash (prompt) (let ((stashes (magit-list-stashes))) (magit-completing-read prompt stashes nil t nil nil (magit-stash-at-point) (car stashes)))) (defun magit-read-remote (prompt &optional default use-only) (let ((remotes (magit-list-remotes))) (if (and use-only (= (length remotes) 1)) (car remotes) (magit-completing-read prompt remotes nil t nil nil (or default (magit-remote-at-point) (magit-get-remote)))))) (defun magit-read-remote-or-url (prompt &optional default) (magit-completing-read prompt (nconc (magit-list-remotes) (list "https://" "git://" "git@")) nil nil nil nil (or default (magit-remote-at-point) (magit-get-remote)))) (defun magit-read-module-path (prompt &optional predicate) (magit-completing-read prompt (magit-list-module-paths) predicate t nil nil (magit-module-at-point predicate))) (defun magit-module-confirm (verb &optional predicate) (let (modules) (if current-prefix-arg (progn (setq modules (magit-list-module-paths)) (when predicate (setq modules (-filter predicate modules))) (unless modules (if predicate (user-error "No modules satisfying %s available" predicate) (user-error "No modules available")))) (setq modules (magit-region-values 'magit-module-section)) (when modules (when predicate (setq modules (-filter predicate modules))) (unless modules (user-error "No modules satisfying %s selected" predicate)))) (if (> (length modules) 1) (magit-confirm t nil (format "%s %%i modules" verb) nil modules) (list (magit-read-module-path (format "%s module" verb) predicate))))) ;;; Variables in Popups (defun magit--format-popup-variable:value (variable width &optional global) (concat variable (make-string (max 1 (- width 3 (length variable))) ?\s) (if-let ((value (magit-get (and global "--global") variable))) (propertize value 'face 'magit-popup-option-value) (propertize "unset" 'face 'magit-popup-disabled-argument)))) (defun magit--format-popup-variable:values (variable width &optional global) (concat variable (make-string (max 1 (- width 3 (length variable))) ?\s) (if-let ((values (magit-get-all (and global "--global") variable))) (concat (propertize (car values) 'face 'magit-popup-option-value) (mapconcat (lambda (value) (concat "\n" (make-string width ?\s) (propertize value 'face 'magit-popup-option-value))) (cdr values) "")) (propertize "unset" 'face 'magit-popup-disabled-argument)))) (defun magit--set-popup-variable (variable choices &optional default other) (magit-set (--if-let (magit-git-string "config" "--local" variable) (cadr (member it choices)) (car choices)) variable) (magit-with-pre-popup-buffer (magit-refresh)) (message "%s %s" variable (magit--format-popup-variable:choices* variable choices default other))) (defun magit--format-popup-variable:choices (variable choices &optional default other width) (concat variable (if width (make-string (- width (length variable)) ?\s) " ") (magit--format-popup-variable:choices* variable choices default other))) (defun magit--format-popup-variable:choices* (variable choices &optional default other) (let ((local (magit-git-string "config" "--local" variable)) (global (magit-git-string "config" "--global" variable))) (when other (setq other (--when-let (magit-get other) (concat other ":" it)))) (concat (propertize "[" 'face 'magit-popup-disabled-argument) (mapconcat (lambda (choice) (propertize choice 'face (if (equal choice local) 'magit-popup-option-value 'magit-popup-disabled-argument))) choices (propertize "|" 'face 'magit-popup-disabled-argument)) (when (or global other default) (concat (propertize "|" 'face 'magit-popup-disabled-argument) (cond (global (propertize (concat "global:" global) 'face (cond (local 'magit-popup-disabled-argument) ((member global choices) 'magit-popup-option-value) (t 'font-lock-warning-face)))) (other (propertize other 'face (if local 'magit-popup-disabled-argument 'magit-popup-option-value))) (default (propertize (concat "default:" default) 'face (if local 'magit-popup-disabled-argument 'magit-popup-option-value)))))) (propertize "]" 'face 'magit-popup-disabled-argument)))) ;;; _ (provide 'magit-git) ;;; magit-git.el ends here magit-2.90.1/lisp/magit-gitignore.el000066400000000000000000000066071337354740400173060ustar00rootroot00000000000000;;; magit-gitignore.el --- intentionally untracked files -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Commands ;;;###autoload (autoload 'magit-gitignore-popup "magit-gitignore" nil t) (magit-define-popup magit-gitignore-popup "Popup console for gitignore commands." :man-page "gitignore" :actions '((?l "ignore locally" magit-gitignore-locally) (?g "ignore globally" magit-gitignore-globally)) :max-action-columns 1) ;;;###autoload (defun magit-gitignore-globally (file-or-pattern) "Instruct Git to globally ignore FILE-OR-PATTERN." (interactive (list (magit-gitignore-read-pattern nil))) (magit--gitignore file-or-pattern nil)) ;;;###autoload (defun magit-gitignore-locally (file-or-pattern) "Instruct Git to locally ignore FILE-OR-PATTERN." (interactive (list (magit-gitignore-read-pattern t))) (magit--gitignore file-or-pattern t)) (defun magit--gitignore (file-or-pattern local) (let ((gitignore (if local (magit-git-dir (convert-standard-filename "info/exclude")) (expand-file-name ".gitignore" (magit-toplevel))))) (make-directory (file-name-directory gitignore) t) (with-temp-buffer (when (file-exists-p gitignore) (insert-file-contents gitignore)) (goto-char (point-max)) (unless (bolp) (insert "\n")) (insert (replace-regexp-in-string "\\(\\\\*\\)" "\\1\\1" file-or-pattern)) (insert "\n") (write-region nil nil gitignore)) (if local (magit-refresh) (magit-run-git "add" ".gitignore")))) (defun magit-gitignore-read-pattern (local) (let* ((default (magit-current-file)) (choices (delete-dups (--mapcat (cons (concat "/" it) (when-let ((ext (file-name-extension it))) (list (concat "/" (file-name-directory "foo") "*." ext) (concat "*." ext)))) (magit-untracked-files))))) (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 (concat "File or pattern to ignore" (and local " locally")) choices nil nil nil nil default))) ;;; _ (provide 'magit-gitignore) ;;; magit-gitignore.el ends here magit-2.90.1/lisp/magit-imenu.el000066400000000000000000000177511337354740400164360ustar00rootroot00000000000000;;; magit-imenu.el --- Integrate Imenu in magit major modes -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (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 magit-2.90.1/lisp/magit-log.el000066400000000000000000002141331337354740400160730ustar00rootroot00000000000000;;; magit-log.el --- inspect Git history -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 logs, including ;; special logs like reflogs and cherry-logs, as well as for selecting ;; a commit from a log. ;;; Code: (require 'magit-core) (require 'magit-diff) (declare-function magit-blob-visit "magit-files" (blob-or-file line)) (declare-function magit-insert-head-branch-header "magit-status" (&optional branch)) (declare-function magit-insert-upstream-branch-header "magit-status" (&optional branch pull keyword)) (declare-function magit-read-file-from-rev "magit-files" (rev prompt &optional default)) (declare-function magit-show-commit "magit-diff" (arg1 &optional arg2 arg3 arg4)) (defvar magit-refs-focus-column-width) (defvar magit-refs-margin) (defvar magit-refs-show-commit-count) (defvar magit-buffer-margin) (defvar magit-status-margin) (defvar magit-status-sections-hook) (require 'ansi-color) (require 'crm) (require 'which-func) (eval-when-compile (require 'subr-x)) (defvar bookmark-make-record-function) ;;; Options ;;;; Log Mode (defgroup magit-log nil "Inspect and manipulate Git history." :link '(info-link "(magit)Logging") :group 'magit-modes) (defcustom magit-log-mode-hook nil "Hook run after entering Magit-Log mode." :group 'magit-log :type 'hook) (defcustom magit-log-arguments '("-n256" "--graph" "--decorate") "The log arguments used in `magit-log-mode' buffers." :package-version '(magit . "2.3.0") :group 'magit-git-arguments :group 'magit-log :type '(repeat (string :tag "Argument"))) (defcustom magit-log-remove-graph-args '("--follow" "--grep" "-G" "-S" "-L") "The log arguments that cause the `--graph' argument to be dropped." :package-version '(magit . "2.3.0") :group 'magit-log :type '(repeat (string :tag "Argument")) :options '("--follow" "--grep" "-G" "-S" "-L")) (defcustom magit-log-revision-headers-format "\ %+b Author: %aN <%aE> Committer: %cN <%cE>" "Additional format string used with the `++header' argument." :package-version '(magit . "2.3.0") :group 'magit-log :type 'string) (defcustom magit-log-auto-more nil "Insert more log entries automatically when moving past the last entry. Only considered when moving past the last entry with `magit-goto-*-section' commands." :group 'magit-log :type 'boolean) (defcustom magit-log-margin '(t age magit-log-margin-width t 18) "Format of the margin in `magit-log-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 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. 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 (apply-partially #'magit-margin-set-variable 'magit-log-mode)) (defcustom magit-log-show-refname-after-summary nil "Whether to show refnames after commit summaries. This is useful if you use really long branch names." :package-version '(magit . "2.2.0") :group 'magit-log :type 'boolean) (defcustom magit-log-highlight-keywords t "Whether to highlight bracketed keywords in commit summaries." :package-version '(magit . "2.12.0") :group 'magit-log :type 'boolean) (defcustom magit-log-header-line-function 'magit-log-header-line-sentence "Function used to generate text shown in header line of log buffers." :package-version '(magit . "2.12.0") :group 'magit-log :type '(choice (function-item magit-log-header-line-arguments) (function-item magit-log-header-line-sentence) function)) (defcustom magit-log-trace-definition-function 'which-function "Function used to determine the function at point. This is used by the command `magit-log-trace-definition'." :package-version '(magit . "2.90.0") :group 'magit-log :type '(choice (function-item which-function) function)) (defface magit-log-graph '((((class color) (background light)) :foreground "grey30") (((class color) (background dark)) :foreground "grey80")) "Face for the graph part of the log output." :group 'magit-faces) (defface magit-log-author '((((class color) (background light)) :foreground "firebrick") (((class color) (background dark)) :foreground "tomato")) "Face for the author part of the log output." :group 'magit-faces) (defface magit-log-date '((((class color) (background light)) :foreground "grey30") (((class color) (background dark)) :foreground "grey80")) "Face for the date part of the log output." :group 'magit-faces) (defface magit-header-line-log-select '((t :inherit bold)) "Face for the `header-line' in `magit-log-select-mode'." :group 'magit-faces) ;;;; File Log (defcustom magit-log-buffer-file-locked t "Whether `magit-log-buffer-file' uses a dedicated buffer." :package-version '(magit . "2.7.0") :group 'magit-commands :group 'magit-log :type 'boolean) ;;;; Select Mode (defcustom magit-log-select-arguments '("-n256" "--graph" "--decorate") "The log arguments used in `magit-log-select-mode' buffers." :package-version '(magit . "2.3.0") :group 'magit-log :type '(repeat (string :tag "Argument"))) (defcustom magit-log-select-show-usage 'both "Whether to show usage information when selecting a commit from a log. The message can be shown in the `echo-area' or the `header-line', or in `both' places. If the value isn't one of these symbols, then it should be nil, in which case no usage information is shown." :package-version '(magit . "2.1.0") :group 'magit-log :type '(choice (const :tag "in echo-area" echo-area) (const :tag "in header-line" header-line) (const :tag "in both places" both) (const :tag "nowhere"))) (defcustom magit-log-select-margin (list (nth 0 magit-log-margin) (nth 1 magit-log-margin) 'magit-log-margin-width t (nth 4 magit-log-margin)) "Format of the margin in `magit-log-select-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 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. 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-log-select-mode)) ;;;; Cherry Mode (defcustom magit-cherry-sections-hook '(magit-insert-cherry-headers magit-insert-cherry-commits) "Hook run to insert sections into the cherry buffer." :package-version '(magit . "2.1.0") :group 'magit-log :type 'hook) (defcustom magit-cherry-margin (list (nth 0 magit-log-margin) (nth 1 magit-log-margin) 'magit-log-margin-width t (nth 4 magit-log-margin)) "Format of the margin in `magit-cherry-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 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. 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-cherry-mode)) ;;;; Reflog Mode (defcustom magit-reflog-arguments '("-n256") "The log arguments used in `magit-reflog-mode' buffers." :package-version '(magit . "2.3.0") :group 'magit-git-arguments :type '(repeat (string :tag "Argument"))) (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 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. 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)) (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) ;;;; Log Sections (defcustom magit-log-section-commit-count 10 "How many recent commits to show in certain log sections. How many recent commits `magit-insert-recent-commits' and `magit-insert-unpulled-from-upstream-or-recent' (provided the upstream isn't ahead of the current branch) show." :package-version '(magit . "2.1.0") :group 'magit-status :type 'number) (defcustom magit-log-section-arguments '("-n256" "--decorate") "The log arguments used in buffers that show other things besides logs." :package-version '(magit . "2.4.0") :group 'magit-git-arguments :group 'magit-log :group 'magit-status :type '(repeat (string :tag "Argument"))) ;;; Commands ;;;; Popups (defvar magit-log-popup '(:variable magit-log-arguments :man-page "git-log" :switches ((?g "Show graph" "--graph") (?c "Show graph in color" "--color") (?d "Show refnames" "--decorate") (?S "Show signatures" "--show-signature") (?u "Show diffs" "--patch") (?s "Show diffstats" "--stat") (?h "Show header" "++header" magit-log++header) (?r "Show in reverse order" "--reverse") (?D "Simplify by decoration" "--simplify-by-decoration") (?f "Follow renames when showing single-file log" "--follow")) :options ((?n "Limit number of commits" "-n") (?f "Limit to files" "-- " magit-read-files) (?a "Limit to author" "--author=") (?o "Order commits by" "++order=" magit-log-select-order) (?g "Search messages" "--grep=") (?G "Search changes" "-G") (?S "Search occurrences" "-S") (?L "Trace line evolution" "-L" magit-read-file-trace)) :actions ((?l "Log current" magit-log-current) (?L "Log local branches" magit-log-branches) (?r "Reflog current" magit-reflog-current) (?o "Log other" magit-log-other) (?b "Log all branches" magit-log-all-branches) (?O "Reflog other" magit-reflog-other) (?h "Log HEAD" magit-log-head) (?a "Log all references" magit-log-all) (?H "Reflog HEAD" magit-reflog-head)) :default-action magit-log-current :max-action-columns 3)) (defvar magit-log-mode-refresh-popup '(:variable magit-log-arguments :man-page "git-log" :switches ((?g "Show graph" "--graph") (?c "Show graph in color" "--color") (?d "Show refnames" "--decorate") (?S "Show signatures" "--show-signature") (?u "Show diffs" "--patch") (?s "Show diffstats" "--stat") (?r "Show in reverse order" "--reverse") (?D "Simplify by decoration" "--simplify-by-decoration") (?f "Follow renames when showing single-file log" "--follow")) :options ((?n "Limit number of commits" "-n") (?f "Limit to files" "-- " magit-read-files) (?a "Limit to author" "--author=") (?o "Order commits by" "++order=" magit-log-select-order) (?g "Search messages" "--grep=") (?G "Search changes" "-G") (?S "Search occurrences" "-S") (?L "Trace line evolution" "-L" magit-read-file-trace)) :actions ((?g "Refresh" magit-log-refresh) (?L "Toggle margin" magit-toggle-margin) (?s "Set defaults" magit-log-set-default-arguments) nil (?w "Save defaults" magit-log-save-default-arguments)) :max-action-columns 2)) (defvar magit-reflog-mode-refresh-popup '(:variable magit-reflog-arguments :man-page "git-reflog" :options ((?n "Limit number of commits" "-n")))) (defvar magit-log-refresh-popup '(:variable magit-log-arguments :man-page "git-log" :switches ((?g "Show graph" "--graph") (?c "Show graph in color" "--color") (?d "Show refnames" "--decorate")) :options ((?n "Limit number of commits" "-n") (?o "Order commits by" "++order=" magit-log-select-order)) :actions ("Refresh" (?g "buffer" magit-log-refresh) (?s "buffer and set defaults" magit-log-set-default-arguments) (?w "buffer and save defaults" magit-log-save-default-arguments) "Margin" (?L "toggle visibility" magit-toggle-margin) (?l "cycle style" magit-cycle-margin-style) (?d "toggle details" magit-toggle-margin-details)) :max-action-columns 1)) (magit-define-popup-keys-deferred 'magit-log-popup) (magit-define-popup-keys-deferred 'magit-log-mode-refresh-popup) (magit-define-popup-keys-deferred 'magit-log-refresh-popup) (defun magit-log-select-order (&rest _ignored) "Set one `---order' option in Git log. This encompasses the options `--author-date-order', `--date-order', and `--topo-order'." (magit-read-char-case "Order commits by " t (?t "[t]opography" "topo") (?a "[a]uthor date" "author-date") (?c "[c]ommitter date" "date"))) ;; This is a dummy procedure used to show help in `magit-log-popup'. (defun magit-log++header () "Insert a header after each revision summary in Git log. Customize `magit-log-revision-headers-format' to change this header." nil) (defun magit-log-get-buffer-args () (cond ((and magit-use-sticky-arguments (derived-mode-p 'magit-log-mode)) (list (nth 1 magit-refresh-args) (nth 2 magit-refresh-args))) ((and (eq magit-use-sticky-arguments t) (--when-let (magit-mode-get-buffer 'magit-log-mode) (with-current-buffer it (list (nth 1 magit-refresh-args) (nth 2 magit-refresh-args)))))) (t (list (default-value 'magit-log-arguments) nil)))) (defun magit-log-arguments (&optional refresh) (cond ((memq magit-current-popup '(magit-log-popup magit-log-refresh-popup)) (magit-popup-export-file-args magit-current-popup-args)) ((and refresh (not (derived-mode-p 'magit-log-mode))) (list magit-log-section-arguments nil)) (t (magit-log-get-buffer-args)))) (defun magit-log-popup (arg) "Popup console for log commands." (interactive "P") (let ((magit-log-refresh-popup (pcase major-mode (`magit-log-mode magit-log-mode-refresh-popup) (_ magit-log-refresh-popup))) (magit-log-arguments (apply #'magit-popup-import-file-args (magit-log-get-buffer-args)))) (magit-invoke-popup 'magit-log-popup nil arg))) ;;;###autoload (defun magit-log-buffer-file-popup () "Popup console for log commands. This is a variant of `magit-log-popup' which shows the same popup but which limits the log to the file being visited in the current buffer." (interactive) (if-let ((file (magit-file-relative-name))) (let ((magit-log-arguments (magit-popup-import-file-args (if-let ((buffer (magit-mode-get-buffer 'magit-log-mode))) (with-current-buffer buffer (nth 2 magit-refresh-args)) (default-value 'magit-log-arguments)) (list file)))) (magit-invoke-popup 'magit-log-popup nil nil)) (user-error "Buffer isn't visiting a file"))) (defun magit-log-refresh-popup (arg) "Popup console for changing log arguments in the current buffer." (interactive "P") (magit-log-refresh-assert) (let ((magit-log-refresh-popup (cond ((derived-mode-p 'magit-log-select-mode) magit-log-refresh-popup) ((derived-mode-p 'magit-log-mode) (let ((def (copy-sequence magit-log-refresh-popup))) (plist-put def :switches (plist-get magit-log-popup :switches)) (plist-put def :options (plist-get magit-log-popup :options)) def)) (t magit-log-refresh-popup))) (magit-log-arguments (cond ((derived-mode-p 'magit-log-select-mode) (cadr magit-refresh-args)) ((derived-mode-p 'magit-log-mode) (magit-popup-import-file-args (nth 1 magit-refresh-args) (nth 2 magit-refresh-args))) (t magit-log-section-arguments)))) (magit-invoke-popup 'magit-log-refresh-popup nil arg))) (defun magit-read-file-trace (&rest _ignored) (let ((file (magit-read-file-from-rev "HEAD" "File")) (trace (magit-read-string "Trace"))) (concat trace (or (match-string 2 trace) ":") file))) ;;;; Refresh Commands (defun magit-log-refresh (args files) "Set the local log arguments for the current buffer." (interactive (magit-log-arguments t)) (magit-log-refresh-assert) (cond ((derived-mode-p 'magit-log-select-mode) (setcar (cdr magit-refresh-args) args)) ((derived-mode-p 'magit-log-mode) (setcdr magit-refresh-args (list args files))) (t (setq-local magit-log-section-arguments args))) (magit-refresh)) (defun magit-log-set-default-arguments (args files) "Set the global log arguments for the current buffer." (interactive (magit-log-arguments t)) (magit-log-refresh-assert) (cond ((derived-mode-p 'magit-log-select-mode) (customize-set-variable 'magit-log-select-arguments args) (setcar (cdr magit-refresh-args) args)) ((derived-mode-p 'magit-log-mode) (customize-set-variable 'magit-log-arguments args) (setcdr magit-refresh-args (list args files))) (t (customize-set-variable 'magit-log-section-arguments args) (kill-local-variable 'magit-log-section-arguments))) (magit-refresh)) (defun magit-log-save-default-arguments (args files) "Set and save the global log arguments for the current buffer." (interactive (magit-log-arguments t)) (magit-log-refresh-assert) (cond ((derived-mode-p 'magit-log-select-mode) (customize-save-variable 'magit-log-select-arguments args) (setcar (cdr magit-refresh-args) args)) ((derived-mode-p 'magit-log-mode) (customize-save-variable 'magit-log-arguments args) (setcdr magit-refresh-args (list args files))) (t (customize-save-variable 'magit-log-section-arguments args) (kill-local-variable 'magit-log-section-arguments))) (magit-refresh)) (defun magit-log-refresh-assert () (cond ((derived-mode-p 'magit-reflog-mode) (user-error "Cannot change log arguments in reflog buffers")) ((derived-mode-p 'magit-cherry-mode) (user-error "Cannot change log arguments in cherry buffers")))) ;;;; Log Commands (defvar magit-log-read-revs-map (let ((map (make-sparse-keymap))) (set-keymap-parent map crm-local-completion-map) (define-key map "\s" 'self-insert-command) map)) (defun magit-log-read-revs (&optional use-current) (or (and use-current (--when-let (magit-get-current-branch) (list it))) (let ((collection `(,@(and (file-exists-p (magit-git-dir "FETCH_HEAD")) (list "FETCH_HEAD")) ,@(magit-list-refnames)))) (split-string (magit-completing-read-multiple "Log rev,s" collection "\\(\\.\\.\\.?\\|[, ]\\)" (or (magit-branch-or-commit-at-point) (unless use-current (magit-get-previous-branch))) 'magit-revision-history magit-log-read-revs-map) "[, ]" t)))) (defun magit-git-log (revs args files) (require 'magit) (magit-mode-setup #'magit-log-mode revs args files) (magit-log-goto-same-commit)) ;;;###autoload (defun magit-log-current (revs &optional args files) "Show log for the current branch. When `HEAD' is detached or with a prefix argument show log for one or more revs read from the minibuffer." (interactive (cons (magit-log-read-revs t) (magit-log-arguments))) (magit-git-log revs args files)) ;;;###autoload (defun magit-log-other (revs &optional args files) "Show log for one or more revs read from the minibuffer. The user can input any revision or revisions separated by a space, or even ranges, but only branches and tags, and a representation of the commit at point, are available as completion candidates." (interactive (cons (magit-log-read-revs) (magit-log-arguments))) (magit-git-log revs args files)) ;;;###autoload (defun magit-log-head (&optional args files) "Show log for `HEAD'." (interactive (magit-log-arguments)) (magit-git-log (list "HEAD") args files)) ;;;###autoload (defun magit-log-branches (&optional args files) "Show log for all local branches and `HEAD'." (interactive (magit-log-arguments)) (magit-git-log (if (magit-get-current-branch) (list "--branches") (list "HEAD" "--branches")) args files)) ;;;###autoload (defun magit-log-all-branches (&optional args files) "Show log for all local and remote branches and `HEAD'." (interactive (magit-log-arguments)) (magit-git-log (if (magit-get-current-branch) (list "--branches" "--remotes") (list "HEAD" "--branches" "--remotes")) args files)) ;;;###autoload (defun magit-log-all (&optional args files) "Show log for all references and `HEAD'." (interactive (magit-log-arguments)) (magit-git-log (if (magit-get-current-branch) (list "--all") (list "HEAD" "--all")) args files)) ;;;###autoload (defun magit-log-buffer-file (&optional follow beg end) "Show log for the blob or file visited in the current buffer. With a prefix argument or when `--follow' is part of `magit-log-arguments', then follow renames. When the region is active, restrict the log to the lines that the region touches." (interactive (cons current-prefix-arg (and (region-active-p) (magit-file-relative-name) (save-restriction (widen) (list (line-number-at-pos (region-beginning)) (line-number-at-pos (let ((end (region-end))) (if (char-after end) end ;; Ensure that we don't get the line number ;; of a trailing newline. (1- end))))))))) (require 'magit) (if-let ((file (magit-file-relative-name))) (magit-mode-setup-internal #'magit-log-mode (list (list (or magit-buffer-refname (magit-get-current-branch) "HEAD")) (let ((args (car (magit-log-arguments)))) (when (and follow (not (member "--follow" args))) (push "--follow" args)) (when (and (file-regular-p (expand-file-name file (magit-toplevel))) beg end) (setq args (cons (format "-L%s,%s:%s" beg end file) (cl-delete "-L" args :test 'string-prefix-p))) (setq file nil)) args) (and file (list file))) magit-log-buffer-file-locked) (user-error "Buffer isn't visiting a file")) (magit-log-goto-same-commit)) ;;;###autoload (defun magit-log-trace-definition (file fn rev) "Show log for the definition at point." (interactive (list (or (magit-file-relative-name) (user-error "Buffer isn't visiting a file")) (funcall magit-log-trace-definition-function) (or magit-buffer-refname (magit-get-current-branch) "HEAD"))) (require 'magit) (magit-mode-setup-internal #'magit-log-mode (list (list rev) (cons (format "-L:%s:%s" (regexp-quote fn) file) (cl-delete "-L" (car (magit-log-arguments)) :test 'string-prefix-p)) nil) magit-log-buffer-file-locked) (magit-log-goto-same-commit)) (defun magit-diff-trace-definition () "Show log for the definition at point in a diff." (interactive) (let (buf pos) (save-window-excursion (call-interactively #'magit-diff-visit-file) (setq buf (current-buffer)) (setq pos (point))) (save-excursion (with-current-buffer buf (goto-char pos) (call-interactively #'magit-log-trace-definition))))) ;;;###autoload (defun magit-log-merged (commit branch &optional args files) "Show log for the merge of COMMIT into BRANCH. More precisely, find merge commit M that brought COMMIT into BRANCH, and show the log of the range \"M^..M\". This command requires git-when-merged, which is available from https://github.com/mhagger/git-when-merged." (interactive (append (let ((commit (magit-read-branch-or-commit "Commit"))) (list commit (magit-read-other-branch "Merged into" commit))) (magit-log-arguments))) (unless (executable-find "git-when-merged") (user-error "This command requires git-when-merged (%s)" "https://github.com/mhagger/git-when-merged")) (magit-git-log (list (or (magit-git-string "when-merged" "--show-branch" commit branch) (user-error "Could not find when %s was merged into %s" commit branch))) args files)) (defun magit-git-reflog (ref args) (require 'magit) (magit-mode-setup #'magit-reflog-mode ref args)) ;;;###autoload (defun magit-reflog-current (args) "Display the reflog of the current branch." (interactive (list magit-reflog-arguments)) (magit-git-reflog (magit-get-current-branch) args)) ;;;###autoload (defun magit-reflog-other (ref args) "Display the reflog of a branch or another ref." (interactive (list (magit-read-local-branch-or-ref "Show reflog for") magit-reflog-arguments)) (magit-git-reflog ref args)) ;;;###autoload (defun magit-reflog-head (args) "Display the `HEAD' reflog." (interactive (list magit-reflog-arguments)) (magit-git-reflog "HEAD" args)) ;;;; Limit Commands (defun magit-log-toggle-commit-limit () "Toggle the number of commits the current log buffer is limited to. If the number of commits is currently limited, then remove that limit. Otherwise set it to 256." (interactive) (magit-log-set-commit-limit (lambda (&rest _) nil))) (defun magit-log-double-commit-limit () "Double the number of commits the current log buffer is limited to." (interactive) (magit-log-set-commit-limit '*)) (defun magit-log-half-commit-limit () "Half the number of commits the current log buffer is limited to." (interactive) (magit-log-set-commit-limit '/)) (defun magit-log-set-commit-limit (fn) (let* ((val (car (magit-log-arguments t))) (arg (--first (string-match "^-n\\([0-9]+\\)?$" it) val)) (num (and arg (string-to-number (match-string 1 arg)))) (num (if num (funcall fn num 2) 256))) (setq val (delete arg val)) (setcar (cdr magit-refresh-args) (if (and num (> num 0)) (cons (format "-n%i" num) val) val))) (magit-refresh)) (defun magit-log-get-commit-limit () (--when-let (--first (string-match "^-n\\([0-9]+\\)?$" it) (car (magit-log-arguments t))) (string-to-number (match-string 1 it)))) ;;;; Other Commands (defun magit-log-bury-buffer (&optional arg) "Bury the current buffer or the revision buffer in the same frame. Like `magit-mode-bury-buffer' (which see) but with a negative prefix argument instead bury the revision buffer, provided it is displayed in the current frame." (interactive "p") (if (< arg 0) (let* ((buf (magit-mode-get-buffer 'magit-revision-mode)) (win (and buf (get-buffer-window buf (selected-frame))))) (if win (with-selected-window win (with-current-buffer buf (magit-mode-bury-buffer (> (abs arg) 1)))) (user-error "No revision buffer in this frame"))) (magit-mode-bury-buffer (> arg 1)))) ;;;###autoload (defun magit-log-move-to-parent (&optional n) "Move to the Nth parent of the current commit." (interactive "p") (when (derived-mode-p 'magit-log-mode) (when (magit-section-match 'commit) (let* ((section (magit-current-section)) (parent-rev (format "%s^%s" (oref section value) (or n 1)))) (if-let ((parent-hash (magit-rev-parse "--short" parent-rev))) (if-let ((parent (--first (equal (oref section value) parent-hash) (magit-section-siblings section 'next)))) (magit-section-goto parent) (user-error (substitute-command-keys (concat "Parent " parent-hash " not found. Try typing " "\\[magit-log-double-commit-limit] first")))) (user-error "Parent %s does not exist" parent-rev)))))) ;;; Log Mode (defvar magit-log-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-mode-map) (define-key map "\C-c\C-b" 'magit-go-backward) (define-key map "\C-c\C-f" 'magit-go-forward) (define-key map "\C-c\C-n" 'magit-log-move-to-parent) (define-key map "=" 'magit-log-toggle-commit-limit) (define-key map "+" 'magit-log-double-commit-limit) (define-key map "-" 'magit-log-half-commit-limit) (define-key map "q" 'magit-log-bury-buffer) map) "Keymap for `magit-log-mode'.") (define-derived-mode magit-log-mode magit-mode "Magit Log" "Mode for looking at Git log. This mode is documented in info node `(magit)Log Buffer'. \\\ 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-branch-popup] to see available branch commands. Type \\[magit-merge-popup] to merge the branch or commit at point. Type \\[magit-cherry-pick-popup] to apply the commit at point. Type \\[magit-reset] to reset `HEAD' to the commit at point. \\{magit-log-mode-map}" :group 'magit-log (hack-dir-local-variables-non-file-buffer) (setq imenu-prev-index-position-function 'magit-imenu--log-prev-index-position-function) (setq imenu-extract-index-name-function 'magit-imenu--log-extract-index-name-function) (setq-local bookmark-make-record-function 'magit-bookmark--log-make-record)) (defvar magit-log-disable-graph-hack-args '("-G" "--grep" "--author") "Arguments which disable the graph speedup hack.") (defun magit-log-refresh-buffer (revs args files) (magit-set-header-line-format (funcall magit-log-header-line-function revs args files)) (if (= (length files) 1) (unless (magit-file-tracked-p (car files)) (setq args (cons "--full-history" args))) (setq args (remove "--follow" args))) (when (--any-p (string-match-p (concat "^" (regexp-opt magit-log-remove-graph-args)) it) args) (setq args (remove "--graph" args))) (unless (member "--graph" args) (setq args (remove "--color" args))) (when-let ((limit (magit-log-get-commit-limit)) (limit (* 2 limit)) ; increase odds for complete graph (count (and (= (length revs) 1) (> limit 1024) ; otherwise it's fast enough (setq revs (car revs)) (not (string-match-p "\\.\\." revs)) (not (member revs '("--all" "--branches"))) (-none-p (lambda (arg) (--any-p (string-prefix-p it arg) magit-log-disable-graph-hack-args)) args) (magit-git-string "rev-list" "--count" "--first-parent" args revs)))) (setq revs (if (< (string-to-number count) limit) revs (format "%s~%s..%s" revs limit revs)))) (magit-insert-section (logbuf) (magit-insert-log revs args files))) (defun magit-log-header-line-arguments (revs args files) "Return string describing some of the used arguments." (mapconcat (lambda (arg) (if (string-match-p " " arg) (prin1 arg) arg)) `("git" "log" ,@args ,@revs "--" ,@files) " ")) (defun magit-log-header-line-sentence (revs args files) "Return string containing all arguments." (concat "Commits in " (mapconcat #'identity revs " ") (and (member "--reverse" args) " in reverse") (and files (concat " touching " (mapconcat 'identity files " "))) (--some (and (string-prefix-p "-L" it) (concat " " it)) args))) (defun magit-insert-log (revs &optional args files) "Insert a log section. Do not add this to a hook variable." (let ((magit-git-global-arguments (remove "--literal-pathspecs" magit-git-global-arguments))) (magit-git-wash (apply-partially #'magit-log-wash-log 'log) "log" (format "--format=%s%%h%s%%x00%s%%x00%%aN%%x00%%at%%x00%%s%s" (if (and (member "--left-right" args) (not (member "--graph" args))) "%m " "") (if (member "--decorate" args) "%d" "") (if (member "--show-signature" args) (progn (setq args (remove "--show-signature" args)) "%G?") "") (if (member "++header" args) (if (member "--graph" (setq args (remove "++header" args))) (concat "\n" magit-log-revision-headers-format "\n") (concat "\n" magit-log-revision-headers-format "\n")) "")) (progn (--when-let (--first (string-match "^\\+\\+order=\\(.+\\)$" it) args) (setq args (cons (format "--%s-order" (match-string 1 it)) (remove it args)))) (when (member "--decorate" args) (setq args (cons "--decorate=full" (remove "--decorate" args)))) (when (member "--reverse" args) (setq args (remove "--graph" args))) args) "--use-mailmap" "--no-prefix" revs "--" files))) (defvar magit-commit-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-show-commit) (define-key map "a" 'magit-cherry-apply) map) "Keymap for `commit' sections.") (defvar magit-module-commit-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-show-commit) map) "Keymap for `module-commit' sections.") (defconst magit-log-heading-re (concat "^" "\\(?4:[-_/|\\*o<>. ]*\\)" ; graph "\\(?1:[0-9a-fA-F]+\\)" ; sha1 "\\(?3:[^\0\n]+)\\)?\0" ; refs "\\(?7:[BGUXYREN]\\)?\0" ; gpg "\\(?5:[^\0\n]*\\)\0" ; author ;; Note: Date is optional because, prior to Git v2.19.0, ;; `git rebase -i --root` corrupts the root's author date. "\\(?6:[^\0\n]*\\)\0" ; date "\\(?2:.*\\)$")) ; msg (defconst magit-log-cherry-re (concat "^" "\\(?8:[-+]\\) " ; cherry "\\(?1:[0-9a-fA-F]+\\) " ; sha1 "\\(?2:.*\\)$")) ; msg (defconst magit-log-module-re (concat "^" "\\(?:\\(?11:[<>]\\) \\)?" ; side "\\(?1:[0-9a-fA-F]+\\) " ; sha1 "\\(?2:.*\\)$")) ; msg (defconst magit-log-bisect-vis-re (concat "^" "\\(?4:[-_/|\\*o<>. ]*\\)" ; graph "\\(?1:[0-9a-fA-F]+\\)" ; sha1 "\\(?3:[^\0\n]+)\\)?\0" ; refs "\\(?2:.*\\)$")) ; msg (defconst magit-log-bisect-log-re (concat "^# " "\\(?3:bad:\\|skip:\\|good:\\) " ; "refs" "\\[\\(?1:[^]\n]+\\)\\] " ; sha1 "\\(?2:.*\\)$")) ; msg (defconst magit-log-reflog-re (concat "^" "\\(?1:[^\0\n]+\\)\0" ; sha1 "\\(?5:[^\0\n]*\\)\0" ; author "\\(?:\\(?:[^@\n]+@{\\(?6:[^}\n]+\\)}\0" ; date "\\(?10:merge \\|autosave \\|restart \\|[^:\n]+: \\)?" ; refsub "\\(?2:.*\\)?\\)\\|\0\\)$")) ; msg (defconst magit-reflog-subject-re (concat "\\(?1:[^ ]+\\) ?" ; command "\\(?2:\\(?: ?-[^ ]+\\)+\\)?" ; option "\\(?: ?(\\(?3:[^)]+\\))\\)?")) ; type (defconst magit-log-stash-re (concat "^" "\\(?1:[^\0\n]+\\)\0" ; "sha1" "\\(?5:[^\0\n]*\\)\0" ; author "\\(?6:[^\0\n]+\\)\0" ; date "\\(?2:.*\\)$")) ; msg (defvar magit-log-count nil) (defvar magit-log-format-message-function 'magit-log-propertize-keywords) (defun magit-log-wash-log (style args) (setq args (-flatten args)) (when (and (member "--graph" args) (member "--color" args)) (let ((ansi-color-apply-face-function (lambda (beg end face) (put-text-property beg end 'font-lock-face (or face 'magit-log-graph))))) (ansi-color-apply-on-region (point-min) (point-max)))) (when (eq style 'cherry) (reverse-region (point-min) (point-max))) (let ((magit-log-count 0)) (magit-wash-sequence (apply-partially 'magit-log-wash-rev style (magit-abbrev-length))) (if (derived-mode-p 'magit-log-mode) (when (eq magit-log-count (magit-log-get-commit-limit)) (magit-insert-section (longer) (insert-text-button (substitute-command-keys (format "Type \\<%s>\\[%s] to show more history" 'magit-log-mode-map 'magit-log-double-commit-limit)) 'action (lambda (_button) (magit-log-double-commit-limit)) 'follow-link t 'mouse-face 'magit-section-highlight))) (insert ?\n)))) (cl-defun magit-log-wash-rev (style abbrev) (when (derived-mode-p 'magit-log-mode) (cl-incf magit-log-count)) (looking-at (pcase style (`log magit-log-heading-re) (`cherry magit-log-cherry-re) (`module magit-log-module-re) (`reflog magit-log-reflog-re) (`stash magit-log-stash-re) (`bisect-vis magit-log-bisect-vis-re) (`bisect-log magit-log-bisect-log-re))) (magit-bind-match-strings (hash msg refs graph author date gpg cherry _ refsub side) nil (setq msg (substring-no-properties msg)) (when refs (setq refs (substring-no-properties refs))) (let ((align (or (eq style 'cherry) (not (member "--stat" (cadr magit-refresh-args))))) (non-graph-re (if (eq style 'bisect-vis) magit-log-bisect-vis-re magit-log-heading-re))) (magit-delete-line) ;; If the reflog entries have been pruned, the output of `git ;; reflog show' includes a partial line that refers to the hash ;; of the youngest expired reflog entry. (when (and (eq style 'reflog) (not date)) (cl-return-from magit-log-wash-rev t)) (magit-insert-section section (commit hash) (pcase style (`stash (oset section type 'stash)) (`module (oset section type 'module-commit)) (`bisect-log (setq hash (magit-rev-parse "--short" hash)))) (when cherry (when (and (derived-mode-p 'magit-refs-mode) magit-refs-show-commit-count) (insert (make-string (1- magit-refs-focus-column-width) ?\s))) (insert (propertize cherry 'face (if (string= cherry "-") 'magit-cherry-equivalent 'magit-cherry-unmatched))) (insert ?\s)) (when side (insert (propertize side 'face (if (string= side "<") 'magit-cherry-equivalent 'magit-cherry-unmatched))) (insert ?\s)) (when align (insert (propertize hash 'face 'magit-hash) ?\s)) (when graph (insert graph)) (unless align (insert (propertize hash 'face 'magit-hash) ?\s)) (when (and refs (not magit-log-show-refname-after-summary)) (insert (magit-format-ref-labels refs) ?\s)) (when (eq style 'reflog) (insert (format "%-2s " (1- magit-log-count))) (when refsub (insert (magit-reflog-format-subject (substring refsub 0 (if (string-match-p ":" refsub) -2 -1)))))) (when msg (when gpg (setq msg (propertize msg 'face (pcase (aref gpg 0) (?G 'magit-signature-good) (?B 'magit-signature-bad) (?U 'magit-signature-untrusted) (?X 'magit-signature-expired) (?Y 'magit-signature-expired-key) (?R 'magit-signature-revoked) (?E 'magit-signature-error))))) (insert (funcall magit-log-format-message-function hash msg))) (when (and refs magit-log-show-refname-after-summary) (insert ?\s) (insert (magit-format-ref-labels refs))) (insert ?\n) (when (memq style '(log reflog stash)) (goto-char (line-beginning-position)) (when (and refsub (string-match "\\`\\([^ ]\\) \\+\\(..\\)\\(..\\)" date)) (setq date (+ (string-to-number (match-string 1 date)) (* (string-to-number (match-string 2 date)) 60 60) (* (string-to-number (match-string 3 date)) 60)))) (save-excursion (backward-char) (magit-log-format-margin hash author date))) (when (and (eq style 'cherry) (magit-buffer-margin-p)) (save-excursion (backward-char) (apply #'magit-log-format-margin hash (split-string (magit-rev-format "%aN%x00%ct" hash) "\0")))) (when (and graph (not (eobp)) (not (looking-at non-graph-re))) (when (looking-at "") (magit-insert-heading) (delete-char 1) (magit-insert-section (commit-header) (forward-line) (magit-insert-heading) (re-search-forward "") (backward-delete-char 1) (forward-char) (insert ?\n)) (delete-char 1)) (if (looking-at "^\\(---\\|\n\s\\|\ndiff\\)") (let ((limit (save-excursion (and (re-search-forward non-graph-re nil t) (match-beginning 0))))) (unless (oref magit-insert-section--current content) (magit-insert-heading)) (delete-char (if (looking-at "\n") 1 4)) (magit-diff-wash-diffs (list "--stat") limit)) (when align (setq align (make-string (1+ abbrev) ? ))) (when (and (not (eobp)) (not (looking-at non-graph-re))) (when align (setq align (make-string (1+ abbrev) ? ))) (while (and (not (eobp)) (not (looking-at non-graph-re))) (when align (save-excursion (insert align))) (magit-make-margin-overlay) (forward-line)) ;; When `--format' is used and its value isn't one of the ;; predefined formats, then `git-log' does not insert a ;; separator line. (save-excursion (forward-line -1) (looking-at "[-_/|\\*o<>. ]*")) (setq graph (match-string 0)) (unless (string-match-p "[/\\]" graph) (insert graph ?\n)))))))) t) (defun magit-log-propertize-keywords (_rev msg) (let ((start 0)) (when (string-match "^\\(squash\\|fixup\\)! " msg start) (setq start (match-end 0)) (put-text-property (match-beginning 0) (match-end 0) 'face 'magit-keyword-squash msg)) (while (string-match "\\[[^[]*\\]" msg start) (setq start (match-end 0)) (when magit-log-highlight-keywords (put-text-property (match-beginning 0) (match-end 0) 'face 'magit-keyword msg)))) msg) (defun magit-log-maybe-show-more-commits (section) "When point is at the end of a log buffer, insert more commits. Log buffers end with a button \"Type + to show more history\". When the use of a section movement command puts point on that button, then automatically show more commits, without the user having to press \"+\". This function is called by `magit-section-movement-hook' and exists mostly for backward compatibility reasons." (when (and (eq (oref section type) 'longer) magit-log-auto-more) (magit-log-double-commit-limit) (forward-line -1) (magit-section-forward))) (defvar magit--update-revision-buffer nil) (defun magit-log-maybe-update-revision-buffer (&optional _) "When moving in the log buffer, update the revision buffer. If there is no revision buffer in the same frame, then do nothing." (when (derived-mode-p 'magit-log-mode) (magit-log-maybe-update-revision-buffer-1))) (defun magit-log-maybe-update-revision-buffer-1 () (unless magit--update-revision-buffer (when-let ((commit (magit-section-value-if 'commit)) (buffer (magit-mode-get-buffer 'magit-revision-mode nil t))) (setq magit--update-revision-buffer (list commit buffer)) (run-with-idle-timer magit-update-other-window-delay nil (let ((args (magit-show-commit--arguments))) (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 args)))) (setq magit--update-revision-buffer nil))))))) (defvar magit--update-blob-buffer nil) (defun magit-log-maybe-update-blob-buffer (&optional _) "When moving in the log buffer, update the blob buffer. If there is no blob buffer in the same frame, then do nothing." (when (derived-mode-p 'magit-log-mode) (magit-log-maybe-update-blob-buffer-1))) (defun magit-log-maybe-update-blob-buffer-1 () (unless magit--update-revision-buffer (when-let ((commit (magit-section-value-if 'commit)) (buffer (--first (with-current-buffer it magit-buffer-revision) (mapcar #'window-buffer (window-list))))) (setq magit--update-blob-buffer (list commit buffer)) (run-with-idle-timer magit-update-other-window-delay nil (lambda () (pcase-let ((`(,rev ,buf) magit--update-blob-buffer)) (setq magit--update-blob-buffer nil) (when (buffer-live-p buf) (save-excursion (with-selected-window (get-buffer-window buf) (with-current-buffer buf (magit-blob-visit (list (magit-rev-parse rev) (magit-file-relative-name magit-buffer-file-name)) (line-number-at-pos)))))))))))) (defun magit-log-goto-same-commit (&optional default) (let ((prev magit-previous-section)) (when-let ((rev (cond ((and prev (magit-section-match 'commit prev)) (oref prev value)) ((and prev (magit-section-match 'branch prev)) (magit-rev-format "%h" (oref prev value))) (default (magit-rev-format "%h" default)))) (same (--first (equal (oref it value) rev) (oref magit-root-section children)))) (goto-char (oref same start))))) ;;; Log Margin (defvar-local magit-log-margin-show-shortstat nil) (defun magit-toggle-log-margin-style () "Toggle between the regular and the shortstat margin style. The shortstat style is experimental and rather slow." (interactive) (setq magit-log-margin-show-shortstat (not magit-log-margin-show-shortstat)) (magit-set-buffer-margin nil t)) (defun magit-log-format-margin (rev author date) (when-let ((option (magit-margin-option))) (if magit-log-margin-show-shortstat (magit-log-format-shortstat-margin rev) (pcase-let ((`(,_ ,style ,width ,details ,details-width) (or magit-buffer-margin (symbol-value option)))) (magit-make-margin-overlay (concat (and details (concat (propertize (truncate-string-to-width (or author "") details-width nil ?\s (make-string 1 magit-ellipsis)) 'face 'magit-log-author) " ")) (propertize (if (stringp style) (format-time-string style (seconds-to-time (string-to-number date))) (pcase-let* ((abbr (eq style 'age-abbreviated)) (`(,cnt ,unit) (magit--age date abbr))) (format (format (if abbr "%%2i%%-%ic" "%%2i %%-%is") (- width (if details (1+ details-width) 0))) cnt unit))) 'face 'magit-log-date))))))) (defun magit-log-format-shortstat-margin (rev) (magit-make-margin-overlay (if-let ((line (and rev (magit-git-string "show" "--format=" "--shortstat" rev)))) (if (string-match "\ \\([0-9]+\\) files? changed, \ \\(?:\\([0-9]+\\) insertions?(\\+)\\)?\ \\(?:\\(?:, \\)?\\([0-9]+\\) deletions?(-)\\)?\\'" line) (magit-bind-match-strings (files add del) line (format "%5s %5s%4s" (if add (propertize (format "%s+" add) 'face 'magit-diffstat-added) "") (if del (propertize (format "%s-" del) 'face 'magit-diffstat-removed) "") files)) "") ""))) (defun magit-log-margin-width (style details details-width) (if magit-log-margin-show-shortstat 16 (+ (if details (1+ details-width) 0) (if (stringp style) (length (format-time-string style)) (+ 2 ; two digits 1 ; trailing space (if (eq style 'age-abbreviated) 1 ; single character (+ 1 ; gap after digits (apply #'max (--map (max (length (nth 1 it)) (length (nth 2 it))) magit--age-spec))))))))) ;;; Select Mode (defvar magit-log-select-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-log-mode-map) (define-key map "\C-c\C-b" 'undefined) (define-key map "\C-c\C-f" 'undefined) (define-key map "." 'magit-log-select-pick) (define-key map "e" 'magit-log-select-pick) (define-key map "\C-c\C-c" 'magit-log-select-pick) (define-key map "q" 'magit-log-select-quit) (define-key map "\C-c\C-k" 'magit-log-select-quit) map) "Keymap for `magit-log-select-mode'.") (put 'magit-log-select-pick :advertised-binding [?\C-c ?\C-c]) (put 'magit-log-select-quit :advertised-binding [?\C-c ?\C-k]) (define-derived-mode magit-log-select-mode magit-log-mode "Magit Select" "Mode for selecting a commit from history. This mode is documented in info node `(magit)Select from Log'. \\\ 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-log-select-pick] to select the commit at point. Type \\[magit-log-select-quit] to abort without selecting a commit." :group 'magit-log (hack-dir-local-variables-non-file-buffer)) (defun magit-log-select-refresh-buffer (rev args) (magit-insert-section (logbuf) (magit-insert-log rev args))) (defvar-local magit-log-select-pick-function nil) (defvar-local magit-log-select-quit-function nil) (defun magit-log-select (pick &optional msg quit branch args initial) (declare (indent defun)) (magit-mode-setup #'magit-log-select-mode (or branch (magit-get-current-branch) "HEAD") (append args magit-log-select-arguments)) (magit-log-goto-same-commit initial) (setq magit-log-select-pick-function pick) (setq magit-log-select-quit-function quit) (when magit-log-select-show-usage (let ((pick (propertize (substitute-command-keys "\\[magit-log-select-pick]") 'face 'magit-header-line-key)) (quit (propertize (substitute-command-keys "\\[magit-log-select-quit]") 'face 'magit-header-line-key))) (setq msg (format-spec (if msg (if (string-suffix-p "," msg) (concat msg " or %q to abort") msg) "Type %p to select commit at point, or %q to abort") `((?p . ,pick) (?q . ,quit))))) (add-face-text-property 0 (length msg) 'magit-header-line-log-select t msg) (when (memq magit-log-select-show-usage '(both header-line)) (magit-set-header-line-format msg)) (when (memq magit-log-select-show-usage '(both echo-area)) (message "%s" (substring-no-properties msg))))) (defun magit-log-select-pick () "Select the commit at point and act on it. Call `magit-log-select-pick-function' with the selected commit as argument." (interactive) (let ((fun magit-log-select-pick-function) (rev (magit-commit-at-point))) (magit-mode-bury-buffer 'kill) (funcall fun rev))) (defun magit-log-select-quit () "Abort selecting a commit, don't act on any commit." (interactive) (magit-mode-bury-buffer 'kill) (when magit-log-select-quit-function (funcall magit-log-select-quit-function))) ;;; Cherry Mode (defvar magit-cherry-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-mode-map) (define-key map "q" 'magit-log-bury-buffer) (define-key map "L" 'magit-margin-popup) map) "Keymap for `magit-cherry-mode'.") (define-derived-mode magit-cherry-mode magit-mode "Magit Cherry" "Mode for looking at commits not merged upstream. \\\ 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-popup] to apply the commit at point. \\{magit-cherry-mode-map}" :group 'magit-log (hack-dir-local-variables-non-file-buffer) (setq imenu-create-index-function 'magit-imenu--cherry-create-index-function) (setq-local bookmark-make-record-function 'magit-bookmark--cherry-make-record)) ;;;###autoload (defun magit-cherry (head upstream) "Show commits in a branch that are not merged in the upstream branch." (interactive (let ((head (magit-read-branch "Cherry head"))) (list head (magit-read-other-branch "Cherry upstream" head (magit-get-upstream-branch head))))) (require 'magit) (magit-mode-setup #'magit-cherry-mode upstream head)) (defun magit-cherry-refresh-buffer (_upstream _head) (magit-insert-section (cherry) (magit-run-section-hook 'magit-cherry-sections-hook))) (defun magit-insert-cherry-headers () "Insert headers appropriate for `magit-cherry-mode' buffers." (magit-insert-head-branch-header (nth 1 magit-refresh-args)) (magit-insert-upstream-branch-header (nth 1 magit-refresh-args) (nth 0 magit-refresh-args) "Upstream: ") (insert ?\n)) (defun magit-insert-cherry-commits () "Insert commit sections into a `magit-cherry-mode' buffer." (magit-insert-section (cherries) (magit-insert-heading "Cherry commits:") (magit-git-wash (apply-partially 'magit-log-wash-log 'cherry) "cherry" "-v" "--abbrev" magit-refresh-args))) ;;; Reflog Mode (defvar magit-reflog-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-log-mode-map) (define-key map "L" 'magit-margin-popup) map) "Keymap for `magit-reflog-mode'.") (define-derived-mode magit-reflog-mode magit-log-mode "Magit Reflog" "Mode for looking at Git reflog. This mode is documented in info node `(magit)Reflog'. \\\ 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-popup] 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) (setq-local bookmark-make-record-function 'magit-bookmark--reflog-make-record)) (defun magit-reflog-refresh-buffer (ref args) (magit-set-header-line-format (concat "Reflog for " ref)) (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" args ref "--"))) (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 " (propertize text 'face (or (cdr (assoc label magit-reflog-labels)) 'magit-reflog-other))))) ;;; Log Sections ;;;; Standard Log Sections (defvar magit-unpulled-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-diff-dwim) map) "Keymap for `unpulled' sections.") (magit-define-section-jumper magit-jump-to-unpulled-from-upstream "Unpulled from @{upstream}" unpulled "..@{upstream}") (defun magit-insert-unpulled-from-upstream () "Insert commits that haven't been pulled from the upstream yet." (when (magit-git-success "rev-parse" "@{upstream}") (magit-insert-section (unpulled "..@{upstream}" t) (magit-insert-heading (format (propertize "Unpulled from %s:" 'face 'magit-section-heading) (magit-get-upstream-branch))) (magit-insert-log "..@{upstream}" magit-log-section-arguments)))) (magit-define-section-jumper magit-jump-to-unpulled-from-pushremote "Unpulled from " unpulled (concat ".." (magit-get-push-branch))) (defun magit-insert-unpulled-from-pushremote () "Insert commits that haven't been pulled from the push-remote yet." (--when-let (magit-get-push-branch) (unless (and (equal (magit-rev-name it) (magit-rev-name "@{upstream}")) (or (memq 'magit-insert-unpulled-from-upstream magit-status-sections-hook) (memq 'magit-insert-unpulled-from-upstream-or-recent magit-status-sections-hook))) (magit-insert-section (unpulled (concat ".." it) t) (magit-insert-heading (format (propertize "Unpulled from %s:" 'face 'magit-section-heading) (propertize it 'face 'magit-branch-remote))) (magit-insert-log (concat ".." it) magit-log-section-arguments))))) (defvar magit-unpushed-section-map (let ((map (make-sparse-keymap))) (define-key map [remap magit-visit-thing] 'magit-diff-dwim) map) "Keymap for `unpushed' sections.") (magit-define-section-jumper magit-jump-to-unpushed-to-upstream "Unpushed to @{upstream}" unpushed "@{upstream}..") (defun magit-insert-unpushed-to-upstream-or-recent () "Insert section showing unpushed or other recent commits. If an upstream is configured for the current branch and it is behind of the current branch, then show the commits that have not yet been pushed into the upstream branch. If no upstream is configured or if the upstream is not behind of the current branch, then show the last `magit-log-section-commit-count' commits." (let ((upstream (magit-rev-parse "@{upstream}"))) (if (or (not upstream) (magit-rev-ancestor-p "HEAD" upstream)) (magit-insert-recent-commits 'unpushed "@{upstream}..") (magit-insert-unpushed-to-upstream)))) (defun magit-insert-unpushed-to-upstream () "Insert commits that haven't been pushed to the upstream yet." (when (magit-git-success "rev-parse" "@{upstream}") (magit-insert-section (unpushed "@{upstream}..") (magit-insert-heading (format (propertize "Unmerged into %s:" 'face 'magit-section-heading) (magit-get-upstream-branch))) (magit-insert-log "@{upstream}.." magit-log-section-arguments)))) (defun magit-insert-recent-commits (&optional type value) "Insert section showing recent commits. Show the last `magit-log-section-commit-count' commits." (let* ((start (format "HEAD~%s" magit-log-section-commit-count)) (range (and (magit-rev-verify start) (concat start "..HEAD")))) (magit-insert-section ((eval (or type 'recent)) (or value range) t) (magit-insert-heading "Recent commits") (magit-insert-log range (cons (format "-n%d" magit-log-section-commit-count) (--remove (string-prefix-p "-n" it) magit-log-section-arguments)))))) (magit-define-section-jumper magit-jump-to-unpushed-to-pushremote "Unpushed to " unpushed (concat (magit-get-push-branch) "..")) (defun magit-insert-unpushed-to-pushremote () "Insert commits that haven't been pushed to the push-remote yet." (--when-let (magit-get-push-branch) (unless (and (equal (magit-rev-name it) (magit-rev-name "@{upstream}")) (or (memq 'magit-insert-unpushed-to-upstream magit-status-sections-hook) (memq 'magit-insert-unpushed-to-upstream-or-recent magit-status-sections-hook))) (magit-insert-section (unpushed (concat it "..") t) (magit-insert-heading (format (propertize "Unpushed to %s:" 'face 'magit-section-heading) (propertize it 'face 'magit-branch-remote))) (magit-insert-log (concat it "..") magit-log-section-arguments))))) ;;;; Auxiliary Log Sections (defun magit-insert-unpulled-cherries () "Insert section showing unpulled commits. Like `magit-insert-unpulled-from-upstream' but prefix each commit which has not been applied yet (i.e. a commit with a patch-id not shared with any local commit) with \"+\", and all others with \"-\"." (when (magit-git-success "rev-parse" "@{upstream}") (magit-insert-section (unpulled "..@{upstream}") (magit-insert-heading "Unpulled commits:") (magit-git-wash (apply-partially 'magit-log-wash-log 'cherry) "cherry" "-v" (magit-abbrev-arg) (magit-get-current-branch) "@{upstream}")))) (defun magit-insert-unpushed-cherries () "Insert section showing unpushed commits. Like `magit-insert-unpushed-to-upstream' but prefix each commit which has not been applied to upstream yet (i.e. a commit with a patch-id not shared with any upstream commit) with \"+\", and all others with \"-\"." (when (magit-git-success "rev-parse" "@{upstream}") (magit-insert-section (unpushed "@{upstream}..") (magit-insert-heading "Unpushed commits:") (magit-git-wash (apply-partially 'magit-log-wash-log 'cherry) "cherry" "-v" (magit-abbrev-arg) "@{upstream}")))) ;;; _ (provide 'magit-log) ;;; magit-log.el ends here magit-2.90.1/lisp/magit-margin.el000066400000000000000000000222041337354740400165630ustar00rootroot00000000000000;;; magit-margin.el --- margins in Magit buffers -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-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 (magit-define-popup magit-margin-popup "Popup console for changing appearance of the margin." :actions '("Margin" (?L "Toggle visibility" magit-toggle-margin) (?l "Cycle style" magit-cycle-margin-style) (?d "Toggle details" magit-toggle-margin-details) (lambda () (and (with-current-buffer magit-pre-popup-buffer (derived-mode-p 'magit-refs-mode)) (propertize "Left edge" 'face 'magit-popup-heading))) (?v "Change verbosity" magit-refs-set-show-commit-count)) :max-action-columns 1) (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))) (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 magit-2.90.1/lisp/magit-merge.el000066400000000000000000000260321337354740400164100ustar00rootroot00000000000000;;; magit-merge.el --- merge functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (declare-function magit-git-push "magit-push" (branch target args)) ;;; Commands ;;;###autoload (autoload 'magit-merge-popup "magit" nil t) (magit-define-popup magit-merge-popup "Popup console for merge commands." :man-page "git-merge" :switches '((?f "Fast-forward only" "--ff-only") (?n "No fast-forward" "--no-ff")) :options '((?s "Strategy" "--strategy=")) :actions '((?m "Merge" magit-merge-plain) (?p "Preview merge" magit-merge-preview) (?e "Merge and edit message" magit-merge-editmsg) nil (?n "Merge but don't commit" magit-merge-nocommit) (?s "Squash merge" magit-merge-squash) (?a "Absorb" magit-merge-absorb) (?i "Merge into" magit-merge-into)) :sequence-actions '((?m "Commit merge" magit-commit-create) (?a "Abort merge" magit-merge-abort)) :sequence-predicate 'magit-merge-in-progress-p :default-action 'magit-merge :max-action-columns 2) ;;;###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 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 `magit-branch-pull-request' was used to create the merged 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))) (when-let ((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-absort 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 `magit-branch-pull-request' 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-absort branch args)) (defun magit--merge-absort (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-absort-1 branch args)))))) (magit--merge-absort-1 branch args))) (defun magit--merge-absort-1 (branch args) (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-mode-setup #'magit-merge-preview-mode rev)) (define-derived-mode magit-merge-preview-mode magit-diff-mode "Magit Merge" "Mode for previewing a merge." :group 'magit-diff (hack-dir-local-variables-non-file-buffer)) (defun magit-merge-preview-refresh-buffer (rev) (let* ((branch (magit-get-current-branch)) (head (or branch (magit-rev-verify "HEAD")))) (magit-set-header-line-format (format "Preview merge of %s into %s" rev (or branch "HEAD"))) (magit-insert-section (diffbuf) (magit-git-wash #'magit-diff-wash-diffs "merge-tree" (magit-git-string "merge-base" head rev) head 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-log-section-arguments)) (unless (member "--decorate=full" magit-log-section-arguments) (push "--decorate=full" args)) args)))))) ;;; _ (provide 'magit-merge) ;;; magit-merge.el ends here magit-2.90.1/lisp/magit-mode.el000066400000000000000000001616731337354740400162500ustar00rootroot00000000000000;;; magit-mode.el --- create and refresh Magit buffers -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 abstract major-mode `magit-mode' from ;; which almost all other Magit major-modes derive. The code in here ;; is mostly concerned with creating and refreshing Magit buffers. ;;; Code: (require 'cl-lib) (require 'dash) (eval-when-compile (require 'subr-x)) (require 'magit-section) (require 'magit-git) ;; For `magit-display-buffer-fullcolumn-most-v1' from `git-commit' (defvar git-commit-mode) ;; For `magit-xref-insert-buttons' from `magit' (defvar magit-diff-show-xref-buttons) (defvar magit-revision-show-xref-buttons) ;; For `magit-refresh' (defvar magit-post-commit-hook-commands) (defvar magit-post-stage-hook-commands) (defvar magit-post-unstage-hook-commands) ;; For `magit-refresh' and `magit-refresh-all' (declare-function magit-auto-revert-buffers "magit-autorevert" ()) ;; For `magit-refresh-buffer' (declare-function magit-process-unset-mode-line-error-status "magit-process" ()) ;; For `magit-mode-setup-internal' (declare-function magit-status-goto-initial-section "magit-status" ()) (require 'format-spec) (require 'help-mode) ;;; Options (defcustom magit-mode-hook '(magit-load-config-extensions magit-xref-setup) "Hook run when entering a mode derived from Magit mode." :group 'magit-modes :type 'hook :options '(magit-load-config-extensions magit-xref-setup bug-reference-mode)) (defcustom magit-mode-setup-hook '(magit-maybe-save-repository-buffers magit-set-buffer-margin) "Hook run by `magit-mode-setup'. This is run right after displaying the buffer and right before generating or updating its content. `magit-mode-hook' and other, more specific, `magit-mode-*-hook's on the other hand are run right before displaying the buffer. Usually one of these hooks should be used instead of this one." :package-version '(magit . "2.3.0") :group 'magit-modes :type 'hook :options '(magit-maybe-save-repository-buffers magit-set-buffer-margin)) (defcustom magit-pre-refresh-hook '(magit-maybe-save-repository-buffers) "Hook run before refreshing in `magit-refresh'. This hook, or `magit-post-refresh-hook', should be used for functions that are not tied to a particular buffer. To run a function with a particular buffer current, use `magit-refresh-buffer-hook' and use `derived-mode-p' inside your function." :package-version '(magit . "2.4.0") :group 'magit-refresh :type 'hook :options '(magit-maybe-save-repository-buffers)) (defcustom magit-post-refresh-hook nil "Hook run after refreshing in `magit-refresh'. This hook, or `magit-pre-refresh-hook', should be used for functions that are not tied to a particular buffer. To run a function with a particular buffer current, use `magit-refresh-buffer-hook' and use `derived-mode-p' inside your function." :package-version '(magit . "2.4.0") :group 'magit-refresh :type 'hook) (defcustom magit-display-buffer-function 'magit-display-buffer-traditional "The function used display a Magit buffer. All Magit buffers (buffers whose major-modes derive from `magit-mode') are displayed using `magit-display-buffer', which in turn uses the function specified here." :package-version '(magit . "2.3.0") :group 'magit-buffers :type '(radio (function-item magit-display-buffer-traditional) (function-item magit-display-buffer-same-window-except-diff-v1) (function-item magit-display-buffer-fullframe-status-v1) (function-item magit-display-buffer-fullframe-status-topleft-v1) (function-item magit-display-buffer-fullcolumn-most-v1) (function-item display-buffer) (function :tag "Function"))) (defcustom magit-pre-display-buffer-hook '(magit-save-window-configuration) "Hook run by `magit-display-buffer' before displaying the buffer." :package-version '(magit . "2.3.0") :group 'magit-buffers :type 'hook :get 'magit-hook-custom-get :options '(magit-save-window-configuration)) (defcustom magit-post-display-buffer-hook '(magit-maybe-set-dedicated) "Hook run by `magit-display-buffer' after displaying the buffer." :package-version '(magit . "2.3.0") :group 'magit-buffers :type 'hook :get 'magit-hook-custom-get :options '(magit-maybe-set-dedicated)) (defcustom magit-generate-buffer-name-function 'magit-generate-buffer-name-default-function "The function used to generate the name for a Magit buffer." :package-version '(magit . "2.3.0") :group 'magit-buffers :type '(radio (function-item magit-generate-buffer-name-default-function) (function :tag "Function"))) (defcustom magit-buffer-name-format "%x%M%v: %t%x" "The format string used to name Magit buffers. The following %-sequences are supported: `%m' The name of the major-mode, but with the `-mode' suffix removed. `%M' Like \"%m\" but abbreviate `magit-status-mode' as `magit'. `%v' The value the buffer is locked to, in parentheses, or an empty string if the buffer is not locked to a value. `%V' Like \"%v\", but the string is prefixed with a space, unless it is an empty string. `%t' The top-level directory of the working tree of the repository, or if `magit-uniquify-buffer-names' is non-nil an abbreviation of that. `%x' If `magit-uniquify-buffer-names' is nil \"*\", otherwise the empty string. Due to limitations of the `uniquify' package, buffer names must end with the path. `%T' Obsolete, use \"%t%x\" instead. Like \"%t\", but append an asterisk if and only if `magit-uniquify-buffer-names' is nil. The value should always contain \"%m\" or \"%M\", \"%v\" or \"%V\", and \"%t\" (or the obsolete \"%T\"). If `magit-uniquify-buffer-names' is non-nil, then the value must end with \"%t\" or \"%t%x\" (or the obsolete \"%T\"). See issue #2841. This is used by `magit-generate-buffer-name-default-function'. If another `magit-generate-buffer-name-function' is used, then it may not respect this option, or on the contrary it may support additional %-sequences." :package-version '(magit . "2.12.0") :group 'magit-buffers :type 'string) (defcustom magit-uniquify-buffer-names t "Whether to uniquify the names of Magit buffers." :package-version '(magit . "2.3.0") :group 'magit-buffers :type 'boolean) (defcustom magit-bury-buffer-function 'magit-restore-window-configuration "The function used to bury or kill the current Magit buffer." :package-version '(magit . "2.3.0") :group 'magit-buffers :type '(radio (function-item quit-window) (function-item magit-mode-quit-window) (function-item magit-restore-window-configuration) (function :tag "Function"))) (defcustom magit-use-sticky-arguments t "How to reuse arguments from existing diff and log buffers. nil Always use the default value of the variable `magit-log-arguments' for log commands. Likewise, always use the default value of the variable `magit-diff-arguments' for diff command calls. current If the mode of the current buffer is derived from `magit-log-mode' or `magit-diff-mode', reuse the arguments from that buffer instead of those given by the variable `magit-log-arguments' or `magit-diff-arguments', respectively. t Like `current', but if the mode of the current buffer is not derived from `magit-log-mode' or `magit-diff-mode', use the arguments from the current repository's active (i.e. non-locked) `magit-log-mode' or `magit-diff-mode' buffer, respectively, if it exists. Note that commands that generate a `magit-revision-mode' or `magit-stash-mode' buffer will also collect their diff arguments from the active `magit-diff-mode' buffer. In general, there is a separation between the \"sticky\" arguments for log and diff buffers, but there is one special case: if the current buffer is a log buffer, `magit-show-commit' (considered a diff command) uses the file filter from the log buffer." :package-version '(magit . "2.11.0") :group 'magit-buffers :type '(choice (const :tag "disabled" nil) (const :tag "sticky for current" current) (const :tag "sticky" t))) (defcustom magit-region-highlight-hook '(magit-section-update-region magit-diff-update-hunk-region) "Functions used to highlight the region. Each function is run with the current section as only argument until one of them returns non-nil. If all functions return nil, then fall back to regular region highlighting." :package-version '(magit . "2.1.0") :group 'magit-refresh :type 'hook :options '(magit-section-update-region magit-diff-update-hunk-region)) (defcustom magit-create-buffer-hook nil "Normal hook run after creating a new `magit-mode' buffer." :package-version '(magit . "2.90.0") :group 'magit-refresh :type 'hook) (defcustom magit-refresh-buffer-hook nil "Normal hook for `magit-refresh-buffer' to run after refreshing." :package-version '(magit . "2.1.0") :group 'magit-refresh :type 'hook) (defcustom magit-refresh-status-buffer t "Whether the status buffer is refreshed after running git. When this is non-nil, then the status buffer is automatically refreshed after running git for side-effects, in addition to the current Magit buffer, which is always refreshed automatically. Only set this to nil after exhausting all other options to improve performance." :package-version '(magit . "2.4.0") :group 'magit-refresh :group 'magit-status :type 'boolean) (defcustom magit-refresh-verbose nil "Whether to revert Magit buffers verbosely." :package-version '(magit . "2.1.0") :group 'magit-refresh :type 'boolean) (defcustom magit-save-repository-buffers t "Whether to save file-visiting buffers when appropriate. If non-nil, then all modified file-visiting buffers belonging to the current repository may be saved before running Magit commands and before creating or refreshing Magit buffers. If `dontask', then this is done without user intervention, for any other non-nil value the user has to confirm each save. The default is t to avoid surprises, but `dontask' is the recommended value." :group 'magit-essentials :group 'magit-buffers :type '(choice (const :tag "Never" nil) (const :tag "Ask" t) (const :tag "Save without asking" dontask))) (defcustom magit-keep-region-overlay nil "Whether to keep the region overlay when there is a valid selection. By default Magit removes the regular region overlay if, and only if, that region constitutes a valid selection as understood by Magit commands. Otherwise it does not remove that overlay, and the region looks like it would in other buffers. There are two types of such valid selections: hunk-internal regions and regions that select two or more sibling sections. In such cases Magit removes the region overlay and instead highlights a slightly larger range. All text (for hunk-internal regions) or the headings of all sections (for sibling selections) that are inside that range (not just inside the region) are acted on by commands such as the staging command. This buffer range begins at the beginning of the line on which the region begins and ends at the end of the line on which the region ends. Because Magit acts on this larger range and not the region, it is actually quite important to visualize that larger range. If we don't do that, then one might think that these commands act on the region instead. If you want to *also* visualize the region, then set this option to t. But please note that when the region does *not* constitute a valid selection, then the region is *always* visualized as usual, and that it is usually under such circumstances that you want to use a non-magit command to act on the region. Besides keeping the region overlay, setting this option to t also causes all face properties, except for `:foreground', to be ignored for the faces used to highlight headings of selected sections. This avoids the worst conflicts that result from displaying the region and the selection overlays at the same time. We are not interested in dealing with other conflicts. In fact we *already* provide a way to avoid all of these conflicts: *not* changing the value of this option. It should be clear by now that we consider it a mistake to set this to display the region when the Magit selection is also visualized, but since it has been requested a few times and because it doesn't cost much to offer this option we do so. However that might change. If the existence of this option starts complicating other things, then it will be removed." :package-version '(magit . "2.3.0") :group 'magit-miscellaneous :type 'boolean) ;;; Magit Mode (defvar magit-mode-map (let ((map (make-keymap))) (suppress-keymap map t) (cond ((featurep 'jkl) (define-key map [return] 'magit-visit-thing) (define-key map [C-return] 'magit-dired-jump) (define-key map [tab] 'magit-section-toggle) (define-key map [C-tab] 'magit-section-cycle) (define-key map [M-tab] 'magit-section-cycle-diffs) (define-key map [S-tab] 'magit-section-cycle-global) (define-key map (kbd "M-o") 'magit-section-up) (define-key map (kbd "i") 'magit-section-backward) (define-key map (kbd "k") 'magit-section-forward) (define-key map (kbd "M-i") 'magit-section-backward-sibling) (define-key map (kbd "M-k") 'magit-section-forward-sibling) (define-key map (kbd "p") 'magit-push-popup) (define-key map (kbd ",") 'magit-delete-thing) (define-key map (kbd ";") 'magit-file-untrack) (define-key map (kbd "C-c C-i") 'magit-gitignore-popup)) (t (define-key map [C-return] 'magit-visit-thing) (define-key map (kbd "C-m") 'magit-visit-thing) (define-key map (kbd "C-M-i") 'magit-dired-jump) (define-key map (kbd "C-i") 'magit-section-toggle) (define-key map [C-tab] 'magit-section-cycle) (define-key map [M-tab] 'magit-section-cycle-diffs) ;; [backtab] is the most portable binding for Shift+Tab. (define-key map [backtab] 'magit-section-cycle-global) (define-key map (kbd "^") 'magit-section-up) (define-key map (kbd "p") 'magit-section-backward) (define-key map (kbd "n") 'magit-section-forward) (define-key map (kbd "M-p") 'magit-section-backward-sibling) (define-key map (kbd "M-n") 'magit-section-forward-sibling) (define-key map (kbd "P") 'magit-push-popup) (define-key map (kbd "k") 'magit-delete-thing) (define-key map (kbd "K") 'magit-file-untrack) (define-key map (kbd "i") 'magit-gitignore-popup) (define-key map (kbd "I") 'magit-gitignore-popup))) (define-key map (kbd "SPC") 'magit-diff-show-or-scroll-up) (define-key map (kbd "DEL") 'magit-diff-show-or-scroll-down) (define-key map "+" 'magit-diff-more-context) (define-key map "-" 'magit-diff-less-context) (define-key map "0" 'magit-diff-default-context) (define-key map "1" 'magit-section-show-level-1) (define-key map "2" 'magit-section-show-level-2) (define-key map "3" 'magit-section-show-level-3) (define-key map "4" 'magit-section-show-level-4) (define-key map (kbd "M-1") 'magit-section-show-level-1-all) (define-key map (kbd "M-2") 'magit-section-show-level-2-all) (define-key map (kbd "M-3") 'magit-section-show-level-3-all) (define-key map (kbd "M-4") 'magit-section-show-level-4-all) (define-key map "$" 'magit-process-buffer) (define-key map "%" 'magit-worktree-popup) (define-key map "a" 'magit-cherry-apply) (define-key map "A" 'magit-cherry-pick-popup) (define-key map "b" 'magit-branch-popup) (define-key map "B" 'magit-bisect-popup) (define-key map "c" 'magit-commit-popup) (define-key map "d" 'magit-diff-popup) (define-key map "D" 'magit-diff-refresh-popup) (define-key map "e" 'magit-ediff-dwim) (define-key map "E" 'magit-ediff-popup) (define-key map "f" 'magit-fetch-popup) (define-key map "F" 'magit-pull-popup) (define-key map "g" 'magit-refresh) (define-key map "G" 'magit-refresh-all) (define-key map "h" 'magit-dispatch-popup) (define-key map "?" 'magit-dispatch-popup) (define-key map "l" 'magit-log-popup) (define-key map "L" 'magit-log-refresh-popup) (define-key map "m" 'magit-merge-popup) (define-key map "M" 'magit-remote-popup) (define-key map "o" 'magit-submodule-popup) (define-key map "O" 'magit-subtree-popup) (define-key map "q" 'magit-mode-bury-buffer) (define-key map "r" 'magit-rebase-popup) (define-key map "R" 'magit-file-rename) (define-key map "t" 'magit-tag-popup) (define-key map "T" 'magit-notes-popup) (define-key map "s" 'magit-stage-file) (define-key map "S" 'magit-stage-modified) (define-key map "u" 'magit-unstage-file) (define-key map "U" 'magit-unstage-all) (define-key map "v" 'magit-revert-no-commit) (define-key map "V" 'magit-revert-popup) (define-key map "w" 'magit-am-popup) (define-key map "W" 'magit-patch-popup) (define-key map "x" 'magit-reset-quickly) (define-key map "X" 'magit-reset-popup) (define-key map "y" 'magit-show-refs-popup) (define-key map "Y" 'magit-cherry) (define-key map "z" 'magit-stash-popup) (define-key map "Z" 'magit-stash-popup) (define-key map ":" 'magit-git-command) (define-key map "!" 'magit-run-popup) (define-key map (kbd "C-c C-b") 'magit-browse-thing) (define-key map (kbd "C-c C-c") 'magit-dispatch-popup) (define-key map (kbd "C-c C-e") 'magit-dispatch-popup) (define-key map (kbd "C-x a") 'magit-add-change-log-entry) (define-key map (kbd "C-x 4 a") 'magit-add-change-log-entry-other-window) (define-key map (kbd "C-w") 'magit-copy-section-value) (define-key map (kbd "M-w") 'magit-copy-buffer-revision) (define-key map [remap previous-line] 'magit-previous-line) (define-key map [remap next-line] 'magit-next-line) (define-key map [remap evil-previous-line] 'evil-previous-visual-line) (define-key map [remap evil-next-line] 'evil-next-visual-line) map) "Parent keymap for all keymaps of modes derived from `magit-mode'.") (defun magit-delete-thing () "This is a placeholder command. Where applicable, section-specific keymaps bind another command which deletes the thing at point." (interactive) (user-error "There is no thing at point that could be deleted")) (defun magit-visit-thing () "This is a placeholder command. Where applicable, section-specific keymaps bind another command which visits the thing at point." (interactive) (if (eq magit-current-popup 'magit-dispatch-popup) (progn (setq magit-current-popup nil) (call-interactively (key-binding (this-command-keys)))) (user-error "There is no thing at point that could be visited"))) (defun magit-edit-thing () "This is a placeholder command. Where applicable, section-specific keymaps bind another command which lets you edit the thing at point, likely in another buffer." (interactive) (if (eq magit-current-popup 'magit-dispatch-popup) (progn (setq magit-current-popup nil) (call-interactively (key-binding (this-command-keys)))) (user-error "There is no thing at point that could be edited"))) (defun magit-browse-thing () "This is a placeholder command. Where applicable, section-specific keymaps bind another command which visits the thing at point using `browse-url'." (interactive) (user-error "There is no thing at point that could be browsed")) (easy-menu-define magit-mode-menu magit-mode-map "Magit menu" '("Magit" ["Refresh" magit-refresh t] ["Refresh all" magit-refresh-all t] "---" ["Stage" magit-stage t] ["Stage modified" magit-stage-modified t] ["Unstage" magit-unstage t] ["Reset index" magit-reset-index t] ["Commit" magit-commit-popup t] ["Add log entry" magit-commit-add-log t] ["Tag" magit-tag-create t] "---" ["Diff working tree" magit-diff-working-tree t] ["Diff" magit-diff t] ("Log" ["Log" magit-log-other t] ["Reflog" magit-reflog-other t] ["Extended..." magit-log-popup t]) "---" ["Cherry pick" magit-cherry-pick t] ["Revert commit" magit-revert-popup t] "---" ["Ignore globally" magit-gitignore-globally t] ["Ignore locally" magit-gitignore-locally t] ["Discard" magit-discard t] ["Reset head and index" magit-reset-mixed t] ["Stash" magit-stash-both t] ["Snapshot" magit-snapshot-both t] "---" ["Branch..." magit-checkout t] ["Merge" magit-merge t] ["Ediff resolve" magit-ediff-resolve t] ["Rebase..." magit-rebase-popup t] "---" ["Push" magit-push t] ["Pull" magit-pull-branch t] ["Remote update" magit-fetch-all t] ("Submodule" ["Submodule update" magit-submodule-update t] ["Submodule update and init" magit-submodule-setup t] ["Submodule init" magit-submodule-init t] ["Submodule sync" magit-submodule-sync t]) "---" ("Extensions") "---" ["Display Git output" magit-process-buffer t] ["Quit Magit" magit-mode-bury-buffer t])) (defun magit-load-config-extensions () "Load Magit extensions that are defined at the Git config layer." (dolist (ext (magit-get-all "magit.extension")) (let ((sym (intern (format "magit-%s-mode" ext)))) (when (fboundp sym) (funcall sym 1))))) (define-derived-mode magit-mode special-mode "Magit" "Parent major mode from which Magit major modes inherit. Magit is documented in info node `(magit)'." :group 'magit-modes (buffer-disable-undo) (setq truncate-lines t) (setq buffer-read-only t) (setq-local line-move-visual t) ; see #1771 (setq show-trailing-whitespace nil) (setq list-buffers-directory (abbreviate-file-name default-directory)) (hack-dir-local-variables-non-file-buffer) (make-local-variable 'text-property-default-nonsticky) (push (cons 'keymap t) text-property-default-nonsticky) (add-hook 'post-command-hook #'magit-section-update-highlight t t) (add-hook 'deactivate-mark-hook #'magit-section-update-highlight t t) (setq-local redisplay-highlight-region-function 'magit-highlight-region) (setq-local redisplay-unhighlight-region-function 'magit-unhighlight-region) (setq mode-line-process (magit-repository-local-get 'mode-line-process)) (when (bound-and-true-p global-linum-mode) (linum-mode -1)) (when (and (fboundp 'nlinum-mode) (bound-and-true-p global-nlinum-mode)) (nlinum-mode -1)) (when (and (fboundp 'display-line-numbers-mode) (bound-and-true-p global-display-line-numbers-mode)) (display-line-numbers-mode -1)) (add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache)) (defvar-local magit-region-overlays nil) (defun magit-delete-region-overlays () (mapc #'delete-overlay magit-region-overlays) (setq magit-region-overlays nil)) (defun magit-highlight-region (start end window rol) (magit-delete-region-overlays) (if (and (run-hook-with-args-until-success 'magit-region-highlight-hook (magit-current-section)) (not magit-keep-region-overlay) (not (= (line-number-at-pos start) (line-number-at-pos end))) ;; (not (eq (car-safe last-command-event) 'mouse-movement)) ) (funcall (default-value 'redisplay-unhighlight-region-function) rol) (funcall (default-value 'redisplay-highlight-region-function) start end window rol))) (defun magit-unhighlight-region (rol) (setq magit-section-highlighted-section nil) (magit-delete-region-overlays) (funcall (default-value 'redisplay-unhighlight-region-function) rol)) (defvar-local magit-refresh-args nil "The arguments used to refresh the current buffer.") (put 'magit-refresh-args 'permanent-local t) (defvar-local magit-previous-section nil) (put 'magit-previous-section 'permanent-local t) (defun magit-mode-setup (mode &rest args) "Setup up a MODE buffer using ARGS to generate its content." (magit-mode-setup-internal mode args)) (defun magit-mode-setup-internal (mode args &optional locked) "Setup up a MODE buffer using ARGS to generate its content. When optional LOCKED is non-nil, then create a buffer that is locked to its value, which is derived from MODE and ARGS." (let* ((value (and locked (magit-buffer-lock-value mode args))) (buffer (magit-mode-get-buffer mode nil nil value)) (section (and buffer (magit-current-section))) (created (not buffer))) (unless buffer (setq buffer (magit-with-toplevel (magit-generate-new-buffer mode value)))) (with-current-buffer buffer (setq magit-previous-section section) (setq magit-refresh-args args) (funcall mode) (when created (magit-status-goto-initial-section) (run-hooks 'magit-create-buffer-hook))) (magit-display-buffer buffer) (with-current-buffer buffer (run-hooks 'magit-mode-setup-hook) (magit-refresh-buffer)))) (defvar magit-display-buffer-noselect nil "If non-nil, then `magit-display-buffer' doesn't call `select-window'.") (defun magit-display-buffer (buffer) "Display BUFFER in some window and maybe select it. Display the buffer using `magit-display-buffer-function' and then, unless `magit-display-buffer-noselect' is non-nil, select the window which was used to display the buffer. Also run the hooks `magit-pre-display-buffer-hook' and `magit-post-display-buffer-hook'." (with-current-buffer buffer (run-hooks 'magit-pre-display-buffer-hook)) (let ((window (funcall magit-display-buffer-function buffer))) (unless magit-display-buffer-noselect (let* ((old-frame (selected-frame)) (new-frame (window-frame window))) (select-window window) (unless (eq old-frame new-frame) (select-frame-set-input-focus new-frame))))) (with-current-buffer buffer (run-hooks 'magit-post-display-buffer-hook))) (defun magit-display-buffer-traditional (buffer) "Display BUFFER the way this has traditionally been done." (display-buffer buffer (if (and (derived-mode-p 'magit-mode) (not (memq (with-current-buffer buffer major-mode) '(magit-process-mode magit-revision-mode magit-diff-mode magit-stash-mode magit-status-mode)))) '(display-buffer-same-window) nil))) ; display in another window (defun magit-display-buffer-same-window-except-diff-v1 (buffer) "Display BUFFER in the selected window except for some modes. If a buffer's `major-mode' derives from `magit-diff-mode' or `magit-process-mode', display it in another window. Display all other buffers in the selected window." (display-buffer buffer (if (with-current-buffer buffer (derived-mode-p 'magit-diff-mode 'magit-process-mode)) nil ; display in another window '(display-buffer-same-window)))) (defun magit--display-buffer-fullframe (buffer alist) (when-let ((window (or (display-buffer-reuse-window buffer alist) (display-buffer-same-window buffer alist) (display-buffer-pop-up-window buffer alist) (display-buffer-use-some-window buffer alist)))) (delete-other-windows window) window)) (defun magit-display-buffer-fullframe-status-v1 (buffer) "Display BUFFER, filling entire frame if BUFFER is a status buffer. Otherwise, behave like `magit-display-buffer-traditional'." (if (eq (with-current-buffer buffer major-mode) 'magit-status-mode) (display-buffer buffer '(magit--display-buffer-fullframe)) (magit-display-buffer-traditional buffer))) (defun magit--display-buffer-topleft (buffer alist) (or (display-buffer-reuse-window buffer alist) (when-let ((window2 (display-buffer-pop-up-window buffer alist))) (let ((window1 (get-buffer-window)) (buffer1 (current-buffer)) (buffer2 (window-buffer window2)) (w2-quit-restore (window-parameter window2 'quit-restore))) (set-window-buffer window1 buffer2) (set-window-buffer window2 buffer1) (select-window window2) ;; Swap some window state that `magit-mode-quit-window' and ;; `quit-restore-window' inspect. (set-window-prev-buffers window2 (cdr (window-prev-buffers window1))) (set-window-prev-buffers window1 nil) (set-window-parameter window2 'magit-dedicated (window-parameter window1 'magit-dedicated)) (set-window-parameter window1 'magit-dedicated t) (set-window-parameter window1 'quit-restore (list 'window 'window (nth 2 w2-quit-restore) (nth 3 w2-quit-restore))) (set-window-parameter window2 'quit-restore nil) window1)))) (defun magit-display-buffer-fullframe-status-topleft-v1 (buffer) "Display BUFFER, filling entire frame if BUFFER is a status buffer. When BUFFER derives from `magit-diff-mode' or `magit-process-mode', try to display BUFFER to the top or left of the current buffer rather than to the bottom or right, as `magit-display-buffer-fullframe-status-v1' would. Whether the split is made vertically or horizontally is determined by `split-window-preferred-function'." (display-buffer buffer (cond ((eq (with-current-buffer buffer major-mode) 'magit-status-mode) '(magit--display-buffer-fullframe)) ((with-current-buffer buffer (derived-mode-p 'magit-diff-mode 'magit-process-mode)) '(magit--display-buffer-topleft)) (t '(display-buffer-same-window))))) (defun magit--display-buffer-fullcolumn (buffer alist) (when-let ((window (or (display-buffer-reuse-window buffer alist) (display-buffer-same-window buffer alist) (display-buffer-below-selected buffer alist)))) (delete-other-windows-vertically window) window)) (defun magit-display-buffer-fullcolumn-most-v1 (buffer) "Display BUFFER using the full column except in some cases. For most cases where BUFFER's `major-mode' derives from `magit-mode', display it in the selected window and grow that window to the full height of the frame, deleting other windows in that column as necessary. However, display BUFFER in another window if 1) BUFFER's mode derives from `magit-process-mode', or 2) BUFFER's mode derives from `magit-diff-mode', provided that the mode of the current buffer derives from `magit-log-mode' or `magit-cherry-mode'." (display-buffer buffer (cond ((and (or git-commit-mode (derived-mode-p 'magit-log-mode 'magit-cherry-mode)) (with-current-buffer buffer (derived-mode-p 'magit-diff-mode))) nil) ((with-current-buffer buffer (derived-mode-p 'magit-process-mode)) nil) (t '(magit--display-buffer-fullcolumn))))) (defun magit-maybe-set-dedicated () "Mark the selected window as dedicated if appropriate. If a new window was created to display the buffer, then remember that fact. That information is used by `magit-mode-quit-window', to determine whether the window should be deleted when its last Magit buffer is buried." (let ((window (get-buffer-window (current-buffer)))) (when (and (window-live-p window) (not (window-prev-buffers window))) (set-window-parameter window 'magit-dedicated t)))) (defvar-local magit--default-directory nil "Value of `default-directory' when buffer is generated. This exists to prevent a let-bound `default-directory' from tricking `magit-mode-get-buffer' or `magit-mode-get-buffers' into thinking a buffer belongs to a repo that it doesn't.") (put 'magit--default-directory 'permanent-local t) (defun magit-mode-get-buffers () (let ((topdir (magit-toplevel))) (--filter (with-current-buffer it (and (derived-mode-p 'magit-mode) (equal magit--default-directory topdir))) (buffer-list)))) (defvar-local magit-buffer-locked-p nil) (put 'magit-buffer-locked-p 'permanent-local t) (defun magit-mode-get-buffer (mode &optional create frame value) (when create (error "`magit-mode-get-buffer's CREATE argument is obsolete")) (if-let ((topdir (magit-toplevel))) (--first (with-current-buffer it (and (eq major-mode mode) (equal magit--default-directory topdir) (if value (and magit-buffer-locked-p (equal (magit-buffer-lock-value) value)) (not magit-buffer-locked-p)))) (if frame (mapcar #'window-buffer (window-list (unless (eq frame t) frame))) (buffer-list))) (magit--not-inside-repository-error))) (defun magit-generate-new-buffer (mode &optional value) (let* ((name (funcall magit-generate-buffer-name-function mode value)) (buffer (generate-new-buffer name))) (with-current-buffer buffer (setq magit--default-directory default-directory) (setq magit-buffer-locked-p (and value t)) (magit-restore-section-visibility-cache mode)) (when magit-uniquify-buffer-names (add-to-list 'uniquify-list-buffers-directory-modes mode) (with-current-buffer buffer (setq list-buffers-directory (abbreviate-file-name default-directory))) (let ((uniquify-buffer-name-style (if (memq uniquify-buffer-name-style '(nil forward)) 'post-forward-angle-brackets uniquify-buffer-name-style))) (uniquify-rationalize-file-buffer-names name (file-name-directory (directory-file-name default-directory)) buffer))) buffer)) (defun magit-generate-buffer-name-default-function (mode &optional value) "Generate buffer name for a MODE buffer in the current repository. The returned name is based on `magit-buffer-name-format' and takes `magit-uniquify-buffer-names' and VALUE, if non-nil, into account." (let ((m (substring (symbol-name mode) 0 -5)) (v (and value (format "%s" (if (listp value) value (list value))))) (n (if magit-uniquify-buffer-names (file-name-nondirectory (directory-file-name default-directory)) (abbreviate-file-name default-directory)))) (format-spec magit-buffer-name-format `((?m . ,m) (?M . ,(if (eq mode 'magit-status-mode) "magit" m)) (?v . ,(or v "")) (?V . ,(if v (concat " " v) "")) (?t . ,n) (?x . ,(if magit-uniquify-buffer-names "" "*")) (?T . ,(if magit-uniquify-buffer-names n (concat n "*"))))))) (defun magit-toggle-buffer-lock () "Lock the current buffer to its value or unlock it. Locking a buffer to its value prevents it from being reused to display another value. The name of a locked buffer contains its value, which allows telling it apart from other locked buffers and the unlocked buffer. Not all Magit buffers can be locked to their values, for example it wouldn't make sense to lock a status buffer. There can only be a single unlocked buffer using a certain major-mode per repository. So when a buffer is being unlocked and another unlocked buffer already exists for that mode and repository, then the former buffer is instead deleted and the latter is displayed in its place." (interactive) (if magit-buffer-locked-p (if-let ((unlocked (magit-mode-get-buffer major-mode))) (let ((locked (current-buffer))) (switch-to-buffer unlocked nil t) (kill-buffer locked)) (setq magit-buffer-locked-p nil) (rename-buffer (funcall magit-generate-buffer-name-function major-mode))) (if-let ((value (magit-buffer-lock-value))) (if-let ((locked (magit-mode-get-buffer major-mode nil nil value))) (let ((unlocked (current-buffer))) (switch-to-buffer locked nil t) (kill-buffer unlocked)) (setq magit-buffer-locked-p t) (rename-buffer (funcall magit-generate-buffer-name-function major-mode value))) (user-error "Buffer has no value it could be locked to")))) (defvar magit-buffer-lock-functions nil "Provide buffer-locking support for third-party modes. An alist of symbols to functions. The symbol must be the major-mode the locked buffer will have. The function must take a single argument, a list of refresh arguments (the value of `magit-refresh-args') and return a value that identifies the buffer (i.e., its 'lock value'). If the third-party mode is invoked as (magit-mode-setup-internal #\\='my-mode \\='(1 2 3) t) the function will be invoked as (funcall lock-func \\='(1 2 3)) if the cons (my-mode . lock-func) is in this list. This variable is intended for third-party extensions; `magit-buffer-lock-value' implements all built-in behavior. See also `magit-toggle-buffer-lock'.") (cl-defun magit-buffer-lock-value (&optional (mode major-mode) (args magit-refresh-args)) "Find an appropriate buffer lock value for MODE under ARGS. See also `magit-buffer-lock-functions'." (cl-case mode (magit-cherry-mode (pcase-let ((`(,upstream ,head) args)) (concat head ".." upstream))) (magit-diff-mode (pcase-let ((`(,rev-or-range ,const ,_args ,files) args)) (nconc (cons (or rev-or-range (if (member "--cached" const) (progn (setq const (delete "--cached" const)) 'staged) 'unstaged)) const) (and files (cons "--" files))))) (magit-log-mode (pcase-let ((`(,revs ,_args ,files) args)) (if (and revs files) (append revs (cons "--" files)) (append revs files)))) (magit-refs-mode (pcase-let ((`(,ref ,args) args)) (cons (or ref "HEAD") args))) (magit-revision-mode (pcase-let ((`(,rev ,_const ,_args ,files) args)) (if files (cons rev files) (list rev)))) ((magit-reflog-mode ; (ref ~args) magit-stash-mode ; (stash _const _args _files) magit-stashes-mode) ; (ref) (car args)) (t (--when-let (cdr (assq mode magit-buffer-lock-functions)) (funcall it args))))) (defun magit-mode-bury-buffer (&optional kill-buffer) "Bury the current buffer. With a prefix argument, kill the buffer instead. This is done using `magit-bury-buffer-function'." (interactive "P") (funcall magit-bury-buffer-function kill-buffer)) (defun magit-mode-quit-window (kill-buffer) "Quit the selected window and bury its buffer. This behaves similar to `quit-window', but when the window was originally created to display a Magit buffer and the current buffer is the last remaining Magit buffer that was ever displayed in the selected window, then delete that window." (if (or (one-window-p) (--first (let ((buffer (car it))) (and (not (eq buffer (current-buffer))) (buffer-live-p buffer) (or (not (window-parameter nil 'magit-dedicated)) (with-current-buffer buffer (derived-mode-p 'magit-mode 'magit-process-mode))))) (window-prev-buffers))) (quit-window kill-buffer) (let ((window (selected-window))) (quit-window kill-buffer) (when (window-live-p window) (delete-window window))))) ;;; Refresh Magit Buffers (defvar inhibit-magit-refresh nil) (defun magit-refresh () "Refresh some buffers belonging to the current repository. Refresh the current buffer if its major mode derives from `magit-mode', and refresh the corresponding status buffer. Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (interactive) (unless inhibit-magit-refresh (unwind-protect (let ((start (current-time)) (magit--refresh-cache (or magit--refresh-cache (list (cons 0 0))))) (when magit-refresh-verbose (message "Refreshing magit...")) (magit-run-hook-with-benchmark 'magit-pre-refresh-hook) (when (derived-mode-p 'magit-mode) (magit-refresh-buffer)) (--when-let (and magit-refresh-status-buffer (not (derived-mode-p 'magit-status-mode)) (magit-mode-get-buffer 'magit-status-mode)) (with-current-buffer it (magit-refresh-buffer))) (magit-auto-revert-buffers) (cond ((and (not this-command) (memq last-command magit-post-commit-hook-commands)) (magit-run-hook-with-benchmark 'magit-post-commit-hook)) ((memq this-command magit-post-stage-hook-commands) (magit-run-hook-with-benchmark 'magit-post-stage-hook)) ((memq this-command magit-post-unstage-hook-commands) (magit-run-hook-with-benchmark 'magit-post-unstage-hook))) (magit-run-hook-with-benchmark 'magit-post-refresh-hook) (when magit-refresh-verbose (message "Refreshing magit...done (%.3fs, cached %s/%s)" (float-time (time-subtract (current-time) start)) (caar magit--refresh-cache) (+ (caar magit--refresh-cache) (cdar magit--refresh-cache))))) (run-hooks 'magit-unwind-refresh-hook)))) (defun magit-refresh-all () "Refresh all buffers belonging to the current repository. Refresh all Magit buffers belonging to the current repository, and revert buffers that visit files located inside the current repository. Run hooks `magit-pre-refresh-hook' and `magit-post-refresh-hook'." (interactive) (magit-run-hook-with-benchmark 'magit-pre-refresh-hook) (dolist (buffer (magit-mode-get-buffers)) (with-current-buffer buffer (magit-refresh-buffer))) (magit-auto-revert-buffers) (magit-run-hook-with-benchmark 'magit-post-refresh-hook)) (defvar-local magit-refresh-start-time nil) (defun magit-refresh-buffer () "Refresh the current Magit buffer." (setq magit-refresh-start-time (current-time)) (let ((refresh (intern (format "%s-refresh-buffer" (substring (symbol-name major-mode) 0 -5)))) (magit--refresh-cache (or magit--refresh-cache (list (cons 0 0))))) (when (functionp refresh) (when magit-refresh-verbose (message "Refreshing buffer `%s'..." (buffer-name))) (let* ((buffer (current-buffer)) (windows (--mapcat (with-selected-window it (with-current-buffer buffer (when-let ((section (magit-current-section))) (list (nconc (list it section) (magit-refresh-get-relative-position)))))) (or (get-buffer-window-list buffer nil t) (list (selected-window)))))) (deactivate-mark) (setq magit-section-highlight-overlays nil) (setq magit-section-highlighted-section nil) (setq magit-section-highlighted-sections nil) (setq magit-section-unhighlight-sections nil) (magit-process-unset-mode-line-error-status) (let ((inhibit-read-only t)) (erase-buffer) (save-excursion (apply refresh magit-refresh-args))) (dolist (window windows) (with-selected-window (car window) (with-current-buffer buffer (apply #'magit-section-goto-successor (cdr window))))) (run-hooks 'magit-refresh-buffer-hook) (magit-section-update-highlight) (set-buffer-modified-p nil)) (when magit-refresh-verbose (message "Refreshing buffer `%s'...done (%.3fs)" (buffer-name) (float-time (time-subtract (current-time) magit-refresh-start-time))))))) (defun magit-refresh-get-relative-position () (when-let ((section (magit-current-section))) (let ((start (oref section start))) (list (count-lines start (point)) (- (point) (line-beginning-position)) (and (magit-hunk-section-p section) (region-active-p) (progn (goto-char (line-beginning-position)) (when (looking-at "^[-+]") (forward-line)) (while (looking-at "^[ @]") (forward-line)) (let ((beg (point))) (cond ((looking-at "^[-+]") (forward-line) (while (looking-at "^[-+]") (forward-line)) (while (looking-at "^ ") (forward-line)) (forward-line -1) (regexp-quote (buffer-substring-no-properties beg (line-end-position)))) (t t))))))))) ;;; Save File-Visiting Buffers (defvar disable-magit-save-buffers nil) (defun magit-pre-command-hook () (setq disable-magit-save-buffers nil)) (add-hook 'pre-command-hook #'magit-pre-command-hook) (defvar magit-after-save-refresh-buffers nil) (defun magit-after-save-refresh-buffers () (dolist (buffer magit-after-save-refresh-buffers) (when (buffer-live-p buffer) (with-current-buffer buffer (magit-refresh-buffer)))) (setq magit-after-save-refresh-buffers nil) (remove-hook 'post-command-hook 'magit-after-save-refresh-buffers)) (defun magit-after-save-refresh-status () "Refresh the status buffer of the current repository. This function is intended to be added to `after-save-hook'. If the status buffer does not exist or the file being visited in the current buffer isn't inside the working tree of a repository, then do nothing. Note that refreshing a Magit buffer is done by re-creating its contents from scratch, which can be slow in large repositories. If you are not satisfied with Magit's performance, then you should obviously not add this function to that hook." (when (and (not disable-magit-save-buffers) (magit-inside-worktree-p t)) (--when-let (ignore-errors (magit-mode-get-buffer 'magit-status-mode)) (add-to-list 'magit-after-save-refresh-buffers it) (add-hook 'post-command-hook 'magit-after-save-refresh-buffers)))) (defun magit-maybe-save-repository-buffers () "Maybe save file-visiting buffers belonging to the current repository. Do so if `magit-save-repository-buffers' is non-nil. You should not remove this from any hooks, instead set that variable to nil if you so desire." (when (and magit-save-repository-buffers (not disable-magit-save-buffers)) (setq disable-magit-save-buffers t) (let ((msg (current-message))) (magit-save-repository-buffers (eq magit-save-repository-buffers 'dontask)) (when (and msg (current-message) (not (equal msg (current-message)))) (message "%s" msg))))) (add-hook 'magit-pre-refresh-hook #'magit-maybe-save-repository-buffers) (add-hook 'magit-pre-call-git-hook #'magit-maybe-save-repository-buffers) (add-hook 'magit-pre-start-git-hook #'magit-maybe-save-repository-buffers) (defvar-local magit-inhibit-refresh-save nil) (defun magit-save-repository-buffers (&optional arg) "Save file-visiting buffers belonging to the current repository. After any buffer where `buffer-save-without-query' is non-nil is saved without asking, the user is asked about each modified buffer which visits a file in the current repository. Optional argument (the prefix) non-nil means save all with no questions." (interactive "P") (when-let ((topdir (magit-rev-parse-safe "--show-toplevel"))) (let ((remote (file-remote-p topdir)) (save-some-buffers-action-alist `((?Y (lambda (buffer) (with-current-buffer buffer (setq buffer-save-without-query t) (save-buffer))) "to save the current buffer and remember choice") (?N (lambda (buffer) (with-current-buffer buffer (setq magit-inhibit-refresh-save t))) "to skip the current buffer and remember choice") ,@save-some-buffers-action-alist))) (save-some-buffers arg (lambda () (and (not magit-inhibit-refresh-save) buffer-file-name (file-exists-p (file-name-directory buffer-file-name)) ;; Avoid needlessly connecting to unrelated remotes. (equal (file-remote-p buffer-file-name) remote) (string-prefix-p topdir (file-truename buffer-file-name)) (equal (magit-rev-parse-safe "--show-toplevel") topdir))))))) ;;; Restore Window Configuration (defvar magit-inhibit-save-previous-winconf nil) (defvar-local magit-previous-window-configuration nil) (put 'magit-previous-window-configuration 'permanent-local t) (defun magit-save-window-configuration () "Save the current window configuration. Later, when the buffer is buried, it may be restored by `magit-restore-window-configuration'." (if magit-inhibit-save-previous-winconf (when (eq magit-inhibit-save-previous-winconf 'unset) (setq magit-previous-window-configuration nil)) (unless (get-buffer-window (current-buffer) (selected-frame)) (setq magit-previous-window-configuration (current-window-configuration))))) (defun magit-restore-window-configuration (&optional kill-buffer) "Bury or kill the current buffer and restore previous window configuration." (let ((winconf magit-previous-window-configuration) (buffer (current-buffer)) (frame (selected-frame))) (quit-window kill-buffer (selected-window)) (when (and winconf (equal frame (window-configuration-frame winconf))) (set-window-configuration winconf) (when (buffer-live-p buffer) (with-current-buffer buffer (setq magit-previous-window-configuration nil)))))) ;;; Buffer History (defun magit-go-backward () "Move backward in current buffer's history." (interactive) (if help-xref-stack (help-xref-go-back (current-buffer)) (user-error "No previous entry in buffer's history"))) (defun magit-go-forward () "Move forward in current buffer's history." (interactive) (if help-xref-forward-stack (help-xref-go-forward (current-buffer)) (user-error "No next entry in buffer's history"))) (defun magit-insert-xref-buttons (&optional _) "Insert xref buttons." (when (or help-xref-stack help-xref-forward-stack) (when help-xref-stack (magit-xref-insert-button help-back-label 'magit-xref-backward)) (when help-xref-forward-stack (when help-xref-stack (insert " ")) (magit-xref-insert-button help-forward-label 'magit-xref-forward)))) (defun magit-xref-insert-button (label type) (magit-insert-section (button label) (insert-text-button label 'type type 'help-args (list (current-buffer))))) (define-button-type 'magit-xref-backward :supertype 'help-back 'mouse-face 'magit-section-highlight 'help-echo (purecopy "mouse-2, RET: go back to previous history entry")) (define-button-type 'magit-xref-forward :supertype 'help-forward 'mouse-face 'magit-section-highlight 'help-echo (purecopy "mouse-2, RET: go back to next history entry")) (defun magit-xref-setup () "Insert backward/forward buttons if the major-mode supports it. Currently `magit-log-mode', `magit-reflog-mode', `magit-diff-mode', and `magit-revision-mode' support it" (when (memq major-mode '(magit-log-mode magit-reflog-mode magit-diff-mode magit-revision-mode)) (when help-xref-stack-item (push (cons (point) help-xref-stack-item) help-xref-stack) (setq help-xref-forward-stack nil)) (when (called-interactively-p 'interactive) (--when-let (nthcdr 10 help-xref-stack) (setcdr it nil))) (setq help-xref-stack-item `(magit-xref-restore ,default-directory ,@magit-refresh-args)))) (defun magit-xref-restore (&rest args) (magit-xref-setup) (setq default-directory (car args)) (setq magit-refresh-args (cdr args)) (magit-refresh-buffer)) ;;; Repository-Local Cache (defvar magit-repository-local-cache nil "Alist mapping `magit-toplevel' paths to alists of key/value pairs.") (defun magit-repository-local-repository () "Return the key for the current repository." (or (bound-and-true-p magit--default-directory) (magit-toplevel))) (defun magit-repository-local-set (key value &optional repository) "Set the repository-local VALUE for KEY. Unless specified, REPOSITORY is the current buffer's repository. If REPOSITORY is nil (meaning there is no current repository), then the value is not cached, and we return nil." (let* ((repokey (or repository (magit-repository-local-repository))) (cache (assoc repokey magit-repository-local-cache))) ;; Don't cache values for a nil REPOSITORY, as the 'set' and 'get' ;; calls for some KEY may happen in unrelated contexts. (when repokey (if cache (let ((keyvalue (assoc key (cdr cache)))) (if keyvalue ;; Update pre-existing value for key. (setcdr keyvalue value) ;; No such key in repository-local cache. (push (cons key value) (cdr cache)))) ;; No cache for this repository. (push (cons repokey (list (cons key value))) magit-repository-local-cache))))) (defun magit-repository-local-exists-p (key &optional repository) "Non-nil when a repository-local value exists for KEY. Returns a (KEY . value) cons cell. The KEY is matched using `equal'. Unless specified, REPOSITORY is the current buffer's repository." (let* ((repokey (or repository (magit-repository-local-repository))) (cache (assoc repokey magit-repository-local-cache))) (and cache (assoc key (cdr cache))))) (defun magit-repository-local-get (key &optional default repository) "Return the repository-local value for KEY. Return DEFAULT if no value for KEY exists. The KEY is matched using `equal'. Unless specified, REPOSITORY is the current buffer's repository." (let ((keyvalue (magit-repository-local-exists-p key repository))) (if keyvalue (cdr keyvalue) default))) (defun magit-repository-local-delete (key &optional repository) "Delete the repository-local value for KEY. Unless specified, REPOSITORY is the current buffer's repository." (let* ((repokey (or repository (magit-repository-local-repository))) (cache (assoc repokey magit-repository-local-cache))) (when cache ;; There is no `assoc-delete-all'. (setf (cdr cache) (cl-delete key (cdr cache) :key #'car :test #'equal))))) (defun magit-zap-caches () "Zap caches for the current repository. Remove the repository's entry from `magit-repository-local-cache' and set `magit-section-visibility-cache' to nil in all of the repository's Magit buffers." (interactive) (magit-with-toplevel (setq magit-repository-local-cache (cl-delete default-directory magit-repository-local-cache :key #'car :test #'equal))) (dolist (buffer (magit-mode-get-buffers)) (with-current-buffer buffer (setq magit-section-visibility-cache nil)))) ;;; Utilities (defun magit-run-hook-with-benchmark (hook) (when hook (if magit-refresh-verbose (let ((start (current-time))) (message "Running %s..." hook) (run-hooks hook) (message "Running %s...done (%.3fs)" hook (float-time (time-subtract (current-time) start)))) (run-hooks hook)))) ;;; _ (provide 'magit-mode) ;;; magit-mode.el ends here magit-2.90.1/lisp/magit-notes.el000066400000000000000000000166311337354740400164450ustar00rootroot00000000000000;;; magit-notes.el --- notes support -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Popup ;;;###autoload (autoload 'magit-notes-popup "magit" nil t) (magit-define-popup magit-notes-popup "Popup console for notes commands." :man-page "git-notes" :variables '("Configure local settings" (?c "core.notesRef" magit-set-core.notesRef magit-format-core.notesRef) (?d "notes.displayRef" magit-set-notes.displayRef magit-format-notes.displayRef) "Configure global settings" (?C "core.notesRef" magit-set-global-core.notesRef magit-format-global-core.notesRef) (?D "notes.displayRef" magit-set-global-notes.displayRef magit-format-global-notes.displayRef)) :switches '("Switch for prune" (?n "Dry run" "--dry-run")) :options '("Option for edit and remove" (?r "Manipulate ref" "--ref=" magit-notes-popup-read-ref) "Option for merge" (?s "Merge strategy" "--strategy=")) :actions '((?T "Edit" magit-notes-edit) (?r "Remove" magit-notes-remove) (?m "Merge" magit-notes-merge) (?p "Prune" magit-notes-prune)) :sequence-actions '((?c "Commit merge" magit-notes-merge-commit) (?a "Abort merge" magit-notes-merge-abort)) :sequence-predicate 'magit-notes-merging-p :default-action 'magit-notes-edit) (defun magit-notes-merging-p () (let ((dir (magit-git-dir "NOTES_MERGE_WORKTREE"))) (and (file-directory-p dir) (directory-files dir nil "^[^.]")))) (defun magit-format-core.notesRef () (magit--format-popup-variable:value "core.notesRef" 22)) (defun magit-format-notes.displayRef () (magit--format-popup-variable:values "notes.displayRef" 22)) (defun magit-format-global-core.notesRef () (magit--format-popup-variable:value "core.notesRef" 22 t)) (defun magit-format-global-notes.displayRef () (magit--format-popup-variable:values "notes.displayRef" 22 t)) ;;; Commands (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" (magit-notes-arguments)) t))) (when dry-run (magit-process-buffer)) (magit-run-git-with-editor "notes" "prune" (and dry-run "--dry-run"))) (defun magit-set-core.notesRef (ref) "Set the local value of `core.notesRef' to REF." (interactive (list (magit-notes-read-ref "Set local core.notesRef"))) (magit-set ref "core.notesRef") (magit-with-pre-popup-buffer (magit-refresh))) (defun magit-set-global-core.notesRef (ref) "Set the global value of `core.notesRef' to REF." (interactive (list (magit-notes-read-ref "Set global core.notesRef"))) (magit-set ref "--global" "core.notesRef") (magit-with-pre-popup-buffer (magit-refresh))) (defun magit-set-notes.displayRef (refs) "Set the local values of `notes.displayRef' to REFS." (interactive (list (magit-notes-read-refs "Set local notes.displayRef"))) (magit-set-all refs "notes.displayRef") (magit-with-pre-popup-buffer (magit-refresh))) (defun magit-set-global-notes.displayRef (refs) "Set the global values of `notes.displayRef' to REFS." (interactive (list (magit-notes-read-refs "Set global notes.displayRef"))) (magit-set-all refs "--global" "notes.displayRef") (magit-with-pre-popup-buffer (magit-refresh))) (defun magit-notes-read-ref (prompt) (--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))) (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) (magit-notes-arguments)) (match-string 1 it)))) ;;; _ (provide 'magit-notes) ;;; magit-notes.el ends here magit-2.90.1/lisp/magit-obsolete.el000066400000000000000000000051361337354740400171270ustar00rootroot00000000000000;;; magit-obsolete.el --- obsolete definitions -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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.90.0 (define-obsolete-function-alias 'magit-reset-head 'magit-reset-mixed "Magit 2.90.0") (define-obsolete-function-alias 'magit-gitignore 'magit-gitignore-globally "Magit 2.90.0") (define-obsolete-function-alias 'magit-branch 'magit-branch-create "Magit 2.90.0") (define-obsolete-function-alias 'magit-tag 'magit-tag-create "Magit 2.90.0") (define-obsolete-function-alias 'magit-fetch 'magit-fetch-other "Magit 2.90.0") (define-obsolete-function-alias 'magit-pull 'magit-pull-branch "Magit 2.90.0") (define-obsolete-function-alias 'magit-rebase 'magit-rebase-branch "Magit 2.90.0") (define-obsolete-function-alias 'magit-blame 'magit-blame-addition "Magit 2.90.0") (define-obsolete-function-alias 'magit-revert 'magit-revert-and-commit "Magit 2.90.0") (define-obsolete-function-alias 'magit-reset 'magit-reset-quickly "Magit 2.90.0") (define-obsolete-function-alias 'magit-merge 'magit-merge-plain "Magit 2.90.0") (define-obsolete-function-alias 'magit-stash 'magit-stash-both "Magit 2.90.0") (define-obsolete-function-alias 'magit-snapshot 'magit-snapshot-both "Magit 2.90.0") (define-obsolete-function-alias 'magit-push 'magit-push-other "Magit 2.90.0") (define-obsolete-function-alias 'magit-commit 'magit-commit-create "Magit 2.90.0") (define-obsolete-function-alias 'magit-log 'magit-log-other "Magit 2.90.0") (define-obsolete-function-alias 'magit-reflog 'magit-reflog-other "Magit 2.90.0") (define-obsolete-function-alias 'magit-diff 'magit-diff-range "Magit 2.90.0") ;;; _ (provide 'magit-obsolete) ;;; magit-obsolete.el ends here magit-2.90.1/lisp/magit-patch.el000066400000000000000000000166551337354740400164220ustar00rootroot00000000000000;;; magit-patch.el --- creating and applying patches -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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") "Arguments used by `magit-patch-save-arguments' (which see)" :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-popup "magit-patch" nil t) (magit-define-popup magit-patch-popup "Popup console for patch commands." :man-page "git-format-patch" :switches '("Switches for formatting patches" (?l "Add cover letter" "--cover-letter")) :options '("Options for formatting patches" (?f "From" "--from=") (?t "To" "--to=") (?c "CC" "--cc=") (?r "In reply to" "--in-reply-to=") (?P "Subject Prefix" "--subject-prefix=") (?v "Reroll count" "--reroll-count=") (?s "Thread style" "--thread=") (?U "Context lines" "-U") (?M "Detect renames" "-M") (?C "Detect copies" "-C") (?A "Diff algorithm" "--diff-algorithm=" magit-diff-select-algorithm) (?o "Output directory" "--output-directory=") (?F "Limit to files" "-- " magit-read-files)) :actions '((?p "Format patches" magit-format-patch) (?r "Request pull" magit-request-pull)) :default-action 'magit-format-patch) ;;;###autoload (defun magit-format-patch (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)." (interactive (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)))) (magit-popup-export-file-args (magit-patch-arguments)))) (magit-run-git "format-patch" range args "--" files) (when (member "--cover-letter" args) (find-file (expand-file-name "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)))))) ;;;###autoload (defun magit-request-pull (url start end) "Request upstream to pull from you public repository. URL is the url of your publically 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)) ;;;###autoload (autoload 'magit-patch-apply-popup "magit-patch" nil t) (magit-define-popup magit-patch-apply-popup "Popup console for applying a patch file." :man-page "git-apply" :switches '((?i "Also apply to index" "--index") (?c "Only apply to index" "--cached") (?3 "Fall back on 3way merge" "--3way")) :actions '((?a "Apply patch" magit-patch-apply)) :default-action 'magit-patch-apply) ;;;###autoload (defun magit-patch-apply (file &rest args) "Apply the patch file FILE." (interactive (list (expand-file-name (read-file-name "Apply patch: " default-directory nil nil (--when-let (magit-file-at-point) (file-relative-name it)))) (magit-patch-apply-arguments))) (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")) (pcase-let ((`(,rev ,const ,args ,files) magit-refresh-args)) (when (derived-mode-p 'magit-revision-mode) (setq rev (format "%s~..%s" rev rev))) (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" const args "--" files))) (magit-refresh)) ;;; _ (provide 'magit-patch) ;;; magit-patch.el ends here magit-2.90.1/lisp/magit-pkg.el000066400000000000000000000003421337354740400160660ustar00rootroot00000000000000(define-package "magit" "2.90.1" "A Git porcelain inside Emacs." '((emacs "25.1") (async "1.9.3") (dash "2.14.1") (ghub "3.0.0") (git-commit "2.90.0") (magit-popup "2.12.4") (with-editor "2.8.0"))) magit-2.90.1/lisp/magit-process.el000066400000000000000000001345711337354740400167770ustar00rootroot00000000000000;;; magit-process.el --- process functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 tools used to run Git for side-effects. ;; Note that the functions used to run Git and then consume its ;; output, are defined in `magit-git.el'. There's a bit of overlap ;; though. ;;; Code: (require 'ansi-color) (require 'cl-lib) (require 'dash) (eval-when-compile (require 'subr-x)) (require 'with-editor) (require 'magit-utils) (require 'magit-section) (require 'magit-git) (require 'magit-mode) (declare-function auth-source-search "auth-source" (&rest spec &key max require create delete &allow-other-keys)) ;;; Options (defcustom magit-process-connection-type (not (eq system-type 'cygwin)) "Connection type used for the Git process. If nil, use pipes: this is usually more efficient, and works on Cygwin. If t, use ptys: this enables Magit to prompt for passphrases when needed." :group 'magit-process :type '(choice (const :tag "pipe" nil) (const :tag "pty" t))) (defcustom magit-need-cygwin-noglob (and (eq system-type 'windows-nt) (with-temp-buffer (let ((process-environment (append magit-git-environment process-environment))) (condition-case e (process-file magit-git-executable nil (current-buffer) nil "-c" "alias.echo=!echo" "echo" "x{0}") (file-error (lwarn 'magit-process :warning "Could not run Git: %S" e)))) (equal "x0\n" (buffer-string)))) "Whether to use a workaround for Cygwin's globbing behavior. If non-nil, add environment variables to `process-environment' to prevent the git.exe distributed by Cygwin and MSYS2 from attempting to perform glob expansion when called from a native Windows build of Emacs. See #2246." :package-version '(magit . "2.3.0") :group 'magit-process :type '(choice (const :tag "Yes" t) (const :tag "No" nil))) (defcustom magit-process-popup-time -1 "Popup the process buffer if a command takes longer than this many seconds." :group 'magit-process :type '(choice (const :tag "Never" -1) (const :tag "Immediately" 0) (integer :tag "After this many seconds"))) (defcustom magit-process-log-max 32 "Maximum number of sections to keep in a process log buffer. When adding a new section would go beyond the limit set here, then the older half of the sections are remove. Sections that belong to processes that are still running are never removed. When this is nil, no sections are ever removed." :package-version '(magit . "2.1.0") :group 'magit-process :type '(choice (const :tag "Never remove old sections" nil) integer)) (defcustom magit-process-error-tooltip-max-lines 20 "The number of lines for `magit-process-error-lines' to return. These are displayed in a tooltip for `mode-line-process' errors. If `magit-process-error-tooltip-max-lines' is nil, the tooltip displays the text of `magit-process-error-summary' instead." :package-version '(magit . "2.12.0") :group 'magit-process :type '(choice (const :tag "Use summary line" nil) integer)) (defcustom magit-credential-cache-daemon-socket (--some (pcase-let ((`(,prog . ,args) (split-string it))) (if (and prog (string-match-p "\\`\\(?:\\(?:/.*/\\)?git-credential-\\)?cache\\'" prog)) (or (cl-loop for (opt val) on args if (string= opt "--socket") return val) (expand-file-name "~/.git-credential-cache/socket")))) ;; Note: `magit-process-file' is not yet defined when ;; evaluating this form, so we use `process-lines'. (ignore-errors (let ((process-environment (append magit-git-environment process-environment))) (process-lines magit-git-executable "config" "--get-all" "credential.helper")))) "If non-nil, start a credential cache daemon using this socket. When using Git's cache credential helper in the normal way, Emacs sends a SIGHUP to the credential daemon after the git subprocess has exited, causing the daemon to also quit. This can be avoided by starting the `git-credential-cache--daemon' process directly from Emacs. The function `magit-maybe-start-credential-cache-daemon' takes care of starting the daemon if necessary, using the value of this option as the socket. If this option is nil, then it does not start any daemon. Likewise if another daemon is already running, then it starts no new daemon. This function has to be a member of the hook variable `magit-credential-hook' for this to work. If an error occurs while starting the daemon, most likely because the necessary executable is missing, then the function removes itself from the hook, to avoid further futile attempts." :package-version '(magit . "2.3.0") :group 'magit-process :type '(choice (file :tag "Socket") (const :tag "Don't start a cache daemon" nil))) (defcustom magit-process-yes-or-no-prompt-regexp " [\[(]\\([Yy]\\(?:es\\)?\\)[/|]\\([Nn]o?\\)[\])] ?[?:] ?$" "Regexp matching Yes-or-No prompts of Git and its subprocesses." :package-version '(magit . "2.1.0") :group 'magit-process :type 'regexp) (defcustom magit-process-password-prompt-regexps '("^\\(Enter \\)?[Pp]assphrase\\( for \\(RSA \\)?key '.*'\\)?: ?$" ;; Match-group 99 is used to identify the "user@host" part. "^\\(Enter \\)?[Pp]assword\\( for '\\(https?://\\)?\\(?99:.*\\)'\\)?: ?$" "^.*'s password: ?$" "^Yubikey for .*: ?$" "^Enter PIN for .*: ?$") "List of regexps matching password prompts of Git and its subprocesses. Also see `magit-process-find-password-functions'." :package-version '(magit . "2.8.0") :group 'magit-process :type '(repeat (regexp))) (defcustom magit-process-find-password-functions nil "List of functions to try in sequence to get a password. These functions may be called when git asks for a password, which is detected using `magit-process-password-prompt-regexps'. They are called if and only if matching the prompt resulted in the value of the 99th submatch to be non-nil. Therefore users can control for which prompts these functions should be called by putting the host name in the 99th submatch, or not. If the functions are called, then they are called in the order given, with the host name as only argument, until one of them returns non-nil. If they are not called or none of them returns non-nil, then the password is read from the user instead." :package-version '(magit . "2.3.0") :group 'magit-process :type 'hook :options '(magit-process-password-auth-source)) (defcustom magit-process-username-prompt-regexps '("^Username for '.*': ?$") "List of regexps matching username prompts of Git and its subprocesses." :package-version '(magit . "2.1.0") :group 'magit-process :type '(repeat (regexp))) (defcustom magit-process-ensure-unix-line-ending t "Whether Magit should ensure a unix coding system when talking to Git." :package-version '(magit . "2.6.0") :group 'magit-process :type 'boolean) (defcustom magit-process-display-mode-line-error t "Whether Magit should retain and highlight process errors in the mode line." :package-version '(magit . "2.12.0") :group 'magit-process :type 'boolean) (defface magit-process-ok '((t :inherit magit-section-heading :foreground "green")) "Face for zero exit-status." :group 'magit-faces) (defface magit-process-ng '((t :inherit magit-section-heading :foreground "red")) "Face for non-zero exit-status." :group 'magit-faces) (defface magit-mode-line-process '((t :inherit mode-line-emphasis)) "Face for `mode-line-process' status when Git is running for side-effects." :group 'magit-faces) (defface magit-mode-line-process-error '((t :inherit error)) "Face for `mode-line-process' error status. Used when `magit-process-display-mode-line-error' is non-nil." :group 'magit-faces) ;;; Process Mode (defvar magit-process-mode-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-mode-map) map) "Keymap for `magit-process-mode'.") (define-derived-mode magit-process-mode magit-mode "Magit Process" "Mode for looking at Git process output." :group 'magit-process (hack-dir-local-variables-non-file-buffer) (setq imenu-prev-index-position-function 'magit-imenu--process-prev-index-position-function) (setq imenu-extract-index-name-function 'magit-imenu--process-extract-index-name-function)) (defun magit-process-buffer (&optional nodisplay) "Display the current repository's process buffer. If that buffer doesn't exist yet, then create it. Non-interactively return the buffer and unless optional NODISPLAY is non-nil also display it." (interactive) (let ((topdir (magit-toplevel))) (unless topdir (magit--with-safe-default-directory nil (setq topdir default-directory) (let (prev) (while (not (equal topdir prev)) (setq prev topdir) (setq topdir (file-name-directory (directory-file-name topdir))))))) (let ((buffer (or (--first (with-current-buffer it (and (eq major-mode 'magit-process-mode) (equal default-directory topdir))) (buffer-list)) (let ((default-directory topdir)) (magit-generate-new-buffer 'magit-process-mode))))) (with-current-buffer buffer (if magit-root-section (when magit-process-log-max (magit-process-truncate-log)) (magit-process-mode) (let ((inhibit-read-only t) (magit-insert-section--parent nil) (magit-insert-section--oldroot nil)) (make-local-variable 'text-property-default-nonsticky) (magit-insert-section (processbuf) (insert "\n"))))) (unless nodisplay (magit-display-buffer buffer)) buffer))) (defun magit-process-kill () "Kill the process at point." (interactive) (when-let ((process (magit-section-value-if 'process))) (unless (eq (process-status process) 'run) (user-error "Process isn't running")) (magit-confirm 'kill-process) (kill-process process))) ;;; Synchronous Processes (defvar magit-process-raise-error nil) (defun magit-git (&rest args) "Call Git synchronously in a separate process, for side-effects. Option `magit-git-executable' specifies the Git executable. The arguments ARGS specify arguments to Git, they are flattened before use. Process output goes into a new section in the buffer returned by `magit-process-buffer'. If Git exits with a non-zero status, then raise an error." (let ((magit-process-raise-error t)) (magit-call-git args))) (defun magit-run-git (&rest args) "Call Git synchronously in a separate process, and refresh. Option `magit-git-executable' specifies the Git executable and option `magit-git-global-arguments' specifies constant arguments. The arguments ARGS specify arguments to Git, they are flattened before use. After Git returns, the current buffer (if it is a Magit buffer) as well as the current repository's status buffer are refreshed. Process output goes into a new section in the buffer returned by `magit-process-buffer'." (let ((magit--refresh-cache (list (cons 0 0)))) (magit-call-git args) (when (member (car args) '("init" "clone")) ;; Creating a new repository invalidates the cache. (setq magit--refresh-cache nil)) (magit-refresh))) (defvar magit-pre-call-git-hook nil) (defun magit-call-git (&rest args) "Call Git synchronously in a separate process. Option `magit-git-executable' specifies the Git executable and option `magit-git-global-arguments' specifies constant arguments. The arguments ARGS specify arguments to Git, they are flattened before use. Process output goes into a new section in the buffer returned by `magit-process-buffer'." (run-hooks 'magit-pre-call-git-hook) (let ((default-process-coding-system (magit--process-coding-system))) (apply #'magit-call-process magit-git-executable (magit-process-git-arguments args)))) (defun magit-call-process (program &rest args) "Call PROGRAM synchronously in a separate process. Process output goes into a new section in the buffer returned by `magit-process-buffer'." (pcase-let ((`(,process-buf . ,section) (magit-process-setup program args))) (magit-process-finish (let ((inhibit-read-only t)) (apply #'magit-process-file program nil process-buf nil args)) process-buf (current-buffer) default-directory section))) (defun magit-process-file (process &optional infile buffer display &rest args) "Process files synchronously in a separate process. Identical to `process-file' but temporarily enable Cygwin's \"noglob\" option during the call and ensure unix eol conversion." (let ((process-environment (magit-process-environment)) (default-process-coding-system (magit--process-coding-system))) (apply #'process-file process infile buffer display args))) (defun magit-process-environment () ;; The various w32 hacks are only applicable when running on the ;; local machine. As of Emacs 25.1, a local binding of ;; process-environment different from the top-level value affects ;; the environment used in ;; tramp-sh-handle-{start-file-process,process-file}. (let ((local (not (file-remote-p default-directory)))) (append magit-git-environment (and local (cdr (assoc magit-git-executable magit-git-w32-path-hack))) (and local magit-need-cygwin-noglob (mapcar (lambda (var) (concat var "=" (--if-let (getenv var) (concat it " noglob") "noglob"))) '("CYGWIN" "MSYS"))) process-environment))) (defvar magit-this-process nil) (defun magit-run-git-with-input (&rest args) "Call Git in a separate process. ARGS is flattened and then used as arguments to Git. The current buffer's content is used as the process' standard input. Option `magit-git-executable' specifies the Git executable and option `magit-git-global-arguments' specifies constant arguments. The remaining arguments ARGS specify arguments to Git, they are flattened before use." (when (eq system-type 'windows-nt) ;; On w32, git expects UTF-8 encoded input, ignore any user ;; configuration telling us otherwise (see #3250). (encode-coding-region (point-min) (point-max) 'utf-8-unix)) (if (file-remote-p default-directory) ;; We lack `process-file-region', so fall back to asynch + ;; waiting in remote case. (progn (magit-start-git (current-buffer) args) (while (and magit-this-process (eq (process-status magit-this-process) 'run)) (sleep-for 0.005))) (run-hooks 'magit-pre-call-git-hook) (pcase-let* ((process-environment (magit-process-environment)) (default-process-coding-system (magit--process-coding-system)) (flat-args (magit-process-git-arguments args)) (`(,process-buf . ,section) (magit-process-setup magit-git-executable flat-args)) (inhibit-read-only t)) (magit-process-finish (apply #'call-process-region (point-min) (point-max) magit-git-executable nil process-buf nil flat-args) process-buf nil default-directory section)))) (defun magit-run-git-with-logfile (file &rest args) "Call Git in a separate process and log its output to FILE. This function might have a short halflive." (apply #'magit-process-file magit-git-executable nil `(:file ,file) nil (magit-process-git-arguments args)) (magit-refresh)) ;;; Asynchronous Processes (defun magit-run-git-async (&rest args) "Start Git, prepare for refresh, and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. See `magit-start-process' for more information." (message "Running %s %s" magit-git-executable (let ((m (mapconcat #'identity (-flatten args) " "))) (remove-list-of-text-properties 0 (length m) '(face) m) m)) (magit-start-git nil args)) (defun magit-run-git-with-editor (&rest args) "Export GIT_EDITOR and start Git. Also prepare for refresh and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. See `magit-start-process' and `with-editor' for more information." (magit--record-separated-gitdir) (magit-with-editor (magit-run-git-async args))) (defun magit-run-git-sequencer (&rest args) "Export GIT_EDITOR and start Git. Also prepare for refresh and return the process object. ARGS is flattened and then used as arguments to Git. Display the command line arguments in the echo area. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. If the sequence stops at a commit, make the section representing that commit the current section by moving `point' there. See `magit-start-process' and `with-editor' for more information." (apply #'magit-run-git-with-editor args) (set-process-sentinel magit-this-process #'magit-sequencer-process-sentinel) magit-this-process) (defvar magit-pre-start-git-hook nil) (defun magit-start-git (input &rest args) "Start Git, prepare for refresh, and return the process object. If INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. Option `magit-git-executable' specifies the Git executable and option `magit-git-global-arguments' specifies constant arguments. The remaining arguments ARGS specify arguments to Git, they are flattened before use. After Git returns some buffers are refreshed: the buffer that was current when this function was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer. See `magit-start-process' for more information." (run-hooks 'magit-pre-start-git-hook) (let ((default-process-coding-system (magit--process-coding-system))) (apply #'magit-start-process magit-git-executable input (magit-process-git-arguments args)))) (defun magit-start-process (program &optional input &rest args) "Start PROGRAM, prepare for refresh, and return the process object. If optional argument INPUT is non-nil, it has to be a buffer or the name of an existing buffer. The buffer content becomes the processes standard input. The process is started using `start-file-process' and then setup to use the sentinel `magit-process-sentinel' and the filter `magit-process-filter'. Information required by these functions is stored in the process object. When this function returns the process has not started to run yet so it is possible to override the sentinel and filter. After the process returns, `magit-process-sentinel' refreshes the buffer that was current when `magit-start-process' was called (if it is a Magit buffer and still alive), as well as the respective Magit status buffer." (pcase-let* ((`(,process-buf . ,section) (magit-process-setup program args)) (process (let ((process-connection-type ;; Don't use a pty, because it would set icrnl ;; which would modify the input (issue #20). (and (not input) magit-process-connection-type)) (process-environment (magit-process-environment)) (default-process-coding-system (magit--process-coding-system))) (apply #'start-file-process (file-name-nondirectory program) process-buf program args)))) (with-editor-set-process-filter process #'magit-process-filter) (set-process-sentinel process #'magit-process-sentinel) (set-process-buffer process process-buf) (when (eq system-type 'windows-nt) ;; On w32, git expects UTF-8 encoded input, ignore any user ;; configuration telling us otherwise. (set-process-coding-system process 'utf-8-unix)) (process-put process 'section section) (process-put process 'command-buf (current-buffer)) (process-put process 'default-dir default-directory) (when inhibit-magit-refresh (process-put process 'inhibit-refresh t)) (oset section process process) (with-current-buffer process-buf (set-marker (process-mark process) (point))) (when input (with-current-buffer input (process-send-region process (point-min) (point-max)) (process-send-eof process))) (setq magit-this-process process) (oset section value process) (magit-process-display-buffer process) process)) (defun magit-parse-git-async (&rest args) (setq args (magit-process-git-arguments args)) (let ((command-buf (current-buffer)) (process-buf (generate-new-buffer " *temp*")) (toplevel (magit-toplevel))) (with-current-buffer process-buf (setq default-directory toplevel) (let ((process (let ((process-connection-type nil) (process-environment (magit-process-environment)) (default-process-coding-system (magit--process-coding-system))) (apply #'start-file-process "git" process-buf magit-git-executable args)))) (process-put process 'command-buf command-buf) (process-put process 'parsed (point)) (setq magit-this-process process) process)))) ;;; Process Internals (defun magit-process-setup (program args) (magit-process-set-mode-line program args) (let ((pwd default-directory) (buf (magit-process-buffer t))) (cons buf (with-current-buffer buf (prog1 (magit-process-insert-section pwd program args nil nil) (backward-char 1)))))) (defun magit-process-insert-section (pwd program args &optional errcode errlog) (let ((inhibit-read-only t) (magit-insert-section--parent magit-root-section) (magit-insert-section--oldroot nil)) (goto-char (1- (point-max))) (magit-insert-section (process) (insert (if errcode (format "%3s " (propertize (number-to-string errcode) 'face 'magit-process-ng)) "run ")) (unless (equal (expand-file-name pwd) (expand-file-name default-directory)) (insert (file-relative-name pwd default-directory) ?\s)) (cond ((and args (equal program magit-git-executable)) (setq args (-split-at (length magit-git-global-arguments) args)) (insert (propertize (file-name-nondirectory program) 'face 'magit-section-heading) " ") (insert (propertize (char-to-string magit-ellipsis) 'face 'magit-section-heading 'help-echo (mapconcat #'identity (car args) " "))) (insert " ") (insert (propertize (mapconcat #'shell-quote-argument (cadr args) " ") 'face 'magit-section-heading))) ((and args (equal program shell-file-name)) (insert (propertize (cadr args) 'face 'magit-section-heading))) (t (insert (propertize (file-name-nondirectory program) 'face 'magit-section-heading) " ") (insert (propertize (mapconcat #'shell-quote-argument args " ") 'face 'magit-section-heading)))) (magit-insert-heading) (when errlog (insert-file-contents errlog) (goto-char (1- (point-max)))) (insert "\n")))) (defun magit-process-truncate-log () (let* ((head nil) (tail (oref magit-root-section children)) (count (length tail))) (when (> (1+ count) magit-process-log-max) (while (and (cdr tail) (> count (/ magit-process-log-max 2))) (let* ((inhibit-read-only t) (section (car tail)) (process (oref section process))) (cond ((not process)) ((memq (process-status process) '(exit signal)) (delete-region (oref section start) (1+ (oref section end))) (cl-decf count)) (t (push section head)))) (pop tail)) (oset magit-root-section children (nconc (reverse head) tail))))) (defun magit-process-sentinel (process event) "Default sentinel used by `magit-start-process'." (when (memq (process-status process) '(exit signal)) (setq event (substring event 0 -1)) (when (string-match "^finished" event) (message (concat (capitalize (process-name process)) " finished"))) (magit-process-finish process) (when (eq process magit-this-process) (setq magit-this-process nil)) (unless (process-get process 'inhibit-refresh) (let ((command-buf (process-get process 'command-buf))) (if (buffer-live-p command-buf) (with-current-buffer command-buf (magit-refresh)) (with-temp-buffer (setq default-directory (process-get process 'default-dir)) (magit-refresh))))))) (defun magit-sequencer-process-sentinel (process event) "Special sentinel used by `magit-run-git-sequencer'." (when (memq (process-status process) '(exit signal)) (magit-process-sentinel process event) (when-let ((process-buf (process-buffer process))) (when (buffer-live-p process-buf) (when-let ((status-buf (with-current-buffer process-buf (magit-mode-get-buffer 'magit-status-mode)))) (with-current-buffer status-buf (--when-let (magit-get-section `((commit . ,(magit-rev-parse "HEAD")) (,(pcase (car (cadr (-split-at (1+ (length magit-git-global-arguments)) (process-command process)))) ((or "rebase" "am") 'rebase-sequence) ((or "cherry-pick" "revert") 'sequence))) (status))) (goto-char (oref it start)) (magit-section-update-highlight)))))))) (defun magit-process-filter (proc string) "Default filter used by `magit-start-process'." (with-current-buffer (process-buffer proc) (let ((inhibit-read-only t)) (magit-process-yes-or-no-prompt proc string) (magit-process-username-prompt proc string) (magit-process-password-prompt proc string) (goto-char (process-mark proc)) (setq string (propertize string 'magit-section (process-get proc 'section))) ;; Find last ^M in string. If one was found, ignore ;; everything before it and delete the current line. (let ((ret-pos (length string))) (while (and (>= (cl-decf ret-pos) 0) (/= ?\r (aref string ret-pos)))) (if (< ret-pos 0) (insert string) (delete-region (line-beginning-position) (point)) (insert (substring string (1+ ret-pos))))) (set-marker (process-mark proc) (point))))) (defmacro magit-process-kill-on-abort (proc &rest body) (declare (indent 1) (debug (form body))) (let ((map (cl-gensym))) `(let ((,map (make-sparse-keymap))) (set-keymap-parent ,map minibuffer-local-map) (define-key ,map "\C-g" (lambda () (interactive) (ignore-errors (kill-process ,proc)) (abort-recursive-edit))) (let ((minibuffer-local-map ,map)) ,@body)))) (defun magit-process-yes-or-no-prompt (process string) "Forward Yes-or-No prompts to the user." (when-let ((beg (string-match magit-process-yes-or-no-prompt-regexp string))) (let ((max-mini-window-height 30)) (process-send-string process (downcase (concat (match-string (if (save-match-data (magit-process-kill-on-abort process (yes-or-no-p (substring string 0 beg)))) 1 2) string) "\n")))))) (defun magit-process-password-auth-source (key) "Use `auth-source-search' to get a password. If found, return the password. Otherwise, return nil. To use this function add it to the appropriate hook (add-hook 'magit-process-find-password-functions 'magit-process-password-auth-source) KEY typically derives from a prompt such as: Password for 'https://tarsius@bitbucket.org' in which case it would be the string tarsius@bitbucket.org which matches the ~/.authinfo.gpg entry machine bitbucket.org login tarsius password 12345 or iff that is undefined, for backward compatibility machine tarsius@bitbucket.org password 12345" (require 'auth-source) (and (string-match "\\`\\([^@]+\\)@\\([^@]+\\)\\'" key) (let* ((user (match-string 1 key)) (host (match-string 2 key)) (secret (plist-get (car (or (auth-source-search :max 1 :host host :user user) (auth-source-search :max 1 :host key))) :secret))) (if (functionp secret) (funcall secret) secret)))) (defun magit-process-password-prompt (process string) "Find a password based on prompt STRING and send it to git. Use `magit-process-password-prompt-regexps' to find a known prompt. If and only if one is found, then call functions in `magit-process-find-password-functions' until one of them returns the password. If all function return nil, then read the password from the user." (when-let ((prompt (magit-process-match-prompt magit-process-password-prompt-regexps string))) (process-send-string process (magit-process-kill-on-abort process (concat (or (when-let ((key (match-string 99 string))) (run-hook-with-args-until-success 'magit-process-find-password-functions key)) (read-passwd prompt)) "\n"))))) (defun magit-process-username-prompt (process string) "Forward username prompts to the user." (--when-let (magit-process-match-prompt magit-process-username-prompt-regexps string) (process-send-string process (magit-process-kill-on-abort process (concat (read-string it nil nil (user-login-name)) "\n"))))) (defun magit-process-match-prompt (prompts string) "Match STRING against PROMPTS and set match data. Return the matched string suffixed with \": \", if needed." (when (--any-p (string-match it string) prompts) (let ((prompt (match-string 0 string))) (cond ((string-suffix-p ": " prompt) prompt) ((string-suffix-p ":" prompt) (concat prompt " ")) (t (concat prompt ": ")))))) (defun magit--process-coding-system () (let ((fro (or magit-git-output-coding-system (car default-process-coding-system))) (to (cdr default-process-coding-system))) (if magit-process-ensure-unix-line-ending (cons (coding-system-change-eol-conversion fro 'unix) (coding-system-change-eol-conversion to 'unix)) (cons fro to)))) (defvar magit-credential-hook nil "Hook run before Git needs credentials.") (defvar magit-credential-cache-daemon-process nil) (defun magit-maybe-start-credential-cache-daemon () "Maybe start a `git-credential-cache--daemon' process. If such a process is already running or if the value of option `magit-credential-cache-daemon-socket' is nil, then do nothing. Otherwise start the process passing the value of that options as argument." (unless (or (not magit-credential-cache-daemon-socket) (process-live-p magit-credential-cache-daemon-process) (memq magit-credential-cache-daemon-process (list-system-processes))) (setq magit-credential-cache-daemon-process (or (--first (let* ((attr (process-attributes it)) (comm (cdr (assq 'comm attr))) (user (cdr (assq 'user attr)))) (and (string= comm "git-credential-cache--daemon") (string= user user-login-name))) (list-system-processes)) (condition-case nil (start-process "git-credential-cache--daemon" " *git-credential-cache--daemon*" magit-git-executable "credential-cache--daemon" magit-credential-cache-daemon-socket) ;; Some Git implementations (e.g. Windows) won't have ;; this program; if we fail the first time, stop trying. ((debug error) (remove-hook 'magit-credential-hook #'magit-maybe-start-credential-cache-daemon))))))) (add-hook 'magit-credential-hook #'magit-maybe-start-credential-cache-daemon) (defun tramp-sh-handle-start-file-process--magit-tramp-process-environment (fn name buffer program &rest args) (if magit-tramp-process-environment (apply fn name buffer (car magit-tramp-process-environment) (append (cdr magit-tramp-process-environment) (cons program args))) (apply fn name buffer program args))) (advice-add 'tramp-sh-handle-start-file-process :around 'tramp-sh-handle-start-file-process--magit-tramp-process-environment) (defun tramp-sh-handle-process-file--magit-tramp-process-environment (fn program &optional infile destination display &rest args) (if magit-tramp-process-environment (apply fn "env" infile destination display (append magit-tramp-process-environment (cons program args))) (apply fn program infile destination display args))) (advice-add 'tramp-sh-handle-process-file :around 'tramp-sh-handle-process-file--magit-tramp-process-environment) (defvar magit-mode-line-process-map (let ((map (make-sparse-keymap))) (define-key map (kbd " ") 'magit-process-buffer) map) "Keymap for `mode-line-process'.") (defun magit-process-set-mode-line (program args) "Display the git command (sans arguments) in the mode line." (when (equal program magit-git-executable) (setq args (nthcdr (length magit-git-global-arguments) args))) (let ((str (concat " " (propertize (concat (file-name-nondirectory program) (and args (concat " " (car args)))) 'mouse-face 'highlight 'keymap magit-mode-line-process-map 'help-echo "mouse-1: Show process buffer" 'face 'magit-mode-line-process)))) (magit-repository-local-set 'mode-line-process str) (dolist (buf (magit-mode-get-buffers)) (with-current-buffer buf (setq mode-line-process str))) (force-mode-line-update t))) (defun magit-process-set-mode-line-error-status (&optional error str) "Apply an error face to the string set by `magit-process-set-mode-line'. If ERROR is supplied, include it in the `mode-line-process' tooltip. If STR is supplied, it replaces the `mode-line-process' text." (setq str (or str (magit-repository-local-get 'mode-line-process))) (when str (setq error (format "%smouse-1: Show process buffer" (if (stringp error) (concat error "\n\n") ""))) (setq str (concat " " (propertize (substring-no-properties str 1) 'mouse-face 'highlight 'keymap magit-mode-line-process-map 'help-echo error 'face 'magit-mode-line-process-error))) (magit-repository-local-set 'mode-line-process str) (dolist (buf (magit-mode-get-buffers)) (with-current-buffer buf (setq mode-line-process str))) (force-mode-line-update t) ;; We remove any error status from the mode line when a magit ;; buffer is refreshed (see `magit-refresh-buffer'), but we must ;; ensure that we ignore any refreshes during the remainder of the ;; current command -- otherwise a newly-set error status would be ;; removed before it was seen. We set a flag which prevents the ;; status from being removed prior to the next command, so that ;; the error status is guaranteed to remain visible until then. (let ((repokey (magit-repository-local-repository))) ;; The following closure captures the repokey value, and is ;; added to `pre-command-hook'. (cl-labels ((enable-magit-process-unset-mode-line () ;; Remove ourself from the hook variable, so ;; that we only run once. (remove-hook 'pre-command-hook #'enable-magit-process-unset-mode-line) ;; Clear the inhibit flag for the repository in ;; which we set it. (magit-repository-local-set 'inhibit-magit-process-unset-mode-line nil repokey))) ;; Set the inhibit flag until the next command is invoked. (magit-repository-local-set 'inhibit-magit-process-unset-mode-line t repokey) (add-hook 'pre-command-hook #'enable-magit-process-unset-mode-line))))) (defun magit-process-unset-mode-line-error-status () "Remove any current error status from the mode line." (let ((status (or mode-line-process (magit-repository-local-get 'mode-line-process)))) (when (and status (eq (get-text-property 1 'face status) 'magit-mode-line-process-error)) (magit-process-unset-mode-line)))) (defun magit-process-unset-mode-line () "Remove the git command from the mode line." (unless (magit-repository-local-get 'inhibit-magit-process-unset-mode-line) (magit-repository-local-set 'mode-line-process nil) (dolist (buf (magit-mode-get-buffers)) (with-current-buffer buf (setq mode-line-process nil))) (force-mode-line-update t))) (defvar magit-process-error-message-regexps (list "^\\*ERROR\\*: Canceled by user$" "^\\(?:error\\|fatal\\|git\\): \\(.*\\)$" "^\\(Cannot rebase:.*\\)$")) (define-error 'magit-git-error "Git error") (defun magit-process-error-summary (process-buf section) "A one-line error summary from the given SECTION." (or (and (buffer-live-p process-buf) (with-current-buffer process-buf (and (oref section content) (save-excursion (goto-char (oref section end)) (run-hook-wrapped 'magit-process-error-message-regexps (lambda (re) (save-excursion (and (re-search-backward re (oref section start) t) (or (match-string-no-properties 1) (and (not magit-process-raise-error) 'suppressed)))))))))) "Git failed")) (defun magit-process-error-tooltip (process-buf section) "Returns the text from SECTION of the PROCESS-BUF buffer. Limited by `magit-process-error-tooltip-max-lines'." (and (integerp magit-process-error-tooltip-max-lines) (> magit-process-error-tooltip-max-lines 0) (buffer-live-p process-buf) (with-current-buffer process-buf (save-excursion (goto-char (or (oref section content) (oref section start))) (buffer-substring-no-properties (point) (save-excursion (forward-line magit-process-error-tooltip-max-lines) (goto-char (if (> (point) (oref section end)) (oref section end) (point))) ;; Remove any trailing whitespace. (when (re-search-backward "[^[:space:]\n]" (oref section start) t) (forward-char 1)) (point))))))) (defvar-local magit-this-error nil) (defvar magit-process-finish-apply-ansi-colors nil) (defun magit-process-finish (arg &optional process-buf command-buf default-dir section) (unless (integerp arg) (setq process-buf (process-buffer arg)) (setq command-buf (process-get arg 'command-buf)) (setq default-dir (process-get arg 'default-dir)) (setq section (process-get arg 'section)) (setq arg (process-exit-status arg))) (when (fboundp 'dired-uncache) (dired-uncache default-dir)) (when (buffer-live-p process-buf) (with-current-buffer process-buf (let ((inhibit-read-only t) (marker (oref section start))) (goto-char marker) (save-excursion (delete-char 3) (set-marker-insertion-type marker nil) (insert (propertize (format "%3s" arg) 'magit-section section 'face (if (= arg 0) 'magit-process-ok 'magit-process-ng))) (set-marker-insertion-type marker t)) (when magit-process-finish-apply-ansi-colors (ansi-color-apply-on-region (oref section content) (oref section end))) (if (= (oref section end) (+ (line-end-position) 2)) (save-excursion (goto-char (1+ (line-end-position))) (delete-char -1) (oset section content nil)) (let ((buf (magit-process-buffer t))) (when (and (= arg 0) (not (--any-p (eq (window-buffer it) buf) (window-list)))) (magit-section-hide section))))))) (if (= arg 0) ;; Unset the `mode-line-process' value upon success. (magit-process-unset-mode-line) ;; Otherwise process the error. (let ((msg (magit-process-error-summary process-buf section))) ;; Change `mode-line-process' to an error face upon failure. (if magit-process-display-mode-line-error (magit-process-set-mode-line-error-status (or (magit-process-error-tooltip process-buf section) msg)) (magit-process-unset-mode-line)) ;; Either signal the error, or else display the error summary in ;; the status buffer and with a message in the echo area. (cond (magit-process-raise-error (signal 'magit-git-error (list (format "%s (in %s)" msg default-dir)))) ((not (eq msg 'suppressed)) (when (buffer-live-p process-buf) (with-current-buffer process-buf (when-let ((status-buf (magit-mode-get-buffer 'magit-status-mode))) (with-current-buffer status-buf (setq magit-this-error msg))))) (message "%s ... [%s buffer %s for details]" msg (if-let ((key (and (buffer-live-p command-buf) (with-current-buffer command-buf (car (where-is-internal 'magit-process-buffer)))))) (format "Hit %s to see" (key-description key)) "See") (buffer-name process-buf)))))) arg) (defun magit-process-display-buffer (process) (when (process-live-p process) (let ((buf (process-buffer process))) (cond ((not (buffer-live-p buf))) ((= magit-process-popup-time 0) (if (minibufferp) (switch-to-buffer-other-window buf) (pop-to-buffer buf))) ((> magit-process-popup-time 0) (run-with-timer magit-process-popup-time nil (lambda (p) (when (eq (process-status p) 'run) (let ((buf (process-buffer p))) (when (buffer-live-p buf) (if (minibufferp) (switch-to-buffer-other-window buf) (pop-to-buffer buf)))))) process)))))) (defun magit--log-action (summary line list) (let (heading lines) (if (cdr list) (progn (setq heading (funcall summary list)) (setq lines (mapcar line list))) (setq heading (funcall line (car list)))) (with-current-buffer (magit-process-buffer t) (goto-char (1- (point-max))) (let ((inhibit-read-only t)) (magit-insert-section (message) (magit-insert-heading (concat " * " heading)) (when lines (dolist (line lines) (insert line "\n")) (insert "\n")))) (let ((inhibit-message t)) (when heading (setq lines (cons heading lines))) (message (mapconcat #'identity lines "\n")))))) ;;; _ (provide 'magit-process) ;;; magit-process.el ends here magit-2.90.1/lisp/magit-pull.el000066400000000000000000000137471337354740400162760ustar00rootroot00000000000000;;; magit-pull.el --- update local objects and refs -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Commands ;;;###autoload (autoload 'magit-pull-popup "magit-pull" nil t) (magit-define-popup magit-pull-popup "Popup console for pull commands." :man-page "git-pull" :variables '("Configure" (?r "branch.%s.rebase" magit-cycle-branch*rebase magit-pull-format-branch*rebase) (?C "variables..." magit-branch-config-popup)) :actions '((lambda () (--if-let (magit-get-current-branch) (concat (propertize "Pull into " 'face 'magit-popup-heading) (propertize it 'face 'magit-branch-local) (propertize " from" 'face 'magit-popup-heading)) (propertize "Pull from" 'face 'magit-popup-heading))) (?p magit-get-push-branch magit-pull-from-pushremote) (?u magit-get-upstream-branch magit-pull-from-upstream) (?e "elsewhere" magit-pull-branch)) :default-action 'magit-pull :max-action-columns 1) ;;;###autoload (autoload 'magit-pull-and-fetch-popup "magit-pull" nil t) (magit-define-popup magit-pull-and-fetch-popup "Popup console for pull and fetch commands. This popup is intended as a replacement for the separate popups `magit-pull-popup' and `magit-fetch-popup'. To use it, add this to your init file: (with-eval-after-load \\='magit-remote (define-key magit-mode-map \"f\" \\='magit-pull-and-fetch-popup) (define-key magit-mode-map \"F\" nil)) The combined popup does not offer all commands and arguments available from the individual popups. Instead of the argument `--prune' and the command `magit-fetch-all' it uses two commands `magit-fetch-prune' and `magit-fetch-no-prune'. And the commands `magit-fetch-from-pushremote' and `magit-fetch-from-upstream' are missing. To add them use something like: (with-eval-after-load \\='magit-remote (magit-define-popup-action \\='magit-pull-and-fetch-popup ?U \\='magit-get-upstream-branch \\='magit-fetch-from-upstream-remote ?F) (magit-define-popup-action \\='magit-pull-and-fetch-popup ?P \\='magit-get-push-branch \\='magit-fetch-from-push-remote ?F))" :man-page "git-pull" :variables '("Configure" (?r "branch.%s.rebase" magit-cycle-branch*rebase magit-pull-format-branch*rebase) (?C "variables..." magit-branch-config-popup)) :actions '((lambda () (--if-let (magit-get-current-branch) (concat (propertize "Pull into " 'face 'magit-popup-heading) (propertize it 'face 'magit-branch-local) (propertize " from" 'face 'magit-popup-heading)) (propertize "Pull from" 'face 'magit-popup-heading))) (?p magit-get-push-branch magit-pull-from-pushremote) (?u magit-get-upstream-branch magit-pull-from-upstream) (?e "elsewhere" magit-pull-branch) "Fetch from" (?f "remotes" magit-fetch-all-no-prune) (?F "remotes and prune" magit-fetch-all-prune) "Fetch" (?o "another branch" magit-fetch-branch) (?s "explicit refspec" magit-fetch-refspec) (?m "submodules" magit-fetch-modules)) :default-action 'magit-fetch :max-action-columns 1) (defun magit-pull-format-branch*rebase () (magit--format-popup-variable:choices (format "branch.%s.rebase" (or (magit-get-current-branch) "")) '("true" "false") "false" "pull.rebase")) (defun magit-git-pull (source args) (run-hooks 'magit-credential-hook) (pcase-let ((`(,remote . ,branch) (magit-split-branch-name source))) (magit-run-git-with-editor "pull" args remote branch))) ;;;###autoload (defun magit-pull-from-pushremote (args) "Pull from the push-remote of the current branch." (interactive (list (magit-pull-arguments))) (--if-let (magit-get-push-branch) (magit-git-pull it args) (--if-let (magit-get-current-branch) (user-error "No push-remote is configured for %s" it) (user-error "No branch is checked out")))) ;;;###autoload (defun magit-pull-from-upstream (args) "Pull from the upstream of the current branch." (interactive (list (magit-pull-arguments))) (--if-let (magit-get-upstream-branch) (progn (run-hooks 'magit-credential-hook) (magit-run-git-with-editor "pull" args (car (magit-split-branch-name it)))) (--if-let (magit-get-current-branch) (user-error "No upstream is configured for %s" it) (user-error "No branch is checked out")))) ;;;###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))) (magit-git-pull source args)) ;;; _ (provide 'magit-pull) ;;; magit-pull.el ends here magit-2.90.1/lisp/magit-push.el000066400000000000000000000340751337354740400162760ustar00rootroot00000000000000;;; magit-push.el --- update remote objects and refs -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Options (defcustom magit-push-current-set-remote-if-missing t "Whether to configure missing remotes before pushing. When nil, then the command `magit-push-current-to-pushremote' and `magit-push-current-to-upstream' do not appear in the push popup if the push-remote resp. upstream is not configured. If the user invokes one of these commands anyway, then it raises an error. When non-nil, then these commands always appear in the push popup. But if the required configuration is missing, then they do appear in a way that indicates that this is the case. If the user invokes one of them, then it asks for the necessary configuration, stores the configuration, and then uses it to push a first time. This option also affects whether the argument `--set-upstream' is available in the popup. If the value is t, then that argument is redundant. But note that changing the value of this option does not take affect immediately, the argument will only be added or removed after restarting Emacs." :package-version '(magit . "2.6.0") :group 'magit-commands :type '(choice (const :tag "don't set" nil) (const :tag "set branch..pushRemote" t) (const :tag "set remote.pushDefault" default))) ;;; Commands ;;;###autoload (autoload 'magit-push-popup "magit-push" nil t) (magit-define-popup magit-push-popup "Popup console for push commands." :man-page "git-push" :switches `((?f "Force with lease" "--force-with-lease") (?F "Force" "--force") (?h "Disable hooks" "--no-verify") (?d "Dry run" "--dry-run") ,@(and (not magit-push-current-set-remote-if-missing) '((?u "Set upstream" "--set-upstream")))) :actions '("Configure" (?C "variables..." magit-branch-config-popup) (lambda () (--when-let (magit-get-current-branch) (concat (propertize "Push " 'face 'magit-popup-heading) (propertize it 'face 'magit-branch-local) (propertize " to" 'face 'magit-popup-heading)))) (?p magit--push-current-to-pushremote-desc magit-push-current-to-pushremote) (?u magit--push-current-to-upstream-desc magit-push-current-to-upstream) (?e "elsewhere\n" magit-push-current) "Push" (?o "another branch" magit-push-other) (?T "a tag" magit-push-tag) (?r "explicit refspecs" magit-push-refspecs) (?t "all tags" magit-push-tags) (?m "matching branches" magit-push-matching)) :max-action-columns 2) (defun magit-git-push (branch target args) (run-hooks 'magit-credential-hook) (pcase-let ((`(,remote . ,target) (magit-split-branch-name target))) (magit-run-git-async "push" "-v" args remote (format "%s:refs/heads/%s" branch target)))) ;;;###autoload (defun magit-push-current-to-pushremote (args &optional push-remote) "Push the current branch to `branch..pushRemote'. If that variable is unset, then push to `remote.pushDefault'. When `magit-push-current-set-remote-if-missing' is non-nil and 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." (interactive (list (magit-push-arguments) (and (magit--push-current-set-pushremote-p current-prefix-arg) (magit-read-remote (if (eq magit-push-current-set-remote-if-missing 'default) "Set `remote.pushDefault' and push there" (format "Set `branch.%s.pushRemote' and push there" (magit-get-current-branch))))))) (--if-let (magit-get-current-branch) (progn (when push-remote (setf (magit-get (if (eq magit-push-current-set-remote-if-missing 'default) "remote.pushDefault" (format "branch.%s.pushRemote" it))) push-remote)) (if-let ((remote (magit-get-push-remote it))) (if (member remote (magit-list-remotes)) (magit-git-push it (concat remote "/" it) args) (user-error "Remote `%s' doesn't exist" remote)) (user-error "No push-remote is configured for %s" it))) (user-error "No branch is checked out"))) (defun magit--push-current-set-pushremote-p (&optional change) (and (or change (and magit-push-current-set-remote-if-missing (not (magit-get-push-remote)))) (magit-get-current-branch))) (defun magit--push-current-to-pushremote-desc () (--if-let (magit-get-push-branch) (concat (magit-branch-set-face it) "\n") (and (magit--push-current-set-pushremote-p) (concat (propertize (if (eq magit-push-current-set-remote-if-missing 'default) "pushDefault" "pushRemote") 'face 'bold) ", after setting that\n")))) ;;;###autoload (defun magit-push-current-to-upstream (args &optional upstream) "Push the current branch to its upstream branch. When `magit-push-current-set-remote-if-missing' is non-nil and the upstream is not configured, then read the upstream from the user, set it, and then push to it. With a prefix argument the upstream can be changed before pushed to it." (interactive (list (magit-push-arguments) (and (magit--push-current-set-upstream-p current-prefix-arg) (magit-read-upstream-branch)))) (--if-let (magit-get-current-branch) (progn (when upstream (magit-set-upstream-branch it upstream)) (if-let ((target (magit-get-upstream-branch it))) (magit-git-push it target args) (user-error "No upstream is configured for %s" it))) (user-error "No branch is checked out"))) (defun magit--push-current-set-upstream-p (&optional change) (and (or change (and magit-push-current-set-remote-if-missing (not (magit-get-upstream-branch)))) (magit-get-current-branch))) (defun magit--push-current-to-upstream-desc () (--if-let (magit-get-upstream-branch) (concat (magit-branch-set-face it) "\n") (and (magit--push-current-set-upstream-p) (concat (propertize "@{upstream}" 'face 'bold) ", after setting that\n")))) ;;;###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..pushRemote', `branch..remote', `branch..merge', and `remote..push'. To add this command to the push popup add this to your init file: (with-eval-after-load \\='magit-remote (magit-define-popup-action \\='magit-push-popup ?P \\='magit-push-implicitly--desc \\='magit-push-implicitly ?p t)) 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" (propertize remote 'face 'magit-branch-remote) (propertize refspec 'face 'bold))) (--when-let (and (not (magit-get-push-branch)) (magit-get-upstream-branch)) (format "%s aka %s\n" (magit-branch-set-face it) (propertize "@{upstream}" 'face 'bold))) (--when-let (magit-get-push-branch) (format "%s aka %s\n" (magit-branch-set-face it) (propertize "pushRemote" 'face 'bold))) (--when-let (magit-get-@{push}-branch) (format "%s aka %s\n" (magit-branch-set-face it) (propertize "@{push}" 'face 'bold))) (format "using %s (%s is %s)\n" (propertize "git push" 'face 'bold) (propertize "push.default" 'face 'bold) (propertize default 'face '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..pushRemote', `branch..remote', `branch..merge', and `remote..push'. To add this command to the push popup add this to your init file: (with-eval-after-load \\='magit-remote (magit-define-popup-action \\='magit-push-popup ?r \\='magit-push-to-remote--desc \\='magit-push-to-remote ?p t))" (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" (propertize "git push " 'face 'bold))) ;;; _ (provide 'magit-push) ;;; magit-push.el ends here magit-2.90.1/lisp/magit-refs.el000066400000000000000000000755701337354740400162630ustar00rootroot00000000000000;;; magit-refs.el --- listing references -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (defvar bookmark-make-record-function) ;;; 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 preceeding 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 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. 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. 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. Contrary to how they are displayed in the buffer, for comparison each tag begins with \"tags/\" and each remote branch with \"/\"." :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-popup) 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'. \\\ 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-popup] to see available branch commands. Type \\[magit-merge-popup] to merge the branch or commit at point. Type \\[magit-cherry-pick-popup] 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) (setq-local bookmark-make-record-function #'magit-bookmark--refs-make-record)) (defun magit-refs-refresh-buffer (ref &optional args) (setq magit-set-buffer-margin-refresh (not (magit-buffer-margin-p))) (unless ref (setq ref "HEAD")) (unless (magit-rev-verify ref) (setq magit-refs-show-commit-count nil)) (magit-set-header-line-format (format "%s %s" ref (mapconcat #'identity args " "))) (magit-insert-section (branchbuf) (magit-run-section-hook 'magit-refs-sections-hook)) (add-hook 'kill-buffer-hook 'magit-preserve-section-visibility-cache)) ;;; Commands (defcustom magit-show-refs-arguments nil "The arguments used in `magit-refs-mode' buffers." :group 'magit-git-arguments :group 'magit-refs :type '(repeat (string :tag "Argument"))) (defvar magit-show-refs-popup (list :variable 'magit-show-refs-arguments :man-page "git-branch" :switches '((?m "Merged to HEAD" "--merged") (?M "Merged to master" "--merged=master") (?n "Not merged to HEAD" "--no-merged") (?N "Not merged to master" "--no-merged=master")) :options '((?c "Contains" "--contains=" magit-read-branch-or-commit) (?m "Merged" "--merged=" magit-read-branch-or-commit) (?n "Not merged" "--no-merged=" magit-read-branch-or-commit) (?s "Sort" "--sort=" magit-read-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)) :default-action 'magit-show-refs-head :max-action-columns 1 :use-prefix (lambda () (if (derived-mode-p 'magit-refs-mode) (if current-prefix-arg 'popup 'default) 'popup)))) (magit-define-popup-keys-deferred 'magit-show-refs-popup) (defun magit-read-ref-sort (prompt initial-input) (magit-completing-read prompt '("-committerdate" "-authordate" "committerdate" "authordate") nil nil initial-input)) (defun magit-show-refs-get-buffer-args () (cond ((and magit-use-sticky-arguments (derived-mode-p 'magit-refs-mode)) (cadr magit-refresh-args)) ((and (eq magit-use-sticky-arguments t) (--when-let (magit-mode-get-buffer 'magit-refs-mode) (with-current-buffer it (cadr magit-refresh-args))))) (t (default-value 'magit-show-refs-arguments)))) (defun magit-show-refs-arguments () (if (eq magit-current-popup 'magit-show-refs-popup) magit-current-popup-args (magit-show-refs-get-buffer-args))) ;;;###autoload (defun magit-show-refs-popup (&optional arg) "Popup console for `magit-show-refs'." (interactive "P") (let ((magit-show-refs-arguments (magit-show-refs-get-buffer-args))) (magit-invoke-popup 'magit-show-refs-popup nil arg))) ;;;###autoload (defun magit-show-refs-head (&optional args) "List and compare references in a dedicated buffer. Refs are compared with `HEAD'." (interactive (list (magit-show-refs-arguments))) (magit-show-refs nil args)) ;;;###autoload (defun magit-show-refs-current (&optional args) "List and compare references in a dedicated buffer. Refs are compared with the current branch or `HEAD' if it is detached." (interactive (list (magit-show-refs-arguments))) (magit-show-refs (magit-get-current-branch) args)) ;;;###autoload (defun magit-show-refs (&optional ref args) "List and compare references in a dedicated buffer. Refs are compared with a branch read from the user." (interactive (list (magit-read-other-branch "Compare with") (magit-show-refs-arguments))) (magit-mode-setup #'magit-refs-mode 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-show-refs ref)) (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)) (setcar magit-refresh-args 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) (setcar magit-refresh-args 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..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" (cadr magit-refresh-args)))) (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 section (tag tag t) (magit-insert-heading (magit-refs--format-focus-column tag 'tag) (propertize tag '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 section))))) (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):" 'face 'magit-section-heading) (propertize remote '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) (cadr magit-refresh-args))) (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 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 section))))))) (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 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 section)))) (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" (cadr magit-refresh-args))))) (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)) (propertize "(detached)" 'face 'font-lock-warning-face))) (u:ahead (and u:track (string-match "ahead \\([0-9]+\\)" u:track) (propertize (concat (and magit-refs-pad-commit-counts " ") (match-string 1 u:track) ">") 'face 'magit-dimmed))) (u:behind (and u:track (string-match "behind \\([0-9]+\\)" u:track) (propertize (concat "<" (match-string 1 u:track) (and magit-refs-pad-commit-counts " ")) 'face 'magit-dimmed))) (p:ahead (and pushp p:track (string-match "ahead \\([0-9]+\\)" p:track) (propertize (concat (match-string 1 p:track) ">" (and magit-refs-pad-commit-counts " ")) 'face 'magit-branch-remote))) (p:behind (and pushp p:track (string-match "behind \\([0-9]+\\)" p:track) (propertize (concat "<" (match-string 1 p:track) (and magit-refs-pad-commit-counts " ")) 'face '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]") (propertize upstream 'face 'error) (magit-refs--propertize-branch upstream u:ref)) " ")) (and pushp (concat p:behind (propertize push 'face 'magit-branch-remote) " ")) (and msg (magit-log-propertize-keywords nil msg))))))) (defun magit-refs--format-focus-column (ref &optional type) (let ((focus (car magit-refresh-args)) (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) (eq focus nil))) (propertize (concat (if focus "@" "*") (make-string (1- width) ?\s)) 'face '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 (or (car magit-refresh-args) "HEAD") ref))) (propertize (cond ((> ahead 0) (concat "<" (number-to-string ahead))) ((> behind 0) (concat (number-to-string behind) ">")) (t "=")) 'face '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)))) (propertize branch 'face (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 section) (if (oref section hidden) (oset section washer (apply-partially #'magit-refs--insert-cherry-commits-1 ref section)) (magit-refs--insert-cherry-commits-1 ref section))) (defun magit-refs--insert-cherry-commits-1 (ref _section) (let ((start (point)) (magit-insert-section--current nil)) (magit-git-wash (apply-partially 'magit-log-wash-log 'cherry) "cherry" "-v" (magit-abbrev-arg) (or (car magit-refresh-args) "HEAD") ref magit-refresh-args) (unless (= (point) start) (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 magit-2.90.1/lisp/magit-remote.el000066400000000000000000000353551337354740400166140ustar00rootroot00000000000000;;; magit-remote.el --- transfer Git commits -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup-show-variables t "Whether the `magit-remote-popup' shows Git variables. When set to nil, no variables are displayed directly in this popup, instead the sub-popup `magit-remote-config-popup' has to be used to view and change remote related variables." :package-version '(magit . "2.12.0") :group 'magit-commands :type 'boolean) ;;; Commands (defvar magit-remote-config-variables) ;;;###autoload (autoload 'magit-remote-popup "magit-remote" nil t) (magit-define-popup magit-remote-popup "Popup console for remote commands." :man-page "git-remote" :default-arguments '("-f") :variables (lambda () (and magit-remote-popup-show-variables magit-remote-config-variables)) :switches '("Switches for add" (?f "Fetch after add" "-f")) :actions '((?a "Add" magit-remote-add) (?C "Configure..." magit-remote-config-popup) (?r "Rename" magit-remote-rename) (?p "Prune stale branches" magit-remote-prune) (?k "Remove" magit-remote-remove) (?P "Prune stale refspecs" magit-remote-prune-refspecs)) :max-action-columns 2) (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") (magit-remote-arguments))) (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//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//HEAD\"." (interactive (list (magit-read-remote "Unset HEAD for remote"))) (magit-run-git "remote" "set-head" remote "--delete")) ;;; Configure (defvar magit-remote-config--remote nil) ;;;###autoload (defun magit-remote-config-popup (remote) "Popup console for setting remote variables." (interactive (list (if (or current-prefix-arg (and (eq magit-current-popup 'magit-remote-popup) magit-remote-popup-show-variables)) (magit-read-remote "Configure remote") (magit-remote-config--remote-1)))) (let ((magit-remote-config--remote remote)) (magit-invoke-popup 'magit-remote-config-popup nil nil))) (defvar magit-remote-config-variables '((lambda () (concat (propertize "Configure " 'face 'magit-popup-heading) (propertize (magit-remote-config--remote) 'face 'magit-branch-remote))) (?u "remote.%s.url" magit-set-remote*url magit-format-remote*url) (?U "remote.%s.fetch" magit-set-remote*fetch magit-format-remote*fetch) (?s "remote.%s.pushurl" magit-set-remote*pushurl magit-format-remote*pushurl) (?S "remote.%s.push" magit-set-remote*push magit-format-remote*push) (?O "remote.%s.tagOpt" magit-cycle-remote*tagOpt magit-format-remote*tagOpt))) (defvar magit-remote-config-popup `(:man-page "git-remote" :variables ,magit-remote-config-variables :setup-function magit-remote-config-popup-setup)) (defun magit-remote-config-popup-setup (val def) (magit-popup-default-setup val def) (setq-local magit-remote-config--remote magit-remote-config--remote)) (defun magit-remote-config--remote (&optional prompt) (if prompt (or (and (not current-prefix-arg) (or magit-remote-config--remote (magit-remote-config--remote-1))) (magit-read-remote prompt)) (or magit-remote-config--remote (magit-remote-config--remote-1) ""))) (defun magit-remote-config--remote-1 () (let ((remote (magit-get-upstream-remote))) (if (or (not remote) (equal remote ".")) (and (magit-remote-p "origin") "origin") remote))) (defun magit-set-remote*url (remote urls) "Set the variable `url' for the remote named REMOTE to URLS." (interactive (magit-remote-config--read-args "url" "Urls: ")) (magit-remote-config--set-url remote "url" urls)) (defun magit-set-remote*fetch (remote values) "Set the variable `fetch' for the remote named REMOTE to VALUES." (interactive (magit-remote-config--read-args "fetch" "Fetch specs: ")) (magit-set-all values "remote" remote "fetch") (magit-refresh)) (defun magit-set-remote*pushurl (remote urls) "Set the variable `pushurl' for the remote named REMOTE to URLS." (interactive (magit-remote-config--read-args "pushurl" "Urls: ")) (magit-remote-config--set-url remote "pushurl" urls "--push")) (defun magit-set-remote*push (remote values) "Set the variable `push' for the remote named REMOTE to VALUES." (interactive (magit-remote-config--read-args "push" "Push specs: ")) (magit-set-all values "remote" remote "push") (magit-refresh)) (defun magit-cycle-remote*tagOpt (remote) (interactive (list (magit-remote-config--remote))) (magit--set-popup-variable (format "remote.%s.tagOpt" remote) '("--no-tags" "--tags") nil)) (defun magit-format-remote*url () (magit-remote-config--format-variable "url")) (defun magit-format-remote*fetch () (magit-remote-config--format-variable "fetch")) (defun magit-format-remote*pushurl () (magit-remote-config--format-variable "pushurl")) (defun magit-format-remote*push () (magit-remote-config--format-variable "push")) (defun magit-format-remote*tagOpt () (let ((remote (magit-remote-config--remote))) (magit--format-popup-variable:choices (format "remote.%s.tagOpts" remote) '("--no-tags" "--tags") nil nil (+ (length remote) 16)))) (defun magit-remote-config--read-args (var prompt) (let* ((remote (magit-remote-config--remote (format "Set `%s' of remote" var))) (value (magit-get-all "remote" remote var))) (list remote (mapcar (lambda (url) (if (string-prefix-p "~" url) (expand-file-name url) url)) (completing-read-multiple prompt nil nil nil (and value (mapconcat #'identity value ","))))))) (defun magit-remote-config--set-url (remote var values &optional arg) (let ((old (magit-get-all "remote" remote var))) (dolist (v (-difference values old)) (magit-call-git "remote" "set-url" arg "--add" remote v)) (dolist (v (-difference old values)) (magit-call-git "remote" "set-url" arg "--delete" remote (concat "^" (regexp-quote v) "$")))) (magit-refresh)) (defun magit-remote-config--format-variable (variable) (magit--format-popup-variable:values (format "remote.%s.%s" (magit-remote-config--remote) variable) 25)) ;;; _ (provide 'magit-remote) ;;; magit-remote.el ends here magit-2.90.1/lisp/magit-repos.el000066400000000000000000000303251337354740400164410ustar00rootroot00000000000000;;; magit-repos.el --- listing repositories -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-internal "magit-status" (directory)) (defvar x-stretch-cursor) ;;; Options (defcustom magit-repository-directories '(("~/.emacs.d/" . 0) ; this should always be a repository ("~/.emacs.d/lib/" . 1)) ; useful for `borg' users "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." :package-version '(magit . "2.90.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) ("BU" 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")))))) ;;; 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-internal (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 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." (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) (put-text-property (1+ (match-beginning 0)) (length v) 'face '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-dirty (_id) "Insert a letter if there are uncommitted changes. Show N if there is at least one untracked file. Show U if there is at least one unstaged file. Show S if there is at least one staged file. Only one letter is shown, the first that applies." (cond ((magit-untracked-files) "N") ((magit-unstaged-files) "U") ((magit-staged-files) "S"))) (defun magit-repolist-column-unpulled-from-upstream (_id) "Insert number of upstream commits not in the current branch." (--when-let (magit-get-upstream-branch nil t) (let ((n (cadr (magit-rev-diff-count "HEAD" it)))) (propertize (number-to-string n) 'face (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)))) (propertize (number-to-string n) 'face (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 nil t) (let ((n (car (magit-rev-diff-count "HEAD" it)))) (propertize (number-to-string n) 'face (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)))) (propertize (number-to-string n) 'face (if (> n 0) 'bold 'shadow))))) (defun magit-repolist-column-branches (_id) "Insert number of branches." (let ((n (length (magit-list-local-branches)))) (propertize (number-to-string n) 'face (if (> n 1) 'bold 'shadow)))) (defun magit-repolist-column-stashes (_id) "Insert number of stashes." (let ((n (length (magit-list-stashes)))) (propertize (number-to-string n) 'face (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. With prefix argument simply read a directory name using `read-directory-name'." (if-let ((repos (and (not read-directory-name) magit-repository-directories (magit-list-repos-uniquify (--map (cons (file-name-nondirectory (directory-file-name it)) it) (magit-list-repos)))))) (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 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)) ;;; _ (provide 'magit-repos) ;;; magit-repos.el ends here magit-2.90.1/lisp/magit-reset.el000066400000000000000000000116201337354740400164300ustar00rootroot00000000000000;;; magit-reset.el --- reset fuctionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup "magit" nil t) (magit-define-popup magit-reset-popup "Popup console for reset commands." :man-page "git-reset" :actions '((?m "reset mixed (HEAD and index)" magit-reset-mixed) (?s "reset soft (HEAD only)" magit-reset-soft) (?h "reset hard (HEAD, index, and files)" magit-reset-hard) (?i "reset index (only)" magit-reset-index) (?w "reset worktree (only)" magit-reset-worktree) nil (?f "reset a file" magit-file-checkout)) :max-action-columns 1) ;;;###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 (propertize "Hard" 'face '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-with-temp-index commit nil (magit-wip-commit-before-change nil " before reset") (magit-run-git "checkout-index" "--all" "--force") (magit-wip-commit-after-apply nil " after reset"))) ;;;###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 (propertize "Hard" 'face '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 magit-2.90.1/lisp/magit-section.el000066400000000000000000001661701337354740400167650ustar00rootroot00000000000000;;; magit-section.el --- section functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 "sections" as used in all Magit buffers. ;; If you have used Magit before, then you probably know what that ;; means, otherwise think "read-only Org-Mode for Git", kinda. ;;; Code: (require 'cl-lib) (require 'dash) (require 'eieio) (eval-when-compile (require 'subr-x)) (require 'magit-utils) (declare-function magit-maybe-make-margin-overlay "magit-margin" ()) (declare-function magit-repository-local-get "magit-mode" (key &optional default repository)) (declare-function magit-repository-local-set "magit-mode" (key value &optional repository)) (defvar magit-keep-region-overlay) ;;; Options (defgroup magit-section nil "Expandable sections." :link '(info-link "(magit)Sections") :group 'magit) (defcustom magit-section-show-child-count t "Whether to append the number of children to section headings. This only applies to sections for which doing so makes sense." :package-version '(magit . "2.1.0") :group 'magit-section :type 'boolean) (defcustom magit-section-movement-hook '(magit-hunk-set-window-start magit-log-maybe-update-revision-buffer magit-log-maybe-show-more-commits) "Hook run by `magit-section-goto'. That function in turn is used by all section movement commands." :package-version '(magit . "2.3.0") :group 'magit-section :type 'hook :options '(magit-hunk-set-window-start magit-status-maybe-update-revision-buffer magit-status-maybe-update-blob-buffer magit-log-maybe-update-revision-buffer magit-log-maybe-update-blob-buffer magit-log-maybe-show-more-commits)) (defcustom magit-section-highlight-hook '(magit-diff-highlight magit-section-highlight magit-section-highlight-selection) "Functions used to highlight the current section. Each function is run with the current section as only argument until one of them returns non-nil." :package-version '(magit . "2.1.0") :group 'magit-section :type 'hook :options '(magit-diff-highlight magit-section-highlight magit-section-highlight-selection)) (defcustom magit-section-unhighlight-hook '(magit-diff-unhighlight) "Functions used to unhighlight the previously current section. Each function is run with the current section as only argument until one of them returns non-nil. Most sections are properly unhighlighted without requiring a specialized unhighlighter, diff-related sections being the only exception." :package-version '(magit . "2.1.0") :group 'magit-section :type 'hook :options '(magit-diff-unhighlight)) (defcustom magit-section-set-visibility-hook '(magit-diff-expansion-threshold magit-section-cached-visibility) "Hook used to set the initial visibility of a section. Stop at the first function that returns non-nil. The returned value should be `show', `hide' or nil. If no function returns non-nil, determine the visibility as usual, i.e. use the hardcoded section specific default (see `magit-insert-section')." :package-version '(magit . "2.4.0") :group 'magit-section :type 'hook :options '(magit-diff-expansion-threshold magit-section-cached-visibility)) (defcustom magit-section-cache-visibility t "Whether to cache visibility of sections. Sections always retain their visibility state when they are being recreated during a refresh. But if a section disappears and then later reappears again, then this option controls whether this is the case. If t, then cache the visibility of all sections. If a list of section types, then only do so for matching sections. If nil, then don't do so for any sections." :package-version '(magit . "2.12.0") :group 'magit-section :type '(choice (const :tag "Don't cache visibility" nil) (const :tag "Cache visibility of all sections" t) (repeat :tag "Cache visibility for section types" symbol))) (defcustom magit-section-initial-visibility-alist '((stashes . hide)) "Alist controlling the initial visibility of sections. Each element maps a section type or lineage to the initial visibility state for such sections. The state has to be one of `show' or `hide', or a function that returns one of these symbols. A function is called with the section as the only argument. Use the command `magit-describe-section' to determine a section's lineage or type. The vector in the output is the section lineage and the type is the first element of that vector. Wildcards can be used, see `magit-section-match'. Currently this option is only used to override hardcoded defaults, but in the future it will also be used set the defaults. An entry whose key is `magit-status-initial-section' specifies the visibility of the section `magit-status-goto-initial-section' jumps to. This does not only override defaults, but also other entries of this alist." :package-version '(magit . "2.12.0") :group 'magit-section :type '(alist :key-type (sexp :tag "Section type/lineage") :value-type (choice (const hide) (const show) function))) (defface magit-section-highlight '((((class color) (background light)) :background "grey95") (((class color) (background dark)) :background "grey20")) "Face for highlighting the current section." :group 'magit-faces) (defface magit-section-heading '((((class color) (background light)) :foreground "DarkGoldenrod4" :weight bold) (((class color) (background dark)) :foreground "LightGoldenrod2" :weight bold)) "Face for section headings." :group 'magit-faces) (defface magit-section-secondary-heading '((t :weight bold)) "Face for section headings of some secondary headings." :group 'magit-faces) (defface magit-section-heading-selection '((((class color) (background light)) :foreground "salmon4") (((class color) (background dark)) :foreground "LightSalmon3")) "Face for selected section headings." :group 'magit-faces) ;;; Classes (defvar magit--current-section-hook nil "Internal variable used for `magit-explain-section'.") (defvar magit--section-type-alist '( (file . magit-file-section) (hunk . magit-hunk-section) (module . magit-module-section) )) (defclass magit-section () ((type :initform nil :initarg :type) (value :initform nil :initarg :value) (start :initform nil :initarg :start) (content :initform nil) (end :initform nil) (hidden :initform nil) (washer :initform nil) (process :initform nil) (heading-highlight-face :initform nil) (inserter :initform (symbol-value 'magit--current-section-hook)) (parent :initform nil :initarg :parent) (children :initform nil))) (defclass magit-file-section (magit-section) ((source :initform nil) (header :initform nil))) (defclass magit-hunk-section (magit-section) ((refined :initform nil))) (defclass magit-module-section (magit-file-section) ()) ;;; Core (defvar-local magit-root-section nil "The root section in the current buffer. All other sections are descendants of this section. The value of this variable is set by `magit-insert-section' and you should never modify it.") (put 'magit-root-section 'permanent-local t) (defun magit-current-section () "Return the section at point." (or (get-text-property (point) 'magit-section) magit-root-section)) (defun magit-section-ident (section) "Return an unique identifier for SECTION. The return value has the form ((TYPE . VALUE)...)." (with-slots (type value parent) section (cons (cons type (cond ((not (memq type '(unpulled unpushed))) value) ((string-match-p "@{upstream}" value) value) ;; Unfortunately Git chokes on "@{push}" when ;; the value of `push.default' does not allow a ;; 1:1 mapping. Arbitrary commands may consult ;; the section value so we cannot use "@{push}". ;; But `unpushed' and `unpulled' sections should ;; keep their identity when switching branches ;; so we have to use another value here. ((string-match-p "\\`\\.\\." value) "..@{push}") (t "@{push}.."))) (and parent (magit-section-ident parent))))) (defun magit-get-section (ident &optional root) "Return the section identified by IDENT. IDENT has to be a list as returned by `magit-section-ident'." (setq ident (reverse ident)) (let ((section (or root magit-root-section))) (when (eq (car (pop ident)) (oref section type)) (while (and ident (setq section (--first (and (eq (caar ident) (oref it type)) (equal (cdar ident) (oref it value))) (oref section children)))) (pop ident)) section))) (defun magit-section-lineage (section) "Return the lineage of SECTION. The return value has the form (TYPE...)." (cons (oref section type) (when-let ((parent (oref section parent))) (magit-section-lineage parent)))) (defvar magit-insert-section--current nil "For internal use only.") (defvar magit-insert-section--parent nil "For internal use only.") (defvar magit-insert-section--oldroot nil "For internal use only.") ;;; Commands ;;;; Movement (defun magit-section-forward () "Move to the beginning of the next visible section." (interactive) (if (eobp) (user-error "No next section") (let ((section (magit-current-section))) (if (oref section parent) (let ((next (and (not (oref section hidden)) (not (= (oref section end) (1+ (point)))) (car (oref section children))))) (while (and section (not next)) (unless (setq next (car (magit-section-siblings section 'next))) (setq section (oref section parent)))) (if next (magit-section-goto next) (user-error "No next section"))) (magit-section-goto 1))))) (defun magit-section-backward () "Move to the beginning of the current or the previous visible section. When point is at the beginning of a section then move to the beginning of the previous visible section. Otherwise move to the beginning of the current section." (interactive) (if (bobp) (user-error "No previous section") (let ((section (magit-current-section)) children) (cond ((and (= (point) (1- (oref section end))) (setq children (oref section children))) (magit-section-goto (car (last children)))) ((and (oref section parent) (not (= (point) (oref section start)))) (magit-section-goto section)) (t (let ((prev (car (magit-section-siblings section 'prev)))) (if prev (while (and (not (oref prev hidden)) (setq children (oref prev children))) (setq prev (car (last children)))) (setq prev (oref section parent))) (cond (prev (magit-section-goto prev)) ((oref section parent) (user-error "No previous section")) ;; Eob special cases. ((not (get-text-property (1- (point)) 'invisible)) (magit-section-goto -1)) (t (goto-char (previous-single-property-change (1- (point)) 'invisible)) (forward-line -1) (magit-section-goto (magit-current-section)))))))))) (defun magit-section-up () "Move to the beginning of the parent section." (interactive) (--if-let (oref (magit-current-section) parent) (magit-section-goto it) (user-error "No parent section"))) (defun magit-section-forward-sibling () "Move to the beginning of the next sibling section. If there is no next sibling section, then move to the parent." (interactive) (let ((current (magit-current-section))) (if (oref current parent) (--if-let (car (magit-section-siblings current 'next)) (magit-section-goto it) (magit-section-forward)) (magit-section-goto 1)))) (defun magit-section-backward-sibling () "Move to the beginning of the previous sibling section. If there is no previous sibling section, then move to the parent." (interactive) (let ((current (magit-current-section))) (if (oref current parent) (--if-let (car (magit-section-siblings current 'prev)) (magit-section-goto it) (magit-section-backward)) (magit-section-goto -1)))) (defun magit-section-goto (arg) (if (integerp arg) (progn (forward-line arg) (setq arg (magit-current-section))) (goto-char (oref arg start))) (run-hook-with-args 'magit-section-movement-hook arg)) (defun magit-section-set-window-start (section) "Ensure the beginning of SECTION is visible." (unless (pos-visible-in-window-p (oref section end)) (set-window-start (selected-window) (oref section start)))) (defun magit-hunk-set-window-start (section) "When SECTION is a `hunk', ensure that its beginning is visible. It the SECTION has a different type, then do nothing." (when (magit-hunk-section-p section) (magit-section-set-window-start section))) (defmacro magit-define-section-jumper (name heading type &optional value) "Define an interactive function to go some section. Together TYPE and VALUE identify the section. HEADING is the displayed heading of the section." (declare (indent defun)) `(defun ,name (&optional expand) ,(format "\ Jump to the section \"%s\". With a prefix argument also expand it." heading) (interactive "P") (--if-let (magit-get-section (cons (cons ',type ,value) (magit-section-ident magit-root-section))) (progn (goto-char (oref it start)) (when expand (with-local-quit (magit-section-show it)) (recenter 0))) (message ,(format "Section \"%s\" wasn't found" heading))))) ;;;; Visibility (defun magit-section-show (section) "Show the body of the current section." (interactive (list (magit-current-section))) (oset section hidden nil) (when-let ((washer (oref section washer))) (oset section washer nil) (let ((inhibit-read-only t) (magit-insert-section--parent section) (content (oref section content))) (save-excursion (if (and content (< content (oref section end))) (funcall washer section) ; already partially washed (hunk) (goto-char (oref section end)) (oset section content (point-marker)) (funcall washer) (oset section end (point-marker))))) (magit-section-update-highlight)) (when-let ((beg (oref section content))) (remove-overlays beg (oref section end) 'invisible t)) (magit-section-maybe-cache-visibility section) (dolist (child (oref section children)) (if (oref child hidden) (magit-section-hide child) (magit-section-show child)))) (defun magit-section-hide (section) "Hide the body of the current section." (interactive (list (magit-current-section))) (if (eq section magit-root-section) (user-error "Cannot hide root section") (oset section hidden t) (when-let ((beg (oref section content))) (let ((end (oref section end))) (remove-overlays beg end 'invisible t) (let ((o (make-overlay beg end))) (overlay-put o 'evaporate t) (overlay-put o 'invisible t)))) (magit-section-maybe-cache-visibility section))) (defun magit-section-toggle (section) "Toggle visibility of the body of the current section." (interactive (list (magit-current-section))) (if (eq section magit-root-section) (user-error "Cannot hide root section") (goto-char (oref section start)) (if (oref section hidden) (magit-section-show section) (magit-section-hide section)))) (defun magit-section-toggle-children (section) "Toggle visibility of bodies of children of the current section." (interactive (list (magit-current-section))) (goto-char (oref section start)) (let* ((children (oref section children)) (show (--any-p (oref it hidden) children))) (dolist (c children) (oset c hidden show))) (magit-section-show section)) (defun magit-section-show-children (section &optional depth) "Recursively show the bodies of children of the current section. With a prefix argument show children that deep and hide deeper children." (interactive (list (magit-current-section))) (magit-section-show-children-1 section depth) (magit-section-show section)) (defun magit-section-show-children-1 (section &optional depth) (dolist (child (oref section children)) (oset child hidden nil) (if depth (if (> depth 0) (magit-section-show-children-1 child (1- depth)) (magit-section-hide child)) (magit-section-show-children-1 child)))) (defun magit-section-hide-children (section) "Recursively hide the bodies of children of the current section." (interactive (list (magit-current-section))) (mapc 'magit-section-hide (oref section children))) (defun magit-section-show-headings (section) "Recursively show headings of children of the current section. Only show the headings, previously shown text-only bodies are hidden." (interactive (list (magit-current-section))) (magit-section-show-headings-1 section) (magit-section-show section)) (defun magit-section-show-headings-1 (section) (dolist (child (oref section children)) (oset child hidden nil) (when (or (oref child children) (not (oref child content))) (magit-section-show-headings-1 child)))) (defun magit-section-cycle (section) "Cycle visibility of current section and its children." (interactive (list (magit-current-section))) (goto-char (oref section start)) (if (oref section hidden) (progn (magit-section-show section) (magit-section-hide-children section)) (let ((children (oref section children))) (cond ((and (--any-p (oref it hidden) children) (--any-p (oref it children) children)) (magit-section-show-headings section)) ((-any-p 'magit-section-hidden-body children) (magit-section-show-children section)) (t (magit-section-hide section)))))) (defun magit-section-cycle-global () "Cycle visibility of all sections in the current buffer." (interactive) (let ((children (oref magit-root-section children))) (cond ((and (--any-p (oref it hidden) children) (--any-p (oref it children) children)) (magit-section-show-headings magit-root-section)) ((-any-p 'magit-section-hidden-body children) (magit-section-show-children magit-root-section)) (t (mapc 'magit-section-hide children))))) (defun magit-section-cycle-diffs () "Cycle visibility of diff-related sections in the current buffer." (interactive) (when-let ((sections (cond ((derived-mode-p 'magit-status-mode) (--mapcat (when it (when (oref it hidden) (magit-section-show it)) (oref it children)) (list (magit-get-section '((staged) (status))) (magit-get-section '((unstaged) (status)))))) ((derived-mode-p 'magit-diff-mode) (-filter #'magit-file-section-p (oref magit-root-section children)))))) (if (--any-p (oref it hidden) sections) (dolist (s sections) (magit-section-show s) (magit-section-hide-children s)) (let ((children (--mapcat (oref it children) sections))) (cond ((and (--any-p (oref it hidden) children) (--any-p (oref it children) children)) (mapc 'magit-section-show-headings sections)) ((-any-p 'magit-section-hidden-body children) (mapc 'magit-section-show-children sections)) (t (mapc 'magit-section-hide sections))))))) (defun magit-section-hidden-body (section &optional pred) (--if-let (oref section children) (funcall (or pred '-any-p) 'magit-section-hidden-body it) (and (oref section content) (oref section hidden)))) (defun magit-section-invisible-p (section) "Return t if the SECTION's body is invisible. When the body of an ancestor of SECTION is collapsed then SECTION's body (and heading) obviously cannot be visible." (or (oref section hidden) (--when-let (oref section parent) (magit-section-invisible-p it)))) (defun magit-section-show-level (level) "Show surrounding sections up to LEVEL. If LEVEL is negative, show up to the absolute value. Sections at higher levels are hidden." (if (< level 0) (let ((s (magit-current-section))) (setq level (- level)) (while (> (1- (length (magit-section-ident s))) level) (setq s (oref s parent)) (goto-char (oref s start))) (magit-section-show-children magit-root-section (1- level))) (cl-do* ((s (magit-current-section) (oref s parent)) (i (1- (length (magit-section-ident s))) (cl-decf i))) ((cond ((< i level) (magit-section-show-children s (- level i 1)) t) ((= i level) (magit-section-hide s) t)) (magit-section-goto s))))) (defun magit-section-show-level-1 () "Show surrounding sections on first level." (interactive) (magit-section-show-level 1)) (defun magit-section-show-level-1-all () "Show all sections on first level." (interactive) (magit-section-show-level -1)) (defun magit-section-show-level-2 () "Show surrounding sections up to second level." (interactive) (magit-section-show-level 2)) (defun magit-section-show-level-2-all () "Show all sections up to second level." (interactive) (magit-section-show-level -2)) (defun magit-section-show-level-3 () "Show surrounding sections up to third level." (interactive) (magit-section-show-level 3)) (defun magit-section-show-level-3-all () "Show all sections up to third level." (interactive) (magit-section-show-level -3)) (defun magit-section-show-level-4 () "Show surrounding sections up to fourth level." (interactive) (magit-section-show-level 4)) (defun magit-section-show-level-4-all () "Show all sections up to fourth level." (interactive) (magit-section-show-level -4)) ;;;; Auxiliary (defun magit-describe-section-briefly (section &optional message ident) "Show information about the section at point. With a prefix argument show the section identity instead of the section lineage. This command is intended for debugging purposes." (interactive (list (magit-current-section) t)) (let ((str (format "#<%s %S %S %s-%s>" (eieio-object-class section) (let ((val (oref section value))) (cond ((stringp val) (substring-no-properties val)) ((and (eieio-object-p val) (fboundp 'cl-prin1-to-string)) (cl-prin1-to-string val)) (t val))) (if ident (magit-section-ident section) (apply #'vector (magit-section-lineage section))) (when-let ((m (oref section start))) (marker-position m)) (when-let ((m (oref section end))) (marker-position m))))) (if message (message "%s" str) str))) (cl-defmethod cl-print-object ((section magit-section) stream) "Print `magit-describe-section' result of SECTION." ;; Used by debug and edebug as of Emacs 26. (princ (magit-describe-section-briefly section) stream)) (defun magit-describe-section (section &optional interactive-p) "Show information about the section at point." (interactive (list (magit-current-section) t)) (let ((inserter-section section)) (while (and inserter-section (not (oref inserter-section inserter))) (setq inserter-section (oref inserter-section parent))) (when (and inserter-section (oref inserter-section inserter)) (setq section inserter-section))) (pcase (oref section inserter) (`((,hook ,fun) . ,src-src) (help-setup-xref `(magit-describe-section ,section) interactive-p) (with-help-window (help-buffer) (with-current-buffer standard-output (insert (format-message "%s\n is inserted by `%s'\n from `%s'" (magit-describe-section-briefly section) (make-text-button (symbol-name fun) nil :type 'help-function 'help-args (list fun)) (make-text-button (symbol-name hook) nil :type 'help-variable 'help-args (list hook)))) (pcase-dolist (`(,hook ,fun) src-src) (insert (format-message ",\n called by `%s'\n from `%s'" (make-text-button (symbol-name fun) nil :type 'help-function 'help-args (list fun)) (make-text-button (symbol-name hook) nil :type 'help-variable 'help-args (list hook))))) (insert ".\n\n") (insert (format-message "`%s' is " (make-text-button (symbol-name fun) nil :type 'help-function 'help-args (list fun)))) (describe-function-1 fun)))) (_ (message "%s, inserter unknown" (magit-describe-section-briefly section))))) ;;; Match (cl-defun magit-section-match (condition &optional (section (magit-current-section))) "Return t if SECTION matches CONDITION. SECTION defaults to the section at point. If SECTION is not specified and there also is no section at point, then return nil. CONDITION can take the following forms: (CONDITION...) matches if any of the CONDITIONs matches. [CLASS...] matches if the section's class is the same as the first CLASS or a subclass of that; the section's parent class matches the second CLASS; and so on. [* CLASS...] matches sections that match [CLASS...] and also recursively all their child sections. CLASS matches if the section's class is the same as CLASS or a subclass of that; regardless of the classes of the parent sections. Each CLASS should be a class symbol, identifying a class that derives from `magit-section'. For backward compatibility CLASS can also be a \"type symbol\". A section matches such a symbol if the value of its `type' slot is `eq'. If a type symbol has an entry in `magit--section-type-alist', then a section also matches that type if its class is a subclass of the class that corresponds to the type as per that alist. Note that it is not necessary to specify the complete section lineage as printed by `magit-describe-section-briefly', unless of course you want to be that precise." (and section (magit-section-match-1 condition section))) (defun magit-section-match-1 (condition section) (cl-assert condition) (and section (if (listp condition) (--first (magit-section-match-1 it section) condition) (magit-section-match-2 (if (symbolp condition) (list condition) (cl-coerce condition 'list)) section)))) (defun magit-section-match-2 (condition section) (if (eq (car condition) '*) (or (magit-section-match-2 (cdr condition) section) (when-let ((parent (oref section parent))) (magit-section-match-2 condition parent))) (and (let ((c (car condition))) (if (class-p c) (cl-typep section c) (if-let ((class (cdr (assq c magit--section-type-alist)))) (cl-typep section class) (eq (oref section type) c)))) (or (not (setq condition (cdr condition))) (when-let ((parent (oref section parent))) (magit-section-match-2 condition parent)))))) (defun magit-section-value-if (condition &optional section) "If the section at point matches CONDITION, then return its value. If optional SECTION is non-nil then test whether that matches instead. If there is no section at point and SECTION is nil, then return nil. If the section does not match, then return nil. See `magit-section-match' for the forms CONDITION can take." (when-let ((section (or section (magit-current-section)))) (and (magit-section-match condition section) (oref section value)))) (defmacro magit-section-when (condition &rest body) "If the section at point matches CONDITION, evaluate BODY. If the section matches, then evaluate BODY forms sequentially with `it' bound to the section and return the value of the last form. If there are no BODY forms, then return the value of the section. If the section does not match or if there is no section at point, then return nil. See `magit-section-match' for the forms CONDITION can take." (declare (obsolete "instead use `magit-section-match' or `magit-section-value-if'." "Magit 2.90.0") (indent 1) (debug (sexp body))) `(--when-let (magit-current-section) ;; Quoting CONDITION here often leads to double-quotes, which ;; isn't an issue because `magit-section-match-1' implicitly ;; deals with that. We shouldn't force users of this function ;; to not quote CONDITION because that would needlessly break ;; backward compatibility. (when (magit-section-match ',condition it) ,@(or body '((oref it value)))))) (defmacro magit-section-case (&rest clauses) "Choose among clauses on the type of the section at point. Each clause looks like (CONDITION BODY...). The type of the section is compared against each CONDITION; the BODY forms of the first match are evaluated sequentially and the value of the last form is returned. Inside BODY the symbol `it' is bound to the section at point. If no clause succeeds or if there is no section at point, return nil. See `magit-section-match' for the forms CONDITION can take. Additionally a CONDITION of t is allowed in the final clause, and matches if no other CONDITION match, even if there is no section at point." (declare (indent 0) (debug (&rest (sexp body)))) `(let* ((it (magit-current-section))) (cond ,@(mapcar (lambda (clause) `(,(or (eq (car clause) t) `(and it (magit-section-match-1 ',(car clause) it))) ,@(cdr clause))) clauses)))) (defun magit-section-match-assoc (section alist) "Return the value associated with SECTION's type or lineage in ALIST." (-some (pcase-lambda (`(,key . ,val)) (and (magit-section-match-1 key section) val)) alist)) ;;; Create (defvar magit-insert-section-hook nil "Hook run after `magit-insert-section's BODY. Avoid using this hook and only ever do so if you know what you are doing and are sure there is no other way.") (defmacro magit-insert-section (&rest args) "Insert a section at point. TYPE is the section type, a symbol. Many commands that act on the current section behave differently depending on that type. Also if a variable `magit-TYPE-section-map' exists, then use that as the text-property `keymap' of all text belonging to the section (but this may be overwritten in subsections). TYPE can also have the form `(eval FORM)' in which case FORM is evaluated at runtime. Optional VALUE is the value of the section, usually a string that is required when acting on the section. When optional HIDE is non-nil collapse the section body by default, i.e. when first creating the section, but not when refreshing the buffer. Else expand it by default. This can be overwritten using `magit-section-set-visibility-hook'. When a section is recreated during a refresh, then the visibility of predecessor is inherited and HIDE is ignored (but the hook is still honored). BODY is any number of forms that actually insert the section's heading and body. Optional NAME, if specified, has to be a symbol, which is then bound to the struct of the section being inserted. Before BODY is evaluated the `start' of the section object is set to the value of `point' and after BODY was evaluated its `end' is set to the new value of `point'; BODY is responsible for moving `point' forward. If it turns out inside BODY that the section is empty, then `magit-cancel-section' can be used to abort and remove all traces of the partially inserted section. This can happen when creating a section by washing Git's output and Git didn't actually output anything this time around. \(fn [NAME] (TYPE &optional VALUE HIDE) &rest BODY)" (declare (indent defun) (debug ([&optional symbolp] (&or [("eval" symbolp) &optional form form] [symbolp &optional form form]) body))) (let ((tp (cl-gensym "type")) (s* (and (symbolp (car args)) (pop args))) (s (cl-gensym "section"))) `(let* ((,tp ,(let ((type (nth 0 (car args)))) (if (eq (car-safe type) 'eval) (cadr type) `',type))) (,s (funcall (if (class-p ,tp) ,tp (or (cdr (assq ,tp magit--section-type-alist)) 'magit-section)) :type (if (class-p ,tp) (or (car (rassq ,tp magit--section-type-alist)) (error "BUG: No entry for %s in %s" ,tp 'magit--section-type-alist)) ,tp) :value ,(nth 1 (car args)) :start (point-marker) :parent magit-insert-section--parent))) (oset ,s hidden (if-let ((value (run-hook-with-args-until-success 'magit-section-set-visibility-hook ,s))) (eq value 'hide) (if-let ((incarnation (and magit-insert-section--oldroot (magit-get-section (magit-section-ident ,s) magit-insert-section--oldroot)))) (oref incarnation hidden) (if-let ((value (magit-section-match-assoc ,s magit-section-initial-visibility-alist))) (progn (when (functionp value) (setq value (funcall value ,s))) (eq value 'hide)) ,(nth 2 (car args)))))) (let ((magit-insert-section--current ,s) (magit-insert-section--parent ,s) (magit-insert-section--oldroot (or magit-insert-section--oldroot (unless magit-insert-section--parent (prog1 magit-root-section (setq magit-root-section ,s)))))) (catch 'cancel-section ,@(if s* `((let ((,s* ,s)) ,@(cdr args))) (cdr args)) ;; `magit-insert-section-hook' should *not* be run with ;; `magit-run-section-hook' because it's a hook that runs ;; on section insertion, not a section inserting hook. (run-hooks 'magit-insert-section-hook) (magit-insert-child-count ,s) (set-marker-insertion-type (oref ,s start) t) (let* ((end (oset ,s end (point-marker))) (magit-map (intern (format "magit-%s-section-map" (oref ,s type)))) (forge-map (intern (format "forge-%s-section-map" (oref ,s type)))) (map (or (and (boundp magit-map) (symbol-value magit-map)) (and (boundp forge-map) (symbol-value forge-map))))) (save-excursion (goto-char (oref ,s start)) (while (< (point) end) (let ((next (or (next-single-property-change (point) 'magit-section) end))) (unless (get-text-property (point) 'magit-section) (put-text-property (point) next 'magit-section ,s) (when map (put-text-property (point) next 'keymap map))) (goto-char next))))) (if (eq ,s magit-root-section) (let ((magit-section-cache-visibility nil)) (magit-section-show ,s)) (oset (oref ,s parent) children (nconc (oref (oref ,s parent) children) (list ,s))))) ,s)))) (defun magit-cancel-section () (when magit-insert-section--current (if (not (oref magit-insert-section--current parent)) (insert "(empty)\n") (delete-region (oref magit-insert-section--current start) (point)) (setq magit-insert-section--current nil) (throw 'cancel-section nil)))) (defun magit-insert-heading (&rest args) "Insert the heading for the section currently being inserted. This function should only be used inside `magit-insert-section'. When called without any arguments, then just set the `content' slot of the object representing the section being inserted to a marker at `point'. The section should only contain a single line when this function is used like this. When called with arguments ARGS, which have to be strings, or nil, then insert those strings at point. The section should not contain any text before this happens and afterwards it should again only contain a single line. If the `face' property is set anywhere inside any of these strings, then insert all of them unchanged. Otherwise use the `magit-section-heading' face for all inserted text. The `content' property of the section struct is the end of the heading (which lasts from `start' to `content') and the beginning of the the body (which lasts from `content' to `end'). If the value of `content' is nil, then the section has no heading and its body cannot be collapsed. If a section does have a heading, then its height must be exactly one line, including a trailing newline character. This isn't enforced, you are responsible for getting it right. The only exception is that this function does insert a newline character if necessary." (declare (indent defun)) (when args (let ((heading (apply #'concat args))) (insert (if (text-property-not-all 0 (length heading) 'face nil heading) heading (propertize heading 'face 'magit-section-heading))))) (unless (bolp) (insert ?\n)) (magit-maybe-make-margin-overlay) (oset magit-insert-section--current content (point-marker))) (defun magit-insert-headers (hook) (let* ((header-sections nil) (magit-insert-section-hook (cons (lambda () (push magit-insert-section--current header-sections)) (if (listp magit-insert-section-hook) magit-insert-section-hook (list magit-insert-section-hook))))) (magit-run-section-hook hook) (when header-sections (insert "\n") ;; Make the first header into the parent of the rest. (when (cdr header-sections) (cl-callf nreverse header-sections) (let* ((1st-header (pop header-sections)) (header-parent (oref 1st-header parent))) (oset header-parent children (list 1st-header)) (oset 1st-header children header-sections) (oset 1st-header content (oref (car header-sections) start)) (oset 1st-header end (oref (car (last header-sections)) end)) (dolist (sub-header header-sections) (oset sub-header parent 1st-header))))))) (defun magit-insert-child-count (section) "Modify SECTION's heading to contain number of child sections. If `magit-section-show-child-count' is non-nil and the SECTION has children and its heading ends with \":\", then replace that with \" (N)\", where N is the number of child sections. This function is called by `magit-insert-section' after that has evaluated its BODY. Admittedly that's a bit of a hack." ;; This has to be fast, not pretty! (let (content count) (when (and magit-section-show-child-count (setq count (length (oref section children))) (> count 0) (setq content (oref section content)) (eq (char-before (1- content)) ?:)) (save-excursion (goto-char (- content 2)) (insert (format " (%s)" count)) (delete-char 1))))) ;;; Update (defvar-local magit-section-highlight-overlays nil) (defvar-local magit-section-highlighted-section nil) (defvar-local magit-section-highlighted-sections nil) (defvar-local magit-section-unhighlight-sections nil) (defun magit-section-update-region (_) "When the region is a valid section-selection, highlight them all." ;; At least that's what it does conceptually. In actuality it just ;; returns a list of those sections, and it doesn't even matter if ;; this is a member of `magit-region-highlight-hook'. It probably ;; should be removed, but I want to make sure before removing it. (magit-region-sections)) (defun magit-section-update-highlight () (let ((section (magit-current-section))) (unless (eq section magit-section-highlighted-section) (let ((inhibit-read-only t) (deactivate-mark nil) (selection (magit-region-sections))) (mapc #'delete-overlay magit-section-highlight-overlays) (setq magit-section-highlight-overlays nil) (setq magit-section-unhighlight-sections magit-section-highlighted-sections) (setq magit-section-highlighted-sections nil) (unless (eq section magit-root-section) (run-hook-with-args-until-success 'magit-section-highlight-hook section selection)) (dolist (s magit-section-unhighlight-sections) (run-hook-with-args-until-success 'magit-section-unhighlight-hook s selection)) (restore-buffer-modified-p nil) (unless (eq magit-section-highlighted-section section) (setq magit-section-highlighted-section (and (not (oref section hidden)) section)))) (when (version< emacs-version "25.1") (setq deactivate-mark nil))))) (defun magit-section-highlight (section selection) "Highlight SECTION and if non-nil all sections in SELECTION. This function works for any section but produces undesirable effects for diff related sections, which by default are highlighted using `magit-diff-highlight'. Return t." (when-let ((face (oref section heading-highlight-face))) (dolist (section (or selection (list section))) (magit-section-make-overlay (oref section start) (or (oref section content) (oref section end)) face))) (cond (selection (magit-section-make-overlay (oref (car selection) start) (oref (car (last selection)) end) 'magit-section-highlight) (magit-section-highlight-selection nil selection)) (t (magit-section-make-overlay (oref section start) (oref section end) 'magit-section-highlight))) t) (defun magit-section-highlight-selection (_ selection) "Highlight the section-selection region. If SELECTION is non-nil, then it is a list of sections selected by the region. The headings of these sections are then highlighted. This is a fallback for people who don't want to highlight the current section and therefore removed `magit-section-highlight' from `magit-section-highlight-hook'. This function is necessary to ensure that a representation of such a region is visible. If neither of these functions were part of the hook variable, then such a region would be invisible." (when (and selection (not (and (eq this-command 'mouse-drag-region)))) (dolist (section selection) (magit-section-make-overlay (oref section start) (or (oref section content) (oref section end)) 'magit-section-heading-selection)) t)) (defun magit-section-make-overlay (start end face) ;; Yes, this doesn't belong here. But the alternative of ;; spreading this hack across the code base is even worse. (when (and magit-keep-region-overlay (memq face '(magit-section-heading-selection magit-diff-file-heading-selection magit-diff-hunk-heading-selection))) (setq face (list :foreground (face-foreground face)))) (let ((ov (make-overlay start end nil t))) (overlay-put ov 'face face) (overlay-put ov 'evaporate t) (push ov magit-section-highlight-overlays) ov)) (defun magit-section-goto-successor (section line char arg) (let ((ident (magit-section-ident section))) (--if-let (magit-get-section ident) (let ((start (oref it start))) (goto-char start) (unless (eq it magit-root-section) (ignore-errors (forward-line line) (forward-char char)) (unless (eq (magit-current-section) it) (goto-char start)))) (or (and (magit-hunk-section-p section) (when-let ((parent (magit-get-section (magit-section-ident (oref section parent))))) (let* ((children (oref parent children)) (siblings (magit-section-siblings section 'prev)) (previous (nth (length siblings) children))) (if (not arg) (--when-let (or previous (car (last children))) (magit-section-goto it) t) (when previous (magit-section-goto previous)) (if (and (stringp arg) (re-search-forward arg (oref parent end) t)) (goto-char (match-beginning 0)) (goto-char (oref (car (last children)) end)) (forward-line -1) (while (looking-at "^ ") (forward-line -1)) (while (looking-at "^[-+]") (forward-line -1)) (forward-line)))))) (goto-char (--if-let (magit-section-goto-successor-1 section) (if (eq (oref it type) 'button) (point-min) (oref it start)) (point-min))))))) (defun magit-section-goto-successor-1 (section) (or (--when-let (pcase (oref section type) (`staged 'unstaged) (`unstaged 'staged) (`unpushed 'unpulled) (`unpulled 'unpushed)) (magit-get-section `((,it) (status)))) (--when-let (car (magit-section-siblings section 'next)) (magit-get-section (magit-section-ident it))) (--when-let (car (magit-section-siblings section 'prev)) (magit-get-section (magit-section-ident it))) (--when-let (oref section parent) (or (magit-get-section (magit-section-ident it)) (magit-section-goto-successor-1 it))))) ;;; Visibility (defvar-local magit-section-visibility-cache nil) (put 'magit-section-visibility-cache 'permanent-local t) (defun magit-section-cached-visibility (section) "Set SECTION's visibility to the cached value." (cdr (assoc (magit-section-ident section) magit-section-visibility-cache))) (cl-defun magit-section-cache-visibility (&optional (section magit-insert-section--current)) ;; Emacs 25's `alist-get' lacks TESTFN. (let* ((id (magit-section-ident section)) (elt (assoc id magit-section-visibility-cache)) (val (if (oref section hidden) 'hide 'show))) (if elt (setcdr elt val) (push (cons id val) magit-section-visibility-cache)))) (cl-defun magit-section-maybe-cache-visibility (&optional (section magit-insert-section--current)) (when (or (eq magit-section-cache-visibility t) (memq (oref section type) magit-section-cache-visibility)) (magit-section-cache-visibility section))) (defun magit-preserve-section-visibility-cache () (when (derived-mode-p 'magit-status-mode 'magit-refs-mode) (magit-repository-local-set (cons major-mode 'magit-section-visibility-cache) magit-section-visibility-cache))) (defun magit-restore-section-visibility-cache (mode) (setq magit-section-visibility-cache (magit-repository-local-get (cons mode 'magit-section-visibility-cache)))) ;;; Utilities (cl-defun magit-section-selected-p (section &optional (selection nil sselection)) (and (not (eq section magit-root-section)) (or (eq section (magit-current-section)) (memq section (if sselection selection (setq selection (magit-region-sections)))) (--when-let (oref section parent) (magit-section-selected-p it selection))))) (defun magit-section-parent-value (section) (when-let ((parent (oref section parent))) (oref parent value))) (defun magit-section-siblings (section &optional direction) "Return a list of the sibling sections of SECTION. If optional DIRECTION is `prev', then return siblings that come before SECTION. If it is `next', then return siblings that come after SECTION. For all other values, return all siblings excluding SECTION itself." (when-let ((parent (oref section parent))) (let ((siblings (oref parent children))) (pcase direction (`prev (cdr (member section (reverse siblings)))) (`next (cdr (member section siblings))) (_ (remq section siblings)))))) (defun magit-region-values (&optional condition multiple) "Return a list of the values of the selected sections. Return the values that themselves would be returned by `magit-region-sections' (which see)." (--map (oref it value) (magit-region-sections condition multiple))) (defun magit-region-sections (&optional condition multiple) "Return a list of the selected sections. When the region is active and constitutes a valid section selection, then return a list of all selected sections. This is the case when the region begins in the heading of a section and ends in the heading of the same section or in that of a sibling section. If optional MULTIPLE is non-nil, then the region cannot begin and end in the same section. When the selection is not valid, then return nil. In this case, most commands that can act on the selected sections will instead act on the section at point. When the region looks like it would in any other buffer then the selection is invalid. When the selection is valid then the region uses the `magit-section-highlight' face. This does not apply to diffs where things get a bit more complicated, but even here if the region looks like it usually does, then that's not a valid selection as far as this function is concerned. If optional CONDITION is non-nil, then the selection not only has to be valid; all selected sections additionally have to match CONDITION, or nil is returned. See `magit-section-match' for the forms CONDITION can take." (when (region-active-p) (let* ((rbeg (region-beginning)) (rend (region-end)) (sbeg (get-text-property rbeg 'magit-section)) (send (get-text-property rend 'magit-section))) (when (and send (not (eq send magit-root-section)) (not (and multiple (eq send sbeg)))) (let ((siblings (cons sbeg (magit-section-siblings sbeg 'next))) sections) (when (and (memq send siblings) (magit-section-position-in-heading-p sbeg rbeg) (magit-section-position-in-heading-p send rend)) (while siblings (push (car siblings) sections) (when (eq (pop siblings) send) (setq siblings nil))) (setq sections (nreverse sections)) (when (or (not condition) (--all-p (magit-section-match condition it) sections)) sections))))))) (defun magit-section-position-in-heading-p (&optional section pos) "Return t if POSITION is inside the heading of SECTION. POSITION defaults to point and SECTION defaults to the current section." (unless section (setq section (magit-current-section))) (unless pos (setq pos (point))) (and section (>= pos (oref section start)) (< pos (or (oref section content) (oref section end))) t)) (defun magit-section-internal-region-p (&optional section) "Return t if the region is active and inside SECTION's body. If optional SECTION is nil, use the current section." (and (region-active-p) (or section (setq section (magit-current-section))) (let ((beg (get-text-property (region-beginning) 'magit-section))) (and (eq beg (get-text-property (region-end) 'magit-section)) (eq beg section))) (not (or (magit-section-position-in-heading-p section (region-beginning)) (magit-section-position-in-heading-p section (region-end)))) t)) (defun magit-section--backward-protected () "Move to the beginning of the current or the previous visible section. Same as `magit-section-backward' but for non-interactive use. Suppress `magit-section-movement-hook', and return a boolean to indicate whether a section was found, instead of raising an error if not." (condition-case nil (let ((magit-section-movement-hook nil)) (magit-section-backward) t) (user-error nil))) (defun magit-section--backward-find (predicate) "Move to the first previous section satisfying PREDICATE. PREDICATE does not take any parameter and should not move point." (let (found) (while (and (setq found (magit-section--backward-protected)) (not (funcall predicate)))) found)) (defun magit-wash-sequence (function) "Repeatedly call FUNCTION until it returns nil or eob is reached. FUNCTION has to move point forward or return nil." (while (and (not (eobp)) (funcall function)))) (defun magit-add-section-hook (hook function &optional at append local) "Add to the value of section hook HOOK the function FUNCTION. Add FUNCTION at the beginning of the hook list unless optional APPEND is non-nil, in which case FUNCTION is added at the end. If FUNCTION already is a member, then move it to the new location. If optional AT is non-nil and a member of the hook list, then add FUNCTION next to that instead. Add before or after AT, or replace AT with FUNCTION depending on APPEND. If APPEND is the symbol `replace', then replace AT with FUNCTION. For any other non-nil value place FUNCTION right after AT. If nil, then place FUNCTION right before AT. If FUNCTION already is a member of the list but AT is not, then leave FUNCTION where ever it already is. If optional LOCAL is non-nil, then modify the hook's buffer-local value rather than its global value. This makes the hook local by copying the default value. That copy is then modified. HOOK should be a symbol. If HOOK is void, it is first set to nil. HOOK's value must not be a single hook function. FUNCTION should be a function that takes no arguments and inserts one or multiple sections at point, moving point forward. FUNCTION may choose not to insert its section(s), when doing so would not make sense. It should not be abused for other side-effects. To remove FUNCTION again use `remove-hook'." (unless (boundp hook) (error "Cannot add function to undefined hook variable %s" hook)) (or (default-boundp hook) (set-default hook nil)) (let ((value (if local (if (local-variable-p hook) (symbol-value hook) (unless (local-variable-if-set-p hook) (make-local-variable hook)) (copy-sequence (default-value hook))) (default-value hook)))) (if at (when (setq at (member at value)) (setq value (delq function value)) (cond ((eq append 'replace) (setcar at function)) (append (push function (cdr at))) (t (push (car at) (cdr at)) (setcar at function)))) (setq value (delq function value))) (unless (member function value) (setq value (if append (append value (list function)) (cons function value)))) (when (eq append 'replace) (setq value (delq at value))) (if local (set hook value) (set-default hook value)))) (defun magit-run-section-hook (hook &rest args) "Run HOOK with ARGS, warning about invalid entries." (let ((entries (symbol-value hook))) (unless (listp entries) (setq entries (list entries))) (--when-let (-remove #'functionp entries) (message "`%s' contains entries that are no longer valid. %s\nUsing standard value instead. Please re-configure hook variable." hook (mapconcat (lambda (sym) (format " `%s'" sym)) it "\n")) (sit-for 5) (setq entries (eval (car (get hook 'standard-value))))) (dolist (entry entries) (let ((magit--current-section-hook (cons (list hook entry) magit--current-section-hook))) (apply entry args))))) ;;; _ (provide 'magit-section) ;;; magit-section.el ends here magit-2.90.1/lisp/magit-sequence.el000066400000000000000000001147461337354740400171330ustar00rootroot00000000000000;;; magit-sequence.el --- history manipulation in Magit -*- lexical-binding: t -*- ;; Copyright (C) 2011-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 commands that replay commits and help the user make ;; changes along the way. Supports `cherry-pick', `revert', `rebase', ;; `rebase--interactive' and `am'. ;;; Code: (eval-when-compile (require 'subr-x)) (require 'magit) ;;; Options ;;;; Faces (defface magit-sequence-pick '((t :inherit default)) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-stop '((((class color) (background light)) :foreground "DarkOliveGreen4") (((class color) (background dark)) :foreground "DarkSeaGreen2")) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-part '((((class color) (background light)) :foreground "Goldenrod4") (((class color) (background dark)) :foreground "LightGoldenrod2")) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-head '((((class color) (background light)) :foreground "SkyBlue4") (((class color) (background dark)) :foreground "LightSkyBlue1")) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-drop '((((class color) (background light)) :foreground "IndianRed") (((class color) (background dark)) :foreground "IndianRed")) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-done '((t :inherit magit-hash)) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-onto '((t :inherit magit-sequence-done)) "Face used in sequence sections." :group 'magit-faces) (defface magit-sequence-exec '((t :inherit magit-hash)) "Face used in sequence sections." :group 'magit-faces) ;;; Common ;;;###autoload (defun magit-sequencer-continue () "Resume the current cherry-pick or revert sequence." (interactive) (if (magit-sequencer-in-progress-p) (if (magit-anything-unstaged-p t) (user-error "Cannot continue due to unstaged changes") (magit-run-git-sequencer (if (magit-revert-in-progress-p) "revert" "cherry-pick") "--continue")) (user-error "No cherry-pick or revert in progress"))) ;;;###autoload (defun magit-sequencer-skip () "Skip the stopped at commit during a cherry-pick or revert sequence." (interactive) (if (magit-sequencer-in-progress-p) (progn (magit-call-git "reset" "--hard") (magit-sequencer-continue)) (user-error "No cherry-pick or revert in progress"))) ;;;###autoload (defun magit-sequencer-abort () "Abort the current cherry-pick or revert sequence. This discards all changes made since the sequence started." (interactive) (if (magit-sequencer-in-progress-p) (magit-run-git-sequencer (if (magit-revert-in-progress-p) "revert" "cherry-pick") "--abort") (user-error "No cherry-pick or revert in progress"))) (defun magit-sequencer-in-progress-p () (or (magit-cherry-pick-in-progress-p) (magit-revert-in-progress-p))) ;;; Cherry-Pick (defvar magit-perl-executable "perl" "The Perl executable.") ;;;###autoload (autoload 'magit-cherry-pick-popup "magit-sequence" nil t) (magit-define-popup magit-cherry-pick-popup "Popup console for cherry-pick commands." :man-page "git-cherry-pick" :switches '((?s "Add Signed-off-by lines" "--signoff") (?e "Edit commit messages" "--edit") (?x "Reference cherry in commit message" "-x") (?F "Attempt fast-forward" "--ff")) :options '((?s "Strategy" "--strategy=") (?m "Replay merge relative to parent" "--mainline=")) :actions '("Apply here" (?A "Pick" magit-cherry-copy) (?a "Apply" magit-cherry-apply) (?h "Harvest" magit-cherry-harvest) "Apply elsewhere" (?d "Donate" magit-cherry-donate) (?n "Spinout" magit-cherry-spinout) (?s "Spinoff" magit-cherry-spinoff)) :sequence-actions '((?A "Continue" magit-sequencer-continue) (?s "Skip" magit-sequencer-skip) (?a "Abort" magit-sequencer-abort)) :sequence-predicate 'magit-sequencer-in-progress-p :default-arguments '("--ff")) (defun magit-cherry-pick-read-args (prompt) (list (or (nreverse (magit-region-values 'commit)) (magit-read-other-branch-or-commit prompt)) (magit-cherry-pick-arguments))) (defun magit--cherry-move-read-args (verb away fn) (declare (indent defun)) (let ((commits (or (nreverse (magit-region-values 'commit)) (list (funcall (if away 'magit-read-branch-or-commit 'magit-read-other-branch-or-commit) (format "%s cherry" (capitalize verb)))))) (current (magit-get-current-branch))) (unless current (user-error "Cannot %s cherries while HEAD is detached" verb)) (let ((reachable (magit-rev-ancestor-p (car commits) current)) (msg "Cannot %s cherries that %s reachable from HEAD")) (pcase (list away reachable) (`(nil t) (user-error msg verb "are")) (`(t nil) (user-error msg verb "are not")))) `(,commits ,@(funcall fn commits) ,(magit-cherry-pick-arguments)))) (defun magit--cherry-spinoff-read-args (verb) (magit--cherry-move-read-args verb t (lambda (commits) (butlast (magit-branch-read-args (format "Create branch from %s cherries" commits)))))) ;;;###autoload (defun magit-cherry-copy (commits &optional args) "Copy COMMITS from another branch onto the current branch. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then pick all of them, without prompting." (interactive (magit-cherry-pick-read-args "Cherry-pick")) (magit--cherry-pick commits args)) ;;;###autoload (defun magit-cherry-apply (commits &optional args) "Apply the changes in COMMITS but do not commit them. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then apply all of them, without prompting." (interactive (magit-cherry-pick-read-args "Apply changes from commit")) (magit--cherry-pick commits (cons "--no-commit" (remove "--ff" args)))) ;;;###autoload (defun magit-cherry-harvest (commits branch &optional args) "Move COMMITS from another BRANCH onto the current branch. Remove the COMMITS from BRANCH and stay on the current branch. If a conflict occurs, then you have to fix that and finish the process manually." (interactive (magit--cherry-move-read-args "harvest" nil (lambda (commits) (list (let ((branches (magit-list-containing-branches (car commits)))) (pcase (length branches) (0 nil) (1 (car branches)) (_ (magit-completing-read (format "Remove %s cherries from branch" (length commits)) branches nil t)))))))) (magit--cherry-move commits branch (magit-get-current-branch) args nil t)) ;;;###autoload (defun magit-cherry-donate (commits branch &optional args) "Move COMMITS from the current branch onto another existing BRANCH. Remove COMMITS from the current branch and stay on that branch. If a conflict occurs, then you have to fix that and finish the process manually." (interactive (magit--cherry-move-read-args "donate" t (lambda (commits) (list (magit-read-other-branch (format "Move %s cherries to branch" (length commits))))))) (magit--cherry-move commits (magit-get-current-branch) branch args)) ;;;###autoload (defun magit-cherry-spinout (commits branch start-point &optional args) "Move COMMITS from the current branch onto a new BRANCH. Remove COMMITS from the current branch and stay on that branch. If a conflict occurs, then you have to fix that and finish the process manually." (interactive (magit--cherry-spinoff-read-args "spinout")) (magit--cherry-move commits (magit-get-current-branch) branch args start-point)) ;;;###autoload (defun magit-cherry-spinoff (commits branch start-point &optional args) "Move COMMITS from the current branch onto a new BRANCH. Remove COMMITS from the current branch and checkout BRANCH. If a conflict occurs, then you have to fix that and finish the process manually." (interactive (magit--cherry-spinoff-read-args "spinoff")) (magit--cherry-move commits (magit-get-current-branch) branch args start-point t)) (defun magit--cherry-move (commits src dst args &optional start-point checkout-dst) (let ((current (magit-get-current-branch))) (unless (magit-branch-p dst) (let ((magit-process-raise-error t)) (magit-call-git "branch" dst start-point)) (--when-let (magit-get-indirect-upstream-branch start-point) (magit-call-git "branch" "--set-upstream-to" it dst))) (unless (equal dst current) (let ((magit-process-raise-error t)) (magit-call-git "checkout" dst))) (if (not src) ; harvest only (magit--cherry-pick commits args) (let ((tip (car (last commits))) (keep (concat (car commits) "^"))) (magit--cherry-pick commits 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) (cond ((magit-rev-equal tip src) (magit-call-git "update-ref" "-m" (format "reset: moving to %s" keep) (magit-ref-fullname src) keep tip) (if (not checkout-dst) (magit-run-git "checkout" src) (magit-refresh))) (t (magit-git "checkout" src) (let ((process-environment process-environment)) (push (format "%s=%s -i -ne '/^pick (%s)/ or print'" "GIT_SEQUENCE_EDITOR" magit-perl-executable (mapconcat #'magit-rev-abbrev commits "|")) process-environment) (magit-run-git-sequencer "rebase" "-i" keep)) (when checkout-dst (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 "checkout" dst)))))))))))))))) (defun magit--cherry-pick (commits args &optional revert) (let ((command (if revert "revert" "cherry-pick"))) (when (stringp commits) (setq commits (if (string-match-p "\\.\\." commits) (split-string commits "\\.\\.") (list commits)))) (magit-run-git-sequencer (if revert "revert" "cherry-pick") (pcase-let ((`(,merge ,non-merge) (-separate 'magit-merge-commit-p commits))) (cond ((not merge) (--remove (string-prefix-p "--mainline=" it) args)) (non-merge (user-error "Cannot %s merge and non-merge commits at once" command)) ((--first (string-prefix-p "--mainline=" it) args) args) (t (cons (format "--mainline=%s" (read-number "Replay merges relative to parent: ")) args)))) commits))) (defun magit-cherry-pick-in-progress-p () ;; .git/sequencer/todo does not exist when there is only one commit left. (file-exists-p (magit-git-dir "CHERRY_PICK_HEAD"))) ;;; Revert ;;;###autoload (autoload 'magit-revert-popup "magit-sequence" nil t) (magit-define-popup magit-revert-popup "Popup console for revert commands." :man-page "git-revert" :switches '((?s "Add Signed-off-by lines" "--signoff") (?e "Edit commit message" "--edit") (?E "Don't edit commit message" "--no-edit")) :options '((?s "Strategy" "--strategy=") (?S "Sign using gpg" "--gpg-sign=" magit-read-gpg-secret-key) (?m "Replay merge relative to parent" "--mainline=")) :actions '((?V "Revert commit(s)" magit-revert-and-commit) (?v "Revert changes" magit-revert-no-commit)) :sequence-actions '((?V "Continue" magit-sequencer-continue) (?s "Skip" magit-sequencer-skip) (?a "Abort" magit-sequencer-abort)) :sequence-predicate 'magit-sequencer-in-progress-p :default-arguments '("--edit")) (defun magit-revert-read-args (prompt) (list (or (magit-region-values 'commit) (magit-read-branch-or-commit prompt)) (magit-revert-arguments))) ;;;###autoload (defun magit-revert-and-commit (commit &optional args) "Revert COMMIT by creating a new commit. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting." (interactive (magit-revert-read-args "Revert commit")) (magit--cherry-pick commit args t)) ;;;###autoload (defun magit-revert-no-commit (commit &optional args) "Revert COMMIT by applying it in reverse to the worktree. Prompt for a commit, defaulting to the commit at point. If the region selects multiple commits, then revert all of them, without prompting." (interactive (magit-revert-read-args "Revert changes")) (magit--cherry-pick commit (cons "--no-commit" args) t)) (defun magit-revert-in-progress-p () ;; .git/sequencer/todo does not exist when there is only one commit left. (file-exists-p (magit-git-dir "REVERT_HEAD"))) ;;; Patch ;;;###autoload (autoload 'magit-am-popup "magit-sequence" nil t) (magit-define-popup magit-am-popup "Popup console for mailbox commands." :man-page "git-am" :switches '((?3 "Fall back on 3way merge" "--3way") (?s "Add Signed-off-by lines" "--signoff") (?c "Remove text before scissors line" "--scissors") (?k "Inhibit removal of email cruft" "--keep") (?b "Limit removal of email cruft" "--keep-non-patch") (?d "Use author date as committer date" "--committer-date-is-author-date") (?D "Use committer date as author date" "--ignore-date")) :options '((?p "Remove leading slashes from paths" "-p" magit-read-number-string)) :actions '((?m "Apply maildir" magit-am-apply-maildir) (?w "Apply patches" magit-am-apply-patches) (?a "Apply plain patch" magit-patch-apply-popup)) :default-arguments '("--3way") :default-actions 'magit-am-apply-patches :max-action-columns 1 :sequence-actions '((?w "Continue" magit-am-continue) (?s "Skip" magit-am-skip) (?a "Abort" magit-am-abort)) :sequence-predicate 'magit-am-in-progress-p) ;;;###autoload (defun magit-am-apply-patches (&optional files args) "Apply the patches FILES." (interactive (list (or (magit-region-values 'file) (list (let ((default (magit-file-at-point))) (read-file-name (if default (format "Apply patch (%s): " default) "Apply patch: ") nil default)))) (magit-am-arguments))) (magit-run-git-sequencer "am" args "--" (--map (magit-convert-filename-for-git (expand-file-name it)) files))) ;;;###autoload (defun magit-am-apply-maildir (&optional maildir args) "Apply the patches from MAILDIR." (interactive (list (read-file-name "Apply mbox or Maildir: ") (magit-am-arguments))) (magit-run-git-sequencer "am" args (magit-convert-filename-for-git (expand-file-name maildir)))) ;;;###autoload (defun magit-am-continue () "Resume the current patch applying sequence." (interactive) (if (magit-am-in-progress-p) (if (magit-anything-unstaged-p t) (error "Cannot continue due to unstaged changes") (magit-run-git-sequencer "am" "--continue")) (user-error "Not applying any patches"))) ;;;###autoload (defun magit-am-skip () "Skip the stopped at patch during a patch applying sequence." (interactive) (if (magit-am-in-progress-p) (magit-run-git-sequencer "am" "--skip") (user-error "Not applying any patches"))) ;;;###autoload (defun magit-am-abort () "Abort the current patch applying sequence. This discards all changes made since the sequence started." (interactive) (if (magit-am-in-progress-p) (magit-run-git "am" "--abort") (user-error "Not applying any patches"))) (defun magit-am-in-progress-p () (file-exists-p (magit-git-dir "rebase-apply/applying"))) ;;; Rebase ;;;###autoload (autoload 'magit-rebase-popup "magit-sequence" nil t) (magit-define-popup magit-rebase-popup "Key menu for rebasing." :man-page "git-rebase" :switches '((?k "Keep empty commits" "--keep-empty") (?p "Preserve merges" "--preserve-merges") (?c "Lie about committer date" "--committer-date-is-author-date") (?a "Autosquash" "--autosquash") (?A "Autostash" "--autostash") (?i "Interactive" "--interactive") (?h "Disable hooks" "--no-verify")) :actions '((lambda () (concat (propertize "Rebase " 'face 'magit-popup-heading) (propertize (or (magit-get-current-branch) "HEAD") 'face 'magit-branch-local) (propertize " onto" 'face 'magit-popup-heading))) (?p (lambda () (--when-let (magit-get-push-branch) (concat it "\n"))) magit-rebase-onto-pushremote) (?u (lambda () (--when-let (magit-get-upstream-branch) (concat it "\n"))) magit-rebase-onto-upstream) (?e "elsewhere" magit-rebase-branch) "Rebase" (?i "interactively" magit-rebase-interactive) (?m "to modify a commit" magit-rebase-edit-commit) (?s "a subset" magit-rebase-subset) (?w "to reword a commit" magit-rebase-reword-commit) nil (?k "to remove a commit" magit-rebase-remove-commit) nil (?f "to autosquash" magit-rebase-autosquash)) :sequence-actions '((?r "Continue" magit-rebase-continue) (?s "Skip" magit-rebase-skip) (?e "Edit" magit-rebase-edit) (?a "Abort" magit-rebase-abort)) :sequence-predicate 'magit-rebase-in-progress-p :max-action-columns 2) (defun magit-git-rebase (target args) (magit-run-git-sequencer "rebase" target args)) ;;;###autoload (defun magit-rebase-onto-pushremote (args) "Rebase the current branch onto `branch..pushRemote'. If that variable is unset, then rebase onto `remote.pushDefault'." (interactive (list (magit-rebase-arguments))) (--if-let (magit-get-current-branch) (if-let ((remote (magit-get-push-remote it))) (if (member remote (magit-list-remotes)) (magit-git-rebase (concat remote "/" it) args) (user-error "Remote `%s' doesn't exist" remote)) (user-error "No push-remote is configured for %s" it)) (user-error "No branch is checked out"))) ;;;###autoload (defun magit-rebase-onto-upstream (args) "Rebase the current branch onto its upstream branch." (interactive (list (magit-rebase-arguments))) (--if-let (magit-get-current-branch) (if-let ((target (magit-get-upstream-branch it))) (magit-git-rebase target args) (user-error "No upstream is configured for %s" it)) (user-error "No branch is checked out"))) ;;;###autoload (defun magit-rebase-branch (target args) "Rebase the current branch onto a branch read in the minibuffer. All commits that are reachable from `HEAD' but not from the selected branch TARGET are being rebased." (interactive (list (magit-read-other-branch-or-commit "Rebase onto") (magit-rebase-arguments))) (message "Rebasing...") (magit-git-rebase target args) (message "Rebasing...done")) ;;;###autoload (defun magit-rebase-subset (newbase start args) "Rebase a subset of the current branch's history onto a new base. Rebase commits from START to `HEAD' onto NEWBASE. START has to be selected from a list of recent commits." (interactive (list (magit-read-other-branch-or-commit "Rebase subset onto" nil (magit-get-upstream-branch)) nil (magit-rebase-arguments))) (if start (progn (message "Rebasing...") (magit-run-git-sequencer "rebase" "--onto" newbase start args) (message "Rebasing...done")) (magit-log-select `(lambda (commit) (magit-rebase-subset ,newbase (concat commit "^") (list ,@args))) (concat "Type %p on a commit to rebase it " "and commits above it onto " newbase ",")))) (defun magit-rebase-interactive-1 (commit args message &optional editor delay-edit-confirm noassert confirm) (declare (indent 2)) (when commit (if (eq commit :merge-base) (setq commit (--if-let (magit-get-upstream-branch) (magit-git-string "merge-base" it "HEAD") nil)) (unless (magit-rev-ancestor-p commit "HEAD") (user-error "%s isn't an ancestor of HEAD" commit)) (if (magit-commit-parents commit) (setq commit (concat commit "^")) (setq args (cons "--root" args))))) (when (and commit (not noassert)) (setq commit (magit-rebase-interactive-assert commit delay-edit-confirm))) (if (and commit (not confirm)) (let ((process-environment process-environment)) (when editor (push (concat "GIT_SEQUENCE_EDITOR=" editor) process-environment)) (magit-run-git-sequencer "rebase" "-i" args (unless (member "--root" args) commit))) (magit-log-select `(lambda (commit) (magit-rebase-interactive-1 commit (list ,@args) ,message ,editor ,delay-edit-confirm ,noassert)) message))) (defvar magit--rebase-published-symbol nil) (defvar magit--rebase-public-edit-confirmed nil) (defun magit-rebase-interactive-assert (since &optional delay-edit-confirm) (let* ((commit (if (string-suffix-p "^" since) ;; If SINCE is "REV^", then the user selected ;; "REV", which is the first commit that will ;; be replaced. (from^..to] <=> [from..to]. (substring since 0 -1) ;; The "--root" argument is being used. since)) (branches (magit-list-publishing-branches commit))) (setq magit--rebase-public-edit-confirmed (delete (magit-toplevel) magit--rebase-public-edit-confirmed)) (when (and branches (or (not delay-edit-confirm) ;; The user might have stopped at a published commit ;; merely to add new commits *after* it. Try not to ;; ask users whether they really want to edit public ;; commits, when they don't actually intend to do so. (not (--all-p (magit-rev-equal it commit) branches)))) (let ((m1 "Some of these commits have already been published to ") (m2 ".\nDo you really want to modify them")) (magit-confirm (or magit--rebase-published-symbol 'rebase-published) (concat m1 "%s" m2) (concat m1 "%i public branches" m2) nil branches)) (push (magit-toplevel) magit--rebase-public-edit-confirmed))) (if (magit-git-lines "rev-list" "--merges" (concat since "..HEAD")) (magit-read-char-case "Proceed despite merge in rebase range? " nil (?c "[c]ontinue" since) (?s "[s]elect other" nil) (?a "[a]bort" (user-error "Quit"))) since)) ;;;###autoload (defun magit-rebase-interactive (commit args) "Start an interactive rebase sequence." (interactive (list (magit-commit-at-point) (magit-rebase-arguments))) (magit-rebase-interactive-1 commit args "Type %p on a commit to rebase it and all commits above it," nil t)) ;;;###autoload (defun magit-rebase-autosquash (args) "Combine squash and fixup commits with their intended targets." (interactive (list (magit-rebase-arguments))) (magit-rebase-interactive-1 :merge-base (cons "--autosquash" args) "Type %p on a commit to squash into it and then rebase as necessary," "true" nil t)) ;;;###autoload (defun magit-rebase-edit-commit (commit args) "Edit a single older commit using rebase." (interactive (list (magit-commit-at-point) (magit-rebase-arguments))) (magit-rebase-interactive-1 commit args "Type %p on a commit to edit it," (concat magit-perl-executable " -i -p -e '++$x if not $x and s/^pick/edit/'") t)) ;;;###autoload (defun magit-rebase-reword-commit (commit args) "Reword a single older commit using rebase." (interactive (list (magit-commit-at-point) (magit-rebase-arguments))) (magit-rebase-interactive-1 commit args "Type %p on a commit to reword its message," (concat magit-perl-executable " -i -p -e '++$x if not $x and s/^pick/reword/'"))) ;;;###autoload (defun magit-rebase-remove-commit (commit args) "Remove a single older commit using rebase." (interactive (list (magit-commit-at-point) (magit-rebase-arguments))) (magit-rebase-interactive-1 commit args "Type %p on a commit to remove it," (concat magit-perl-executable " -i -p -e '++$x if not $x and s/^pick/# pick/'") nil nil t)) ;;;###autoload (defun magit-rebase-continue (&optional noedit) "Restart the current rebasing operation. In some cases this pops up a commit message buffer for you do edit. With a prefix argument the old message is reused as-is." (interactive "P") (if (magit-rebase-in-progress-p) (if (magit-anything-unstaged-p t) (user-error "Cannot continue rebase with unstaged changes") (when (and (magit-anything-staged-p) (file-exists-p (magit-git-dir "rebase-merge")) (not (member (magit-toplevel) magit--rebase-public-edit-confirmed))) (magit-commit-amend-assert)) (if noedit (let ((process-environment process-environment)) (push "GIT_EDITOR=true" process-environment) (magit-run-git-async (magit--rebase-resume-command) "--continue") (set-process-sentinel magit-this-process #'magit-sequencer-process-sentinel) magit-this-process) (magit-run-git-sequencer (magit--rebase-resume-command) "--continue"))) (user-error "No rebase in progress"))) ;;;###autoload (defun magit-rebase-skip () "Skip the current commit and restart the current rebase operation." (interactive) (unless (magit-rebase-in-progress-p) (user-error "No rebase in progress")) (magit-run-git-sequencer (magit--rebase-resume-command) "--skip")) ;;;###autoload (defun magit-rebase-edit () "Edit the todo list of the current rebase operation." (interactive) (unless (magit-rebase-in-progress-p) (user-error "No rebase in progress")) (magit-run-git-sequencer "rebase" "--edit-todo")) ;;;###autoload (defun magit-rebase-abort () "Abort the current rebase operation, restoring the original branch." (interactive) (unless (magit-rebase-in-progress-p) (user-error "No rebase in progress")) (magit-confirm 'abort-rebase "Abort this rebase") (magit-run-git (magit--rebase-resume-command) "--abort")) (defun magit-rebase-in-progress-p () "Return t if a rebase is in progress." (or (file-exists-p (magit-git-dir "rebase-merge")) (file-exists-p (magit-git-dir "rebase-apply/onto")))) (defun magit--rebase-resume-command () (if (file-exists-p (magit-git-dir "rebase-recursive")) "rbr" "rebase")) ;;; Sections (defun magit-insert-sequencer-sequence () "Insert section for the on-going cherry-pick or revert sequence. If no such sequence is in progress, do nothing." (let ((picking (magit-cherry-pick-in-progress-p))) (when (or picking (magit-revert-in-progress-p)) (magit-insert-section (sequence) (magit-insert-heading (if picking "Cherry Picking" "Reverting")) (when-let ((lines (cdr (magit-file-lines (magit-git-dir "sequencer/todo"))))) (dolist (line (nreverse lines)) (when (string-match "^\\(pick\\|revert\\) \\([^ ]+\\) \\(.*\\)$" line) (magit-bind-match-strings (cmd hash msg) line (magit-insert-section (commit hash) (insert (propertize cmd 'face 'magit-sequence-pick) " " (propertize hash 'face 'magit-hash) " " msg "\n")))))) (magit-sequence-insert-sequence (magit-file-line (magit-git-dir (if picking "CHERRY_PICK_HEAD" "REVERT_HEAD"))) (magit-file-line (magit-git-dir "sequencer/head"))) (insert "\n"))))) (defun magit-insert-am-sequence () "Insert section for the on-going patch applying sequence. If no such sequence is in progress, do nothing." (when (magit-am-in-progress-p) (magit-insert-section (rebase-sequence) (magit-insert-heading "Applying patches") (let ((patches (nreverse (magit-rebase-patches))) patch commit) (while patches (setq patch (pop patches)) (setq commit (magit-rev-verify-commit (cadr (split-string (magit-file-line patch))))) (cond ((and commit patches) (magit-sequence-insert-commit "pick" commit 'magit-sequence-pick)) (patches (magit-sequence-insert-am-patch "pick" patch 'magit-sequence-pick)) (commit (magit-sequence-insert-sequence commit "ORIG_HEAD")) (t (magit-sequence-insert-am-patch "stop" patch 'magit-sequence-stop) (magit-sequence-insert-sequence nil "ORIG_HEAD"))))) (insert ?\n)))) (defun magit-sequence-insert-am-patch (type patch face) (magit-insert-section (file patch) (let ((title (with-temp-buffer (insert-file-contents patch nil nil 4096) (unless (re-search-forward "^Subject: " nil t) (goto-char (point-min))) (buffer-substring (point) (line-end-position))))) (insert (propertize type 'face face) ?\s (propertize (file-name-nondirectory patch) 'face 'magit-hash) ?\s title ?\n)))) (defun magit-insert-rebase-sequence () "Insert section for the on-going rebase sequence. If no such sequence is in progress, do nothing." (when (magit-rebase-in-progress-p) (let* ((interactive (file-directory-p (magit-git-dir "rebase-merge"))) (dir (if interactive "rebase-merge/" "rebase-apply/")) (name (-> (concat dir "head-name") magit-git-dir magit-file-line)) (onto (-> (concat dir "onto") magit-git-dir magit-file-line)) (onto (or (magit-rev-name onto name) (magit-rev-name onto "refs/heads/*") onto)) (name (or (magit-rev-name name "refs/heads/*") name))) (magit-insert-section (rebase-sequence) (magit-insert-heading (format "Rebasing %s onto %s" name onto)) (if interactive (magit-rebase-insert-merge-sequence onto) (magit-rebase-insert-apply-sequence onto)) (insert ?\n))))) (defun magit-rebase-insert-merge-sequence (onto) (let (exec) (dolist (line (nreverse (magit-file-lines (magit-git-dir "rebase-merge/git-rebase-todo")))) (cond ((string-prefix-p "exec" line) (setq exec (substring line 5))) ((string-match (format "^\\([^%c ]+\\) \\([^ ]+\\) .*$" (string-to-char (or (magit-get "core.commentChar") "#"))) line) (magit-bind-match-strings (action hash) line (unless (equal action "exec") (magit-sequence-insert-commit action hash 'magit-sequence-pick exec))) (setq exec nil))))) (magit-sequence-insert-sequence (magit-file-line (magit-git-dir "rebase-merge/stopped-sha")) onto (--when-let (magit-file-lines (magit-git-dir "rebase-merge/done")) (cadr (split-string (car (last it))))))) (defun magit-rebase-insert-apply-sequence (onto) (let ((rewritten (--map (car (split-string it)) (magit-file-lines (magit-git-dir "rebase-apply/rewritten")))) (stop (magit-file-line (magit-git-dir "rebase-apply/original-commit")))) (dolist (patch (nreverse (cdr (magit-rebase-patches)))) (let ((hash (cadr (split-string (magit-file-line patch))))) (unless (or (member hash rewritten) (equal hash stop)) (magit-sequence-insert-commit "pick" hash 'magit-sequence-pick))))) (magit-sequence-insert-sequence (magit-file-line (magit-git-dir "rebase-apply/original-commit")) onto)) (defun magit-rebase-patches () (directory-files (magit-git-dir "rebase-apply") t "^[0-9]\\{4\\}$")) (defun magit-sequence-insert-sequence (stop onto &optional orig) (let ((head (magit-rev-parse "HEAD")) done) (setq onto (if onto (magit-rev-parse onto) head)) (setq done (magit-git-lines "log" "--format=%H" (concat onto "..HEAD"))) (when (and stop (not (member stop done))) (let ((id (magit-patch-id stop))) (--if-let (--first (equal (magit-patch-id it) id) done) (setq stop it) (cond ((--first (magit-rev-equal it stop) done) ;; The commit's testament has been executed. (magit-sequence-insert-commit "void" stop 'magit-sequence-drop)) ;; The faith of the commit is still undecided... ((magit-anything-unmerged-p) ;; ...and time travel isn't for the faint of heart. (magit-sequence-insert-commit "join" stop 'magit-sequence-part)) ((magit-anything-modified-p t) ;; ...and the dust hasn't settled yet... (magit-sequence-insert-commit (let* ((magit--refresh-cache nil) (staged (magit-commit-tree "oO" nil "HEAD")) (unstaged (magit-commit-worktree "oO" "--reset"))) (cond ;; ...but we could end up at the same tree just by committing. ((or (magit-rev-equal staged stop) (magit-rev-equal unstaged stop)) "goal") ;; ...but the changes are still there, untainted. ((or (equal (magit-patch-id staged) id) (equal (magit-patch-id unstaged) id)) "same") ;; ...and some changes are gone and/or others were added. (t "work"))) stop 'magit-sequence-part)) ;; The commit is definitely gone... ((--first (magit-rev-equal it stop) done) ;; ...but all of its changes are still in effect. (magit-sequence-insert-commit "poof" stop 'magit-sequence-drop)) (t ;; ...and some changes are gone and/or other changes were added. (magit-sequence-insert-commit "gone" stop 'magit-sequence-drop))) (setq stop nil)))) (dolist (rev done) (apply 'magit-sequence-insert-commit (cond ((equal rev stop) ;; ...but its reincarnation lives on. ;; Or it didn't die in the first place. (list (if (and (equal rev head) (equal (magit-patch-id rev) (magit-patch-id orig))) "stop" ; We haven't done anything yet. "like") ; There are new commits. rev (if (equal rev head) 'magit-sequence-head 'magit-sequence-stop))) ((equal rev head) (list "done" rev 'magit-sequence-head)) (t (list "done" rev 'magit-sequence-done))))) (magit-sequence-insert-commit "onto" onto (if (equal onto head) 'magit-sequence-head 'magit-sequence-onto)))) (defun magit-sequence-insert-commit (type hash face &optional exec) (magit-insert-section (commit hash) (magit-insert-heading (propertize type 'face face) "\s" (magit-format-rev-summary hash) "\n") (when exec (insert (propertize "exec" 'face 'magit-sequence-onto) "\s" exec "\n")))) ;;; _ (provide 'magit-sequence) ;;; magit-sequence.el ends here magit-2.90.1/lisp/magit-stash.el000066400000000000000000000473141337354740400164410ustar00rootroot00000000000000;;; magit-stash.el --- stash support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (defvar bookmark-make-record-function) ;;; 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 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. 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-popup "magit-stash" nil t) (magit-define-popup magit-stash-popup "Popup console for stash commands." :man-page "git-stash" :switches '((?u "Also save untracked files" "--include-untracked") (?a "Also save untracked and ignored files" "--all")) :actions '((?z "Save" magit-stash-both) (?Z "Snapshot" magit-snapshot-both) (?p "Pop" magit-stash-pop) (?i "Save index" magit-stash-index) (?I "Snapshot index" magit-snapshot-index) (?a "Apply" magit-stash-apply) (?w "Save worktree" magit-stash-worktree) (?W "Snapshot worktree" magit-snapshot-worktree) (?l "List" magit-stash-list) (?x "Save keeping index" magit-stash-keep-index) (?r "Snapshot to wipref" magit-wip-commit) (?v "Show" magit-stash-show) (?b "Branch" magit-stash-branch) (?k "Drop" magit-stash-drop) nil (?B "Branch here" magit-stash-branch-here) nil nil (?f "Format patch" magit-stash-format-patch)) :default-action 'magit-stash :max-action-columns 3) ;;;###autoload (defun magit-stash-both (message &optional include-untracked) "Create a stash of the index and working tree. Untracked files are included according to popup 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 popup 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 popup 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 popup 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 popup 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 t 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', using the current branch or `HEAD' as the string-point." (interactive (list (magit-read-stash "Branch stash") (magit-read-string-ns "Branch name"))) (let ((inhibit-magit-refresh t)) (magit-branch-create 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" '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-mode-setup #'magit-stashes-mode "refs/stash")) (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) (setq-local bookmark-make-record-function #'magit-bookmark--stashes-make-record)) (cl-defun magit-stashes-refresh-buffer (ref) (magit-insert-section (stashesbuf) (magit-insert-heading (if (equal ref "refs/stash") "Stashes:" (format "Stashes [%s]:" ref))) (magit-git-wash (apply-partially 'magit-log-wash-log 'stash) "reflog" "--format=%gd%x00%aN%x00%at%x00%gs" ref))) ;;; 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))) (list (delete "--stat" args) files)))) (magit-mode-setup #'magit-stash-mode stash nil 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) (setq-local bookmark-make-record-function #'magit-bookmark--stash-make-record)) (defun magit-stash-refresh-buffer (stash _const _args _files) (magit-set-header-line-format (concat (propertize (capitalize stash) 'face 'magit-section-heading) " " (magit-rev-format "%s" stash))) (setq magit-buffer-revision-hash (magit-rev-parse stash)) (magit-insert-section (stash) (magit-run-section-hook 'magit-stash-sections-hook))) (defun magit-stash-insert-section (commit range message &optional files) (magit-insert-section (commit commit) (magit-insert-heading message) (magit-git-wash #'magit-diff-wash-diffs "diff" range "-p" "--no-prefix" (nth 2 magit-refresh-args) "--" (or files (nth 3 magit-refresh-args))))) (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" (car magit-refresh-args)) (if (= (point) (oref section content)) (magit-cancel-section) (insert "\n")))) (defun magit-insert-stash-index () "Insert section showing staged changes of the stash." (let ((stash (car magit-refresh-args))) (magit-stash-insert-section (format "%s^2" stash) (format "%s^..%s^2" stash stash) "Staged"))) (defun magit-insert-stash-worktree () "Insert section showing unstaged changes of the stash." (let ((stash (car magit-refresh-args))) (magit-stash-insert-section stash (format "%s^2..%s" stash stash) "Unstaged"))) (defun magit-insert-stash-untracked () "Insert section showing the untracked files commit of the stash." (let ((stash (car magit-refresh-args)) (rev (concat (car magit-refresh-args) "^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 magit-2.90.1/lisp/magit-status.el000066400000000000000000000624761337354740400166500ustar00rootroot00000000000000;;; magit-status.el --- the grand overview -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (defvar bookmark-make-record-function) ;;; 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 burried, 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-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 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. 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-internal directory)) ;;;###autoload (defun magit-status (&optional directory cache) "Show the status of the current Git repository in a buffer. With a prefix argument prompt for a repository to be shown. With two prefix arguments prompt for an arbitrary directory. If that directory isn't the root of an existing repository, then offer to initialize it as a new repository." (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-internal 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 will invalidate cached ;; values. (setq magit--refresh-cache nil) (magit-init directory)))) (magit-status-internal default-directory)))) (put 'magit-status 'interactive-only 'magit-status-internal) (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-internal (directory) (magit--tramp-asserts directory) (let ((default-directory directory)) (magit-mode-setup #'magit-status-mode))) (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 [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'. \\\ 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-popup] to see available prefix popups. Staging and applying changes is documented in info node `(magit)Staging and Unstaging' and info node `(magit)Applying'. \\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. \\\ Type \\[magit-commit-popup] 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) (setq-local bookmark-make-record-function #'magit-bookmark--status-make-record)) (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-log-maybe-update-revision-buffer-1))) (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-log-maybe-update-blob-buffer-1))) ;;; 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 occured. 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! ") 'face 'magit-section-heading)) (insert (propertize magit-this-error '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-diff-section-file-args) (insert (propertize (format "%-10s" "Filter! ") 'face 'magit-section-heading)) (when ignore-modules (insert ignore-modules) (when magit-diff-section-file-args (insert " -- "))) (when magit-diff-section-file-args (insert (mapconcat #'identity magit-diff-section-file-args " "))) (insert ?\n)))) ;;;; Reference Headers (cl-defun magit-insert-head-branch-header (&optional (branch (magit-get-current-branch))) "Insert a header line about BRANCH. When BRANCH is nil, use the current branch or, if none, the detached `HEAD'." (let ((output (magit-rev-format "%h %s" (or branch "HEAD")))) (string-match "^\\([^ ]+\\) \\(.*\\)" output) (magit-bind-match-strings (commit summary) output (if branch (magit-insert-section (branch branch) (insert (format "%-10s" "Head: ")) (when magit-status-show-hashes-in-headers (insert (propertize commit 'face 'magit-hash) ?\s)) (insert (propertize branch '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 'face 'magit-hash)) (insert ?\s summary ?\n)))))) (cl-defun magit-insert-upstream-branch-header (&optional (branch (magit-get-current-branch)) (pull (magit-get-upstream-branch branch)) keyword) "Insert a header line about branch usually pulled into current branch." (when pull (magit-insert-section (branch pull) (let ((rebase (magit-get "branch" branch "rebase"))) (pcase rebase ("true") ("false" (setq rebase nil)) (_ (setq rebase (magit-get-boolean "pull.rebase")))) (insert (format "%-10s" (or keyword (if rebase "Rebase: " "Merge: "))))) (--when-let (and magit-status-show-hashes-in-headers (not (string-match-p " " pull)) (magit-rev-format "%h" pull)) (insert (propertize it 'face 'magit-hash) " ")) (if (string-match-p " " pull) (pcase-let ((`(,url ,branch) (split-string pull " "))) (insert branch " from " url " ")) (insert pull " ") (--if-let (and (magit-rev-verify pull) (magit-rev-format "%s" pull)) (insert (funcall magit-log-format-message-function pull it)) (insert (propertize "is missing" 'face 'font-lock-warning-face)))) (insert ?\n)))) (cl-defun magit-insert-push-branch-header (&optional (branch (magit-get-current-branch)) (push (magit-get-push-branch branch))) "Insert a header line about the branch the current branch is pushed to." (when push (magit-insert-section (branch push) (insert (format "%-10s" "Push: ")) (--when-let (and magit-status-show-hashes-in-headers (magit-rev-format "%h" push)) (insert (propertize it 'face 'magit-hash) ?\s)) (insert (propertize push 'face 'magit-branch-remote) ?\s) (--if-let (and (magit-rev-verify push) (magit-rev-format "%s" push)) (insert (funcall magit-log-format-message-function push it)) (insert (propertize "is missing" '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 'face 'magit-tag) (and (> count 0) (format " (%s)" (propertize (format "%s" count) '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 '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 '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-diff-section-arguments' is a directory, then limit the list to files below that. The value value of that variable can be set using \"D = f DIRECTORY RET g\"." (let* ((show (or (magit-get "status.showUntrackedFiles") "normal")) (base (car magit-diff-section-file-args)) (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 '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-diff-section-arguments' is a directory, then limit the list to files below that. The value value of that variable can be set using \"D = f DIRECTORY RET g\"." (when-let ((files (magit-list-files))) (let* ((base (car magit-diff-section-file-args)) (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-diff-section-arguments' is a directory, then limit the list to files below that. The value of that variable can be set using \"D = f DIRECTORY RET g\"." (when-let ((files (magit-ignored-files))) (let* ((base (car magit-diff-section-file-args)) (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))))) (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 '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 magit-2.90.1/lisp/magit-submodule.el000066400000000000000000000663671337354740400173270ustar00rootroot00000000000000;;; magit-submodule.el --- submodule support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2011-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) (defvar bookmark-make-record-function) ;;; 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) ("BU" 3 magit-repolist-column-unpushed-to-upstream ((:right-align t))) ("BP" 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-popup "magit-submodule" nil t) (magit-define-popup magit-submodule-popup "Popup console for submodule commands." :man-page "git-submodule" :switches '((?f "Force" "--force") (?r "Recursive" "--recursive") (?N "Do not fetch" "--no-fetch") (?C "Checkout tip" "--checkout") (?R "Rebase onto tip" "--rebase") (?M "Merge tip" "--merge") (?U "Use upstream tip" "--remote")) :actions '((?a "Add git submodule add [--force]" magit-submodule-add) (?r "Register git submodule init" magit-submodule-register) (?p "Populate git submodule update --init" magit-submodule-populate) (?u "Update git submodule update [--force] [--no-fetch] [--remote] [--recursive] [--checkout|--rebase|--merge]" magit-submodule-update) (?s "Synchronize git submodule sync [--recursive]" magit-submodule-synchronize) (?d "Unpopulate git submodule deinit [--force]" magit-submodule-unpopulate) (?k "Remove" magit-submodule-remove) nil (?l "List all modules" magit-list-submodules) (?f "Fetch all modules" magit-fetch-modules)) :max-action-columns 1) (defun magit-submodule-filtered-arguments (&rest filters) (--filter (and (member it filters) it) (magit-submodule-arguments))) ;;;###autoload (defun 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." (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-filtered-arguments "--force"))))) (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 (defun 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. (interactive (list (magit-module-confirm "Register" 'magit-module-no-worktree-p))) (magit-with-toplevel (magit-run-git-async "submodule" "init" "--" modules))) ;;;###autoload (defun 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. (interactive (list (magit-module-confirm "Populate" 'magit-module-no-worktree-p))) (magit-with-toplevel (magit-run-git-async "submodule" "update" "--init" "--" modules))) ;;;###autoload (defun 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. (interactive (list (magit-module-confirm "Update" 'magit-module-worktree-p) (magit-submodule-filtered-arguments "--force" "--remote" "--recursive" "--checkout" "--rebase" "--merge" "--no-fetch"))) (magit-with-toplevel (magit-run-git-async "submodule" "update" args "--" modules))) ;;;###autoload (defun 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." (interactive (list (magit-module-confirm "Synchronize" 'magit-module-worktree-p) (magit-submodule-filtered-arguments "--recursive"))) (magit-with-toplevel (magit-run-git-async "submodule" "sync" args "--" modules))) ;;;###autoload (defun 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. (interactive (list (magit-module-confirm "Unpopulate") (magit-submodule-filtered-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-filtered-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 section (modules nil t) (magit-insert-heading (format "%s (%s)" (propertize "Modules" 'face 'magit-section-heading) (length modules))) (if (oref section hidden) (oset section washer 'magit--insert-modules) (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 section (modules nil t) (magit-insert-heading (format "%s (%s)" (propertize "Modules overview" 'face 'magit-section-heading) (length modules))) (if (oref section hidden) (oset section washer 'magit--insert-modules-overview) (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) '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 'face 'magit-branch-local) (propertize "(detached)" '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 'face 'magit-tag))) (--when-let (magit-rev-format "%h") (insert (propertize it '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) 'face 'magit-section-heading) " " (propertize (match-string 2 heading) '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 '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-mode-get-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 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) (setq-local bookmark-make-record-function #'magit-bookmark--submodules-make-record)) (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 magit-2.90.1/lisp/magit-subtree.el000066400000000000000000000133511337354740400167620ustar00rootroot00000000000000;;; magit-subtree.el --- subtree support for Magit -*- lexical-binding: t -*- ;; Copyright (C) 2011-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Popup ;;;###autoload (autoload 'magit-subtree-popup "magit-subtree" nil t) (magit-define-popup magit-subtree-popup "Popup console for subtree commands." :man-page "git-subtree" :switches '("Switches for add, merge, push, and pull" (?s "Squash" "--squash") "Switches for split" (?i "Ignore joins" "--ignore-joins") (?j "Rejoin" "--rejoin")) :options '("Options" (?p "Prefix" "--prefix=" magit-subtree-read-prefix) "Options for add, merge, and pull" (?m "Message" "--message=") "Options for split" (?a "Annotate" "--annotate=") (?b "Branch" "--branch=") (?o "Onto" "--onto=" magit-read-branch-or-commit)) :actions '((?a "Add" magit-subtree-add) (?m "Merge" magit-subtree-merge) (?p "Push" magit-subtree-push) (?c "Add commit" magit-subtree-add-commit) (?f "Pull" magit-subtree-pull) (?s "Split" magit-subtree-split)) :max-action-columns 3) (defun magit-subtree-read-prefix (prompt &optional default) (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))) ;;; Commands (defun magit-subtree-prefix (prompt) (--if-let (--first (string-prefix-p "--prefix=" it) (magit-subtree-arguments)) (substring it 9) (magit-subtree-read-prefix prompt))) (defun magit-subtree-args () (-filter (lambda (arg) (if (eq this-command 'magit-subtree-split) (or (equal arg "--ignore-joins") (equal arg "--rejoin") (string-prefix-p "--annotate=" arg) (string-prefix-p "--branch=" arg) (string-prefix-p "--onto=" arg)) (or (equal arg "--squash") (and (string-prefix-p "--message=" arg) (not (eq this-command 'magit-subtree-push)))))) (magit-subtree-arguments))) (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 "Add subtree") (let ((remote (magit-read-remote-or-url "From repository"))) (list remote (magit-read-refspec "Ref" remote) (magit-subtree-args))))) (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 "Add subtree") (magit-read-string-ns "Commit") (magit-subtree-args))) (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 "Merge into subtree") (magit-read-string-ns "Commit") (magit-subtree-args))) (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 "Pull into subtree") (let ((remote (magit-read-remote-or-url "From repository"))) (list remote (magit-read-refspec "Ref" remote) (magit-subtree-args))))) (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 "Push subtree") (magit-read-remote-or-url "To repository") (magit-read-string-ns "To reference") (magit-subtree-args))) (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 "Split subtree") (magit-read-string-ns "Commit") (magit-subtree-args))) (magit-git-subtree "split" prefix args commit)) ;;; _ (provide 'magit-subtree) ;;; magit-subtree.el ends here magit-2.90.1/lisp/magit-tag.el000066400000000000000000000117301337354740400160630ustar00rootroot00000000000000;;; magit-tag.el --- tag functionality -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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-popup "magit" nil t) (magit-define-popup magit-tag-popup "Popup console for tag commands." :man-page "git-tag" :switches '((?a "Annotate" "--annotate") (?f "Force" "--force") (?s "Sign" "--sign")) :options '((?f "Sign" "--local-user=" magit-read-gpg-secret-key)) :actions '((?t "Create" magit-tag-create) (?k "Delete" magit-tag-delete) (?p "Prune" magit-tag-prune)) :default-action 'magit-tag-create) ;;;###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)))) ;;;###autoload (defun magit-tag-release (tag) "Create an opinionated release tag. Assume version tags that match \"\\\\`v?[0-9]\\\\(\\\\.[0-9]\\\\)*\\\\'\". Prompt for the name of the new tag using the highest existing tag as initial input and call \"git tag --annotate --sign -m MSG\" TAG, regardless of whether these arguments are enabled in the popup. Given a TAG \"v1.2.3\" and a repository \"/path/to/foo-bar\", the MESSAGE would be \"Foo-Bar 1.2.3\". Because it is so opinionated, this command is not available from the tag popup by default." (interactive (list (read-string "Create tag: " (car (nreverse (cl-sort (magit-list-tags) #'version< :key (lambda (tag) (if (string-prefix-p "v" tag) (substring tag 1) tag)))))))) (magit-run-git "tag" "--annotate" "--sign" "-m" (format "%s %s" (capitalize (file-name-nondirectory (directory-file-name (magit-toplevel)))) (if (string-prefix-p "v" tag) (substring tag 1) tag)) tag) (magit-show-refs)) ;;; _ (provide 'magit-tag) ;;; magit-tag.el ends here magit-2.90.1/lisp/magit-utils.el000066400000000000000000001305201337354740400164470ustar00rootroot00000000000000;;; magit-utils.el --- various utilities -*- lexical-binding: t; coding: utf-8 -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; Contains code from GNU Emacs https://www.gnu.org/software/emacs, ;; released under the GNU General Public License version 3 or later. ;; 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 several utility functions used by several ;; other libraries which cannot depend on one another (because ;; circular dependencies are not good). Luckily most (all) of these ;; functions have very little (nothing) to do with Git, so we not only ;; have to do this, it even makes sense. ;; Unfortunately there are also some options which are used by several ;; libraries which cannot depend on one another, they are defined here ;; too. ;;; Code: (require 'cl-lib) (require 'dash) (eval-when-compile (require 'subr-x)) (require 'crm) (eval-when-compile (require 'ido)) (declare-function ido-completing-read+ "ido-completing-read+" (prompt collection &optional predicate require-match initial-input hist def inherit-input-method)) (declare-function Info-get-token "info" (pos start all &optional errorstring)) (eval-when-compile (require 'vc-git)) (declare-function vc-git--run-command-string "vc-git" (file &rest args)) (defvar magit-wip-before-change-mode) (require 'magit-popup) ;;; Options (defcustom magit-completing-read-function 'magit-builtin-completing-read "Function to be called when requesting input from the user. If you have enabled `ivy-mode' or `helm-mode', then you don't have to customize this option; `magit-builtin-completing-read' will work just fine. However, if you use Ido completion, then you do have to use `magit-ido-completion-read', because Ido is less well behaved than the former, more modern alternatives. If you would like to use Ivy or Helm completion with Magit but not enable the respective modes globally, then customize this option to use `ivy-completing-read' or `helm--completing-read-default'. If you choose to use `ivy-completing-read', note that the items may always be shown in alphabetical order, depending on your version of Ivy." :group 'magit-essentials :type '(radio (function-item magit-builtin-completing-read) (function-item magit-ido-completing-read) (function-item ivy-completing-read) (function-item helm--completing-read-default) (function :tag "Other function"))) (defcustom magit-dwim-selection '((magit-stash-apply nil t) (magit-stash-branch nil t) (magit-stash-branch-here nil t) (magit-stash-format-patch nil t) (magit-stash-drop nil ask) (magit-stash-pop nil ask) (forge-browse-commit nil t) (forge-browse-branch nil t) (forge-browse-remote nil t) (forge-browse-issue nil t) (forge-browse-pullreq nil t) (forge-edit-topic-title nil t) (forge-edit-topic-labels nil t) (forge-edit-topic-assignees nil t) (forge-visit-issue nil t) (forge-visit-pullreq nil t)) "When not to offer alternatives and ask for confirmation. Many commands by default ask the user to select from a list of possible candidates. They do so even when there is a thing at point that they can act on, which is then offered as the default. This option can be used to tell certain commands to use the thing at point instead of asking the user to select a candidate to act on, with or without confirmation. The value has the form ((COMMAND nil|PROMPT DEFAULT)...). - COMMAND is the command that should not prompt for a choice. To have an effect, the command has to use the function `magit-completing-read' or a utility function which in turn uses that function. - If the command uses `magit-completing-read' multiple times, then PROMPT can be used to only affect one of these uses. PROMPT, if non-nil, is a regular expression that is used to match against the PROMPT argument passed to `magit-completing-read'. - DEFAULT specifies how to use the default. If it is t, then the DEFAULT argument passed to `magit-completing-read' is used without confirmation. If it is `ask', then the user is given a chance to abort. DEFAULT can also be nil, in which case the entry has no effect." :package-version '(magit . "2.12.0") :group 'magit-commands :type '(repeat (list (symbol :tag "Command") ; It might not be fboundp yet. (choice (const :tag "for all prompts" nil) (regexp :tag "for prompts matching regexp")) (choice (const :tag "offer other choices" nil) (const :tag "require confirmation" ask) (const :tag "use default without confirmation" t))))) (defconst magit--confirm-actions '((const reverse) (const discard) (const rename) (const resurrect) (const untrack) (const trash) (const delete) (const abort-rebase) (const abort-merge) (const merge-dirty) (const drop-stashes) (const reset-bisect) (const kill-process) (const delete-unmerged-branch) (const delete-pr-branch) (const remove-modules) (const stage-all-changes) (const unstage-all-changes) (const safe-with-wip))) (defcustom magit-no-confirm nil "A list of symbols for actions Magit should not confirm, or t. Many potentially dangerous commands by default ask the user for confirmation. Each of the below symbols stands for an action which, when invoked unintentionally or without being fully aware of the consequences, could lead to tears. In many cases there are several commands that perform variations of a certain action, so we don't use the command names but more generic symbols. Applying changes: `discard' Discarding one or more changes (i.e. hunks or the complete diff for a file) loses that change, obviously. `reverse' Reverting one or more changes can usually be undone by reverting the reversion. `stage-all-changes', `unstage-all-changes' When there are both staged and unstaged changes, then un-/staging everything would destroy that distinction. Of course that also applies when un-/staging a single change, but then less is lost and one does that so often that having to confirm every time would be unacceptable. Files: `delete' When a file that isn't yet tracked by Git is deleted then it is completely lost, not just the last changes. Very dangerous. `trash' Instead of deleting a file it can also be move to the system trash. Obviously much less dangerous than deleting it. Also see option `magit-delete-by-moving-to-trash'. `resurrect' A deleted file can easily be resurrected by \"deleting\" the deletion, which is done using the same command that was used to delete the same file in the first place. `untrack' Untracking a file can be undone by tracking it again. `rename' Renaming a file can easily be undone. Sequences: `reset-bisect' Aborting (known to Git as \"resetting\") a bisect operation loses all information collected so far. `abort-rebase' Aborting a rebase throws away all already modified commits, but it's possible to restore those from the reflog. `abort-merge' Aborting a merge throws away all conflict resolutions which has already been carried out by the user. `merge-dirty' Merging with a dirty worktree can make it hard to go back to the state before the merge was initiated. References: `delete-unmerged-branch' Once a branch has been deleted it can only be restored using low-level recovery tools provided by Git. And even then the reflog is gone. The user always has to confirm the deletion of a branch by accepting the default choice (or selecting another branch), but when a branch has not been merged yet, also make sure the user is aware of that. `delete-pr-branch' When deleting a branch that was created from a pull request and if no other branches still exist on that remote, then `magit-branch-delete' offers to delete the remote as well. This should be safe because it only happens if no other refs exist in the remotes namespace, and you can recreate the remote if necessary. `drop-stashes' Dropping a stash is dangerous because Git stores stashes in the reflog. Once a stash is removed, there is no going back without using low-level recovery tools provided by Git. When a single stash is dropped, then the user always has to confirm by accepting the default (or selecting another). This action only concerns the deletion of multiple stashes at once. Edit published history: Without adding these symbols here, you will be warned before editing commits that have already been pushed to one of the branches listed in `magit-published-branches'. `amend-published' Affects most commands that amend to \"HEAD\". `rebase-published' Affects commands that perform interactive rebases. This includes commands from the commit popup that modify a commit other than \"HEAD\", namely the various fixup and squash variants. `edit-published' Affects the commands `magit-edit-line-commit' and `magit-diff-edit-hunk-commit'. These two commands make it quite easy to accidentally edit a published commit, so you should think twice before configuring them not to ask for confirmation. To disable confirmation completely, add all three symbols here or set `magit-published-branches' to nil. Removing modules: `remove-modules' When you remove the working directory of a module that does not contain uncommitted changes, then that is safer than doing so when there are uncommitted changes and/or when you also remove the gitdir. Still, you don't want to do that by accident. `remove-dirty-modules' When you remove the working directory of a module that contains uncommitted changes, then those changes are gone for good. It is better to go to the module, inspect these changes and only if appropriate discard them manually. `trash-module-gitdirs' When you remove the gitdir of a module, then all unpushed changes are gone for good. It is very easy to forget that you have some unfinished work on an unpublished feature branch or even in a stash. Actually there are some safety precautions in place, that might help you out if you make an unwise choice here, but don't count on it. In case of emergency, stay calm and check the stash and the `trash-directory' for traces of lost work. Various: `kill-process' There seldom is a reason to kill a process. Global settings: Instead of adding all of the above symbols to the value of this option you can also set it to the atom `t', which has the same effect as adding all of the above symbols. Doing that most certainly is a bad idea, especially because other symbols might be added in the future. So even if you don't want to be asked for confirmation for any of these actions, you are still better of adding all of the respective symbols individually. When `magit-wip-before-change-mode' is enabled then these actions can fairly easily be undone: `discard', `reverse', `stage-all-changes', and `unstage-all-changes'. If and only if this mode is enabled, then `safe-with-wip' has the same effect as adding all of these symbols individually." :package-version '(magit . "2.1.0") :group 'magit-essentials :group 'magit-commands :type `(choice (const :tag "Always require confirmation" nil) (const :tag "Never require confirmation" t) (set :tag "Require confirmation except for" ;; `remove-dirty-modules' and ;; `trash-module-gitdirs' intentionally ;; omitted. ,@magit--confirm-actions))) (defcustom magit-slow-confirm '(drop-stashes) "Whether to ask user \"y or n\" or \"yes or no\" questions. When this is nil, then `y-or-n-p' is used when the user has to confirm a potentially destructive action. When this is t, then `yes-or-no-p' is used instead. If this is a list of symbols identifying actions, then `yes-or-no-p' is used for those, `y-or-no-p' for all others. The list of actions is the same as for `magit-no-confirm' (which see)." :package-version '(magit . "2.9.0") :group 'magit-miscellaneous :type `(choice (const :tag "Always ask \"yes or no\" questions" t) (const :tag "Always ask \"y or n\" questions" nil) (set :tag "Ask \"yes or no\" questions only for" ,@magit--confirm-actions))) (defcustom magit-no-message nil "A list of messages Magit should not display. Magit displays most echo area messages using `message', but a few are displayed using `magit-message' instead, which takes the same arguments as the former, FORMAT-STRING and ARGS. `magit-message' forgoes printing a message if any member of this list is a prefix of the respective FORMAT-STRING. If Magit prints a message which causes you grief, then please first investigate whether there is another option which can be used to suppress it. If that is not the case, then ask the Magit maintainers to start using `magit-message' instead of `message' in that case. We are not proactively replacing all uses of `message' with `magit-message', just in case someone *might* find some of these messages useless. Messages which can currently be suppressed using this option are: * \"Turning on magit-auto-revert-mode...\"" :package-version '(magit . "2.8.0") :group 'magit-miscellaneous :type '(repeat string)) (defcustom magit-ellipsis ?… "Character used to abbreviate text. Currently this is used to abbreviate author names in the margin and in process buffers to elide `magit-git-global-arguments'." :package-version '(magit . "2.1.0") :group 'magit-miscellaneous :type 'character) (defcustom magit-update-other-window-delay 0.2 "Delay before automatically updating the other window. When moving around in certain buffers, then certain other buffers, which are being displayed in another window, may optionally be updated to display information about the section at point. When holding down a key to move by more than just one section, then that would update that buffer for each section on the way. To prevent that, updating the revision buffer is delayed, and this option controls for how long. For optimal experience you might have to adjust this delay and/or the keyboard repeat rate and delay of your graphical environment or operating system." :package-version '(magit . "2.3.0") :group 'magit-miscellaneous :type 'number) (defcustom magit-view-git-manual-method 'info "How links to Git documentation are followed from Magit's Info manuals. `info' Follow the link to the node in the `gitman' Info manual as usual. Unfortunately that manual is not installed by default on some platforms, and when it is then the nodes look worse than the actual manpages. `man' View the respective man-page using the `man' package. `woman' View the respective man-page using the `woman' package." :package-version '(magit . "2.9.0") :group 'magit-miscellaneous :type '(choice (const :tag "view info manual" info) (const :tag "view manpage using `man'" man) (const :tag "view manpage using `woman'" woman))) ;;; User Input (defvar helm-completion-in-region-default-sort-fn) (defvar ivy-sort-functions-alist) (defvar magit-completing-read--silent-default nil) (defun magit-completing-read (prompt collection &optional predicate require-match initial-input hist def fallback) "Read a choice in the minibuffer, or use the default choice. This is the function that Magit commands use when they need the user to select a single thing to act on. The arguments have the same meaning as for `completing-read', except for FALLBACK, which is unique to this function and is described below. Instead of asking the user to choose from a list of possible candidates, this function may instead just return the default specified by DEF, with or without requiring user confirmation. Whether that is the case depends on PROMPT, `this-command' and `magit-dwim-selection'. See the documentation of the latter for more information. If it does use the default without the user even having to confirm that, then `magit-completing-read--silent-default' is set to t, otherwise nil. If it does read a value in the minibuffer, then this function acts similarly to `completing-read', except for the following: - If REQUIRE-MATCH is nil and the user exits without a choice, then nil is returned instead of an empty string. - If REQUIRE-MATCH is non-nil and the users exits without a choice, an user-error is raised. - FALLBACK specifies a secondary default that is only used if the primary default DEF is nil. The secondary default is not subject to `magit-dwim-selection' — if DEF is nil but FALLBACK is not, then this function always asks the user to choose a candidate, just as if both defaults were nil. - \": \" is appended to PROMPT. - PROMPT is modified to end with \" (default DEF|FALLBACK): \" provided that DEF or FALLBACK is non-nil, that neither `ivy-mode' nor `helm-mode' is enabled, and that `magit-completing-read-function' is set to its default value of `magit-builtin-completing-read'." (setq magit-completing-read--silent-default nil) (if-let ((dwim (and def (nth 2 (-first (pcase-lambda (`(,cmd ,re ,_)) (and (eq this-command cmd) (or (not re) (string-match-p re prompt)))) magit-dwim-selection))))) (if (eq dwim 'ask) (if (y-or-n-p (format "%s %s? " prompt def)) def (user-error "Abort")) (setq magit-completing-read--silent-default t) def) (unless def (setq def fallback)) (let ((command this-command) (reply (funcall magit-completing-read-function (concat prompt ": ") (if (and def (not (member def collection))) (cons def collection) collection) predicate require-match initial-input hist def))) (setq this-command command) (if (string= reply "") (if require-match (user-error "Nothing selected") nil) reply)))) (defun magit--completion-table (collection) (lambda (string pred action) (if (eq action 'metadata) '(metadata (display-sort-function . identity)) (complete-with-action action collection string pred)))) (defun magit-builtin-completing-read (prompt choices &optional predicate require-match initial-input hist def) "Magit wrapper for standard `completing-read' function." (unless (or (bound-and-true-p helm-mode) (bound-and-true-p ivy-mode)) (setq prompt (magit-prompt-with-default prompt def)) (setq choices (magit--completion-table choices))) (cl-letf (((symbol-function 'completion-pcm--all-completions) #'magit-completion-pcm--all-completions)) (let ((ivy-sort-functions-alist nil)) (completing-read prompt choices predicate require-match initial-input hist def)))) (defun magit-completing-read-multiple (prompt choices &optional sep default hist keymap) "Read multiple items from CHOICES, separated by SEP. Set up the `crm' variables needed to read multiple values with `read-from-minibuffer'. SEP is a regexp matching characters that can separate choices. When SEP is nil, it defaults to `crm-default-separator'. DEFAULT, HIST, and KEYMAP are passed to `read-from-minibuffer'. When KEYMAP is nil, it defaults to `crm-local-completion-map'. Unlike `completing-read-multiple', the return value is not split into a list." (let* ((crm-separator (or sep crm-default-separator)) (crm-completion-table (magit--completion-table choices)) (choose-completion-string-functions '(crm--choose-completion-string)) (minibuffer-completion-table #'crm--collection-fn) (minibuffer-completion-confirm t) (helm-completion-in-region-default-sort-fn nil) (input (cl-letf (((symbol-function 'completion-pcm--all-completions) #'magit-completion-pcm--all-completions)) (read-from-minibuffer (concat prompt (and default (format " (%s)" default)) ": ") nil (or keymap crm-local-completion-map) nil hist default)))) (when (string-equal input "") (or (setq input default) (user-error "Nothing selected"))) input)) (defun magit-completing-read-multiple* (prompt table &optional predicate require-match initial-input hist def inherit-input-method) "Read multiple strings in the minibuffer, with completion. Like `completing-read-multiple' but don't mess with order of TABLE. Also bind `helm-completion-in-region-default-sort-fn' to nil." (unwind-protect (cl-letf (((symbol-function 'completion-pcm--all-completions) #'magit-completion-pcm--all-completions)) (add-hook 'choose-completion-string-functions 'crm--choose-completion-string) (let* ((minibuffer-completion-table #'crm--collection-fn) (minibuffer-completion-predicate predicate) ;; see completing_read in src/minibuf.c (minibuffer-completion-confirm (unless (eq require-match t) require-match)) (crm-completion-table (magit--completion-table table)) (map (if require-match crm-local-must-match-map crm-local-completion-map)) (helm-completion-in-region-default-sort-fn nil) ;; If the user enters empty input, `read-from-minibuffer' ;; returns the empty string, not DEF. (input (read-from-minibuffer prompt initial-input map nil hist def inherit-input-method))) (and def (string-equal input "") (setq input def)) ;; Remove empty strings in the list of read strings. (split-string input crm-separator t))) (remove-hook 'choose-completion-string-functions 'crm--choose-completion-string))) (defun magit-ido-completing-read (prompt choices &optional predicate require-match initial-input hist def) "Ido-based `completing-read' almost-replacement. Unfortunately `ido-completing-read' is not suitable as a drop-in replacement for `completing-read', instead we use `ido-completing-read+' from the third-party package by the same name." (if (require 'ido-completing-read+ nil t) (ido-completing-read+ prompt choices predicate require-match initial-input hist def) (display-warning 'magit "ido-completing-read+ is not installed To use Ido completion with Magit you need to install the third-party `ido-completing-read+' packages. Falling back to built-in `completing-read' for now." :error) (magit-builtin-completing-read prompt choices predicate require-match initial-input hist def))) (defun magit-prompt-with-default (prompt def) (if (and def (> (length prompt) 2) (string-equal ": " (substring prompt -2))) (format "%s (default %s): " (substring prompt 0 -2) def) prompt)) (defvar magit-minibuffer-local-ns-map (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (define-key map "\s" 'magit-whitespace-disallowed) (define-key map "\t" 'magit-whitespace-disallowed) map)) (defun magit-whitespace-disallowed () "Beep to tell the user that whitespace is not allowed." (interactive) (ding) (message "Whitespace isn't allowed here") (setq defining-kbd-macro nil) (force-mode-line-update)) (defun magit-read-string (prompt &optional initial-input history default-value inherit-input-method no-whitespace) "Read a string from the minibuffer, prompting with string PROMPT. This is similar to `read-string', but * empty input is only allowed if DEFAULT-VALUE is non-nil in which case that is returned, * whitespace is not allowed and leading and trailing whitespace is removed automatically if NO-WHITESPACE is non-nil, * \": \" is appended to PROMPT, and * an invalid DEFAULT-VALUE is silently ignored." (when default-value (when (consp default-value) (setq default-value (car default-value))) (unless (stringp default-value) (setq default-value nil))) (let* ((minibuffer-completion-table nil) (val (read-from-minibuffer (magit-prompt-with-default (concat prompt ": ") default-value) initial-input (and no-whitespace magit-minibuffer-local-ns-map) nil history default-value inherit-input-method)) (trim (lambda (regexp string) (save-match-data (if (string-match regexp string) (replace-match "" t t string) string))))) (when (and (string= val "") default-value) (setq val default-value)) (when no-whitespace (setq val (funcall trim "\\`\\(?:[ \t\n\r]+\\)" (funcall trim "\\(?:[ \t\n\r]+\\)\\'" val)))) (cond ((string= val "") (user-error "Need non-empty input")) ((and no-whitespace (string-match-p "[\s\t\n]" val)) (user-error "Input contains whitespace")) (t val)))) (defun magit-read-string-ns (prompt &optional initial-input history default-value inherit-input-method) "Call `magit-read-string' with non-nil NO-WHITESPACE." (magit-read-string prompt initial-input history default-value inherit-input-method t)) (defmacro magit-read-char-case (prompt verbose &rest clauses) (declare (indent 2) (debug (form form &rest (characterp form body)))) `(pcase (read-char-choice (concat ,prompt ,(concat (mapconcat 'cadr clauses ", ") (and verbose ", or [C-g] to abort") " ")) ',(mapcar 'car clauses)) ,@(--map `(,(car it) ,@(cddr it)) clauses))) (defun magit-y-or-n-p (prompt &optional action) "Ask user a \"y or n\" or a \"yes or no\" question using PROMPT. Which kind of question is used depends on whether ACTION is a member of option `magit-slow-confirm'." (if (or (eq magit-slow-confirm t) (and action (member action magit-slow-confirm))) (yes-or-no-p prompt) (y-or-n-p prompt))) (defvar magit--no-confirm-alist '((safe-with-wip magit-wip-before-change-mode discard reverse stage-all-changes unstage-all-changes))) (cl-defun magit-confirm (action &optional prompt prompt-n noabort (items nil sitems)) (declare (indent defun)) (setq prompt-n (format (concat (or prompt-n prompt) "? ") (length items))) (setq prompt (format (concat (or prompt (magit-confirm-make-prompt action)) "? ") (car items))) (or (cond ((and (not (eq action t)) (or (eq magit-no-confirm t) (memq action magit-no-confirm) (cl-member-if (pcase-lambda (`(,key ,var . ,sub)) (and (memq key magit-no-confirm) (memq action sub) (or (not var) (and (boundp var) (symbol-value var))))) magit--no-confirm-alist))) (or (not sitems) items)) ((not sitems) (magit-y-or-n-p prompt action)) ((= (length items) 1) (and (magit-y-or-n-p prompt action) items)) ((> (length items) 1) (and (magit-y-or-n-p (concat (mapconcat #'identity items "\n") "\n\n" prompt-n) action) items))) (if noabort nil (user-error "Abort")))) (defun magit-confirm-files (action files &optional prompt) (when files (unless prompt (setq prompt (magit-confirm-make-prompt action))) (magit-confirm action (concat prompt " %s") (concat prompt " %i files") nil files))) (defun magit-confirm-make-prompt (action) (let ((prompt (symbol-name action))) (replace-regexp-in-string "-" " " (concat (upcase (substring prompt 0 1)) (substring prompt 1))))) (defun magit-read-number-string (prompt &optional default) "Like `read-number' but return value is a string. DEFAULT may be a number or a numeric string." (number-to-string (read-number prompt (if (stringp default) (string-to-number default) default)))) ;;; Debug Utilities ;;;###autoload (defun magit-emacs-Q-command () "Show a shell command that runs an uncustomized Emacs with only Magit loaded. See info node `(magit)Debugging Tools' for more information." (interactive) (let ((cmd (mapconcat #'shell-quote-argument `(,(concat invocation-directory invocation-name) "-Q" "--eval" "(setq debug-on-error t)" ,@(cl-mapcan (lambda (dir) (list "-L" dir)) (delete-dups (cl-mapcan (lambda (lib) (let ((path (locate-library lib))) (cond (path (list (file-name-directory path))) ((not (member lib '("lv" "transient"))) (error "Cannot find mandatory dependency %s" lib))))) '(;; Like `LOAD_PATH' in `default.mk'. "dash" "ghub" "graphql" "lv" "magit-popup" "transient" "treepy" "with-editor" ;; Obviously `magit' itself is needed too. "magit" ;; While this is part of the Magit repository, ;; it is distributed as a separate package. "git-commit" ;; Even though `async' is a dependency of the ;; `magit' package, it is not required here. )))) ;; Avoid Emacs bug#16406 by using full path. "-l" ,(file-name-sans-extension (locate-library "magit"))) " "))) (message "Uncustomized Magit command saved to kill-ring, %s" "please run it in a terminal.") (kill-new cmd))) ;;; Text Utilities (defmacro magit-bind-match-strings (varlist string &rest body) "Bind variables to submatches according to VARLIST then evaluate BODY. Bind the symbols in VARLIST to submatches of the current match data, starting with 1 and incrementing by 1 for each symbol. If the last match was against a string, then that has to be provided as STRING." (declare (indent 2) (debug (listp form body))) (let ((s (cl-gensym "string")) (i 0)) `(let ((,s ,string)) (let ,(save-match-data (--map (list it (list 'match-string (cl-incf i) s)) varlist)) ,@body)))) (defun magit-delete-line () "Delete the rest of the current line." (delete-region (point) (1+ (line-end-position)))) (defun magit-delete-match (&optional num) "Delete text matched by last search. If optional NUM is specified, only delete that subexpression." (delete-region (match-beginning (or num 0)) (match-end (or num 0)))) (defun magit-file-line (file) "Return the first line of FILE as a string." (when (file-regular-p file) (with-temp-buffer (insert-file-contents file) (buffer-substring-no-properties (point-min) (line-end-position))))) (defun magit-file-lines (file &optional keep-empty-lines) "Return a list of strings containing one element per line in FILE. Unless optional argument KEEP-EMPTY-LINES is t, trim all empty lines." (when (file-regular-p file) (with-temp-buffer (insert-file-contents file) (split-string (buffer-string) "\n" (not keep-empty-lines))))) (defun magit-set-header-line-format (string) "Set the header-line using STRING. Propertize STRING with the `magit-header-line' face if no face is present, and pad the left and right sides of STRING equally such that it will align with the text area." (let* ((header-line (concat (propertize " " 'display '(space :align-to 0)) string (propertize " " 'display `(space :width (+ left-fringe left-margin ,@(and (eq (car (window-current-scroll-bars)) 'left) '(scroll-bar))))))) (len (length header-line))) (setq header-line-format (if (text-property-not-all 0 len 'face nil header-line) (let ((face (get-text-property 0 'face string))) (when (and (atom face) (magit-face-property-all face string)) (add-face-text-property 0 1 face nil header-line) (add-face-text-property (1- len) len face nil header-line)) header-line) (propertize header-line 'face 'magit-header-line))))) (defun magit-face-property-all (face string) "Return non-nil if FACE is present in all of STRING." (cl-loop for pos = 0 then (next-single-property-change pos 'face string) unless pos return t for current = (get-text-property pos 'face string) unless (if (consp current) (memq face current) (eq face current)) return nil)) (defun magit--format-spec (format specification) "Like `format-spec' but preserve text properties in SPECIFICATION." (with-temp-buffer (insert format) (goto-char (point-min)) (while (search-forward "%" nil t) (cond ;; Quoted percent sign. ((eq (char-after) ?%) (delete-char 1)) ;; Valid format spec. ((looking-at "\\([-0-9.]*\\)\\([a-zA-Z]\\)") (let* ((num (match-string 1)) (spec (string-to-char (match-string 2))) (val (assq spec specification))) (unless val (error "Invalid format character: `%%%c'" spec)) (setq val (cdr val)) ;; Pad result to desired length. (let ((text (format (concat "%" num "s") val))) ;; Insert first, to preserve text properties. (if (next-property-change 0 (concat " " text)) ;; If the inserted text has properties, then preserve those. (insert text) ;; Otherwise preserve FORMAT's properties, like `format-spec'. (insert-and-inherit text)) ;; Delete the specifier body. (delete-region (+ (match-beginning 0) (length text)) (+ (match-end 0) (length text))) ;; Delete the percent sign. (delete-region (1- (match-beginning 0)) (match-beginning 0))))) ;; Signal an error on bogus format strings. (t (error "Invalid format string")))) (buffer-string))) ;;; Missing from Emacs (defun magit-kill-this-buffer () "Kill the current buffer." (interactive) (kill-buffer (current-buffer))) ;;; Kludges for Emacs Bugs (defun magit-file-accessible-directory-p (filename) "Like `file-accessible-directory-p' but work around an Apple bug. See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21573#17 and https://github.com/magit/magit/issues/2295." (and (file-directory-p filename) (file-accessible-directory-p filename))) (when (version<= "25.1" emacs-version) (with-eval-after-load 'vc-git (defun vc-git-conflicted-files (directory) "Return the list of files with conflicts in DIRECTORY." (let* ((status (vc-git--run-command-string directory "diff-files" "--name-status")) (lines (when status (split-string status "\n" 'omit-nulls))) files) (dolist (line lines files) (when (string-match "\\([ MADRCU?!]\\)[ \t]+\\(.+\\)" line) (let ((state (match-string 1 line)) (file (match-string 2 line))) (when (equal state "U") (push (expand-file-name file directory) files))))))))) (when (< emacs-major-version 27) (defun vc-git--call@bug21559 (fn buffer command &rest args) "Backport https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559." (let ((process-environment process-environment)) (when revert-buffer-in-progress-p (push "GIT_OPTIONAL_LOCKS=0" process-environment)) (apply fn buffer command args))) (advice-add 'vc-git--call :around 'vc-git--call@bug21559) (defun vc-git-command@bug21559 (fn buffer okstatus file-or-list &rest flags) "Backport https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559." (let ((process-environment process-environment)) (when revert-buffer-in-progress-p (push "GIT_OPTIONAL_LOCKS=0" process-environment)) (apply fn buffer okstatus file-or-list flags))) (advice-add 'vc-git-command :around 'vc-git-command@bug21559) (defun auto-revert-handler@bug21559 (fn) "Backport https://debbugs.gnu.org/cgi/bugreport.cgi?bug=21559." (let ((revert-buffer-in-progress-p t)) (funcall fn))) (advice-add 'auto-revert-handler :around 'auto-revert-handler@bug21559) ) ;; `completion-pcm--all-completions' reverses the completion list. To ;; preserve the order of our pre-sorted completions, we'll temporarily ;; override it with the function below. bug#24676 (defun magit-completion-pcm--all-completions (prefix pattern table pred) (if (completion-pcm--pattern-trivial-p pattern) (all-completions (concat prefix (car pattern)) table pred) (let* ((regex (completion-pcm--pattern->regex pattern)) (case-fold-search completion-ignore-case) (completion-regexp-list (cons regex completion-regexp-list)) (compl (all-completions (concat prefix (if (stringp (car pattern)) (car pattern) "")) table pred))) (if (not (functionp table)) compl (let ((poss ())) (dolist (c compl) (when (string-match-p regex c) (push c poss))) ;; This `nreverse' call is the only code change made to the ;; `completion-pcm--all-completions' that shipped with Emacs 25.1. (nreverse poss)))))) ;;; Kludges for Incompatible Modes (defvar whitespace-mode) (defun whitespace-dont-turn-on-in-magit-mode (fn) "Prevent `whitespace-mode' from being turned on in Magit buffers. Because `whitespace-mode' uses font-lock and Magit does not, they are not compatible. Therefore you cannot turn on that minor-mode in Magit buffers. If you try to enable it anyway, then this advice prevents that. If the reason the attempt is made is that `global-whitespace-mode' is enabled, then that is done silently. However if you call the local minor-mode interactively, then that results in an error. See `magit-diff-paint-whitespace' for an alternative." (if (not (derived-mode-p 'magit-mode)) (funcall fn) (setq whitespace-mode nil) (when (eq this-command 'whitespace-mode) (user-error "Whitespace mode NOT enabled because it is not compatible with Magit")))) (advice-add 'whitespace-turn-on :around 'whitespace-dont-turn-on-in-magit-mode) ;;; Kludges for Custom (defun magit-custom-initialize-reset (symbol exp) "Initialize SYMBOL based on EXP. Set the symbol, using `set-default' (unlike `custom-initialize-reset' which uses the `:set' function if any.) The value is either the symbol's current value (as obtained using the `:get' function), if any, or the value in the symbol's `saved-value' property if any, or (last of all) the value of EXP." (set-default-toplevel-value symbol (condition-case nil (let ((def (default-toplevel-value symbol)) (getter (get symbol 'custom-get))) (if getter (funcall getter symbol) def)) (error (eval (let ((sv (get symbol 'saved-value))) (if sv (car sv) exp))))))) (defun magit-hook-custom-get (symbol) (if (symbol-file symbol 'defvar) (default-toplevel-value symbol) ;; ;; Called by `custom-initialize-reset' on behalf of `symbol's ;; `defcustom', which is being evaluated for the first time to ;; set the initial value, but there's already a default value, ;; which most likely was established by one or more `add-hook' ;; calls. ;; ;; We combine the `standard-value' and the current value, while ;; preserving the order established by `:options', and return ;; the result of that to be used as the "initial" default value. ;; (let ((standard (eval (car (get symbol 'standard-value)))) (current (default-toplevel-value symbol)) (value nil)) (dolist (fn (get symbol 'custom-options)) (when (or (memq fn standard) (memq fn current)) (push fn value))) (dolist (fn current) (unless (memq fn value) (push fn value))) (nreverse value)))) ;;; Kludges for Info Manuals ;;;###autoload (defun Info-follow-nearest-node--magit-gitman (fn &optional fork) (if magit-view-git-manual-method (let ((node (Info-get-token (point) "\\*note[ \n\t]+" "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))) (if (and node (string-match "^(gitman)\\(.+\\)" node)) (pcase magit-view-git-manual-method (`man (require 'man) (man (match-string 1 node))) (`woman (require 'woman) (woman (match-string 1 node))) (_ (user-error "Invalid value for `magit-view-git-documentation'"))) (funcall fn fork))) (funcall fn fork))) ;;;###autoload (advice-add 'Info-follow-nearest-node :around 'Info-follow-nearest-node--magit-gitman) ;;;###autoload (defun org-man-export--magit-gitman (fn link description format) (if (and (eq format 'texinfo) (string-match-p "\\`git" link)) (replace-regexp-in-string "%s" link " @ifinfo @ref{%s,,,gitman,}. @end ifinfo @ifhtml @html the %s(1) manpage. @end html @end ifhtml @iftex the %s(1) manpage. @end iftex ") (funcall fn link description format))) ;;;###autoload (advice-add 'org-man-export :around 'org-man-export--magit-gitman) ;;; Miscellaneous (defun magit-message (format-string &rest args) "Display a message at the bottom of the screen, or not. Like `message', except that if the users configured option `magit-no-message' to prevent the message corresponding to FORMAT-STRING to be displayed, then don't." (unless (--first (string-prefix-p it format-string) magit-no-message) (apply #'message format-string args))) (defun magit-msg (format-string &rest args) "Display a message at the bottom of the screen, but don't log it. Like `message', except that `message-log-max' is bound to nil." (let ((message-log-max nil)) (apply #'message format-string args))) ;;; _ (provide 'magit-utils) ;;; magit-utils.el ends here magit-2.90.1/lisp/magit-wip.el000066400000000000000000000400251337354740400161060ustar00rootroot00000000000000;;; magit-wip.el --- commit snapshots to work-in-progress refs -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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 \"index/\" and \"wtree/\". 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-git-log (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-git-log (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-git-log (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 magit-2.90.1/lisp/magit-worktree.el000066400000000000000000000165611337354740400171610ustar00rootroot00000000000000;;; magit-worktree.el --- worktree support -*- lexical-binding: t -*- ;; Copyright (C) 2010-2018 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 ;; Maintainer: Jonas Bernoulli ;; 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) ;;; Commands ;;;###autoload (autoload 'magit-worktree-popup "magit-worktree" nil t) (magit-define-popup magit-worktree-popup "Popup console for worktree commands." :man-page "git-worktree" :actions `((?b "Create new worktree" magit-worktree-checkout) (?c "Create new branch and worktree" magit-worktree-branch) ,@(and (not (require (quote forge) nil t)) '((?p "Create new worktree from pull-request" magit-worktree-checkout-pull-request))) (?k "Delete worktree" magit-worktree-delete) (?g "Show status for worktree" magit-worktree-status)) :max-action-columns 1) ;;;###autoload (defun magit-worktree-checkout (path branch) "Checkout BRANCH in a new worktree at PATH." (interactive (let ((branch (magit-read-local-branch-or-commit "Checkout"))) (list (read-directory-name (format "Checkout %s in new worktree: " branch)) branch))) (magit-run-git "worktree" "add" (expand-file-name path) branch) (magit-diff-visit-directory path)) (defun magit-worktree-checkout-pull-request (path pr) "Create, configure and checkout a new worktree from a pull-request. This is like `magit-checkout-pull-request', except that it also creates a new worktree. Please see the manual for more information." (interactive (let ((pr (magit-read-pull-request "Checkout pull request"))) (let-alist pr (let ((path (let ((branch (magit--pullreq-branch pr t))) (read-directory-name (format "Checkout #%s as `%s' in new worktree: " .number branch) (file-name-directory (directory-file-name default-directory)) nil nil (if (string-match-p "\\`pr-[0-9]+\\'" branch) (number-to-string .number) (format "%s-%s" .number .head.ref)))))) (when (equal path "") (user-error "The empty string isn't a valid path")) (list path pr))))) (when (and (file-exists-p path) (not (and (file-directory-p path) (= (length (directory-files "/tmp/testing/")) 2)))) (user-error "%s already exists and isn't empty" path)) (magit-worktree-checkout path (let ((inhibit-magit-refresh t)) (magit-branch-pull-request pr)))) ;;;###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 `(,(read-directory-name "Create worktree: ") ,@(butlast (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)) (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-internal 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 'face 'magit-branch-local)) (commit (propertize (magit-rev-abbrev commit) '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 magit-2.90.1/lisp/magit.el000066400000000000000000000577731337354740400153330ustar00rootroot00000000000000;;; magit.el --- A Git porcelain inside Emacs -*- lexical-binding: t; coding: utf-8 -*- ;; Copyright (C) 2008-2018 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 ;; Maintainer: Jonas Bernoulli ;; Kyle Meyer ;; Noam Postavsky ;; Former-Maintainers: ;; Nicolas Dudebout ;; Peter J. Weisberg ;; Phil Jackson ;; Rémi Vanicat ;; Yann Hodique ;; Keywords: git tools vc ;; Homepage: https://github.com/magit/magit ;; Magit requires at least GNU Emacs 25.1 and Git 2.0.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) (eval-when-compile (require 'subr-x)) (require 'with-editor) (require 'git-commit) (require 'magit-core) (require 'magit-diff) (require 'magit-apply) (require 'magit-log) (require 'magit-repos) (require 'format-spec) (require 'package nil t) ; used in `magit-version' (defconst magit--minimal-git "2.0.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-popup "magit" nil t) (magit-define-popup magit-dispatch-popup "Popup console for dispatching other popups." :actions '("Popup and dwim commands" (?A "Cherry-picking" magit-cherry-pick-popup) (?b "Branching" magit-branch-popup) (?B "Bisecting" magit-bisect-popup) (?c "Committing" magit-commit-popup) (?d "Diffing" magit-diff-popup) (?D "Change diffs" magit-diff-refresh-popup) (?e "Ediff dwimming" magit-ediff-dwim) (?E "Ediffing" magit-ediff-popup) (?f "Fetching" magit-fetch-popup) (?F "Pulling" magit-pull-popup) (?l "Logging" magit-log-popup) (?L "Change logs" magit-log-refresh-popup) (?m "Merging" magit-merge-popup) (?M "Remoting" magit-remote-popup) (?o "Submodules" magit-submodule-popup) (?O "Subtrees" magit-subtree-popup) (?P "Pushing" magit-push-popup) (?r "Rebasing" magit-rebase-popup) (?t "Tagging" magit-tag-popup) (?T "Notes" magit-notes-popup) (?V "Reverting" magit-revert-popup) (?w "Apply patches" magit-am-popup) (?W "Format patches" magit-patch-popup) (?X "Resetting" magit-reset-popup) (?y "Show Refs" magit-show-refs-popup) (?z "Stashing" magit-stash-popup) (?! "Running" magit-run-popup) (?% "Worktree" magit-worktree-popup) (lambda () (and (with-current-buffer magit-pre-popup-buffer (derived-mode-p 'magit-mode)) (propertize "Applying changes" 'face 'magit-popup-heading))) (?a "Apply" magit-apply) (?s "Stage" magit-stage) (?u "Unstage" magit-unstage) (?v "Reverse" magit-reverse) (?S "Stage all" magit-stage-modified) (?U "Unstage all" magit-unstage-all) (?k "Discard" magit-discard) (lambda () (and (with-current-buffer magit-pre-popup-buffer (derived-mode-p 'magit-mode)) (propertize "Essential commands" 'face 'magit-popup-heading))) (?g " refresh current buffer" magit-refresh) ;; These bindings only work because of :setup-function. (?\t " toggle section at point" magit-section-toggle) (?\r " visit thing at point" magit-visit-thing) ;; This binding has no effect and only appears to do ;; so because it is identical to the global binding. ("C-h m" "show all key bindings" describe-mode)) :setup-function 'magit-dispatch-popup-setup :max-action-columns (lambda (heading) (pcase heading ("Popup and dwim commands" 4) ("Applying changes" 3) ("Essential commands" 1)))) (defvar magit-dispatch-popup-map (let ((map (make-sparse-keymap))) (set-keymap-parent map magit-popup-mode-map) (cond ((featurep 'jkl) (define-key map [tab] 'magit-invoke-popup-action) (define-key map [return] 'magit-invoke-popup-action)) (t (define-key map (kbd "C-i") 'magit-invoke-popup-action) (define-key map (kbd "C-m") 'magit-invoke-popup-action))) map) "Keymap used by `magit-dispatch-popup'.") (defun magit-dispatch-popup-setup (val def) (magit-popup-default-setup val def) (use-local-map magit-dispatch-popup-map) ;; This is necessary for users (i.e. me) who have broken the ;; connection between C-i (aka TAB) and tab, and C-m (aka RET) ;; and return. (magit-popup-put :actions (nconc (magit-popup-get :actions) (list (make-magit-popup-event :key 'tab :fun 'magit-section-toggle) (make-magit-popup-event :key 'return :fun 'magit-visit-thing))))) ;;; 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-popup "magit" nil t) (magit-define-popup magit-run-popup "Popup console for running raw Git commands." :actions '((?! "Git Subcommand (in topdir)" magit-git-command-topdir) (?k "Gitk" magit-run-gitk) (?p "Git Subcommand (in pwd)" magit-git-command) (?a "Gitk --all" magit-run-gitk-all) (?s "Shell command (in topdir)" magit-shell-command-topdir) (?b "Gitk --branches" magit-run-gitk-branches) (?S "Shell command (in pwd)" magit-shell-command) (?g "Git Gui" magit-run-git-gui)) :default-action 'magit-git-command :max-action-columns 2) ;;;###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-collab) (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-subtree) (require 'magit-ediff) (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 magit-2.90.1/t/000077500000000000000000000000001337354740400131615ustar00rootroot00000000000000magit-2.90.1/t/magit-tests.el000066400000000000000000000315401337354740400157470ustar00rootroot00000000000000;;; magit-tests.el --- tests for Magit ;; Copyright (C) 2011-2018 The Magit Project Contributors ;; ;; License: GPLv3 ;;; Code: (require 'cl-lib) (require 'dash) (require 'ert) (require 'tramp) (require 'tramp-sh) (require 'magit) (defmacro magit-with-test-directory (&rest body) (declare (indent 0) (debug t)) (let ((dir (make-symbol "dir"))) `(let ((,dir (file-name-as-directory (make-temp-file "magit-" t))) (process-environment process-environment)) (push "GIT_AUTHOR_NAME=A U Thor" process-environment) (push "GIT_AUTHOR_EMAIL=a.u.thor@example.com" process-environment) (condition-case err (cl-letf (((symbol-function #'message) (lambda (&rest _)))) (let ((default-directory ,dir)) ,@body)) (error (message "Keeping test directory:\n %s" ,dir) (signal (car err) (cdr err)))) (delete-directory ,dir t)))) (defmacro magit-with-test-repository (&rest body) (declare (indent 0) (debug t)) `(magit-with-test-directory (magit-git "init" ".") ,@body)) ;;; Git (ert-deftest magit--with-safe-default-directory () (magit-with-test-directory (let ((find-file-visit-truename nil)) (should (equal (magit-toplevel "repo/") (magit-toplevel (expand-file-name "repo/")))) (should (equal (magit-toplevel "repo") (magit-toplevel (expand-file-name "repo/"))))))) (ert-deftest magit-toplevel:basic () (let ((find-file-visit-truename nil)) (magit-with-test-directory (magit-git "init" "repo") (magit-test-magit-toplevel) (should (equal (magit-toplevel "repo/.git/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo/.git/objects/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo-link/.git/") (expand-file-name "repo-link/"))) (should (equal (magit-toplevel "repo-link/.git/objects/") ;; We could theoretically return "repo-link/" ;; here by going up until `--git-dir' gives us ;; "." . But that would be a bit risky and Magit ;; never goes there anyway, so it's not worth it. ;; But in the doc-string we say we cannot do it. (expand-file-name "repo/")))))) (ert-deftest magit-toplevel:tramp () (cl-letf* ((find-file-visit-truename nil) ;; Override tramp method so that we don't actually ;; require a functioning `sudo'. (sudo-method (cdr (assoc "sudo" tramp-methods))) ((cdr (assq 'tramp-login-program sudo-method)) (list shell-file-name)) ((cdr (assq 'tramp-login-args sudo-method)) nil)) (magit-with-test-directory (setq default-directory (concat (format "/sudo:%s@localhost:" (user-login-name)) default-directory)) (magit-git "init" "repo") (magit-test-magit-toplevel) (should (equal (magit-toplevel "repo/.git/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo/.git/objects/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo-link/.git/") (expand-file-name "repo-link/"))) (should (equal (magit-toplevel "repo-link/.git/objects/") (expand-file-name "repo/")))))) (ert-deftest magit-toplevel:submodule () (let ((find-file-visit-truename nil)) (magit-with-test-directory (magit-git "init" "remote") (let ((default-directory (expand-file-name "remote/"))) (magit-git "commit" "-m" "init" "--allow-empty")) (magit-git "init" "super") (setq default-directory (expand-file-name "super/")) (magit-git "submodule" "add" "../remote" "repo/") (magit-test-magit-toplevel) (should (equal (magit-toplevel ".git/modules/repo/") (expand-file-name "repo/"))) (should (equal (magit-toplevel ".git/modules/repo/objects/") (expand-file-name "repo/")))))) (defun magit-test-magit-toplevel () ;; repo (make-directory "repo/subdir/subsubdir" t) (should (equal (magit-toplevel "repo/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo/subdir/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "repo/subdir/subsubdir/") (expand-file-name "repo/"))) ;; repo-link (make-symbolic-link "repo" "repo-link") (should (equal (magit-toplevel "repo-link/") (expand-file-name "repo-link/"))) (should (equal (magit-toplevel "repo-link/subdir/") (expand-file-name "repo-link/"))) (should (equal (magit-toplevel "repo-link/subdir/subsubdir/") (expand-file-name "repo-link/"))) ;; *subdir-link (make-symbolic-link "repo/subdir" "subdir-link") (make-symbolic-link "repo/subdir/subsubdir" "subsubdir-link") (should (equal (magit-toplevel "subdir-link/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "subdir-link/subsubdir/") (expand-file-name "repo/"))) (should (equal (magit-toplevel "subsubdir-link") (expand-file-name "repo/"))) ;; subdir-link-indirect (make-symbolic-link "subdir-link" "subdir-link-indirect") (should (equal (magit-toplevel "subdir-link-indirect") (expand-file-name "repo/"))) ;; wrap/*link (magit-git "init" "wrap") (make-symbolic-link "../repo" "wrap/repo-link") (make-symbolic-link "../repo/subdir" "wrap/subdir-link") (make-symbolic-link "../repo/subdir/subsubdir" "wrap/subsubdir-link") (should (equal (magit-toplevel "wrap/repo-link/") (expand-file-name "wrap/repo-link/"))) (should (equal (magit-toplevel "wrap/subdir-link") (expand-file-name "repo/"))) (should (equal (magit-toplevel "wrap/subsubdir-link") (expand-file-name "repo/")))) (defun magit-test-magit-get () (should (equal (magit-get-all "a.b") '("val1" "val2"))) (should (equal (magit-get "a.b") "val2")) (let ((default-directory (expand-file-name "../remote/"))) (should (equal (magit-get "a.b") "remote-value"))) (should (equal (magit-get "CAM.El.Case.VAR") "value")) (should (equal (magit-get "a.b2") "line1\nline2"))) (ert-deftest magit-get () (magit-with-test-directory (magit-git "init" "remote") (let ((default-directory (expand-file-name "remote/"))) (magit-git "commit" "-m" "init" "--allow-empty") (magit-git "config" "a.b" "remote-value")) (magit-git "init" "super") (setq default-directory (expand-file-name "super/")) ;; Some tricky cases: ;; Multiple config values. (magit-git "config" "a.b" "val1") (magit-git "config" "--add" "a.b" "val2") ;; CamelCase variable names. (magit-git "config" "Cam.El.Case.Var" "value") ;; Values with newlines. (magit-git "config" "a.b2" "line1\nline2") ;; Config variables in submodules. (magit-git "submodule" "add" "../remote" "repo/") (magit-test-magit-get) (let ((magit--refresh-cache (list (cons 0 0)))) (magit-test-magit-get)))) (ert-deftest magit-get-boolean () (magit-with-test-repository (magit-git "config" "a.b" "true") (should (magit-get-boolean "a.b")) (should (magit-get-boolean "a" "b")) (magit-git "config" "a.b" "false") (should-not (magit-get-boolean "a.b")) (should-not (magit-get-boolean "a" "b")) ;; Multiple values, last one wins. (magit-git "config" "--add" "a.b" "true") (should (magit-get-boolean "a.b")) (let ((magit--refresh-cache (list (cons 0 0)))) (should (magit-get-boolean "a.b"))))) (ert-deftest magit-get-{current|next}-tag () (magit-with-test-repository (magit-git "commit" "-m" "1" "--allow-empty") (should (equal (magit-get-current-tag) nil)) (should (equal (magit-get-next-tag) nil)) (magit-git "tag" "1") (should (equal (magit-get-current-tag) "1")) (should (equal (magit-get-next-tag) nil)) (magit-git "commit" "-m" "2" "--allow-empty") (magit-git "tag" "2") (should (equal (magit-get-current-tag) "2")) (should (equal (magit-get-next-tag) nil)) (magit-git "commit" "-m" "3" "--allow-empty") (should (equal (magit-get-current-tag) "2")) (should (equal (magit-get-next-tag) nil)) (magit-git "commit" "-m" "4" "--allow-empty") (magit-git "tag" "4") (magit-git "reset" "HEAD~") (should (equal (magit-get-current-tag) "2")) (should (equal (magit-get-next-tag) "4")))) (ert-deftest magit-list-{|local-|remote-}branch-names () (magit-with-test-repository (magit-git "commit" "-m" "init" "--allow-empty") (magit-git "update-ref" "refs/remotes/foobar/master" "master") (magit-git "update-ref" "refs/remotes/origin/master" "master") (should (equal (magit-list-branch-names) (list "master" "foobar/master" "origin/master"))) (should (equal (magit-list-local-branch-names) (list "master"))) (should (equal (magit-list-remote-branch-names) (list "foobar/master" "origin/master"))) (should (equal (magit-list-remote-branch-names "origin") (list "origin/master"))) (should (equal (magit-list-remote-branch-names "origin" t) (list "master"))))) (ert-deftest magit-process:match-prompt-nil-when-no-match () (should (null (magit-process-match-prompt '("^foo: ?$") "bar: ")))) (ert-deftest magit-process:match-prompt-non-nil-when-match () (should (magit-process-match-prompt '("^foo: ?$") "foo: "))) (ert-deftest magit-process:match-prompt-match-non-first-prompt () (should (magit-process-match-prompt '("^bar: ?$ " "^foo: ?$") "foo: "))) (ert-deftest magit-process:match-prompt-suffixes-prompt () (let ((prompts '("^foo: ?$"))) (should (equal (magit-process-match-prompt prompts "foo:") "foo: ")) (should (equal (magit-process-match-prompt prompts "foo: ") "foo: ")))) (ert-deftest magit-process:match-prompt-preserves-match-group () (let* ((prompts '("^foo '\\(?99:.*\\)': ?$")) (prompt (magit-process-match-prompt prompts "foo 'bar':"))) (should (equal prompt "foo 'bar': ")) (should (equal (match-string 99 "foo 'bar':") "bar")))) (ert-deftest magit-process:password-prompt () (let ((magit-process-find-password-functions (list (lambda (host) (when (string= host "www.host.com") "mypasswd"))))) (cl-letf (((symbol-function 'process-send-string) (lambda (process string) string))) (should (string-equal (magit-process-password-prompt nil "Password for 'www.host.com':") "mypasswd\n"))))) ;;; Status (defun magit-test-get-section (list file) (magit-status-internal default-directory) (--first (equal (oref it value) file) (oref (magit-get-section `(,list (status))) children))) (ert-deftest magit-status:file-sections () (magit-with-test-repository (cl-flet ((modify (file) (with-temp-file file (insert (make-temp-name "content"))))) (modify "file") (modify "file with space") (modify "file with äöüéλ") (should (magit-test-get-section '(untracked) "file")) (should (magit-test-get-section '(untracked) "file with space")) (should (magit-test-get-section '(untracked) "file with äöüéλ")) (magit-stage-modified t) (should (magit-test-get-section '(staged) "file")) (should (magit-test-get-section '(staged) "file with space")) (should (magit-test-get-section '(staged) "file with äöüéλ")) (magit-git "add" ".") (modify "file") (modify "file with space") (modify "file with äöüéλ") (should (magit-test-get-section '(unstaged) "file")) (should (magit-test-get-section '(unstaged) "file with space")) (should (magit-test-get-section '(unstaged) "file with äöüéλ"))))) (ert-deftest magit-status:log-sections () (magit-with-test-repository (magit-git "commit" "-m" "common" "--allow-empty") (magit-git "commit" "-m" "unpulled" "--allow-empty") (magit-git "remote" "add" "origin" "/origin") (magit-git "update-ref" "refs/remotes/origin/master" "master") (magit-git "branch" "--set-upstream-to=origin/master") (magit-git "reset" "--hard" "HEAD~") (magit-git "commit" "-m" "unpushed" "--allow-empty") (should (magit-test-get-section '(unpulled . "..@{upstream}") (magit-rev-parse "--short" "origin/master"))) (should (magit-test-get-section '(unpushed . "@{upstream}..") (magit-rev-parse "--short" "master"))))) ;;; magit-tests.el ends soon (provide 'magit-tests) ;; Local Variables: ;; indent-tabs-mode: nil ;; End: ;;; magit-tests.el ends here