You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Status.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (C) 2011, 2013 Christian Halstrick <christian.halstrick@sap.com>
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.api;
  44. import java.util.Collections;
  45. import java.util.Map;
  46. import java.util.Set;
  47. import org.eclipse.jgit.lib.IndexDiff;
  48. import org.eclipse.jgit.lib.IndexDiff.StageState;
  49. /**
  50. * A class telling where the working-tree, the index and the current HEAD differ
  51. * from each other. Collections are exposed containing the paths of the modified
  52. * files. E.g. to find out which files are dirty in the working tree (modified
  53. * but not added) you would inspect the collection returned by
  54. * {@link #getModified()}.
  55. * <p>
  56. * The same path can be returned by multiple getters. E.g. if a modification has
  57. * been added to the index and afterwards the corresponding working tree file is
  58. * again modified this path will be returned by {@link #getModified()} and
  59. * {@link #getChanged()}
  60. */
  61. public class Status {
  62. private final IndexDiff diff;
  63. private final boolean clean;
  64. /**
  65. * @param diff
  66. */
  67. public Status(IndexDiff diff) {
  68. super();
  69. this.diff = diff;
  70. clean = diff.getAdded().isEmpty() //
  71. && diff.getChanged().isEmpty() //
  72. && diff.getRemoved().isEmpty() //
  73. && diff.getMissing().isEmpty() //
  74. && diff.getModified().isEmpty() //
  75. && diff.getUntracked().isEmpty() //
  76. && diff.getConflicting().isEmpty();
  77. }
  78. /**
  79. * @return true if no differences exist between the working-tree, the index,
  80. * and the current HEAD, false if differences do exist
  81. */
  82. public boolean isClean() {
  83. return clean;
  84. }
  85. /**
  86. * @return list of files added to the index, not in HEAD (e.g. what you get
  87. * if you call 'git add ...' on a newly created file)
  88. */
  89. public Set<String> getAdded() {
  90. return Collections.unmodifiableSet(diff.getAdded());
  91. }
  92. /**
  93. * @return list of files changed from HEAD to index (e.g. what you get if
  94. * you modify an existing file and call 'git add ...' on it)
  95. */
  96. public Set<String> getChanged() {
  97. return Collections.unmodifiableSet(diff.getChanged());
  98. }
  99. /**
  100. * @return list of files removed from index, but in HEAD (e.g. what you get
  101. * if you call 'git rm ...' on a existing file)
  102. */
  103. public Set<String> getRemoved() {
  104. return Collections.unmodifiableSet(diff.getRemoved());
  105. }
  106. /**
  107. * @return list of files in index, but not filesystem (e.g. what you get if
  108. * you call 'rm ...' on a existing file)
  109. */
  110. public Set<String> getMissing() {
  111. return Collections.unmodifiableSet(diff.getMissing());
  112. }
  113. /**
  114. * @return list of files modified on disk relative to the index (e.g. what
  115. * you get if you modify an existing file without adding it to the
  116. * index)
  117. */
  118. public Set<String> getModified() {
  119. return Collections.unmodifiableSet(diff.getModified());
  120. }
  121. /**
  122. * @return list of files that are not ignored, and not in the index. (e.g.
  123. * what you get if you create a new file without adding it to the
  124. * index)
  125. */
  126. public Set<String> getUntracked() {
  127. return Collections.unmodifiableSet(diff.getUntracked());
  128. }
  129. /**
  130. * @return set of directories that are not ignored, and not in the index.
  131. */
  132. public Set<String> getUntrackedFolders() {
  133. return Collections.unmodifiableSet(diff.getUntrackedFolders());
  134. }
  135. /**
  136. * @return list of files that are in conflict. (e.g what you get if you
  137. * modify file that was modified by someone else in the meantime)
  138. */
  139. public Set<String> getConflicting() {
  140. return Collections.unmodifiableSet(diff.getConflicting());
  141. }
  142. /**
  143. * @return a map from conflicting path to its {@link StageState}.
  144. * @since 3.0
  145. */
  146. public Map<String, StageState> getConflictingStageState() {
  147. return Collections.unmodifiableMap(diff.getConflictingStageStates());
  148. }
  149. /**
  150. * @return set of files and folders that are ignored and not in the index.
  151. */
  152. public Set<String> getIgnoredNotInIndex() {
  153. return Collections.unmodifiableSet(diff.getIgnoredNotInIndex());
  154. }
  155. }